add display-changed method

This commit is contained in:
Robby Findler 2012-12-21 10:25:11 -06:00
parent 7ff6fd93ef
commit 3f9e60a908
8 changed files with 104 additions and 18 deletions

View File

@ -35,7 +35,8 @@
get-focus-window get-edit-target-window get-focus-window get-edit-target-window
get-focus-object get-edit-target-object get-focus-object get-edit-target-object
center move resize center move resize
on-message)) on-message
display-changed))
(define-local-member-name (define-local-member-name
do-create-status-line do-create-status-line
@ -76,7 +77,8 @@
[get-eventspace (entry-point (lambda () (send wx get-eventspace)))]) [get-eventspace (entry-point (lambda () (send wx get-eventspace)))])
(pubment* (pubment*
[can-close? (lambda () (inner #t can-close?))] [can-close? (lambda () (inner #t can-close?))]
[on-close (lambda () (inner (void) on-close))]) [on-close (lambda () (inner (void) on-close))]
[display-changed (λ () (inner (void) display-changed))])
(public* (public*
[can-exit? (lambda () (can-close?))] [can-exit? (lambda () (can-close?))]
[on-exit (lambda () (on-close) (show #f))] [on-exit (lambda () (on-close) (show #f))]

View File

@ -41,6 +41,19 @@
;; problems. ;; problems.
(define all-windows (make-hash)) (define all-windows (make-hash))
;; called in atomic mode
(define (send-screen-change-notifications flags)
(when (zero? (bitwise-and flags 1)) ;; discard the "about to change" notifications
(for ([b (in-hash-values all-windows)])
(define f (weak-box-value b))
(when f
(parameterize ([current-eventspace (send f get-eventspace)])
(queue-callback
(λ ()
(send f display-changed))))))))
(set-screen-changed-callback! send-screen-change-notifications)
(define-objc-mixin (RacketWindowMethods Superclass) (define-objc-mixin (RacketWindowMethods Superclass)
[wxb] [wxb]
[-a _scheme (getEventspace) [-a _scheme (getEventspace)
@ -627,7 +640,9 @@
(define/public (set-color-callback cb) (define/public (set-color-callback cb)
(set! color-callback cb)) (set! color-callback cb))
(define/override (on-color-change) (define/override (on-color-change)
(queue-window-event this (lambda () (color-callback)))))) (queue-window-event this (lambda () (color-callback))))
(define/public (display-changed) (void))))
;; ---------------------------------------- ;; ----------------------------------------

View File

@ -23,7 +23,8 @@
post-dummy-event post-dummy-event
try-to-sync-refresh try-to-sync-refresh
sync-cocoa-events) sync-cocoa-events
set-screen-changed-callback!)
;; from common/queue: ;; from common/queue:
current-eventspace current-eventspace
@ -127,8 +128,12 @@
;; is called, but sometimes the event loop gets stuck after ;; is called, but sometimes the event loop gets stuck after
;; that, so there's an additional hack above. ;; that, so there's an additional hack above.
(define-appserv CGDisplayRegisterReconfigurationCallback (define-appserv CGDisplayRegisterReconfigurationCallback
(_fun (_fun #:atomic? #t -> _void) _pointer -> _int32)) (_fun (_fun #:atomic? #t _uint32 _uint32 -> _void) _pointer -> _int32))
(define (on-screen-changed) (post-dummy-event)) (define (on-screen-changed display flags)
(screen-changed-callback flags)
(post-dummy-event))
(define screen-changed-callback void)
(define (set-screen-changed-callback! c) (set! screen-changed-callback c))
(let ([v (CGDisplayRegisterReconfigurationCallback on-screen-changed #f)]) (let ([v (CGDisplayRegisterReconfigurationCallback on-screen-changed #f)])
(unless (zero? v) (unless (zero? v)
(log-error (format "error from CGDisplayRegisterReconfigurationCallback: ~a" v)))) (log-error (format "error from CGDisplayRegisterReconfigurationCallback: ~a" v))))

View File

@ -511,7 +511,9 @@
(set! saved-title s) (set! saved-title s)
(gtk_window_set_title gtk (if is-modified? (gtk_window_set_title gtk (if is-modified?
(string-append s "*") (string-append s "*")
s))))) s)))
(define/public (display-changed) (void))))
;; ---------------------------------------- ;; ----------------------------------------
@ -572,3 +574,35 @@
(maybe GDK_CONTROL_MASK 'control) (maybe GDK_CONTROL_MASK 'control)
(maybe GDK_MOD1_MASK 'alt) (maybe GDK_MOD1_MASK 'alt)
(maybe GDK_META_MASK 'meta)))) (maybe GDK_META_MASK 'meta))))
(define (tell-all-frames-signal-changed n)
(define frames (for/list ([f (in-hash-keys all-frames)]) f))
(for ([f (in-hash-keys all-frames)])
(parameterize ([current-eventspace (send f get-eventspace)])
(queue-callback
(λ ()
(send f display-changed))))))
(define-signal-handler
connect-monitor-changed-signal
"monitors-changed"
(_fun _GdkScreen -> _void)
(λ (screen) (tell-all-frames-signal-changed 1)))
(define-signal-handler
connect-screen-changed-signal
"screen-changed"
(_fun _GdkScreen -> _void)
(λ (screen) (tell-all-frames-signal-changed 2)))
(define-signal-handler
connect-composited-changed-signal
"composited-changed"
(_fun _GdkScreen -> _void)
(λ (screen) (tell-all-frames-signal-changed 3)))
(define (screen-size-signal-connect connect-signal)
(void (connect-signal (cast (gdk_screen_get_default) _GdkScreen _GtkWidget))))
(screen-size-signal-connect connect-monitor-changed-signal)
(screen-size-signal-connect connect-screen-changed-signal)
(screen-size-signal-connect connect-composited-changed-signal)

View File

@ -359,7 +359,12 @@
(or min-height (or min-height
(POINT-y (MINMAXINFO-ptMinTrackSize mmi))))))) (POINT-y (MINMAXINFO-ptMinTrackSize mmi)))))))
0] 0]
[else (super wndproc w msg wParam lParam default)])) [(= msg WM_DISPLAYCHANGE)
(parameterize ([current-eventspace (get-eventspace)])
(queue-callback (lambda () (display-changed))))
0]
[else
(super wndproc w msg wParam lParam default)]))
(define/override (try-nc-mouse w msg wParam lParam) (define/override (try-nc-mouse w msg wParam lParam)
#f) #f)
@ -665,4 +670,7 @@
(DefWindowProcW hwnd WM_SYSCHAR (char->integer c) (arithmetic-shift 1 29))) (DefWindowProcW hwnd WM_SYSCHAR (char->integer c) (arithmetic-shift 1 29)))
(define/public (system-menu) (define/public (system-menu)
(popup-menu-with-char #\space))) (popup-menu-with-char #\space))
(define/public (display-changed) (void)))

View File

@ -64,7 +64,6 @@
(define top-x init-top-x) (define top-x init-top-x)
(define top-y init-top-y) (define top-y init-top-y)
(define top-level-windows (make-weak-hasheq))
;; make-top-container%: adds the necessary functionality to wx:frame% and ;; make-top-container%: adds the necessary functionality to wx:frame% and
;; wx:dialog%. ;; wx:dialog%.
@ -362,9 +361,6 @@
(lambda (on? do-show) (lambda (on? do-show)
(when on? (when on?
(position-for-initial-show)) (position-for-initial-show))
(if on?
(hash-set! top-level-windows this #t)
(hash-remove! top-level-windows this))
(as-exit ; as-exit because there's an implicit wx:yield for dialogs (as-exit ; as-exit because there's an implicit wx:yield for dialogs
do-show))]) do-show))])
@ -645,7 +641,10 @@
(lambda () (send (get-mred) on-activate on?))) (lambda () (send (get-mred) on-activate on?)))
(as-exit (as-exit
(lambda () (lambda ()
(super on-activate on?)))))]) (super on-activate on?)))))]
[display-changed
(λ ()
(send (get-mred) display-changed))])
(public* (public*
[is-act-on? (lambda () act-on?)] [is-act-on? (lambda () act-on?)]
[add-activate-update (lambda (win) (set! activate-refresh-wins [add-activate-update (lambda (win) (set! activate-refresh-wins

View File

@ -15,8 +15,11 @@ other actions depend on updating the display.}
@defproc[(get-display-count) exact-positive-integer?]{ @defproc[(get-display-count) exact-positive-integer?]{
Returns the number of monitors currently active. On Windows and Mac OS X, Returns the number of monitors currently active.
the result can change at any time.
On Windows and Mac OS X, the result can change at any time.
See also @xmethod[top-level-window<%> display-changed].
} }
@ -49,7 +52,8 @@ When the optional @racket[avoid-bars?] argument is true, for @racket[monitor]
If @racket[monitor] is not less than the current number of available If @racket[monitor] is not less than the current number of available
monitors (which can change at any time), the results are @racket[#f] monitors (which can change at any time), the results are @racket[#f]
and @racket[#f].} and @racket[#f]. See also @xmethod[top-level-window<%> display-changed].
}
@defproc[(get-display-size [full-screen? any/c #f] @defproc[(get-display-size [full-screen? any/c #f]
@ -67,7 +71,8 @@ On Windows and Mac OS X, if the optional argument is true and @racket[monitor] i
If @racket[monitor] is not less than the current number of available If @racket[monitor] is not less than the current number of available
monitors (which can change at any time), the results are @racket[#f] monitors (which can change at any time), the results are @racket[#f]
and @racket[#f].} and @racket[#f]. See also @xmethod[top-level-window<%> display-changed].
}
@defproc[(is-color-display?) @defproc[(is-color-display?)

View File

@ -192,6 +192,24 @@ Returns @|void-const|.
}} }}
@defmethod[(display-changed) any/c]{
@methspec{
Called when the displays configuration changes.
To determine the new monitor configuration, use
@racket[get-display-count], @racket[get-display-size], and
@racket[get-display-left-top-inset].
Note that this method may be invoked multiple times for a single
logical change to the monitors.
}
@methimpl{
Returns @|void-const|.
}
}
@defmethod[(on-traverse-char [event (is-a?/c key-event%)]) @defmethod[(on-traverse-char [event (is-a?/c key-event%)])
boolean?]{ boolean?]{