Skip to content

Commit 2d322fc

Browse files
committed
Mac OS: handle menu keys when no windows are open
An original assumption about a hidden fake root window was broken in some Mac OS vesion after Catalina and before Sequoia. Finally add a hook to redirect key events to the fake root frame when they're not received by another other window.
1 parent 363ccec commit 2d322fc

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

gui-lib/mred/private/wx/cocoa/const.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
(define NSOtherMouseDown 25)
4040
(define NSOtherMouseUp 26)
4141
(define NSOtherMouseDragged 27)
42+
(define NSEventTypeKeyDown 10)
4243
(define NSEventTypeGesture 29)
4344
(define NSEventTypeMagnify 30)
4445
(define NSEventTypeSwipe 31)

gui-lib/mred/private/wx/cocoa/frame.rkt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,14 @@
863863
(when f
864864
(send f fixup-locations-children))))))
865865

866+
(set-post-key-callback-hook!
867+
(lambda (evt)
868+
(key-event-received #f)
869+
(and root-fake-frame
870+
(lambda (evt)
871+
(unless (key-event-received)
872+
(tellv (send root-fake-frame get-cocoa) keyDown: evt))))))
873+
866874
;; ----------------------------------------
867875
;; As of Mac OS 10.14, NSWindow-specific flushing control is no longer
868876
;; supported. It seems to have been removed as a way of simplifying the

gui-lib/mred/private/wx/cocoa/queue.rkt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
set-front-hook!
2525
set-menu-bar-hooks!
2626
set-mouse-or-key-hook!
27+
set-post-key-callback-hook!
2728
set-fixup-window-locations!
2829
post-dummy-event
2930

@@ -426,6 +427,9 @@
426427
(define front-hook (lambda () (values #f #f)))
427428
(define (set-front-hook! proc) (set! front-hook proc))
428429

430+
(define get-post-key-callback (lambda () #f))
431+
(define (set-post-key-callback-hook! proc) (set! get-post-key-callback proc))
432+
429433
(define in-menu-bar-range? (lambda (p flipped?) #f))
430434
(define (set-menu-bar-hooks! r?)
431435
(set! in-menu-bar-range? r?))
@@ -525,8 +529,14 @@
525529
(lambda ()
526530
;; in atomic mode
527531
(with-autorelease
528-
(tellv app sendEvent: evt)
529-
(release evt))))
532+
(define post-key
533+
(and (not w)
534+
(= NSEventTypeKeyDown (tell #:type _NSUInteger evt type))
535+
(not (tell app keyWindow))
536+
(get-post-key-callback evt)))
537+
(tellv app sendEvent: evt)
538+
(when post-key (post-key evt))
539+
(release evt))))
530540
(when mouse-or-key?
531541
(set! avoid-mouse-key-until #f)))))
532542
(tellv app sendEvent: evt)))

gui-lib/mred/private/wx/cocoa/window.rkt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
KeyMouseTextResponder
2727
CursorDisplayer
2828

29+
key-event-received
30+
2931
queue-window-event
3032
queue-window-refresh-event
3133
queue-window*-event
@@ -302,6 +304,7 @@
302304
(let ([inserted-text (box #f)]
303305
[set-mark (box #f)]
304306
[had-saved-text? (and (send wx get-saved-marked) #t)])
307+
(key-event-received #t)
305308
(when down?
306309
;; Calling `interpretKeyEvents:' allows key combinations to be
307310
;; handled, such as option-e followed by e to produce é. The
@@ -1111,6 +1114,14 @@
11111114

11121115
;; ----------------------------------------
11131116

1117+
(define key-event-received? #f)
1118+
(define key-event-received
1119+
(case-lambda
1120+
[() key-event-received?]
1121+
[(received?) (set! key-event-received? received?)]))
1122+
1123+
;; ----------------------------------------
1124+
11141125
(define (queue-window-event wx thunk)
11151126
(queue-event (send wx get-eventspace) thunk))
11161127

0 commit comments

Comments
 (0)