mirror of
https://github.com/ch11ng/exwm.git
synced 2024-11-23 19:47:58 +01:00
Remove redundant code caused by the concurrency of events (continued)
Remove `exwm--with-current-id`, which was introduced to as a wrapper to `with-current-buffer` to do extra checks. Note that in functions run as hooks, the validation of window ID is still required as they are not synchronized with events.
This commit is contained in:
parent
2d4104a0ec
commit
048994c794
4 changed files with 34 additions and 37 deletions
|
@ -56,7 +56,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
|
||||||
|
|
||||||
(defun exwm-input--set-focus (id)
|
(defun exwm-input--set-focus (id)
|
||||||
"Set input focus to window ID in a proper way."
|
"Set input focus to window ID in a proper way."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(exwm--log "Set focus ID to #x%x" id)
|
(exwm--log "Set focus ID to #x%x" id)
|
||||||
(setq exwm-input--focus-id id)
|
(setq exwm-input--focus-id id)
|
||||||
(if (and (not exwm--hints-input)
|
(if (and (not exwm--hints-input)
|
||||||
|
@ -105,21 +105,24 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
|
||||||
exwm--floating-frame)
|
exwm--floating-frame)
|
||||||
(x-focus-frame exwm--floating-frame)))
|
(x-focus-frame exwm--floating-frame)))
|
||||||
;; Finally focus the window
|
;; Finally focus the window
|
||||||
(exwm-input--set-focus exwm-input--focus-id))
|
(when (exwm--id->buffer exwm-input--focus-id)
|
||||||
(exwm--with-current-id exwm-input--focus-id
|
(exwm-input--set-focus exwm-input--focus-id)))
|
||||||
(exwm--log "Set focus ID to #x%x" xcb:Window:None)
|
(let ((buffer (exwm--id->buffer exwm-input--focus-id)))
|
||||||
(setq exwm-input--focus-id xcb:Window:None)
|
(when buffer
|
||||||
(let ((frame (selected-frame)))
|
(with-current-buffer buffer
|
||||||
(if exwm--floating-frame
|
(exwm--log "Set focus ID to #x%x" xcb:Window:None)
|
||||||
(unless (or (eq frame exwm--floating-frame)
|
(setq exwm-input--focus-id xcb:Window:None)
|
||||||
(active-minibuffer-window))
|
(let ((frame (selected-frame)))
|
||||||
;; Redirect input focus to the workspace frame
|
(if exwm--floating-frame
|
||||||
(exwm--log "Redirect input focus (%s => %s)"
|
(unless (or (eq frame exwm--floating-frame)
|
||||||
exwm--floating-frame frame)
|
(active-minibuffer-window))
|
||||||
(redirect-frame-focus exwm--floating-frame frame))
|
;; Redirect input focus to the workspace frame
|
||||||
;; Focus the workspace frame
|
(exwm--log "Redirect input focus (%s => %s)"
|
||||||
(exwm--log "Focus on workspace %s" frame)
|
exwm--floating-frame frame)
|
||||||
(x-focus-frame frame))))))
|
(redirect-frame-focus exwm--floating-frame frame))
|
||||||
|
;; Focus the workspace frame
|
||||||
|
(exwm--log "Focus on workspace %s" frame)
|
||||||
|
(x-focus-frame frame))))))))
|
||||||
(setq exwm-input--focus-lock nil)))
|
(setq exwm-input--focus-lock nil)))
|
||||||
|
|
||||||
(defun exwm-input--finish-key-sequence ()
|
(defun exwm-input--finish-key-sequence ()
|
||||||
|
@ -163,7 +166,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
|
||||||
(t
|
(t
|
||||||
;; Click to focus
|
;; Click to focus
|
||||||
(unless (and (boundp 'exwm--id) (= event exwm--id))
|
(unless (and (boundp 'exwm--id) (= event exwm--id))
|
||||||
(exwm--with-current-id event
|
(with-current-buffer (exwm--id->buffer event)
|
||||||
(select-frame-set-input-focus (or exwm--floating-frame
|
(select-frame-set-input-focus (or exwm--floating-frame
|
||||||
exwm--frame))
|
exwm--frame))
|
||||||
(select-window (get-buffer-window nil 'visible))))
|
(select-window (get-buffer-window nil 'visible))))
|
||||||
|
|
|
@ -34,7 +34,9 @@
|
||||||
(make-instance 'xcb:icccm:set-WM_STATE
|
(make-instance 'xcb:icccm:set-WM_STATE
|
||||||
:window id :state xcb:icccm:WM_STATE:NormalState
|
:window id :state xcb:icccm:WM_STATE:NormalState
|
||||||
:icon xcb:Window:None))
|
:icon xcb:Window:None))
|
||||||
(let* ((edges (or (exwm--with-current-id id exwm--floating-edges)
|
(let* ((buffer (exwm--id->buffer id))
|
||||||
|
(edges (or (and buffer
|
||||||
|
(with-current-buffer buffer exwm--floating-edges))
|
||||||
(window-inside-pixel-edges window)))
|
(window-inside-pixel-edges window)))
|
||||||
(x (elt edges 0))
|
(x (elt edges 0))
|
||||||
(y (elt edges 1))
|
(y (elt edges 1))
|
||||||
|
|
|
@ -35,7 +35,7 @@ corresponding buffer.")
|
||||||
|
|
||||||
(defun exwm-manage--update-geometry (id &optional force)
|
(defun exwm-manage--update-geometry (id &optional force)
|
||||||
"Update window geometry."
|
"Update window geometry."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(unless (and exwm--geometry (not force))
|
(unless (and exwm--geometry (not force))
|
||||||
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
||||||
(make-instance 'xcb:GetGeometry :drawable id))))
|
(make-instance 'xcb:GetGeometry :drawable id))))
|
||||||
|
@ -137,7 +137,7 @@ corresponding buffer.")
|
||||||
(exwm-input-grab-keyboard id)
|
(exwm-input-grab-keyboard id)
|
||||||
(exwm-workspace--update-switch-history)
|
(exwm-workspace--update-switch-history)
|
||||||
(setq exwm-input--focus-lock nil) ;unlocked in advance
|
(setq exwm-input--focus-lock nil) ;unlocked in advance
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(run-hooks 'exwm-manage-finish-hook))))
|
(run-hooks 'exwm-manage-finish-hook))))
|
||||||
(setq exwm-input--focus-lock nil))
|
(setq exwm-input--focus-lock nil))
|
||||||
|
|
||||||
|
|
26
exwm.el
26
exwm.el
|
@ -208,17 +208,9 @@
|
||||||
(exwm-layout--refresh)
|
(exwm-layout--refresh)
|
||||||
(exwm-input-grab-keyboard))))
|
(exwm-input-grab-keyboard))))
|
||||||
|
|
||||||
(defmacro exwm--with-current-id (id &rest body)
|
|
||||||
"Evaluate BODY in the context of the buffer corresponding to window ID."
|
|
||||||
(declare (indent 1))
|
|
||||||
`(when ,id
|
|
||||||
(let ((buffer (exwm--id->buffer ,id)))
|
|
||||||
(when buffer
|
|
||||||
(with-current-buffer buffer ,@body)))))
|
|
||||||
|
|
||||||
(defun exwm--update-window-type (id &optional force)
|
(defun exwm--update-window-type (id &optional force)
|
||||||
"Update _NET_WM_WINDOW_TYPE."
|
"Update _NET_WM_WINDOW_TYPE."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(unless (and exwm-window-type (not force))
|
(unless (and exwm-window-type (not force))
|
||||||
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
||||||
(make-instance 'xcb:ewmh:get-_NET_WM_WINDOW_TYPE
|
(make-instance 'xcb:ewmh:get-_NET_WM_WINDOW_TYPE
|
||||||
|
@ -231,7 +223,7 @@
|
||||||
|
|
||||||
(defun exwm--update-class (id &optional force)
|
(defun exwm--update-class (id &optional force)
|
||||||
"Update WM_CLASS."
|
"Update WM_CLASS."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(unless (and exwm-instance-name exwm-class-name (not force))
|
(unless (and exwm-instance-name exwm-class-name (not force))
|
||||||
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
||||||
(make-instance 'xcb:icccm:get-WM_CLASS :window id))))
|
(make-instance 'xcb:icccm:get-WM_CLASS :window id))))
|
||||||
|
@ -246,7 +238,7 @@
|
||||||
|
|
||||||
(defun exwm--update-utf8-title (id &optional force)
|
(defun exwm--update-utf8-title (id &optional force)
|
||||||
"Update _NET_WM_NAME."
|
"Update _NET_WM_NAME."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(when (or force (not exwm-title))
|
(when (or force (not exwm-title))
|
||||||
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
||||||
(make-instance 'xcb:ewmh:get-_NET_WM_NAME :window id))))
|
(make-instance 'xcb:ewmh:get-_NET_WM_NAME :window id))))
|
||||||
|
@ -258,7 +250,7 @@
|
||||||
|
|
||||||
(defun exwm--update-ctext-title (id &optional force)
|
(defun exwm--update-ctext-title (id &optional force)
|
||||||
"Update WM_NAME."
|
"Update WM_NAME."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(unless (or exwm--title-is-utf8
|
(unless (or exwm--title-is-utf8
|
||||||
(and exwm-title (not force)))
|
(and exwm-title (not force)))
|
||||||
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
||||||
|
@ -275,7 +267,7 @@
|
||||||
|
|
||||||
(defun exwm--update-transient-for (id &optional force)
|
(defun exwm--update-transient-for (id &optional force)
|
||||||
"Update WM_TRANSIENT_FOR."
|
"Update WM_TRANSIENT_FOR."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(unless (and exwm-transient-for (not force))
|
(unless (and exwm-transient-for (not force))
|
||||||
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
||||||
(make-instance 'xcb:icccm:get-WM_TRANSIENT_FOR
|
(make-instance 'xcb:icccm:get-WM_TRANSIENT_FOR
|
||||||
|
@ -285,7 +277,7 @@
|
||||||
|
|
||||||
(defun exwm--update-normal-hints (id &optional force)
|
(defun exwm--update-normal-hints (id &optional force)
|
||||||
"Update WM_NORMAL_HINTS."
|
"Update WM_NORMAL_HINTS."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(unless (and (not force)
|
(unless (and (not force)
|
||||||
(or exwm--normal-hints-x exwm--normal-hints-y
|
(or exwm--normal-hints-x exwm--normal-hints-y
|
||||||
exwm--normal-hints-width exwm--normal-hints-height
|
exwm--normal-hints-width exwm--normal-hints-height
|
||||||
|
@ -332,7 +324,7 @@
|
||||||
|
|
||||||
(defun exwm--update-hints (id &optional force)
|
(defun exwm--update-hints (id &optional force)
|
||||||
"Update WM_HINTS."
|
"Update WM_HINTS."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(unless (and (not force) exwm--hints-input exwm--hints-urgency)
|
(unless (and (not force) exwm--hints-input exwm--hints-urgency)
|
||||||
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
||||||
(make-instance 'xcb:icccm:get-WM_HINTS :window id))))
|
(make-instance 'xcb:icccm:get-WM_HINTS :window id))))
|
||||||
|
@ -351,7 +343,7 @@
|
||||||
|
|
||||||
(defun exwm--update-protocols (id &optional force)
|
(defun exwm--update-protocols (id &optional force)
|
||||||
"Update WM_PROTOCOLS."
|
"Update WM_PROTOCOLS."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(unless (and exwm--protocols (not force))
|
(unless (and exwm--protocols (not force))
|
||||||
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
||||||
(make-instance 'xcb:icccm:get-WM_PROTOCOLS
|
(make-instance 'xcb:icccm:get-WM_PROTOCOLS
|
||||||
|
@ -361,7 +353,7 @@
|
||||||
|
|
||||||
(defun exwm--update-state (id &optional force)
|
(defun exwm--update-state (id &optional force)
|
||||||
"Update WM_STATE."
|
"Update WM_STATE."
|
||||||
(exwm--with-current-id id
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(unless (and exwm-state (not force))
|
(unless (and exwm-state (not force))
|
||||||
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
||||||
(make-instance 'xcb:icccm:get-WM_STATE :window id))))
|
(make-instance 'xcb:icccm:get-WM_STATE :window id))))
|
||||||
|
|
Loading…
Reference in a new issue