Commit
5502bb9bc77d4f0a7721f2cdecb8748962006f94
clwm-ext: warp-pointer-mixin
Raymond E. Pasco <ray@ameretat.dev> · 2026-10-27 09:23 UTC
4 files changed,
+65
−3
modified clwm-ext.lisp
| @@ -30,4 +30,6 @@ | |||
| 30 | 30 | #:mousebinds-mixin #:mouse-bindings #:grab-buttons #:drag | |
| 31 | 31 | #:drag-function | |
| 32 | 32 | ;; mousebinds respecting commands | |
| 33 | - | #:drag-move #:drag-resize)) | |
| 33 | + | #:drag-move #:drag-resize | |
| 34 | + | ;; warp-pointer-mixin | |
| 35 | + | #:warp-pointer-mixin #:warp-pointer-client #:client-pointer)) | |
added clwm-ext/warp-pointer-mixin.lisp mode 100644
| @@ -0,0 +1,58 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; save a pointer warp position on every client and use on focus | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-ext) | |
| 6 | + | ||
| 7 | + | (defclass warp-pointer-mixin () () | |
| 8 | + | (:documentation "Focusing a client by means other than moving the | |
| 9 | + | pointer warps the pointer to where it last was on that client (falling | |
| 10 | + | back to the center).")) | |
| 11 | + | ||
| 12 | + | (defclass warp-pointer-client () | |
| 13 | + | ((pointer :initform nil :accessor client-pointer | |
| 14 | + | :documentation | |
| 15 | + | "Where the pointer last was on the client, or NIL.")) | |
| 16 | + | (:documentation "A client that remembers where the pointer last was | |
| 17 | + | on it.")) | |
| 18 | + | ||
| 19 | + | (defmethod client-mixins append ((wm warp-pointer-mixin)) | |
| 20 | + | '(warp-pointer-client)) | |
| 21 | + | ||
| 22 | + | (defun pointer-client (wm) | |
| 23 | + | "Helper to find the client the pointer is on and the pointer's | |
| 24 | + | coordinates." | |
| 25 | + | (multiple-value-bind (x y same-screen-p child) | |
| 26 | + | (xlib:query-pointer (root wm)) | |
| 27 | + | (declare (ignore same-screen-p)) | |
| 28 | + | (values (and child (find-client wm child)) x y))) | |
| 29 | + | ||
| 30 | + | (defun remember-pointer (wm client x y) | |
| 31 | + | "Remember where the pointer was on a client. | |
| 32 | + | Expects WARP-POINTER-MIXIN." | |
| 33 | + | (multiple-value-bind (client-x client-y) (client-geometry wm client) | |
| 34 | + | (setf (client-pointer client) | |
| 35 | + | (list (- x client-x) (- y client-y))))) | |
| 36 | + | ||
| 37 | + | (defun warp-to-client (wm client) | |
| 38 | + | "Warp the pointer to where it last was on a client, or fall back | |
| 39 | + | to the center. | |
| 40 | + | Expects WARP-POINTER-MIXIN." | |
| 41 | + | (multiple-value-bind (x y width height) (client-geometry wm client) | |
| 42 | + | (destructuring-bind (&optional px py) (client-pointer client) | |
| 43 | + | (unless (and px (< -1 px width) (< -1 py height)) | |
| 44 | + | (setf px (floor width 2) | |
| 45 | + | py (floor height 2))) | |
| 46 | + | (xlib:warp-pointer (root wm) (+ x px) (+ y py))))) | |
| 47 | + | ||
| 48 | + | (defmethod focus-client :after ((wm warp-pointer-mixin) client) | |
| 49 | + | (multiple-value-bind (under x y) (pointer-client wm) | |
| 50 | + | (unless (eql under client) | |
| 51 | + | (when under | |
| 52 | + | (remember-pointer wm under x y)) | |
| 53 | + | (warp-to-client wm client)))) | |
| 54 | + | ||
| 55 | + | (defmethod hide-client :before ((wm warp-pointer-mixin) client) | |
| 56 | + | (multiple-value-bind (under x y) (pointer-client wm) | |
| 57 | + | (when (eql under client) | |
| 58 | + | (remember-pointer wm client x y)))) | |
modified clwm.asd
| @@ -22,5 +22,6 @@ | |||
| 22 | 22 | (:file "keybinds-mixin") | |
| 23 | 23 | (:file "pointer-keybinds-mixin") | |
| 24 | 24 | (:file "commands") | |
| 25 | - | (:file "mousebinds-mixin"))) | |
| 25 | + | (:file "mousebinds-mixin") | |
| 26 | + | (:file "warp-pointer-mixin"))) | |
| 26 | 27 | (: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 (mousebinds-mixin | |
| 7 | + | (defclass my-wm (warp-pointer-mixin | |
| 8 | + | mousebinds-mixin | |
| 8 | 9 | pointer-keybinds-mixin | |
| 9 | 10 | ignored-clients-mixin | |
| 10 | 11 | focus-tracking-mixin | |