at commit 5502bb9b
| 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))) |