Skip to content

Commit

Permalink
Mac: make sure a wake-up event helper is defined before use
Browse files Browse the repository at this point in the history
  • Loading branch information
mflatt committed Sep 23, 2024
1 parent 619bcd4 commit d8ee912
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions gui-lib/mred/private/wx/cocoa/queue.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@

(define app (tell NSApplication sharedApplication))

;; ------------------------------------------------------------
;; Create an event to post when Racket has been sleeping but is
;; ready to wake up

(import-class NSEvent)
(define wake-evt
(tell NSEvent
otherEventWithType: #:type _NSUInteger NSApplicationDefined
location: #:type _NSPoint (make-NSPoint 0.0 0.0)
modifierFlags: #:type _NSUInteger 0
timestamp: #:type _double 0.0
windowNumber: #:type _NSUInteger 0
context: #:type _pointer #f
subtype: #:type _short 0
data1: #:type _NSInteger 0
data2: #:type _NSInteger 0))
(retain wake-evt)
(define (post-dummy-event)
(tell #:type _void app postEvent: wake-evt atStart: #:type _BOOL YES))

;; This callback will be invoked by the CoreFoundation run loop
;; when data is available on `ready_sock', which is used to indicate
;; that Racket would like to wake up (and posting a Cocoa event
;; causes the event-getting function to unblock).
(define (socket_callback)
(read2 ready_sock read-buf 1)
(post-dummy-event))

;; ------------------------------------------------------------

(define got-file? #f)

(define-objc-class RacketApplicationDelegate NSObject ;; note: NSApplicationDelegate doesn't exist at run time
Expand Down Expand Up @@ -223,34 +253,6 @@
reason: #:type _NSString "Racket default")
retain))

;; ------------------------------------------------------------
;; Create an event to post when Racket has been sleeping but is
;; ready to wake up

(import-class NSEvent)
(define wake-evt
(tell NSEvent
otherEventWithType: #:type _NSUInteger NSApplicationDefined
location: #:type _NSPoint (make-NSPoint 0.0 0.0)
modifierFlags: #:type _NSUInteger 0
timestamp: #:type _double 0.0
windowNumber: #:type _NSUInteger 0
context: #:type _pointer #f
subtype: #:type _short 0
data1: #:type _NSInteger 0
data2: #:type _NSInteger 0))
(retain wake-evt)
(define (post-dummy-event)
(tell #:type _void app postEvent: wake-evt atStart: #:type _BOOL YES))

;; This callback will be invoked by the CoreFoundation run loop
;; when data is available on `ready_sock', which is used to indicate
;; that Racket would like to wake up (and posting a Cocoa event
;; causes the event-getting function to unblock).
(define (socket_callback)
(read2 ready_sock read-buf 1)
(post-dummy-event))

;; ------------------------------------------------------------
;; Create a pipe's pair of file descriptors, used to communicate
;; from the Racket-sleep thread to the CoreFoundation run loop.
Expand Down

0 comments on commit d8ee912

Please sign in to comment.