Commit
3dcbd3de2e2a446dd8915d1e083263e2322af3ab
interaction-mixin: debuggable interactions
Raymond E. Pasco <ray@ameretat.dev> · 2026-10-28 00:48 UTC
2 files changed,
+33
−4
modified clwm-ext.lisp
| @@ -18,6 +18,7 @@ | |||
| 18 | 18 | #:interaction-mixin #:current-interaction #:interaction | |
| 19 | 19 | #:interaction-client #:start-interaction #:stop-interaction | |
| 20 | 20 | #:interaction-event #:stop-current-interaction | |
| 21 | + | #:abort-current-interaction #:with-interaction-abort-on-error | |
| 21 | 22 | ;; bindings | |
| 22 | 23 | #:*lock-modifiers* #:*key-names* | |
| 23 | 24 | ;; keybinds-mixin | |
modified clwm-ext/interaction-mixin.lisp
| @@ -41,12 +41,40 @@ Expects INTERACTION-MIXIN." | |||
| 41 | 41 | (when (eql interaction (current-interaction wm)) | |
| 42 | 42 | (setf (current-interaction wm) nil))) | |
| 43 | 43 | ||
| 44 | + | (defun abort-current-interaction (wm) | |
| 45 | + | "Tear down the current interaction after an error, best-effort. | |
| 46 | + | Releases grabs and flushes, so a debugger can be used afterwards. | |
| 47 | + | Expects INTERACTION-MIXIN." | |
| 48 | + | (ignore-errors (stop-current-interaction wm)) | |
| 49 | + | ;; in case stop-interaction itself died partway | |
| 50 | + | (ignore-errors (xlib:ungrab-keyboard (display wm)) | |
| 51 | + | (xlib:ungrab-pointer (display wm))) | |
| 52 | + | ;; CLX buffers requests; flush before we block in a debugger | |
| 53 | + | (ignore-errors (xlib:display-finish-output (display wm)))) | |
| 54 | + | ||
| 55 | + | (defmacro with-interaction-abort-on-error ((wm) &body body) | |
| 56 | + | "Abort WM's current interaction on any error in BODY, then decline, | |
| 57 | + | so outer handlers (SKIP-EVENT, the debugger) still see the error." | |
| 58 | + | (let ((condition (gensym "CONDITION"))) | |
| 59 | + | `(handler-bind ((error (lambda (,condition) | |
| 60 | + | (declare (ignore ,condition)) | |
| 61 | + | (abort-current-interaction ,wm)))) | |
| 62 | + | ,@body))) | |
| 63 | + | ||
| 44 | 64 | (defmethod handle-event :around | |
| 45 | 65 | ((wm interaction-mixin) event-key &rest e &key) | |
| 46 | - | (let ((interaction (current-interaction wm))) | |
| 47 | - | (unless (and interaction | |
| 48 | - | (apply #'interaction-event wm interaction event-key e)) | |
| 49 | - | (call-next-method)))) | |
| 66 | + | (with-interaction-abort-on-error (wm) | |
| 67 | + | (let ((interaction (current-interaction wm))) | |
| 68 | + | (unless (and interaction | |
| 69 | + | (apply #'interaction-event | |
| 70 | + | wm interaction event-key e)) | |
| 71 | + | (call-next-method))))) | |
| 72 | + | ||
| 73 | + | ;; async X errors often surface outside HANDLE-EVENT, in the event loop | |
| 74 | + | (defmethod handle-x-error :around | |
| 75 | + | ((wm interaction-mixin) error-key &key) | |
| 76 | + | (with-interaction-abort-on-error (wm) | |
| 77 | + | (call-next-method))) | |
| 50 | 78 | ||
| 51 | 79 | (defmethod unmanage-client :before ((wm interaction-mixin) client) | |
| 52 | 80 | (let ((interaction (current-interaction wm))) | |