mirror of
https://github.com/emacs-exwm/exwm.git
synced 2024-11-27 14:57:59 +01:00
Fix race conditions when managing a window
Since it takes some time for EXWM to create a buffer for a window (to do some checking for example), the window may send several MapRequest events before it's mapped. This commit should fix such issue.
This commit is contained in:
parent
84f0f0328b
commit
14628a940c
1 changed files with 13 additions and 1 deletions
|
@ -42,19 +42,28 @@ corresponding buffer.")
|
||||||
(when reply ;nil when destroyed
|
(when reply ;nil when destroyed
|
||||||
(setq exwm--geometry reply))))))
|
(setq exwm--geometry reply))))))
|
||||||
|
|
||||||
|
(defvar exwm-manage--manage-window-queue nil
|
||||||
|
"List of window IDs to prevent race conditions.")
|
||||||
|
|
||||||
(defun exwm-manage--manage-window (id)
|
(defun exwm-manage--manage-window (id)
|
||||||
"Manage window ID."
|
"Manage window ID."
|
||||||
|
(exwm--log "Try to manage #x%x" id)
|
||||||
(setq exwm-input--focus-lock t)
|
(setq exwm-input--focus-lock t)
|
||||||
(catch 'return
|
(catch 'return
|
||||||
;; Ensure it's not managed
|
;; Ensure it's not managed
|
||||||
(when (assoc id exwm--id-buffer-alist)
|
(when (or (assoc id exwm--id-buffer-alist)
|
||||||
|
(memq id exwm-manage--manage-window-queue))
|
||||||
|
(exwm--log "#x%x is already managed" id)
|
||||||
(throw 'return 'managed))
|
(throw 'return 'managed))
|
||||||
|
(push id exwm-manage--manage-window-queue) ;prevent reentering
|
||||||
;; Ensure it's alive
|
;; Ensure it's alive
|
||||||
(when (xcb:+request-checked+request-check exwm--connection
|
(when (xcb:+request-checked+request-check exwm--connection
|
||||||
(make-instance 'xcb:ChangeWindowAttributes
|
(make-instance 'xcb:ChangeWindowAttributes
|
||||||
:window id :value-mask xcb:CW:EventMask
|
:window id :value-mask xcb:CW:EventMask
|
||||||
:event-mask exwm--client-event-mask))
|
:event-mask exwm--client-event-mask))
|
||||||
|
(delq id exwm-manage--manage-window-queue) ;cleanup
|
||||||
(throw 'return 'dead))
|
(throw 'return 'dead))
|
||||||
|
(delq id exwm-manage--manage-window-queue) ;cleanup (late enough)
|
||||||
(with-current-buffer (generate-new-buffer "*EXWM*")
|
(with-current-buffer (generate-new-buffer "*EXWM*")
|
||||||
(push `(,id . ,(current-buffer)) exwm--id-buffer-alist)
|
(push `(,id . ,(current-buffer)) exwm--id-buffer-alist)
|
||||||
(exwm-mode)
|
(exwm-mode)
|
||||||
|
@ -73,6 +82,7 @@ corresponding buffer.")
|
||||||
(and exwm-instance-name
|
(and exwm-instance-name
|
||||||
(string-prefix-p "sun-awt-X11-" exwm-instance-name)
|
(string-prefix-p "sun-awt-X11-" exwm-instance-name)
|
||||||
(not (string-suffix-p "XFramePeer" exwm-instance-name))))
|
(not (string-suffix-p "XFramePeer" exwm-instance-name))))
|
||||||
|
(exwm--log "No need to manage #x%x" id)
|
||||||
;; Remove all events
|
;; Remove all events
|
||||||
(xcb:+request-checked+request-check exwm--connection
|
(xcb:+request-checked+request-check exwm--connection
|
||||||
(make-instance 'xcb:ChangeWindowAttributes
|
(make-instance 'xcb:ChangeWindowAttributes
|
||||||
|
@ -104,6 +114,7 @@ corresponding buffer.")
|
||||||
(kill-buffer (current-buffer))
|
(kill-buffer (current-buffer))
|
||||||
(throw 'return 'ignored))
|
(throw 'return 'ignored))
|
||||||
;; Manage the window
|
;; Manage the window
|
||||||
|
(exwm--log "Manage #x%x" id)
|
||||||
(xcb:+request exwm--connection ;remove border
|
(xcb:+request exwm--connection ;remove border
|
||||||
(make-instance 'xcb:ConfigureWindow
|
(make-instance 'xcb:ConfigureWindow
|
||||||
:window id :value-mask xcb:ConfigWindow:BorderWidth
|
:window id :value-mask xcb:ConfigWindow:BorderWidth
|
||||||
|
@ -140,6 +151,7 @@ corresponding buffer.")
|
||||||
(defun exwm-manage--unmanage-window (id &optional withdraw-only)
|
(defun exwm-manage--unmanage-window (id &optional withdraw-only)
|
||||||
"Unmanage window ID."
|
"Unmanage window ID."
|
||||||
(let ((buffer (exwm--id->buffer id)))
|
(let ((buffer (exwm--id->buffer id)))
|
||||||
|
(exwm--log "Unmanage #x%x (buffer: %s)" id buffer)
|
||||||
(setq exwm--id-buffer-alist (assq-delete-all id exwm--id-buffer-alist))
|
(setq exwm--id-buffer-alist (assq-delete-all id exwm--id-buffer-alist))
|
||||||
(when (buffer-live-p buffer)
|
(when (buffer-live-p buffer)
|
||||||
(with-current-buffer buffer
|
(with-current-buffer buffer
|
||||||
|
|
Loading…
Reference in a new issue