Compare

a262df09cc4cce548e6e94456d969d5c7ecb6ece..2aa41890100f87cac4b922b1eb51c0d2804197f6

clwm-ext: maximize-mixin

Raymond E. Pasco <ray@ameretat.dev> · 2026-10-27 11:28 UTC

Browse files
10 files changed, +665 −6
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 #:lastcar #:format-symbol)
8 + #:when-let #:lastcar #:format-symbol #:clamp #:appendf
9 + #:removef #:extremum)
9 10 (:export
10 11 ;; sloppy-focus-follows-mouse-mixin
11 12 #:sloppy-focus-follows-mouse-mixin
@@ -23,6 +24,29 @@
23 24 #:keybinds-mixin #:key-bindings #:grab-keys #:call-key-command
24 25 ;; pointer-keybinds-mixin
25 26 #:pointer-keybinds-mixin
26 - ;; commands
27 + ;; pointer-keybinds respecting commands
27 28 #:spawn-command #:close-command #:hide-command
28 - #:raise-command #:lower-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
40 + ;; screen-geometry-mixin
41 + #:screen-geometry-mixin #:screen-areas #:reserved-edges
42 + #:screen-geometry-changed #:area-at #:work-area
43 + #:geometry-bounds #:constrain-move #:constrain-resize
44 + ;; screen-geometry using commands
45 + #:bounded-drag-move #:bounded-drag-resize
46 + ;; 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/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)
modified clwm-ext/commands.lisp
@@ -36,3 +36,74 @@ Respects POINTER-KEYBINDS-MIXIN convention."
36 36 Respects POINTER-KEYBINDS-MIXIN convention."
37 37 (declare (ignore x y))
38 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))))))
70 +
71 + (defun bounded-drag-move (wm client x y)
72 + "Raise the client and move it with the pointer within the bounds.
73 + Expects SCREEN-GEOMETRY-MIXIN.
74 + Respects MOUSEBINDS-MIXIN convention."
75 + (configure-client wm client :stack-mode :above)
76 + (multiple-value-bind (client-x client-y width height)
77 + (client-geometry wm client)
78 + (let ((grab-x (- x client-x))
79 + (grab-y (- y client-y)))
80 + (lambda (x y)
81 + (multiple-value-bind (new-x new-y)
82 + (constrain-move wm client
83 + (- x grab-x) (- y grab-y)
84 + width height)
85 + (setf grab-x (grab-offset x new-x width)
86 + grab-y (grab-offset y new-y height))
87 + (configure-client wm client :x new-x :y new-y))))))
88 +
89 + (defun bounded-drag-resize (wm client x y)
90 + "Raise the client and resize it with the pointer within the bounds.
91 + Expects SCREEN-GEOMETRY-MIXIN.
92 + Respects MOUSEBINDS-MIXIN convention."
93 + (configure-client wm client :stack-mode :above)
94 + (multiple-value-bind (client-x client-y width height)
95 + (client-geometry wm client)
96 + ;; measured from the bottom right corner, which is what moves
97 + (let ((grab-x (- (+ client-x width) x))
98 + (grab-y (- (+ client-y height) y)))
99 + (lambda (x y)
100 + (multiple-value-bind (new-width new-height)
101 + (constrain-resize wm client client-x client-y
102 + (- (+ x grab-x) client-x)
103 + (- (+ y grab-y) client-y))
104 + (setf grab-x (grab-offset (+ client-x new-width)
105 + x new-width)
106 + grab-y (grab-offset (+ client-y new-height)
107 + y new-height))
108 + (configure-client wm client
109 + :width new-width :height new-height))))))
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)))
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-placement-mixin.lisp mode 100644
@@ -0,0 +1,39 @@
1 + ;;;; common lisp window manager
2 + ;;;;
3 + ;;;; place new clients under the pointer by default
4 +
5 + (in-package #:clwm-ext)
6 +
7 + (defclass pointer-placement-mixin (screen-geometry-mixin) ()
8 + (:documentation
9 + "Place new clients under the pointer if they don't place themselves.
10 + Keep them inside the SCREEN-GEOMETRY-MIXIN work area."))
11 +
12 + (defmethod place-client ((wm pointer-placement-mixin) client)
13 + (let ((hints (client-normal-hints client)))
14 + (unless (and
15 + hints
16 + ;; ridiculously long names
17 + (or (xlib:wm-size-hints-user-specified-position-p hints)
18 + ;; for some reason, not exported
19 + (xlib::wm-size-hints-program-specified-position-p
20 + hints)))
21 + (multiple-value-bind (x y width height)
22 + (client-geometry wm client)
23 + (declare (ignore x y))
24 + (multiple-value-bind (pointer-x pointer-y)
25 + (xlib:query-pointer (root wm))
26 + (multiple-value-bind (area-x area-y area-width area-height)
27 + (work-area wm (area-at wm pointer-x pointer-y))
28 + (flet ((inside (position size start extent)
29 + (max start
30 + (min position (- (+ start extent) size)))))
31 + (configure-client
32 + wm client
33 + :x (inside
34 + (- pointer-x (floor width 2))
35 + width area-x area-width)
36 + :y (inside
37 + (- pointer-y (floor height 2))
38 + height area-y area-height))))))))
39 + (call-next-method))
added clwm-ext/screen-geometry-mixin.lisp mode 100644
@@ -0,0 +1,120 @@
1 + ;;;; common lisp window manager
2 + ;;;;
3 + ;;;; screen geometry support. todo: multimonitor
4 +
5 + (in-package #:clwm-ext)
6 +
7 + ;; don't need slots until multimonitor
8 + (defclass screen-geometry-mixin () ()
9 + (:documentation "The screen's areas and work areas."))
10 +
11 + (defgeneric screen-areas (wm)
12 + (:documentation "Rectangles for the various screen areas."))
13 + (defgeneric reserved-edges (wm)
14 + (:documentation "Space reserved at edges (left right top bottom).")
15 + (:method-combination append))
16 + (defgeneric screen-geometry-changed (wm)
17 + (:documentation "Handle the screen areas or reserved edges changing."))
18 +
19 + ;; for now, just one
20 + (defmethod screen-areas ((wm screen-geometry-mixin))
21 + (list (list 0 0
22 + (xlib:screen-width (screen wm))
23 + (xlib:screen-height (screen wm)))))
24 +
25 + (defmethod reserved-edges append ((wm screen-geometry-mixin)) '())
26 +
27 + (defmethod screen-geometry-changed ((wm screen-geometry-mixin))
28 + nil)
29 +
30 + (defun area-at (wm x y)
31 + "Helper to find the area containing a point.
32 + Expects SCREEN-GEOMETRY-MIXIN."
33 + (flet ((distance (area)
34 + (destructuring-bind (left top width height) area
35 + (let ((dx (max 0 (- left x) (- x (+ left width -1))))
36 + (dy (max 0 (- top y) (- y (+ top height -1)))))
37 + (+ (* dx dx) (* dy dy))))))
38 + (extremum (screen-areas wm) #'< :key #'distance)))
39 +
40 + (defun work-area (wm area)
41 + "The rectangle that isn't reserved in an area.
42 + Expects SCREEN-GEOMETRY-MIXIN."
43 + (destructuring-bind (x y width height) area
44 + (let* ((edges (reserved-edges wm))
45 + (screen (screen wm))
46 + (left (max x (reduce #'max edges
47 + :key #'first :initial-value 0)))
48 + (top (max y (reduce #'max edges
49 + :key #'third :initial-value 0)))
50 + (right (min (+ x width)
51 + (- (xlib:screen-width screen)
52 + (reduce #'max edges
53 + :key #'second :initial-value 0))))
54 + (bottom (min (+ y height)
55 + (- (xlib:screen-height screen)
56 + (reduce #'max edges
57 + :key #'fourth :initial-value 0)))))
58 + (if (and (< left right) (< top bottom))
59 + (values left top (- right left) (- bottom top))
60 + (values x y width height)))))
61 +
62 + (defgeneric geometry-bounds (wm client x y width height)
63 + (:documentation
64 + "Edges that clients should not be able to move past.
65 + (Left, top, right, bottom.)")
66 + (:method (wm client x y width height)
67 + (declare (ignore wm client x y width height))
68 + (values nil nil nil nil)))
69 +
70 + (defun neighbor-p (area areas side)
71 + "Whether AREA has a neighbor in AREAS on SIDE."
72 + (destructuring-bind (x y width height) area
73 + (some (lambda (other)
74 + (destructuring-bind (ox oy owidth oheight) other
75 + (let ((rows
76 + (and (< oy (+ y height)) (< y (+ oy oheight))))
77 + (columns
78 + (and (< ox (+ x width)) (< x (+ ox owidth)))))
79 + (ecase side
80 + (:left (and rows (= (+ ox owidth) x)))
81 + (:right (and rows (= ox (+ x width))))
82 + (:top (and columns (= (+ oy oheight) y)))
83 + (:bottom (and columns (= oy (+ y height))))))))
84 + (remove area areas))))
85 +
86 + (defmethod geometry-bounds ((wm screen-geometry-mixin) client
87 + x y width height)
88 + (declare (ignore client))
89 + (let* ((areas (screen-areas wm))
90 + (area (area-at wm
91 + (+ x (floor width 2))
92 + (+ y (floor height 2)))))
93 + (multiple-value-bind (left top work-width work-height)
94 + (work-area wm area)
95 + (flet ((wall (side edge)
96 + (unless (neighbor-p area areas side) edge)))
97 + (values (wall :left left)
98 + (wall :top top)
99 + (wall :right (+ left work-width))
100 + (wall :bottom (+ top work-height)))))))
101 +
102 + (defun constrain-move (wm client x y width height)
103 + "Constrain a move by the geometry bounds."
104 + (multiple-value-bind (left top right bottom)
105 + (geometry-bounds wm client x y width height)
106 + (flet ((inside (position size start end)
107 + (when end (setf position (min position (- end size))))
108 + (when start (setf position (max position start)))
109 + position))
110 + (values (inside x width left right)
111 + (inside y height top bottom)))))
112 +
113 + ;; todo: non bottom right resizes
114 + (defun constrain-resize (wm client x y width height)
115 + "Constrain a resize by the geometry bounds."
116 + (multiple-value-bind (left top right bottom)
117 + (geometry-bounds wm client x y width height)
118 + (declare (ignore left top))
119 + (values (max 1 (if right (min width (- right x)) width))
120 + (max 1 (if bottom (min height (- bottom y)) height)))))
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
@@ -21,5 +21,11 @@
21 21 (:file "bindings")
22 22 (:file "keybinds-mixin")
23 23 (:file "pointer-keybinds-mixin")
24 - (:file "commands")))
24 + (:file "commands")
25 + (:file "mousebinds-mixin")
26 + (:file "warp-pointer-mixin")
27 + (:file "alt-tab-ring-mixin")
28 + (:file "screen-geometry-mixin")
29 + (:file "pointer-placement-mixin")
30 + (:file "maximize-mixin")))
25 31 (:file "clwm-user")))
modified example-init.lisp
@@ -4,7 +4,13 @@
4 4
5 5 (in-package #:clwm-user)
6 6
7 - (defclass my-wm (pointer-keybinds-mixin
7 + (defclass my-wm (maximize-mixin
8 + pointer-placement-mixin
9 + screen-geometry-mixin
10 + alt-tab-ring-mixin
11 + warp-pointer-mixin
12 + mousebinds-mixin
13 + pointer-keybinds-mixin
8 14 ignored-clients-mixin
9 15 focus-tracking-mixin
10 16 sloppy-focus-follows-mouse-mixin
@@ -16,7 +22,16 @@
16 22 ((:control :mod-1 #\x) . close-command)
17 23 ((:mod-1 #\Return) . hide-command)
18 24 ((:mod-1 :up) . raise-command)
19 - ((:mod-1 :down) . lower-command)))
25 + ((:mod-1 :down) . lower-command)
26 + ((:mod-1 :tab) . ,(cycle-forward :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)))
31 +
32 + (defmethod mouse-bindings append ((wm my-wm))
33 + '(((:mod-1 1) . bounded-drag-move)
34 + ((:mod-1 3) . bounded-drag-resize)))
20 35
21 36 (run-wm 'my-wm)
22 37