mirror of
https://github.com/stumpwm/stumpwm.git
synced 2026-09-10 07:26:20 -04:00
Added functions IN-MAIN-THREAD-P and PUSH-EVENT
This commit is contained in:
parent
bcf76afaa0
commit
61e53b4c06
|
|
@ -20,9 +20,7 @@
|
|||
(defpackage :stumpwm
|
||||
(:use :cl
|
||||
#:alexandria)
|
||||
(:shadow #:yes-or-no-p #:y-or-n-p)
|
||||
(:export
|
||||
#:call-in-main-thread))
|
||||
(:shadow #:yes-or-no-p #:y-or-n-p))
|
||||
|
||||
(defpackage :stumpwm-user
|
||||
(:use :cl :stumpwm))
|
||||
|
|
|
|||
31
stumpwm.lisp
31
stumpwm.lisp
|
|
@ -26,7 +26,10 @@
|
|||
run-with-timer
|
||||
*toplevel-io*
|
||||
stumpwm
|
||||
timer-p))
|
||||
timer-p
|
||||
call-in-main-thread
|
||||
in-main-thread-p
|
||||
push-event))
|
||||
|
||||
|
||||
;;; Main
|
||||
|
|
@ -236,19 +239,25 @@ The action is to call FUNCTION with arguments ARGS."
|
|||
(dolist (event (reverse events))
|
||||
(funcall event))))
|
||||
|
||||
(defun in-main-thread-p ()
|
||||
*in-main-thread*)
|
||||
|
||||
(defun push-event (fn)
|
||||
(sb-thread:with-mutex ((request-channel-lock *request-channel*))
|
||||
(push fn (request-channel-queue *request-channel*)))
|
||||
(let ((out (request-channel-out *request-channel*)))
|
||||
;; For now, just write a single byte since all we want is for the
|
||||
;; main thread to process the queue. If we want to handle
|
||||
;; different types of events, we'll have to change this so that
|
||||
;; the message sent indicates the event type instead.
|
||||
(write-byte 0 out)
|
||||
(finish-output out)))
|
||||
|
||||
(defun call-in-main-thread (fn)
|
||||
(cond (*in-main-thread*
|
||||
(cond ((in-main-thread-p)
|
||||
(funcall fn))
|
||||
(t
|
||||
(sb-thread:with-mutex ((request-channel-lock *request-channel*))
|
||||
(push fn (request-channel-queue *request-channel*)))
|
||||
(let ((out (request-channel-out *request-channel*)))
|
||||
;; For now, just write a single byte since all we want is for the
|
||||
;; main thread to process the queue. If we want to handle
|
||||
;; different types of events, we'll have to change this so that
|
||||
;; the message sent indicates the event type instead.
|
||||
(write-byte 0 out)
|
||||
(finish-output out)))))
|
||||
(push-event fn))))
|
||||
|
||||
(defclass display-channel ()
|
||||
((display :initarg :display)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue