Compare
71b00a799de990c1bbe7cdc3b1c4d9e31d40864f..0c2f6b6f77fc5ebb35e03b43ec9db72988506a57
clwm-ext: focus-tracking-mixin
Raymond E. Pasco <ray@ameretat.dev> · 2026-10-27 06:32 UTC
4 files changed,
+48
−3
modified clwm-ext.lisp
| @@ -6,4 +6,6 @@ | |||
| 6 | 6 | (:use :cl :clwm) | |
| 7 | 7 | (:export | |
| 8 | 8 | ;; sloppy-focus-follows-mouse-mixin | |
| 9 | - | #:sloppy-focus-follows-mouse-mixin)) | |
| 9 | + | #:sloppy-focus-follows-mouse-mixin | |
| 10 | + | ;; focus-tracking-mixin | |
| 11 | + | #:focus-tracking-mixin #:focused-client)) | |
added clwm-ext/focus-tracking-mixin.lisp mode 100644
| @@ -0,0 +1,41 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; track the focused client | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-ext) | |
| 6 | + | ||
| 7 | + | (defclass focus-tracking-mixin () | |
| 8 | + | ((focused-client | |
| 9 | + | :initform nil :accessor focused-client | |
| 10 | + | :documentation "The client with the input focus or NIL.")) | |
| 11 | + | (:documentation "Track the client with the input focus.")) | |
| 12 | + | ||
| 13 | + | (defmethod root-event-mask append ((wm focus-tracking-mixin)) | |
| 14 | + | '(:focus-change)) | |
| 15 | + | ||
| 16 | + | (defmethod client-event-mask append ((wm focus-tracking-mixin) client) | |
| 17 | + | '(:focus-change)) | |
| 18 | + | ||
| 19 | + | (defun update-focused-client (wm) | |
| 20 | + | "Ask X where the focus is, find the client, and update. | |
| 21 | + | Expects FOCUS-TRACKING-MIXIN." | |
| 22 | + | (setf (focused-client wm) | |
| 23 | + | (loop for window = (xlib:input-focus (display wm)) | |
| 24 | + | then (nth-value 1 (xlib:query-tree window)) | |
| 25 | + | while (and (xlib:window-p window) | |
| 26 | + | (not (xlib:window-equal window (root wm)))) | |
| 27 | + | thereis (find-client wm window)))) | |
| 28 | + | ||
| 29 | + | (defmethod handle-event | |
| 30 | + | ((wm focus-tracking-mixin) (event-key (eql :focus-in)) &key) | |
| 31 | + | (update-focused-client wm) | |
| 32 | + | (call-next-method)) | |
| 33 | + | ||
| 34 | + | (defmethod handle-event | |
| 35 | + | ((wm focus-tracking-mixin) (event-key (eql :focus-out)) &key) | |
| 36 | + | (update-focused-client wm) | |
| 37 | + | (call-next-method)) | |
| 38 | + | ||
| 39 | + | (defmethod unmanage-client :after ((wm focus-tracking-mixin) client) | |
| 40 | + | (when (eql client (focused-client wm)) | |
| 41 | + | (setf (focused-client wm) nil))) | |
modified clwm.asd
| @@ -14,5 +14,6 @@ | |||
| 14 | 14 | (:module "ext" | |
| 15 | 15 | :pathname "clwm-ext" | |
| 16 | 16 | :serial t | |
| 17 | - | :components ((:file "sloppy-focus-follows-mouse-mixin"))) | |
| 17 | + | :components ((:file "sloppy-focus-follows-mouse-mixin") | |
| 18 | + | (:file "focus-tracking-mixin"))) | |
| 18 | 19 | (:file "clwm-user"))) | |
modified example-init.lisp
| @@ -4,7 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | 5 | (in-package #:clwm-user) | |
| 6 | 6 | ||
| 7 | - | (defclass my-wm (sloppy-focus-follows-mouse-mixin | |
| 7 | + | (defclass my-wm (focus-tracking-mixin | |
| 8 | + | sloppy-focus-follows-mouse-mixin | |
| 8 | 9 | wm) | |
| 9 | 10 | ()) | |
| 10 | 11 | ||