at commit 31b6c823
| 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)))))) |
| 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)))))) |