Compare
2478bf1189f2c104246182c7cdbf3aafdc618dcd..7f2aa7db783bf4b1f5559f054758b3cded685bcd
clwm-ext: alt-tab-ring-mixin
Raymond E. Pasco <ray@ameretat.dev> · 2026-10-27 10:12 UTC
10 files changed,
+523
−4
- clwm-ext.lisp
- clwm-ext/alt-tab-ring-mixin.lisp
- clwm-ext/bindings.lisp
- clwm-ext/commands.lisp
- clwm-ext/keybinds-mixin.lisp
- clwm-ext/mousebinds-mixin.lisp
- clwm-ext/pointer-keybinds-mixin.lisp
- clwm-ext/warp-pointer-mixin.lisp
- clwm.asd
- example-init.lisp
modified clwm-ext.lisp
| @@ -5,7 +5,8 @@ | |||
| 5 | 5 | (defpackage #:clwm-ext | |
| 6 | 6 | (:use :cl :clwm) | |
| 7 | 7 | (:import-from #:alexandria | |
| 8 | - | #:when-let) | |
| 8 | + | #:when-let #:lastcar #:format-symbol #:clamp #:appendf | |
| 9 | + | #:removef) | |
| 9 | 10 | (:export | |
| 10 | 11 | ;; sloppy-focus-follows-mouse-mixin | |
| 11 | 12 | #:sloppy-focus-follows-mouse-mixin | |
| @@ -16,4 +17,23 @@ | |||
| 16 | 17 | ;; interaction mixin | |
| 17 | 18 | #:interaction-mixin #:current-interaction #:interaction | |
| 18 | 19 | #:interaction-client #:start-interaction #:stop-interaction | |
| 19 | - | #:interaction-event #:stop-current-interaction)) | |
| 20 | + | #:interaction-event #:stop-current-interaction | |
| 21 | + | ;; bindings | |
| 22 | + | #:*lock-modifiers* #:*key-names* | |
| 23 | + | ;; keybinds-mixin | |
| 24 | + | #:keybinds-mixin #:key-bindings #:grab-keys #:call-key-command | |
| 25 | + | ;; pointer-keybinds-mixin | |
| 26 | + | #:pointer-keybinds-mixin | |
| 27 | + | ;; pointer-keybinds respecting commands | |
| 28 | + | #:spawn-command #:close-command #:hide-command | |
| 29 | + | #:raise-command #:lower-command | |
| 30 | + | ;; mousebinds-mixin | |
| 31 | + | #:mousebinds-mixin #:mouse-bindings #:grab-buttons #:drag | |
| 32 | + | #:drag-function | |
| 33 | + | ;; mousebinds respecting commands | |
| 34 | + | #:drag-move #:drag-resize | |
| 35 | + | ;; warp-pointer-mixin | |
| 36 | + | #:warp-pointer-mixin #:warp-pointer-client #:client-pointer | |
| 37 | + | ;; alt-tab-ring-mixin | |
| 38 | + | #:alt-tab-ring-mixin #:client-ring #:ring-cycle | |
| 39 | + | #:cycle-forward #:cycle-backward)) | |
added clwm-ext/alt-tab-ring-mixin.lisp mode 100644
| @@ -0,0 +1,146 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; most-recently-used alt-tab ring | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-ext) | |
| 6 | + | ||
| 7 | + | (defclass alt-tab-ring-mixin (interaction-mixin) | |
| 8 | + | ((ring :initform '() :accessor client-ring | |
| 9 | + | :documentation "Most-recently-used list of clients.")) | |
| 10 | + | (:documentation "Store clients in an alt-tab ring.")) | |
| 11 | + | ||
| 12 | + | (defmethod manage-client :after ((wm alt-tab-ring-mixin) client) | |
| 13 | + | (appendf (client-ring wm) (list client))) | |
| 14 | + | ||
| 15 | + | (defmethod focus-client :after ((wm alt-tab-ring-mixin) client) | |
| 16 | + | (setf (client-ring wm) | |
| 17 | + | (cons client (remove client (client-ring wm))))) | |
| 18 | + | ||
| 19 | + | (defclass ring-cycle (interaction) | |
| 20 | + | ((candidates :initarg :candidates :accessor cycle-candidates | |
| 21 | + | :documentation "Candidate clients for alt-tabbing.") | |
| 22 | + | (index :initform 0 :accessor cycle-index | |
| 23 | + | :documentation "The position of the selected candidate.") | |
| 24 | + | (modifiers :initarg :modifiers :reader cycle-modifiers | |
| 25 | + | :documentation | |
| 26 | + | "The modifiers that must be held to continue cycling.") | |
| 27 | + | (key :initarg :key :reader cycle-key | |
| 28 | + | :documentation "The key that steps through the cycle.")) | |
| 29 | + | (:documentation "An alt-tab interaction that cycles through the ring | |
| 30 | + | while a modifier is held, focusing the selected client when released.")) | |
| 31 | + | ||
| 32 | + | (defun cycle-held-p (wm cycle) | |
| 33 | + | "Helper to check if the cycle modifiers are held." | |
| 34 | + | (let ((state (nth-value 4 (xlib:query-pointer (root wm)))) | |
| 35 | + | (mask (cycle-modifiers cycle))) | |
| 36 | + | (and (plusp mask) | |
| 37 | + | (= mask (logand state mask))))) | |
| 38 | + | ||
| 39 | + | (defun cycle-selection (cycle) | |
| 40 | + | "Helper to get the current candidate." | |
| 41 | + | (nth (cycle-index cycle) (cycle-candidates cycle))) | |
| 42 | + | ||
| 43 | + | (defun cycle-step (wm cycle direction) | |
| 44 | + | "Helper to select the next candidate and raise it." | |
| 45 | + | (let ((count (length (cycle-candidates cycle)))) | |
| 46 | + | (when (plusp count) | |
| 47 | + | (setf (cycle-index cycle) (mod | |
| 48 | + | (+ (cycle-index cycle) direction) | |
| 49 | + | count)) | |
| 50 | + | (configure-client wm | |
| 51 | + | (cycle-selection cycle) | |
| 52 | + | :stack-mode :above)))) | |
| 53 | + | ||
| 54 | + | (defun cycle-clients (wm direction spec) | |
| 55 | + | "Initialize the cycle through clients in DIRECTION 1 or -1." | |
| 56 | + | (let ((candidates (remove :iconic (client-ring wm) | |
| 57 | + | :key (lambda (client) | |
| 58 | + | (wm-state (client-window client)))))) | |
| 59 | + | (when (rest candidates) | |
| 60 | + | (let ((cycle | |
| 61 | + | (make-instance 'ring-cycle | |
| 62 | + | :candidates candidates | |
| 63 | + | :modifiers (binding-modifier-mask spec) | |
| 64 | + | :key (binding-key spec)))) | |
| 65 | + | (start-interaction wm cycle) | |
| 66 | + | (cycle-step wm cycle direction) | |
| 67 | + | ;; exit right away if it wasn't held (quick alt-tab) | |
| 68 | + | (unless (cycle-held-p wm cycle) | |
| 69 | + | (stop-interaction wm cycle)))))) | |
| 70 | + | ||
| 71 | + | (defun cycle-forward (&rest spec) | |
| 72 | + | "Alt-tab cycle forward. Takes a key binding used during the cycle, | |
| 73 | + | which may be different from the one used to invoke it if you have | |
| 74 | + | dextrous fingers. | |
| 75 | + | Expects ALT-TAB-RING-MIXIN. | |
| 76 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 77 | + | (lambda (wm &rest pointer) | |
| 78 | + | (declare (ignore pointer)) | |
| 79 | + | (cycle-clients wm 1 spec))) | |
| 80 | + | ||
| 81 | + | (defun cycle-backward (&rest spec) | |
| 82 | + | "Alt-tab cycle backward. Takes a key binding used during the cycle, | |
| 83 | + | which may be different from the one used to invoke it if you have | |
| 84 | + | dextrous fingers. | |
| 85 | + | Expects ALT-TAB-RING-MIXIN. | |
| 86 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 87 | + | (lambda (wm &rest pointer) | |
| 88 | + | (declare (ignore pointer)) | |
| 89 | + | (cycle-clients wm -1 spec))) | |
| 90 | + | ||
| 91 | + | (defmethod start-interaction :after | |
| 92 | + | ((wm interaction-mixin) (cycle ring-cycle)) | |
| 93 | + | (unless (eql (xlib:grab-keyboard (root wm)) :success) | |
| 94 | + | (stop-interaction wm cycle))) | |
| 95 | + | ||
| 96 | + | (defmethod stop-interaction :after | |
| 97 | + | ((wm interaction-mixin) (cycle ring-cycle)) | |
| 98 | + | (xlib:ungrab-keyboard (display wm)) | |
| 99 | + | (when-let ((client (cycle-selection cycle))) | |
| 100 | + | (setf (cycle-candidates cycle) '()) | |
| 101 | + | (focus-client wm client))) | |
| 102 | + | ||
| 103 | + | ;; remove a client that goes away while alt-tabbing from the ring | |
| 104 | + | (defmethod unmanage-client :after ((wm alt-tab-ring-mixin) client) | |
| 105 | + | (removef (client-ring wm) client) | |
| 106 | + | (let ((cycle (current-interaction wm))) | |
| 107 | + | (when (typep cycle 'ring-cycle) | |
| 108 | + | (let ((position (position client (cycle-candidates cycle)))) | |
| 109 | + | (when position | |
| 110 | + | (removef (cycle-candidates cycle) client) | |
| 111 | + | (when (< position (cycle-index cycle)) | |
| 112 | + | (decf (cycle-index cycle))) | |
| 113 | + | (when (>= (cycle-index cycle) | |
| 114 | + | (length(cycle-candidates cycle))) | |
| 115 | + | (setf (cycle-index cycle) 0))))))) | |
| 116 | + | ||
| 117 | + | ;; todo: more flexible swapping to reverse cycle than hardcoded shift | |
| 118 | + | (defmethod interaction-event | |
| 119 | + | ((wm interaction-mixin) (cycle ring-cycle) | |
| 120 | + | (event-key (eql :key-press)) &key code state) | |
| 121 | + | (let ((display (display wm))) | |
| 122 | + | (when (member (xlib:keycode->keysym display code 0) | |
| 123 | + | (key-keysyms (cycle-key cycle) display)) | |
| 124 | + | (cycle-step wm cycle | |
| 125 | + | (if (logtest state (xlib:make-state-mask :shift)) | |
| 126 | + | -1 | |
| 127 | + | 1)))) | |
| 128 | + | t) | |
| 129 | + | ||
| 130 | + | (defmethod interaction-event | |
| 131 | + | ((wm interaction-mixin) (cycle ring-cycle) | |
| 132 | + | (event-key (eql :key-release)) &key) | |
| 133 | + | (unless (cycle-held-p wm cycle) | |
| 134 | + | (stop-interaction wm cycle)) | |
| 135 | + | t) | |
| 136 | + | ||
| 137 | + | ;; if we raise a client into the pointer while alt-tabbing, make sure | |
| 138 | + | ;; this doesn't focus it | |
| 139 | + | (defmethod interaction-event | |
| 140 | + | ((wm interaction-mixin) (cycle ring-cycle) | |
| 141 | + | (event-key (eql :enter-notify)) &key) | |
| 142 | + | t) | |
| 143 | + | (defmethod interaction-event | |
| 144 | + | ((wm interaction-mixin) (cycle ring-cycle) | |
| 145 | + | (event-key (eql :leave-notify)) &key) | |
| 146 | + | t) | |
added clwm-ext/bindings.lisp mode 100644
| @@ -0,0 +1,72 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; helpers for key and mouse bindings | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-ext) | |
| 6 | + | ||
| 7 | + | ;; the overall binding shape is ('(modifiers... key) . function) | |
| 8 | + | ;; this depends on xmodmap and stuff, but what's probably the case is: | |
| 9 | + | ;; :control = ctrl | |
| 10 | + | ;; :shift = shift | |
| 11 | + | ;; :mod-1 = alt | |
| 12 | + | ;; :mod-2 = num lock (!) | |
| 13 | + | ;; :mod-4 = that additional modifier key | |
| 14 | + | ;; :lock = scroll lock | |
| 15 | + | ;; and we don't want scroll lock or num lock to affect keybinds. | |
| 16 | + | ;; this is a parameter not a gf because if it's not constant it's deep | |
| 17 | + | ;; in the user keyboard weeds. | |
| 18 | + | (defparameter *lock-modifiers* '(:lock :mod-2) | |
| 19 | + | "Modifiers that bindings should always ignore.") | |
| 20 | + | ||
| 21 | + | ;; name some keys that CLX doesn't name. | |
| 22 | + | (defparameter *key-names* | |
| 23 | + | (append '((:backspace . #xff08) (:tab . #xff09) (:return . #xff0d) | |
| 24 | + | (:pause . #xff13) (:escape . #xff1b) (:delete . #xffff) | |
| 25 | + | (:home . #xff50) (:left . #xff51) (:up . #xff52) | |
| 26 | + | (:right . #xff53) (:down . #xff54) (:page-up . #xff55) | |
| 27 | + | (:page-down . #xff56) (:end . #xff57) (:print . #xff61) | |
| 28 | + | (:insert . #xff63) (:menu . #xff67) (:space . #x20)) | |
| 29 | + | (loop for n from 1 to 24 | |
| 30 | + | collect (cons | |
| 31 | + | (format-symbol :keyword "F~d" n) | |
| 32 | + | (+ #xffbd n)))) | |
| 33 | + | "Keyword names for keys we can't name with escapes.") | |
| 34 | + | ||
| 35 | + | (defun binding-modifier-mask (spec) | |
| 36 | + | "The X state mask for the modifiers in a binding spec." | |
| 37 | + | (apply #'xlib:make-state-mask (butlast spec))) | |
| 38 | + | ||
| 39 | + | (defun binding-key (spec) | |
| 40 | + | "The key part of a binding spec." | |
| 41 | + | (lastcar spec)) | |
| 42 | + | ||
| 43 | + | (defun binding-grab-masks (spec) | |
| 44 | + | "The modifier masks to grab for a binding spec, | |
| 45 | + | ignoring *LOCK-MODIFIERS*." | |
| 46 | + | (reduce | |
| 47 | + | (lambda (masks modifier) | |
| 48 | + | (append masks | |
| 49 | + | (mapcar (lambda (mask) | |
| 50 | + | (logior mask (xlib:make-state-mask modifier))) | |
| 51 | + | masks))) | |
| 52 | + | *lock-modifiers* | |
| 53 | + | :initial-value (list (binding-modifier-mask spec)))) | |
| 54 | + | ||
| 55 | + | (defun find-binding (bindings state key &key (test #'eql)) | |
| 56 | + | "The command bound to a key under an event's modifier state." | |
| 57 | + | (let ((mask | |
| 58 | + | (logandc2 (logand state #xff) | |
| 59 | + | (apply #'xlib:make-state-mask *lock-modifiers*)))) | |
| 60 | + | (cdr (find-if (lambda (spec) | |
| 61 | + | (and (funcall test key (binding-key spec)) | |
| 62 | + | (= (binding-modifier-mask spec) mask))) | |
| 63 | + | bindings | |
| 64 | + | :key #'car)))) | |
| 65 | + | ||
| 66 | + | (defun key-keysyms (key display) | |
| 67 | + | "Turn a key from a binding into a keysym on the display." | |
| 68 | + | (etypecase key | |
| 69 | + | (character (xlib:character->keysyms key display)) | |
| 70 | + | (keyword (list (or (cdr (assoc key *key-names*)) | |
| 71 | + | (error "No key named ~s in *KEY-NAMES*." key)))) | |
| 72 | + | (integer (list key)))) | |
added clwm-ext/commands.lisp mode 100644
| @@ -0,0 +1,69 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; forms intended to be executed as wm commands | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-ext) | |
| 6 | + | ||
| 7 | + | ;;; respecting POINTER-KEYBINDS-MIXIN convention | |
| 8 | + | ||
| 9 | + | (defun spawn-command (program &rest args) | |
| 10 | + | "Spawns a program. | |
| 11 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 12 | + | (lambda (wm &rest pointer) | |
| 13 | + | (declare (ignore pointer)) | |
| 14 | + | (apply #'spawn wm program args))) | |
| 15 | + | ||
| 16 | + | (defun close-command (wm client x y) | |
| 17 | + | "Close the client under the pointer. | |
| 18 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 19 | + | (declare (ignore x y)) | |
| 20 | + | (when client (close-client wm client))) | |
| 21 | + | ||
| 22 | + | (defun hide-command (wm client x y) | |
| 23 | + | "Hide the client under the pointer. | |
| 24 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 25 | + | (declare (ignore x y)) | |
| 26 | + | (when client (hide-client wm client))) | |
| 27 | + | ||
| 28 | + | (defun raise-command (wm client x y) | |
| 29 | + | "Raise the client under the pointer. | |
| 30 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 31 | + | (declare (ignore x y)) | |
| 32 | + | (when client (configure-client wm client :stack-mode :above))) | |
| 33 | + | ||
| 34 | + | (defun lower-command (wm client x y) | |
| 35 | + | "Lower the client under the pointer. | |
| 36 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 37 | + | (declare (ignore x y)) | |
| 38 | + | (when client (configure-client wm client :stack-mode :below))) | |
| 39 | + | ||
| 40 | + | ;;; respecting MOUSEBINDS-MIXIN convention | |
| 41 | + | ||
| 42 | + | (defun grab-offset (pointer edge size) | |
| 43 | + | "Helper to determine where the pointer is along a client's edge." | |
| 44 | + | (clamp (- pointer edge) 0 (1- size))) | |
| 45 | + | ||
| 46 | + | (defun drag-move (wm client x y) | |
| 47 | + | "Raise the client and move it with the pointer. | |
| 48 | + | Respects MOUSEBINDS-MIXIN convention." | |
| 49 | + | (configure-client wm client :stack-mode :above) | |
| 50 | + | (multiple-value-bind (client-x client-y width height) | |
| 51 | + | (client-geometry wm client) | |
| 52 | + | (declare (ignore width height)) | |
| 53 | + | (let ((dx (- client-x x)) | |
| 54 | + | (dy (- client-y y))) | |
| 55 | + | (lambda (x y) | |
| 56 | + | (configure-client wm client :x (+ x dx) :y (+ y dy)))))) | |
| 57 | + | ||
| 58 | + | (defun drag-resize (wm client x y) | |
| 59 | + | "Raise the client and resize it with the pointer. | |
| 60 | + | Respects MOUSEBINDS-MIXIN convention." | |
| 61 | + | (configure-client wm client :stack-mode :above) | |
| 62 | + | (multiple-value-bind (client-x client-y width height) | |
| 63 | + | (client-geometry wm client) | |
| 64 | + | (declare (ignore client-x client-y)) | |
| 65 | + | ;; todo: resize from other corners than bottom right | |
| 66 | + | (lambda (new-x new-y) | |
| 67 | + | (configure-client wm client | |
| 68 | + | :width (+ width (- new-x x)) | |
| 69 | + | :height (+ height (- new-y y)))))) | |
added clwm-ext/keybinds-mixin.lisp mode 100644
| @@ -0,0 +1,55 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; keybinds. | |
| 4 | + | ;;;; the base convention is (lambda (wm) ...) | |
| 5 | + | ||
| 6 | + | (in-package #:clwm-ext) | |
| 7 | + | ||
| 8 | + | (defclass keybinds-mixin () () | |
| 9 | + | (:documentation "Keys grabbed on the root to execute forms.")) | |
| 10 | + | ||
| 11 | + | (defgeneric key-bindings (wm) | |
| 12 | + | (:documentation "Bindings from keybinding specs to functions.") | |
| 13 | + | (:method-combination append)) | |
| 14 | + | (defgeneric grab-keys (wm) | |
| 15 | + | (:documentation "Grab the keys of the key bindings on the root.")) | |
| 16 | + | (defgeneric call-key-command (wm command &key &allow-other-keys) | |
| 17 | + | (:documentation "Run a key binding's command.")) | |
| 18 | + | ||
| 19 | + | (defmethod key-bindings append ((wm keybinds-mixin)) '()) | |
| 20 | + | ||
| 21 | + | (defmethod grab-keys ((wm keybinds-mixin)) | |
| 22 | + | (xlib:ungrab-key (root wm) :any :modifiers :any) | |
| 23 | + | (loop for (spec) in (key-bindings wm) do | |
| 24 | + | (dolist (keysym (key-keysyms (binding-key spec) (display wm))) | |
| 25 | + | (dolist (code (multiple-value-list | |
| 26 | + | (xlib:keysym->keycodes (display wm) keysym))) | |
| 27 | + | (dolist (mask (binding-grab-masks spec)) | |
| 28 | + | (xlib:grab-key (root wm) code :modifiers mask)))))) | |
| 29 | + | ||
| 30 | + | (defmethod initialize-wm :after ((wm keybinds-mixin)) | |
| 31 | + | (grab-keys wm)) | |
| 32 | + | ||
| 33 | + | (defmethod call-key-command ((wm keybinds-mixin) command &key) | |
| 34 | + | (funcall command wm)) | |
| 35 | + | ||
| 36 | + | (defmethod handle-event | |
| 37 | + | ((wm keybinds-mixin) (event-key (eql :key-press)) | |
| 38 | + | &rest e &key code state) | |
| 39 | + | (let ((command (find-binding | |
| 40 | + | (key-bindings wm) state | |
| 41 | + | (xlib:keycode->keysym (display wm) code 0) | |
| 42 | + | :test | |
| 43 | + | (lambda (keysym key) | |
| 44 | + | (member keysym (key-keysyms key (display wm))))))) | |
| 45 | + | (if command | |
| 46 | + | (apply #'call-key-command wm command e) | |
| 47 | + | (call-next-method)))) | |
| 48 | + | ||
| 49 | + | (defmethod handle-event | |
| 50 | + | ((wm keybinds-mixin) (event-key (eql :mapping-notify)) | |
| 51 | + | &key request start count) | |
| 52 | + | (xlib:mapping-notify (display wm) request start count) | |
| 53 | + | (when (eql request :keyboard) | |
| 54 | + | (grab-keys wm)) | |
| 55 | + | (call-next-method)) | |
added clwm-ext/mousebinds-mixin.lisp mode 100644
| @@ -0,0 +1,61 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; mouse bindings | |
| 4 | + | ;;;; the convention is (lambda (wm client x y) ...) | |
| 5 | + | ;;;; possibly returning a (lambda (x y) ...) | |
| 6 | + | ;;;; which is called on every move until the interaction ends | |
| 7 | + | ||
| 8 | + | (in-package #:clwm-ext) | |
| 9 | + | ||
| 10 | + | (defclass mousebinds-mixin (interaction-mixin) () | |
| 11 | + | (:documentation "Buttons (and modifiers) grabbed on the root | |
| 12 | + | to execute forms.")) | |
| 13 | + | ||
| 14 | + | (defclass drag (interaction) | |
| 15 | + | ((function :initarg :function :reader drag-function)) | |
| 16 | + | (:documentation "Call a function on pointer motion until release.")) | |
| 17 | + | ||
| 18 | + | (defgeneric mouse-bindings (wm) | |
| 19 | + | (:documentation "Bindings of (modifiers... button) to functions.") | |
| 20 | + | (:method-combination append)) | |
| 21 | + | (defgeneric grab-buttons (wm) | |
| 22 | + | (:documentation | |
| 23 | + | "Grab the buttons of the mouse bindings on the root.")) | |
| 24 | + | ||
| 25 | + | (defmethod mouse-bindings append ((wm mousebinds-mixin)) '()) | |
| 26 | + | ||
| 27 | + | (defmethod grab-buttons ((wm mousebinds-mixin)) | |
| 28 | + | (xlib:ungrab-button (root wm) :any :modifiers :any) | |
| 29 | + | (loop for (spec) in (mouse-bindings wm) | |
| 30 | + | do (dolist (mask (binding-grab-masks spec)) | |
| 31 | + | (xlib:grab-button (root wm) (binding-key spec) | |
| 32 | + | '(:button-press :button-release | |
| 33 | + | :pointer-motion) | |
| 34 | + | :modifiers mask)))) | |
| 35 | + | ||
| 36 | + | (defmethod initialize-wm :after ((wm mousebinds-mixin)) | |
| 37 | + | (grab-buttons wm)) | |
| 38 | + | ||
| 39 | + | (defmethod handle-client-event | |
| 40 | + | ((wm mousebinds-mixin) client (event-key (eql :button-press)) | |
| 41 | + | &key code state root-x root-y) | |
| 42 | + | (let ((command (find-binding (mouse-bindings wm) state code))) | |
| 43 | + | (if command | |
| 44 | + | (let ((function (funcall command wm client root-x root-y))) | |
| 45 | + | (when (functionp function) | |
| 46 | + | (start-interaction | |
| 47 | + | wm | |
| 48 | + | (make-instance 'drag :client client :function function)))) | |
| 49 | + | (call-next-method)))) | |
| 50 | + | ||
| 51 | + | (defmethod interaction-event | |
| 52 | + | ((wm interaction-mixin) (drag drag) (event-key (eql :motion-notify)) | |
| 53 | + | &key root-x root-y) | |
| 54 | + | (funcall (drag-function drag) root-x root-y) | |
| 55 | + | t) | |
| 56 | + | ||
| 57 | + | (defmethod interaction-event | |
| 58 | + | ((wm interaction-mixin) (drag drag) | |
| 59 | + | (event-key (eql :button-release)) &key) | |
| 60 | + | (stop-interaction wm drag) | |
| 61 | + | t) | |
added clwm-ext/pointer-keybinds-mixin.lisp mode 100644
| @@ -0,0 +1,14 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; keybinds that know where the pointer is | |
| 4 | + | ;;;; the convention is (lambda (wm client x y) ...) | |
| 5 | + | ||
| 6 | + | (in-package #:clwm-ext) | |
| 7 | + | ||
| 8 | + | (defclass pointer-keybinds-mixin (keybinds-mixin) () | |
| 9 | + | (:documentation "Keybinds which know where the pointer is, | |
| 10 | + | and what client is under it.")) | |
| 11 | + | ||
| 12 | + | (defmethod call-key-command ((wm pointer-keybinds-mixin) command | |
| 13 | + | &rest e &key root-x root-y) | |
| 14 | + | (funcall command wm (apply #'event-client wm :key-press e) root-x root-y)) | |
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
| @@ -17,5 +17,12 @@ | |||
| 17 | 17 | :components ((:file "sloppy-focus-follows-mouse-mixin") | |
| 18 | 18 | (:file "focus-tracking-mixin") | |
| 19 | 19 | (:file "ignored-clients-mixin") | |
| 20 | - | (:file "interaction-mixin"))) | |
| 20 | + | (:file "interaction-mixin") | |
| 21 | + | (:file "bindings") | |
| 22 | + | (:file "keybinds-mixin") | |
| 23 | + | (:file "pointer-keybinds-mixin") | |
| 24 | + | (:file "commands") | |
| 25 | + | (:file "mousebinds-mixin") | |
| 26 | + | (:file "warp-pointer-mixin") | |
| 27 | + | (:file "alt-tab-ring-mixin"))) | |
| 21 | 28 | (:file "clwm-user"))) | |
modified example-init.lisp
| @@ -4,12 +4,29 @@ | |||
| 4 | 4 | ||
| 5 | 5 | (in-package #:clwm-user) | |
| 6 | 6 | ||
| 7 | - | (defclass my-wm (ignored-clients-mixin | |
| 7 | + | (defclass my-wm (alt-tab-ring-mixin | |
| 8 | + | warp-pointer-mixin | |
| 9 | + | mousebinds-mixin | |
| 10 | + | pointer-keybinds-mixin | |
| 11 | + | ignored-clients-mixin | |
| 8 | 12 | focus-tracking-mixin | |
| 9 | 13 | sloppy-focus-follows-mouse-mixin | |
| 10 | 14 | wm) | |
| 11 | 15 | ()) | |
| 12 | 16 | ||
| 17 | + | (defmethod key-bindings append ((wm my-wm)) | |
| 18 | + | `(((:control :mod-1 #\Return) . ,(spawn-command "xterm")) | |
| 19 | + | ((:control :mod-1 #\x) . close-command) | |
| 20 | + | ((:mod-1 #\Return) . hide-command) | |
| 21 | + | ((:mod-1 :up) . raise-command) | |
| 22 | + | ((:mod-1 :down) . lower-command) | |
| 23 | + | ((:mod-1 :tab) . ,(cycle-forward :mod-1 :tab)) | |
| 24 | + | ((:mod-1 :shift :tab) . ,(cycle-backward :mod-1 :tab)))) | |
| 25 | + | ||
| 26 | + | (defmethod mouse-bindings append ((wm my-wm)) | |
| 27 | + | '(((:mod-1 1) . drag-move) | |
| 28 | + | ((:mod-1 3) . drag-resize))) | |
| 29 | + | ||
| 13 | 30 | (run-wm 'my-wm) | |
| 14 | 31 | ||
| 15 | 32 | ;; if slynk is desired | |