Don't assume that exwm--connection is non-nil

`exwm-input--exit` could be called (via `exwm-exit`) from `exwm-init`
in case of error when initialising EXWM. It could happen that the bit
that failed when exwm-init is executed was the call to `xcb:connect`,
hence `exwm--connection` would be nil when errors are handled (and
`exwm-exit` is called).

Without this patch, in the case above, the user will see a crash as
there's no method allowing a nil XCB connection object:

  Debugger entered--Lisp error:
  (cl-no-applicable-method xcb:-+request nil #<xcb:SetInputFocus ...

even worse, not even giving the chance to the `warn` call in
`exwm-init`'s error handler to actually inform the user about the
actual problem ("[XELB] Connection timeout", for instance).

* exwm-input.el (exwm-input--exit): Check `exwm--connection' is
set before trying to send requests.
This commit is contained in:
Nacho Barrientos 2023-05-07 12:45:31 +02:00 committed by Adrián Medraño Calvo
parent b62d5e79b0
commit cff02333e2

View file

@ -1215,12 +1215,13 @@ One use is to access the keymap bound to KEYS (as prefix keys) in char-mode."
(when exwm-input--update-focus-timer (when exwm-input--update-focus-timer
(cancel-timer exwm-input--update-focus-timer)) (cancel-timer exwm-input--update-focus-timer))
;; Make input focus working even without a WM. ;; Make input focus working even without a WM.
(xcb:+request exwm--connection (when exwm--connection
(make-instance 'xcb:SetInputFocus (xcb:+request exwm--connection
:revert-to xcb:InputFocus:PointerRoot (make-instance 'xcb:SetInputFocus
:focus exwm--root :revert-to xcb:InputFocus:PointerRoot
:time xcb:Time:CurrentTime)) :focus exwm--root
(xcb:flush exwm--connection)) :time xcb:Time:CurrentTime))
(xcb:flush exwm--connection)))