Skip to content

Commit

Permalink
fix focus for windows within a floating frame
Browse files Browse the repository at this point in the history
Make the `focus` method shift focus to a floating frame. Also, shift
focus away from the floating frame when `focus` is used in an window
within the current main frame.
  • Loading branch information
mflatt committed Mar 28, 2016
1 parent 9fdc917 commit 30c8202
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 3 additions & 1 deletion gui-doc/scribblings/gui/window-intf.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ If @racket[enable?] is true, the window is enabled, otherwise it is
@index['("keyboard focus" "setting")]{Moves} the keyboard focus to the
window, relative to its top-level window, if the window ever accepts
the keyboard focus. If the focus is in the window's top-level
window, then the focus is immediately moved to this
window or if the window's top-level window is visible and floating
(i.e., created with the @racket['float] style), then the focus is
immediately moved to this
window. Otherwise, the focus is not immediately moved, but when the
window's top-level window gets the keyboard focus, the focus is
delegated to this window.
Expand Down
11 changes: 10 additions & 1 deletion gui-lib/mred/private/wx/cocoa/window.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,16 @@
(is-enabled-to-root?))
(let ([w (tell cocoa window)])
(when w
(tellv w makeFirstResponder: (get-cocoa-focus))))))
(tellv w makeFirstResponder: (get-cocoa-focus))
;; Within a floating frame or when potentially taking
;; focus from a floating frame, also make the frame the
;; key window:
(let ([top (get-wx-window)])
(when (and (or (send top floating?)
(tell #:type _BOOL w isMainWindow))
(tell #:type _bool w isVisible))
(tellv w makeKeyAndOrderFront: #f)))))))

(define/public (on-set-focus) (void))
(define/public (on-kill-focus) (void))

Expand Down
10 changes: 9 additions & 1 deletion gui-lib/mred/private/wx/gtk/window.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,15 @@
(send parent in-floating?))

(define/public (set-focus)
(gtk_widget_grab_focus (get-client-gtk)))
(define gtk (get-client-gtk))
(gtk_widget_grab_focus gtk)
;; Force focus to or away from a floating window:
(cond
[(and (in-floating?)
(is-shown-to-root?))
(gdk_keyboard_grab (widget-window gtk) #t 0)]
[else
(gdk_keyboard_ungrab 0)]))

(define cursor-handle #f)
(define/public (set-cursor v)
Expand Down
11 changes: 10 additions & 1 deletion gui-lib/mred/private/wx/win32/frame.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,18 @@
(set! focus-window-path #f)))
(define/override (set-top-focus win win-path child-hwnd)
(set! focus-window-path (cons this win-path))
(when (ptr-equal? hwnd (GetActiveWindow))
(define active-hwnd (GetActiveWindow))
(when (or (ptr-equal? hwnd active-hwnd)
(and (or float-without-caption?
(let ([wx (any-hwnd->wx active-hwnd)])
(and wx
(send wx is-floating?))))
(is-shown?)))
(void (SetFocus child-hwnd))))

(define/public (is-floating?)
float-without-caption?)

(define/private (set-frame-focus)
(let ([p focus-window-path])
(when (pair? p)
Expand Down

0 comments on commit 30c8202

Please sign in to comment.