cocoa: convince dock to not resurrect a closed frame

This commit is contained in:
Matthew Flatt 2010-10-29 15:10:54 -06:00
parent 4e8f51741e
commit 50caefcb38
2 changed files with 25 additions and 11 deletions

View File

@ -47,7 +47,7 @@
(let ([wx (->wx wxb)]) (let ([wx (->wx wxb)])
(and wx (and wx
(not (other-modal? wx))))] (not (other-modal? wx))))]
[-a _BOOL (canBecomeMainWindow) #t] [-a _BOOL (canBecomeMainWindow) #t]
[-a _BOOL (windowShouldClose: [_id win]) [-a _BOOL (windowShouldClose: [_id win])
(queue-window*-event wxb (lambda (wx) (queue-window*-event wxb (lambda (wx)
(unless (other-modal? wx) (unless (other-modal? wx)
@ -73,15 +73,19 @@
(queue-window*-event wxb (lambda (wx) (queue-window*-event wxb (lambda (wx)
(send wx on-size 0 0))))] (send wx on-size 0 0))))]
[-a _void (windowDidBecomeMain: [_id notification]) [-a _void (windowDidBecomeMain: [_id notification])
(when wxb ;; We check whether the window is visible because
(let ([wx (->wx wxb)]) ;; clicking the dock item tries to resurrect a hidden
(when wx ;; frame. See also `setOneShot' below.
(set! front wx) (when (tell #:type _BOOL self isVisible)
(send wx install-wait-cursor) (when wxb
(send wx install-mb) (let ([wx (->wx wxb)])
(send wx notify-responder #t) (when wx
(queue-window-event wx (lambda () (set! front wx)
(send wx on-activate #t))))))] (send wx install-wait-cursor)
(send wx install-mb)
(send wx notify-responder #t)
(queue-window-event wx (lambda ()
(send wx on-activate #t)))))))]
[-a _void (windowDidResignMain: [_id notification]) [-a _void (windowDidResignMain: [_id notification])
(when wxb (when wxb
(let ([wx (->wx wxb)]) (let ([wx (->wx wxb)])
@ -89,7 +93,9 @@
(when (eq? front wx) (when (eq? front wx)
(set! front #f) (set! front #f)
(send wx uninstall-wait-cursor)) (send wx uninstall-wait-cursor))
(send empty-mb install) (if root-fake-frame
(send root-fake-frame install-mb)
(send empty-mb install))
(send wx notify-responder #f) (send wx notify-responder #f)
(queue-window-event wx (lambda () (queue-window-event wx (lambda ()
(send wx on-activate #f))))))] (send wx on-activate #f))))))]
@ -185,6 +191,10 @@
(tellv cocoa setAcceptsMouseMovedEvents: #:type _BOOL #t) (tellv cocoa setAcceptsMouseMovedEvents: #:type _BOOL #t)
;; Setting the window in one-shot mode helps prevent the
;; frame from being resurrected by a click on the dock icon.
(tellv cocoa setOneShot: #:type _BOOL #t)
(define/override (get-cocoa-content) (define/override (get-cocoa-content)
(tell cocoa contentView)) (tell cocoa contentView))
(define/override (get-cocoa-window) cocoa) (define/override (get-cocoa-window) cocoa)

View File

@ -48,6 +48,10 @@
(super-tell #:type _BOOL validateMenuItem: menuItem))] (super-tell #:type _BOOL validateMenuItem: menuItem))]
[-a _BOOL (application: [_id theApplication] openFile: [_NSString filename]) [-a _BOOL (application: [_id theApplication] openFile: [_NSString filename])
(queue-file-event (string->path filename))] (queue-file-event (string->path filename))]
[-a _BOOL (applicationShouldHandleReopen: [_id app] hasVisibleWindows: [_BOOL has-visible?])
;; If we have any visible windows, return #t to do the default thing.
;; Otherwise return #f, because we don't want any invisible windows resurrected.
has-visible?]
[-a _void (applicationDidChangeScreenParameters: notification) [-a _void (applicationDidChangeScreenParameters: notification)
;; Screen changes sometimes make the event loop get stuck; ;; Screen changes sometimes make the event loop get stuck;
;; hack: schedule a wake-up call in 5 seconds ;; hack: schedule a wake-up call in 5 seconds