get-diplay-size' and
get-display-left-top-inset' use #f for failure
Since the number of monitors can change at any time, reliable use of these functions requires handling failure in some way. Handling #f results is easier (and less likely to mask other problems) than catching exceptions.
This commit is contained in:
parent
69832d9925
commit
ce4705cedc
|
@ -89,7 +89,7 @@
|
||||||
|
|
||||||
(define (check-for-break) #f)
|
(define (check-for-break) #f)
|
||||||
|
|
||||||
(define (display-origin xb yb all? num)
|
(define (display-origin xb yb all? num fail)
|
||||||
(if (or all? (positive? num))
|
(if (or all? (positive? num))
|
||||||
(unless (atomically
|
(unless (atomically
|
||||||
(with-autorelease
|
(with-autorelease
|
||||||
|
@ -108,13 +108,13 @@
|
||||||
(NSSize-height (NSRect-size f0)))))))
|
(NSSize-height (NSRect-size f0)))))))
|
||||||
#t)
|
#t)
|
||||||
#f))))
|
#f))))
|
||||||
(error 'get-display-left-top-inset "no such monitor: ~v" num))
|
(fail))
|
||||||
(set-box! xb 0))
|
(set-box! xb 0))
|
||||||
(when (zero? num)
|
(when (zero? num)
|
||||||
(set-box! yb 0))
|
(set-box! yb 0))
|
||||||
(set-box! yb (+ (unbox yb) (get-menu-bar-height))))
|
(set-box! yb (+ (unbox yb) (get-menu-bar-height))))
|
||||||
|
|
||||||
(define (display-size xb yb all? num)
|
(define (display-size xb yb all? num fail)
|
||||||
(unless (atomically
|
(unless (atomically
|
||||||
(with-autorelease
|
(with-autorelease
|
||||||
(let ([screens (tell NSScreen screens)])
|
(let ([screens (tell NSScreen screens)])
|
||||||
|
@ -134,7 +134,7 @@
|
||||||
(get-menu-bar-height)]))))
|
(get-menu-bar-height)]))))
|
||||||
#t)
|
#t)
|
||||||
#f))))
|
#f))))
|
||||||
(error 'get-display-size "no such monitor: ~v" num)))
|
(fail)))
|
||||||
|
|
||||||
|
|
||||||
(define (display-count)
|
(define (display-count)
|
||||||
|
|
|
@ -265,7 +265,7 @@
|
||||||
(send p get-size sw-box sh-box)
|
(send p get-size sw-box sh-box)
|
||||||
(set-box! sx-box (send p get-x))
|
(set-box! sx-box (send p get-x))
|
||||||
(set-box! sy-box (send p get-y)))
|
(set-box! sy-box (send p get-y)))
|
||||||
(display-size sw-box sh-box #t 0)))
|
(display-size sw-box sh-box #t 0 void)))
|
||||||
(let* ([sw (unbox sw-box)]
|
(let* ([sw (unbox sw-box)]
|
||||||
[sh (unbox sh-box)]
|
[sh (unbox sh-box)]
|
||||||
[fw (unbox w-box)]
|
[fw (unbox w-box)]
|
||||||
|
@ -497,21 +497,21 @@
|
||||||
(define-gdk gdk_screen_get_monitor_geometry (_fun _GdkScreen _int _GdkRectangle-pointer -> _void))
|
(define-gdk gdk_screen_get_monitor_geometry (_fun _GdkScreen _int _GdkRectangle-pointer -> _void))
|
||||||
(define-gdk gdk_screen_get_n_monitors (_fun _GdkScreen -> _int))
|
(define-gdk gdk_screen_get_n_monitors (_fun _GdkScreen -> _int))
|
||||||
|
|
||||||
(define (monitor-rect who num)
|
(define (monitor-rect num fail)
|
||||||
(let ([s (gdk_screen_get_default)]
|
(let ([s (gdk_screen_get_default)]
|
||||||
[r (make-GdkRectangle 0 0 0 0)])
|
[r (make-GdkRectangle 0 0 0 0)])
|
||||||
(unless (num . < . (gdk_screen_get_n_monitors s))
|
(unless (num . < . (gdk_screen_get_n_monitors s))
|
||||||
(error who "no such monitor: ~v" num))
|
(fail))
|
||||||
(gdk_screen_get_monitor_geometry s num r)
|
(gdk_screen_get_monitor_geometry s num r)
|
||||||
r))
|
r))
|
||||||
|
|
||||||
(define (display-origin x y all? num)
|
(define (display-origin x y all? num fail)
|
||||||
(let ([r (monitor-rect 'get-display-left-top-inset num)])
|
(let ([r (monitor-rect num fail)])
|
||||||
(set-box! x (- (GdkRectangle-x r)))
|
(set-box! x (- (GdkRectangle-x r)))
|
||||||
(set-box! y (- (GdkRectangle-y r)))))
|
(set-box! y (- (GdkRectangle-y r)))))
|
||||||
|
|
||||||
(define (display-size w h all? num)
|
(define (display-size w h all? num fail)
|
||||||
(let ([r (monitor-rect 'get-display-size num)])
|
(let ([r (monitor-rect num fail)])
|
||||||
(set-box! w (GdkRectangle-width r))
|
(set-box! w (GdkRectangle-width r))
|
||||||
(set-box! h (GdkRectangle-height r))))
|
(set-box! h (GdkRectangle-height r))))
|
||||||
|
|
||||||
|
|
|
@ -78,12 +78,12 @@
|
||||||
#f)
|
#f)
|
||||||
(reverse rects)))
|
(reverse rects)))
|
||||||
|
|
||||||
(define (display-size xb yb all? num)
|
(define (display-size xb yb all? num fail)
|
||||||
(cond
|
(cond
|
||||||
[(positive? num)
|
[(positive? num)
|
||||||
(let ([rs (get-all-screen-rects)])
|
(let ([rs (get-all-screen-rects)])
|
||||||
(unless (num . < . (length rs))
|
(unless (num . < . (length rs))
|
||||||
(error 'get-display-size "no such monitor: ~v" num))
|
(fail))
|
||||||
(let ([r (list-ref rs num)])
|
(let ([r (list-ref rs num)])
|
||||||
(set-box! xb (- (caddr r) (car r)))
|
(set-box! xb (- (caddr r) (car r)))
|
||||||
(set-box! yb (- (cadddr r) (cadr r)))))]
|
(set-box! yb (- (cadddr r) (cadr r)))))]
|
||||||
|
@ -99,12 +99,12 @@
|
||||||
(set-box! xb (- (RECT-right r) (RECT-left r)))
|
(set-box! xb (- (RECT-right r) (RECT-left r)))
|
||||||
(set-box! yb (- (RECT-bottom r) (RECT-top r))))]))
|
(set-box! yb (- (RECT-bottom r) (RECT-top r))))]))
|
||||||
|
|
||||||
(define (display-origin xb yb avoid-bars? num)
|
(define (display-origin xb yb avoid-bars? num fail)
|
||||||
(cond
|
(cond
|
||||||
[(positive? num)
|
[(positive? num)
|
||||||
(let ([rs (get-all-screen-rects)])
|
(let ([rs (get-all-screen-rects)])
|
||||||
(unless (num . < . (length rs))
|
(unless (num . < . (length rs))
|
||||||
(error 'get-display-left-top-inset "no such monitor: ~v" num))
|
(fail))
|
||||||
(let ([r (list-ref rs num)])
|
(let ([r (list-ref rs num)])
|
||||||
(set-box! xb (- (car r)))
|
(set-box! xb (- (car r)))
|
||||||
(set-box! yb (- (cadr r)))))]
|
(set-box! yb (- (cadr r)))))]
|
||||||
|
@ -435,7 +435,7 @@
|
||||||
[wh (box 0)]
|
[wh (box 0)]
|
||||||
[wx (box 0)]
|
[wx (box 0)]
|
||||||
[wy (box 0)])
|
[wy (box 0)])
|
||||||
(display-size sw sh #f 0)
|
(display-size sw sh #f 0 void)
|
||||||
(if wrt
|
(if wrt
|
||||||
(begin
|
(begin
|
||||||
(send wrt get-size ww wh)
|
(send wrt get-size ww wh)
|
||||||
|
|
|
@ -35,19 +35,22 @@
|
||||||
(lambda ([full-screen? #f] #:monitor [monitor 0])
|
(lambda ([full-screen? #f] #:monitor [monitor 0])
|
||||||
(unless (exact-nonnegative-integer? monitor)
|
(unless (exact-nonnegative-integer? monitor)
|
||||||
(raise-type-error 'get-display-size "exact non-negative integer" monitor))
|
(raise-type-error 'get-display-size "exact non-negative integer" monitor))
|
||||||
|
(let/ec esc
|
||||||
(let ([xb (box 0)]
|
(let ([xb (box 0)]
|
||||||
[yb (box 0)])
|
[yb (box 0)])
|
||||||
(wx:display-size xb yb full-screen? monitor)
|
(wx:display-size xb yb full-screen? monitor
|
||||||
(values (unbox xb) (unbox yb)))))
|
(lambda () (esc #f #f)))
|
||||||
|
(values (unbox xb) (unbox yb))))))
|
||||||
|
|
||||||
(define get-display-left-top-inset
|
(define get-display-left-top-inset
|
||||||
(lambda ([advisory? #f] #:monitor [monitor 0])
|
(lambda ([advisory? #f] #:monitor [monitor 0])
|
||||||
(unless (exact-nonnegative-integer? monitor)
|
(unless (exact-nonnegative-integer? monitor)
|
||||||
(raise-type-error 'get-display-left-top-inset "exact non-negative integer" monitor))
|
(raise-type-error 'get-display-left-top-inset "exact non-negative integer" monitor))
|
||||||
|
(let/ec esc
|
||||||
(let ([xb (box 0)]
|
(let ([xb (box 0)]
|
||||||
[yb (box 0)])
|
[yb (box 0)])
|
||||||
(wx:display-origin xb yb advisory? monitor)
|
(wx:display-origin xb yb advisory? monitor (lambda () (esc #f #f)))
|
||||||
(values (unbox xb) (unbox yb)))))
|
(values (unbox xb) (unbox yb))))))
|
||||||
|
|
||||||
(define get-display-count
|
(define get-display-count
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
|
|
@ -29,7 +29,8 @@ Returns the depth of the main display (a value of 1 denotes a monochrome display
|
||||||
|
|
||||||
@defproc[(get-display-left-top-inset [avoid-bars? any/c #f]
|
@defproc[(get-display-left-top-inset [avoid-bars? any/c #f]
|
||||||
[#:monitor monitor exact-nonnegative-integer? 0])
|
[#:monitor monitor exact-nonnegative-integer? 0])
|
||||||
(values exact-nonnegative-integer? exact-nonnegative-integer?)]{
|
(values (or/c exact-nonnegative-integer? #f)
|
||||||
|
(or/c exact-nonnegative-integer? #f))]{
|
||||||
|
|
||||||
When the optional argument is @racket[#f] (the default), this function
|
When the optional argument is @racket[#f] (the default), this function
|
||||||
returns the offset of @racket[monitor]'s origin from the
|
returns the offset of @racket[monitor]'s origin from the
|
||||||
|
@ -46,13 +47,15 @@ When the optional @racket[avoid-bars?] argument is true, for @racket[monitor]
|
||||||
monitor @racket[0], the result is always @racket[0] and @racket[0].
|
monitor @racket[0], the result is always @racket[0] and @racket[0].
|
||||||
For monitors other than @racket[0], @racket[avoid-bars?] has no effect.
|
For monitors other than @racket[0], @racket[avoid-bars?] has no effect.
|
||||||
|
|
||||||
If @racket[monitor] is not less than the current number of available monitors, the
|
If @racket[monitor] is not less than the current number of available
|
||||||
@racket[exn:fail] exception is raised.}
|
monitors (which can change at any time), the results are @racket[#f]
|
||||||
|
and @racket[#f].}
|
||||||
|
|
||||||
|
|
||||||
@defproc[(get-display-size [full-screen? any/c #f]
|
@defproc[(get-display-size [full-screen? any/c #f]
|
||||||
[#:monitor monitor exact-nonnegative-integer? 0])
|
[#:monitor monitor exact-nonnegative-integer? 0])
|
||||||
(values exact-nonnegative-integer? exact-nonnegative-integer?)]{
|
(values (or/c exact-nonnegative-integer? #f)
|
||||||
|
(or/c exact-nonnegative-integer? #f))]{
|
||||||
|
|
||||||
@index["screen resolution"]{Gets} the physical size of the specified @racket[monitor] in
|
@index["screen resolution"]{Gets} the physical size of the specified @racket[monitor] in
|
||||||
pixels. On Windows, this size does not include the task bar by
|
pixels. On Windows, this size does not include the task bar by
|
||||||
|
@ -62,8 +65,9 @@ If @racket[monitor] is not less than the current number of available monitors, t
|
||||||
On Windows and Mac OS X, if the optional argument is true and @racket[monitor] is @racket[0], then
|
On Windows and Mac OS X, if the optional argument is true and @racket[monitor] is @racket[0], then
|
||||||
the task bar, menu bar, and dock area are included in the result.
|
the task bar, menu bar, and dock area are included in the result.
|
||||||
|
|
||||||
If @racket[monitor] is not less than the current number of available monitors, the
|
If @racket[monitor] is not less than the current number of available
|
||||||
@racket[exn:fail] exception is raised.}
|
monitors (which can change at any time), the results are @racket[#f]
|
||||||
|
and @racket[#f].}
|
||||||
|
|
||||||
|
|
||||||
@defproc[(is-color-display?)
|
@defproc[(is-color-display?)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user