Compare
84db1d645616d0023971f959191a4b469c07c5b3..2aa41890100f87cac4b922b1eb51c0d2804197f6
clwm-ext: maximize-mixin
Raymond E. Pasco <ray@ameretat.dev> · 2026-10-27 11:28 UTC
4 files changed,
+133
−4
modified clwm-ext.lisp
| @@ -44,4 +44,9 @@ | |||
| 44 | 44 | ;; screen-geometry using commands | |
| 45 | 45 | #:bounded-drag-move #:bounded-drag-resize | |
| 46 | 46 | ;; pointer-placement-mixin | |
| 47 | - | #:pointer-placement-mixin)) | |
| 47 | + | #:pointer-placement-mixin | |
| 48 | + | ;; maximize-mixin | |
| 49 | + | #:maximize-mixin #:maximizable-client #:client-maximized | |
| 50 | + | #:maximized-axes #:toggle-maximize #:maximize-state-changed | |
| 51 | + | ;; maximize-mixin using commands | |
| 52 | + | #:maximize-command #:vmaximize-command #:hmaximize-command)) | |
added clwm-ext/maximize-mixin.lisp mode 100644
| @@ -0,0 +1,119 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; maximize clients | |
| 4 | + | ||
| 5 | + | (in-package #:clwm-ext) | |
| 6 | + | ||
| 7 | + | (defclass maximize-mixin (screen-geometry-mixin) () | |
| 8 | + | (:documentation "Maximize clients horizontally, vertically, or both, | |
| 9 | + | within the SCREEN-GEOMETRY-MIXIN work area. Geometry is stored to be | |
| 10 | + | restored.")) | |
| 11 | + | ||
| 12 | + | (defclass maximizable-client () | |
| 13 | + | ((maximized :initform nil :accessor client-maximized | |
| 14 | + | :documentation | |
| 15 | + | "A plist of :HORIZONTAL and :VERTICAL axis geometry | |
| 16 | + | to restore, or NIL if totally unmaximized.")) | |
| 17 | + | (:documentation "A client that can be maximized.")) | |
| 18 | + | ||
| 19 | + | (defmethod client-mixins append ((wm maximize-mixin)) | |
| 20 | + | '(maximizable-client)) | |
| 21 | + | ||
| 22 | + | (defgeneric maximize-state-changed (wm client) | |
| 23 | + | (:documentation "Handle a maximization state change.") | |
| 24 | + | (:method (wm client) | |
| 25 | + | (declare (ignore wm client)) | |
| 26 | + | nil)) | |
| 27 | + | ||
| 28 | + | (defun maximized-axes (client) | |
| 29 | + | "The axes a client is maximized along (:HORIZONTAL/:VERTICAL)." | |
| 30 | + | (remove-if-not (lambda (axis) (getf (client-maximized client) axis)) | |
| 31 | + | '(:horizontal :vertical))) | |
| 32 | + | ||
| 33 | + | ;; clear maximizations when resizing maximized windows | |
| 34 | + | (defmethod configure-client :before | |
| 35 | + | ((wm maximize-mixin) client &key width height &allow-other-keys) | |
| 36 | + | (let ((horizontal | |
| 37 | + | (and width (remf (client-maximized client) :horizontal))) | |
| 38 | + | (vertical | |
| 39 | + | (and height (remf (client-maximized client) :vertical)))) | |
| 40 | + | (when (or horizontal vertical) | |
| 41 | + | (maximize-state-changed wm client)))) | |
| 42 | + | ||
| 43 | + | (defun axis-span (axis x y width height) | |
| 44 | + | "The position and size of a rectangle along AXIS | |
| 45 | + | (:HORIZONTAL/:VERTICAL) as a list." | |
| 46 | + | (ecase axis | |
| 47 | + | (:horizontal (list x width)) | |
| 48 | + | (:vertical (list y height)))) | |
| 49 | + | ||
| 50 | + | (defun span-geometry (axis span) | |
| 51 | + | "Helper to build CONFIGURE-CLIENT arguments putting a client at SPAN | |
| 52 | + | along AXIS." | |
| 53 | + | (destructuring-bind (position size) span | |
| 54 | + | (ecase axis | |
| 55 | + | (:horizontal (list :x position :width size)) | |
| 56 | + | (:vertical (list :y position :height size))))) | |
| 57 | + | ||
| 58 | + | (defun remember-axes (client axes x y width height) | |
| 59 | + | "Record outer geometry to restore client to along AXES." | |
| 60 | + | (dolist (axis axes) | |
| 61 | + | (setf (getf (client-maximized client) axis) | |
| 62 | + | (axis-span axis x y width height)))) | |
| 63 | + | ||
| 64 | + | (defun maximize-axes (wm client axes) | |
| 65 | + | "Fill the work area along AXES and remember the restore geometry." | |
| 66 | + | (multiple-value-bind (x y width height) (client-geometry wm client) | |
| 67 | + | (let ((area (multiple-value-list | |
| 68 | + | (work-area wm (area-at wm (+ x (floor width 2)) | |
| 69 | + | (+ y (floor height 2))))))) | |
| 70 | + | (apply #'configure-client wm client | |
| 71 | + | (loop for axis in axes | |
| 72 | + | append (span-geometry | |
| 73 | + | axis | |
| 74 | + | (apply #'axis-span axis area)))) | |
| 75 | + | (remember-axes client axes x y width height) | |
| 76 | + | (when axes | |
| 77 | + | (maximize-state-changed wm client))))) | |
| 78 | + | ||
| 79 | + | (defun restore-axes (wm client axes) | |
| 80 | + | "Restore a client along AXES using the remembered geometry." | |
| 81 | + | (let ((geometry | |
| 82 | + | (loop for axis in axes | |
| 83 | + | for span = (getf (client-maximized client) axis) | |
| 84 | + | when span | |
| 85 | + | append (span-geometry axis span) | |
| 86 | + | do (remf (client-maximized client) axis)))) | |
| 87 | + | (when geometry | |
| 88 | + | (apply #'configure-client wm client geometry) | |
| 89 | + | (maximize-state-changed wm client)))) | |
| 90 | + | ||
| 91 | + | (defun toggle-maximize (wm client &key (horizontal t) (vertical t)) | |
| 92 | + | "Toggle maximization, optionally not along both axes." | |
| 93 | + | (let ((axes (append (when horizontal '(:horizontal)) | |
| 94 | + | (when vertical '(:vertical)))) | |
| 95 | + | (maximized (maximized-axes client))) | |
| 96 | + | (if (subsetp axes maximized) | |
| 97 | + | (restore-axes wm client axes) | |
| 98 | + | (maximize-axes wm client (set-difference axes maximized))))) | |
| 99 | + | ||
| 100 | + | (defun maximize-command (wm client x y) | |
| 101 | + | "Maximize or restore the client under the pointer. | |
| 102 | + | Expects MAXIMIZE-MIXIN. | |
| 103 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 104 | + | (declare (ignore x y)) | |
| 105 | + | (when client (toggle-maximize wm client))) | |
| 106 | + | ||
| 107 | + | (defun vmaximize-command (wm client x y) | |
| 108 | + | "Vertically maximize or restore the client under the pointer. | |
| 109 | + | Expects MAXIMIZE-MIXIN. | |
| 110 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 111 | + | (declare (ignore x y)) | |
| 112 | + | (when client (toggle-maximize wm client :horizontal nil))) | |
| 113 | + | ||
| 114 | + | (defun hmaximize-command (wm client x y) | |
| 115 | + | "Horizontally maximize or restore the client under the pointer. | |
| 116 | + | Expects MAXIMIZE-MIXIN. | |
| 117 | + | Respects POINTER-KEYBINDS-MIXIN convention." | |
| 118 | + | (declare (ignore x y)) | |
| 119 | + | (when client (toggle-maximize wm client :vertical nil))) | |
modified clwm.asd
| @@ -26,5 +26,6 @@ | |||
| 26 | 26 | (:file "warp-pointer-mixin") | |
| 27 | 27 | (:file "alt-tab-ring-mixin") | |
| 28 | 28 | (:file "screen-geometry-mixin") | |
| 29 | - | (:file "pointer-placement-mixin"))) | |
| 29 | + | (:file "pointer-placement-mixin") | |
| 30 | + | (:file "maximize-mixin"))) | |
| 30 | 31 | (: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 (pointer-placement-mixin | |
| 7 | + | (defclass my-wm (maximize-mixin | |
| 8 | + | pointer-placement-mixin | |
| 8 | 9 | screen-geometry-mixin | |
| 9 | 10 | alt-tab-ring-mixin | |
| 10 | 11 | warp-pointer-mixin | |
| @@ -23,7 +24,10 @@ | |||
| 23 | 24 | ((:mod-1 :up) . raise-command) | |
| 24 | 25 | ((:mod-1 :down) . lower-command) | |
| 25 | 26 | ((:mod-1 :tab) . ,(cycle-forward :mod-1 :tab)) | |
| 26 | - | ((:mod-1 :shift :tab) . ,(cycle-backward :mod-1 :tab)))) | |
| 27 | + | ((:mod-1 :shift :tab) . ,(cycle-backward :mod-1 :tab)) | |
| 28 | + | ((:control :mod-1 #\m) . maximize-command) | |
| 29 | + | ((:control :mod-1 #\=) . vmaximize-command) | |
| 30 | + | ((:control :mod-1 :shift #\=) . hmaximize-command))) | |
| 27 | 31 | ||
| 28 | 32 | (defmethod mouse-bindings append ((wm my-wm)) | |
| 29 | 33 | '(((:mod-1 1) . bounded-drag-move) | |