at commit a0296e8f

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))))))