Compare
c63d3797b6dff30e6508a9ab6b23f1e7bc55262a..19d191f2e49457e9f90aaff6cff96b2001b1269b
clwm-ext: ignored-clients-mixin
Raymond E. Pasco <ray@ameretat.dev> · 2026-10-27 06:45 UTC
10 files changed,
+181
−1
- .gitignore
- binary.lisp
- build.sh
- clwm-ext.lisp
- clwm-ext/focus-tracking-mixin.lisp
- clwm-ext/ignored-clients-mixin.lisp
- clwm-ext/sloppy-focus-follows-mouse-mixin.lisp
- clwm-user.lisp
- clwm.asd
- example-init.lisp
modified .gitignore
| @@ -1,3 +1,4 @@ | |||
| 1 | + | /clwm | |
| 1 | 2 | *~ | |
| 2 | 3 | \#*\# | |
| 3 | 4 | *.fasl | |
added binary.lisp mode 100644
| @@ -0,0 +1,47 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; build a binary (assumes you have quicklisp): | |
| 4 | + | ;;;; sbcl --non-interactive --load binary.lisp | |
| 5 | + | ;;;; usage: | |
| 6 | + | ;;;; clwm user-init.lisp | |
| 7 | + | ||
| 8 | + | (unless (find-package '#:quicklisp) | |
| 9 | + | (load | |
| 10 | + | (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))) | |
| 11 | + | ||
| 12 | + | (asdf:load-asd (merge-pathnames "clwm.asd" *load-truename*)) | |
| 13 | + | (ql:quickload "clwm") | |
| 14 | + | ;; get the stuff slynk tries to load on connect into the image | |
| 15 | + | (asdf:load-systems "slynk/arglists" "slynk/fancy-inspector" | |
| 16 | + | "slynk/package-fu" "slynk/mrepl" "slynk/trace-dialog" | |
| 17 | + | "slynk/profiler" "slynk/stickers" "slynk/indentation" | |
| 18 | + | "slynk/retro") | |
| 19 | + | ||
| 20 | + | (in-package #:clwm-user) | |
| 21 | + | ||
| 22 | + | (defun main () | |
| 23 | + | (let ((args (uiop:command-line-arguments))) | |
| 24 | + | (unless (= (length args) 1) | |
| 25 | + | (format *error-output* "usage: clwm user-init.lisp~%") | |
| 26 | + | (uiop:quit 2)) | |
| 27 | + | (handler-case | |
| 28 | + | (let ((*package* (find-package '#:clwm-user))) | |
| 29 | + | (load (first args))) | |
| 30 | + | (error (condition) | |
| 31 | + | (format *error-output* "~&clwm: error loading ~a:~%~a~%" | |
| 32 | + | (first args) condition) | |
| 33 | + | (uiop:quit 1))) | |
| 34 | + | (unless *wm-thread* | |
| 35 | + | (format *error-output* "~&clwm: ~a didn't start a WM~%" | |
| 36 | + | (first args)) | |
| 37 | + | (uiop:quit 1)) | |
| 38 | + | (uiop:quit (if (member (ignore-errors (bt:join-thread *wm-thread*)) | |
| 39 | + | '(:stopped :disconnected)) | |
| 40 | + | 0 | |
| 41 | + | 1)))) | |
| 42 | + | ||
| 43 | + | (sb-ext:save-lisp-and-die | |
| 44 | + | (make-pathname :name "clwm" :type nil :defaults *load-truename*) | |
| 45 | + | :executable t | |
| 46 | + | :toplevel #'main | |
| 47 | + | :save-runtime-options t) | |
added build.sh mode 100755
| @@ -0,0 +1,2 @@ | |||
| 1 | + | #!/bin/sh | |
| 2 | + | sbcl --non-interactive --load binary.lisp | |
added clwm-ext.lisp mode 100644
| @@ -0,0 +1,13 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; package for provided extensions | |
| 4 | + | ||
| 5 | + | (defpackage #:clwm-ext | |
| 6 | + | (:use :cl :clwm) | |
| 7 | + | (:export | |
| 8 | + | ;; sloppy-focus-follows-mouse-mixin | |
| 9 | + | #:sloppy-focus-follows-mouse-mixin | |
| 10 | + | ;; focus-tracking-mixin | |
| 11 | + | #:focus-tracking-mixin #:focused-client | |
| 12 | + | ;; ignored-clients-mixin | |
| 13 | + | #:ignored-clients-mixin #:ignore-window-p #:ignored-window-names)) | |
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))) | |
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/sloppy-focus-follows-mouse-mixin.lisp mode 100644
| @@ -0,0 +1,21 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; sloppy focus-follows-mouse (don't unfocus on moving out) | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-ext) | |
| 6 | + | ||
| 7 | + | (defclass sloppy-focus-follows-mouse-mixin () () | |
| 8 | + | (:documentation | |
| 9 | + | "Focus follows mouse, but entering the root doesn't unfocus.")) | |
| 10 | + | ||
| 11 | + | (defmethod client-event-mask append | |
| 12 | + | ((wm sloppy-focus-follows-mouse-mixin) client) | |
| 13 | + | '(:enter-window)) | |
| 14 | + | ||
| 15 | + | (defmethod handle-client-event | |
| 16 | + | ((wm sloppy-focus-follows-mouse-mixin) client | |
| 17 | + | (event-key (eql :enter-notify)) | |
| 18 | + | &key mode kind) | |
| 19 | + | (if (and (eql mode :normal) (not (eql kind :inferior))) | |
| 20 | + | (focus-client wm client) | |
| 21 | + | (call-next-method))) | |
modified clwm-user.lisp
| @@ -3,4 +3,4 @@ | |||
| 3 | 3 | ;;;; CLWM-USER: package where the user can assemble and run a WM | |
| 4 | 4 | ||
| 5 | 5 | (defpackage #:clwm-user | |
| 6 | - | (:use #:cl #:clwm)) | |
| 6 | + | (:use #:cl #:clwm #:clwm-ext)) | |
modified clwm.asd
| @@ -10,4 +10,11 @@ | |||
| 10 | 10 | "uiop") | |
| 11 | 11 | :serial t | |
| 12 | 12 | :components ((:file "clwm") | |
| 13 | + | (:file "clwm-ext") | |
| 14 | + | (:module "ext" | |
| 15 | + | :pathname "clwm-ext" | |
| 16 | + | :serial t | |
| 17 | + | :components ((:file "sloppy-focus-follows-mouse-mixin") | |
| 18 | + | (:file "focus-tracking-mixin") | |
| 19 | + | (:file "ignored-clients-mixin"))) | |
| 13 | 20 | (:file "clwm-user"))) | |
added example-init.lisp mode 100644
| @@ -0,0 +1,16 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; example user init file | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-user) | |
| 6 | + | ||
| 7 | + | (defclass my-wm (ignored-clients-mixin | |
| 8 | + | focus-tracking-mixin | |
| 9 | + | sloppy-focus-follows-mouse-mixin | |
| 10 | + | wm) | |
| 11 | + | ()) | |
| 12 | + | ||
| 13 | + | (run-wm 'my-wm) | |
| 14 | + | ||
| 15 | + | ;; if slynk is desired | |
| 16 | + | ;; (start-slynk) | |