Compare
0c2f6b6f77fc5ebb35e03b43ec9db72988506a57..2478bf1189f2c104246182c7cdbf3aafdc618dcd
clwm-ext: interaction-mixin
Raymond E. Pasco <ray@ameretat.dev> · 2026-10-27 07:12 UTC
5 files changed,
+107
−3
- clwm-ext.lisp
- clwm-ext/ignored-clients-mixin.lisp
- clwm-ext/interaction-mixin.lisp
- clwm.asd
- example-init.lisp
modified clwm-ext.lisp
| @@ -4,8 +4,16 @@ | |||
| 4 | 4 | ||
| 5 | 5 | (defpackage #:clwm-ext | |
| 6 | 6 | (:use :cl :clwm) | |
| 7 | + | (:import-from #:alexandria | |
| 8 | + | #:when-let) | |
| 7 | 9 | (:export | |
| 8 | 10 | ;; sloppy-focus-follows-mouse-mixin | |
| 9 | 11 | #:sloppy-focus-follows-mouse-mixin | |
| 10 | 12 | ;; focus-tracking-mixin | |
| 11 | - | #:focus-tracking-mixin #:focused-client)) | |
| 13 | + | #:focus-tracking-mixin #:focused-client | |
| 14 | + | ;; ignored-clients-mixin | |
| 15 | + | #:ignored-clients-mixin #:ignore-window-p #:ignored-window-names | |
| 16 | + | ;; interaction mixin | |
| 17 | + | #:interaction-mixin #:current-interaction #:interaction | |
| 18 | + | #:interaction-client #:start-interaction #:stop-interaction | |
| 19 | + | #:interaction-event #:stop-current-interaction)) | |
added clwm-ext/ignored-clients-mixin.lisp mode 100644
| @@ -0,0 +1,32 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; ignore some clients | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-ext) | |
| 6 | + | ||
| 7 | + | (defclass ignored-clients-mixin () () | |
| 8 | + | (:documentation "Leave some windows unmanaged.")) | |
| 9 | + | ||
| 10 | + | (defgeneric ignore-window-p (wm window) | |
| 11 | + | (:documentation "Whether to leave a window unmanaged.") | |
| 12 | + | (:method-combination or)) | |
| 13 | + | (defgeneric ignored-window-names (wm) | |
| 14 | + | (:documentation "Names to match against WM_CLASS and WM_NAME, | |
| 15 | + | and ignore if they match.") | |
| 16 | + | (:method-combination append)) | |
| 17 | + | ||
| 18 | + | (defmethod ignore-window-p or ((wm ignored-clients-mixin) window) | |
| 19 | + | (let ((names (ignored-window-names wm))) | |
| 20 | + | (and names | |
| 21 | + | (multiple-value-bind | |
| 22 | + | (instance class) (xlib:get-wm-class window) | |
| 23 | + | (let ((window-names | |
| 24 | + | (list instance class (xlib:wm-name window)))) | |
| 25 | + | (some (lambda (name) | |
| 26 | + | (member name window-names :test #'equal)) | |
| 27 | + | names)))))) | |
| 28 | + | (defmethod ignored-window-names append ((wm ignored-clients-mixin)) | |
| 29 | + | '()) | |
| 30 | + | ||
| 31 | + | (defmethod manage-window-p and ((wm ignored-clients-mixin) window) | |
| 32 | + | (not (ignore-window-p wm window))) | |
added clwm-ext/interaction-mixin.lisp mode 100644
| @@ -0,0 +1,61 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; modal interactions that get all events | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-ext) | |
| 6 | + | ||
| 7 | + | (defclass interaction-mixin () | |
| 8 | + | ((interaction :initform nil :accessor current-interaction | |
| 9 | + | :documentation "The current modal interaction or NIL.")) | |
| 10 | + | (:documentation | |
| 11 | + | "Allow a single modal interaction, which may get first refusal on | |
| 12 | + | all events.")) | |
| 13 | + | ||
| 14 | + | (defclass interaction () | |
| 15 | + | ((client :initarg :client :initform nil :reader interaction-client)) | |
| 16 | + | (:documentation | |
| 17 | + | "A modal interaction which may get first refusal on all events.")) | |
| 18 | + | ||
| 19 | + | (defgeneric start-interaction (wm interaction) | |
| 20 | + | (:documentation "Make an interaction the WM's current interaction.")) | |
| 21 | + | (defgeneric stop-interaction (wm interaction) | |
| 22 | + | (:documentation "Stop an interaction if it's the current one.")) | |
| 23 | + | (defgeneric interaction-event | |
| 24 | + | (wm interaction event-key &key &allow-other-keys) | |
| 25 | + | (:documentation "Offer an event to an interaction. | |
| 26 | + | Non-NIL return consumes the event.") | |
| 27 | + | (:method (wm interaction event-key &key) nil)) | |
| 28 | + | ||
| 29 | + | (defun stop-current-interaction (wm) | |
| 30 | + | "End the current interaction, whatever it may or may not be. | |
| 31 | + | Expects INTERACTION-MIXIN." | |
| 32 | + | (when-let ((interaction (current-interaction wm))) | |
| 33 | + | (stop-interaction wm interaction))) | |
| 34 | + | ||
| 35 | + | (defmethod start-interaction | |
| 36 | + | ((wm interaction-mixin) (interaction interaction)) | |
| 37 | + | (stop-current-interaction wm) | |
| 38 | + | (setf (current-interaction wm) interaction)) | |
| 39 | + | (defmethod stop-interaction | |
| 40 | + | ((wm interaction-mixin) (interaction interaction)) | |
| 41 | + | (when (eql interaction (current-interaction wm)) | |
| 42 | + | (setf (current-interaction wm) nil))) | |
| 43 | + | ||
| 44 | + | (defmethod handle-event :around | |
| 45 | + | ((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)))) | |
| 50 | + | ||
| 51 | + | (defmethod unmanage-client :before ((wm interaction-mixin) client) | |
| 52 | + | (let ((interaction (current-interaction wm))) | |
| 53 | + | (when (and interaction | |
| 54 | + | (eql client (interaction-client interaction))) | |
| 55 | + | (stop-interaction wm interaction)))) | |
| 56 | + | ||
| 57 | + | (defmethod uninitialize-wm :before ((wm interaction-mixin)) | |
| 58 | + | (stop-current-interaction wm)) | |
| 59 | + | ||
| 60 | + | (defmethod shutdown-wm :before ((wm interaction-mixin)) | |
| 61 | + | (stop-current-interaction wm)) | |
modified clwm.asd
| @@ -15,5 +15,7 @@ | |||
| 15 | 15 | :pathname "clwm-ext" | |
| 16 | 16 | :serial t | |
| 17 | 17 | :components ((:file "sloppy-focus-follows-mouse-mixin") | |
| 18 | - | (:file "focus-tracking-mixin"))) | |
| 18 | + | (:file "focus-tracking-mixin") | |
| 19 | + | (:file "ignored-clients-mixin") | |
| 20 | + | (:file "interaction-mixin"))) | |
| 19 | 21 | (: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 (focus-tracking-mixin | |
| 7 | + | (defclass my-wm (ignored-clients-mixin | |
| 8 | + | focus-tracking-mixin | |
| 8 | 9 | sloppy-focus-follows-mouse-mixin | |
| 9 | 10 | wm) | |
| 10 | 11 | ()) | |