mirror of
https://github.com/ch11ng/exwm.git
synced 2024-11-30 14:38:00 +01:00
Improve code robustness.
* exwm-layout.el (exwm-layout-unset-fullscreen) (exwm-layout-set-fullscreen): Use `user-error' rather than `cl-assert'. * exwm-input.el (exwm-input--set-focus): Silently accept unknown ids. (exwm-input--grab-keyboard) (exwm-input--release-keyboard): Silently ignore calls for windows that have no buffer. * exwm-manage.el (exwm-manage--kill-client): Don't throw error when trying to kill a vanished window.
This commit is contained in:
parent
d998b42b89
commit
d1806e9188
3 changed files with 45 additions and 43 deletions
|
@ -56,6 +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."
|
||||||
|
(when (exwm--id->buffer id)
|
||||||
(with-current-buffer (exwm--id->buffer id)
|
(with-current-buffer (exwm--id->buffer id)
|
||||||
(if (and (not exwm--hints-input)
|
(if (and (not exwm--hints-input)
|
||||||
(memq xcb:Atom:WM_TAKE_FOCUS exwm--protocols))
|
(memq xcb:Atom:WM_TAKE_FOCUS exwm--protocols))
|
||||||
|
@ -75,7 +76,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
|
||||||
(make-instance 'xcb:SetInputFocus
|
(make-instance 'xcb:SetInputFocus
|
||||||
:revert-to xcb:InputFocus:Parent :focus id
|
:revert-to xcb:InputFocus:Parent :focus id
|
||||||
:time xcb:Time:CurrentTime)))
|
:time xcb:Time:CurrentTime)))
|
||||||
(xcb:flush exwm--connection)))
|
(xcb:flush exwm--connection))))
|
||||||
|
|
||||||
(defvar exwm-input--focus-window nil "The (Emacs) window to be focused.")
|
(defvar exwm-input--focus-window nil "The (Emacs) window to be focused.")
|
||||||
(defvar exwm-input--redirected nil
|
(defvar exwm-input--redirected nil
|
||||||
|
@ -311,7 +312,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
|
||||||
(defun exwm-input--grab-keyboard (&optional id)
|
(defun exwm-input--grab-keyboard (&optional id)
|
||||||
"Grab all key events on window ID."
|
"Grab all key events on window ID."
|
||||||
(unless id (setq id (exwm--buffer->id (window-buffer))))
|
(unless id (setq id (exwm--buffer->id (window-buffer))))
|
||||||
(cl-assert id)
|
(when id
|
||||||
(when (xcb:+request-checked+request-check exwm--connection
|
(when (xcb:+request-checked+request-check exwm--connection
|
||||||
(make-instance 'xcb:GrabKey
|
(make-instance 'xcb:GrabKey
|
||||||
:owner-events 0 :grab-window id
|
:owner-events 0 :grab-window id
|
||||||
|
@ -320,18 +321,18 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
|
||||||
:pointer-mode xcb:GrabMode:Async
|
:pointer-mode xcb:GrabMode:Async
|
||||||
:keyboard-mode xcb:GrabMode:Async))
|
:keyboard-mode xcb:GrabMode:Async))
|
||||||
(exwm--log "Failed to grab keyboard for #x%x" id))
|
(exwm--log "Failed to grab keyboard for #x%x" id))
|
||||||
(setq exwm--on-KeyPress 'exwm-input--on-KeyPress-line-mode))
|
(setq exwm--on-KeyPress 'exwm-input--on-KeyPress-line-mode)))
|
||||||
|
|
||||||
(defun exwm-input--release-keyboard (&optional id)
|
(defun exwm-input--release-keyboard (&optional id)
|
||||||
"Ungrab all key events on window ID."
|
"Ungrab all key events on window ID."
|
||||||
(unless id (setq id (exwm--buffer->id (window-buffer))))
|
(unless id (setq id (exwm--buffer->id (window-buffer))))
|
||||||
(cl-assert id)
|
(when id
|
||||||
(when (xcb:+request-checked+request-check exwm--connection
|
(when (xcb:+request-checked+request-check exwm--connection
|
||||||
(make-instance 'xcb:UngrabKey
|
(make-instance 'xcb:UngrabKey
|
||||||
:key xcb:Grab:Any :grab-window id
|
:key xcb:Grab:Any :grab-window id
|
||||||
:modifiers xcb:ModMask:Any))
|
:modifiers xcb:ModMask:Any))
|
||||||
(exwm--log "Failed to release keyboard for #x%x" id))
|
(exwm--log "Failed to release keyboard for #x%x" id))
|
||||||
(setq exwm--on-KeyPress 'exwm-input--on-KeyPress-char-mode))
|
(setq exwm--on-KeyPress 'exwm-input--on-KeyPress-char-mode)))
|
||||||
|
|
||||||
(defun exwm-input-grab-keyboard (&optional id)
|
(defun exwm-input-grab-keyboard (&optional id)
|
||||||
"Switch to line-mode."
|
"Switch to line-mode."
|
||||||
|
|
|
@ -93,6 +93,8 @@
|
||||||
"Make window ID fullscreen."
|
"Make window ID fullscreen."
|
||||||
(interactive)
|
(interactive)
|
||||||
(with-current-buffer (if id (exwm--id->buffer id) (window-buffer))
|
(with-current-buffer (if id (exwm--id->buffer id) (window-buffer))
|
||||||
|
(when exwm--fullscreen
|
||||||
|
(user-error "Already in full-screen mode."))
|
||||||
;; Set the floating frame fullscreen first when the client is floating
|
;; Set the floating frame fullscreen first when the client is floating
|
||||||
(when exwm--floating-frame
|
(when exwm--floating-frame
|
||||||
(let* ((outer-id (frame-parameter exwm--floating-frame 'exwm-outer-id))
|
(let* ((outer-id (frame-parameter exwm--floating-frame 'exwm-outer-id))
|
||||||
|
@ -130,7 +132,6 @@
|
||||||
:window exwm--id
|
:window exwm--id
|
||||||
:data (vector xcb:Atom:_NET_WM_STATE_FULLSCREEN)))
|
:data (vector xcb:Atom:_NET_WM_STATE_FULLSCREEN)))
|
||||||
(xcb:flush exwm--connection)
|
(xcb:flush exwm--connection)
|
||||||
(cl-assert (not exwm--fullscreen))
|
|
||||||
(setq exwm--fullscreen t)
|
(setq exwm--fullscreen t)
|
||||||
(exwm-input-release-keyboard)))
|
(exwm-input-release-keyboard)))
|
||||||
|
|
||||||
|
@ -138,6 +139,8 @@
|
||||||
"Restore window from fullscreen state."
|
"Restore window from fullscreen state."
|
||||||
(interactive)
|
(interactive)
|
||||||
(with-current-buffer (if id (exwm--id->buffer id) (window-buffer))
|
(with-current-buffer (if id (exwm--id->buffer id) (window-buffer))
|
||||||
|
(unless exwm--fullscreen
|
||||||
|
(user-error "Not in full-screen mode."))
|
||||||
;; Restore the floating frame if the client is floating
|
;; Restore the floating frame if the client is floating
|
||||||
(when exwm--floating-frame
|
(when exwm--floating-frame
|
||||||
(xcb:+request exwm--connection
|
(xcb:+request exwm--connection
|
||||||
|
@ -156,7 +159,6 @@
|
||||||
(xcb:+request exwm--connection
|
(xcb:+request exwm--connection
|
||||||
(make-instance 'xcb:ewmh:set-_NET_WM_STATE :window exwm--id :data []))
|
(make-instance 'xcb:ewmh:set-_NET_WM_STATE :window exwm--id :data []))
|
||||||
(xcb:flush exwm--connection)
|
(xcb:flush exwm--connection)
|
||||||
(cl-assert exwm--fullscreen)
|
|
||||||
(setq exwm--fullscreen nil)
|
(setq exwm--fullscreen nil)
|
||||||
(exwm-input-grab-keyboard)))
|
(exwm-input-grab-keyboard)))
|
||||||
|
|
||||||
|
|
|
@ -260,10 +260,9 @@ corresponding buffer.")
|
||||||
"Kill an X client."
|
"Kill an X client."
|
||||||
(interactive)
|
(interactive)
|
||||||
(unless id (setq id (exwm--buffer->id (current-buffer))))
|
(unless id (setq id (exwm--buffer->id (current-buffer))))
|
||||||
(let ((pid (slot-value
|
(let* ((response (xcb:+request-unchecked+reply exwm--connection
|
||||||
(xcb:+request-unchecked+reply exwm--connection
|
(make-instance 'xcb:ewmh:get-_NET_WM_PID :window id)))
|
||||||
(make-instance 'xcb:ewmh:get-_NET_WM_PID :window id))
|
(pid (and response (slot-value response 'value))))
|
||||||
'value)))
|
|
||||||
(if pid
|
(if pid
|
||||||
(signal-process pid 'SIGKILL)
|
(signal-process pid 'SIGKILL)
|
||||||
(xcb:+request exwm--connection
|
(xcb:+request exwm--connection
|
||||||
|
|
Loading…
Reference in a new issue