at commit 9b7c4fe7
| 1 | ;;;; common lisp window manager |
| 2 | ;;;; |
| 3 | ;;;; an EXAMPLE tiling mixin |
| 4 | ;;;; not suitable for real use |
| 5 | |
| 6 | (in-package #:clwm-ext) |
| 7 | |
| 8 | (defclass tiling-mixin (screen-geometry-mixin) |
| 9 | ((order :initform '() :accessor tile-order |
| 10 | :documentation "Clients in tiling order. Master layouts |
| 11 | just use the first client as the master.")) |
| 12 | (:documentation |
| 13 | "Lay out the visible clients in the work area using the |
| 14 | LAYOUT-CLIENTS method.")) |
| 15 | |
| 16 | (defgeneric master-fraction (wm) |
| 17 | (:documentation "How much of the work area's width the master gets, |
| 18 | for master layouts.") |
| 19 | (:method ((wm tiling-mixin)) 1/2)) |
| 20 | |
| 21 | (defgeneric layout-clients (wm clients x y width height) |
| 22 | (:documentation |
| 23 | "Rectangles for CLIENTS in the area at X, Y of WIDTH and HEIGHT. |
| 24 | Gives a list of (client x y width height), in outer geometry.")) |
| 25 | |
| 26 | ;; a hacked-up master left/rest right layout. |
| 27 | ;; it's escaping to the right |
| 28 | (defmethod layout-clients ((wm tiling-mixin) clients x y width height) |
| 29 | (if (null (rest clients)) |
| 30 | (list (list (first clients) x y width height)) |
| 31 | (let* ((master-width (floor (* width (master-fraction wm)))) |
| 32 | (stack (rest clients)) |
| 33 | (stack-height (floor height (length stack)))) |
| 34 | (cons (list (first clients) x y master-width height) |
| 35 | (loop for (client . more) on stack |
| 36 | for top from y by stack-height |
| 37 | collect (list client (+ x master-width) top |
| 38 | (- width master-width) |
| 39 | (if more |
| 40 | stack-height |
| 41 | (- (+ y height) top)))))))) |
| 42 | |
| 43 | (defun retile (wm) |
| 44 | "Retile all the visible clients." |
| 45 | (let ((clients (remove :iconic (tile-order wm) |
| 46 | :key (lambda (client) |
| 47 | (wm-state (client-window client)))))) |
| 48 | (when clients |
| 49 | (multiple-value-bind (x y width height) |
| 50 | (work-area wm (first (screen-areas wm))) |
| 51 | (loop for (client cx cy cwidth cheight) |
| 52 | in (layout-clients wm clients x y width height) |
| 53 | do (configure-client |
| 54 | wm client :x cx :y cy |
| 55 | :width cwidth :height cheight)))))) |
| 56 | |
| 57 | (defmethod manage-client :after ((wm tiling-mixin) client) |
| 58 | (appendf (tile-order wm) (list client))) |
| 59 | |
| 60 | (defmethod unmanage-client :after ((wm tiling-mixin) client) |
| 61 | (removef (tile-order wm) client) |
| 62 | (retile wm)) |
| 63 | |
| 64 | (defmethod show-client :after ((wm tiling-mixin) client) |
| 65 | (retile wm)) |
| 66 | |
| 67 | (defmethod hide-client :after ((wm tiling-mixin) client) |
| 68 | (retile wm)) |
| 69 | |
| 70 | (defmethod screen-geometry-changed :after ((wm tiling-mixin)) |
| 71 | (retile wm)) |
| 72 | |
| 73 | ;; Deny other forms of placement. |
| 74 | (defmethod place-client ((wm tiling-mixin) client) |
| 75 | nil) |
| 76 | |
| 77 | ;; Deny clients asking to be placed too. |
| 78 | (defmethod handle-configure-request-geometry |
| 79 | ((wm tiling-mixin) client &key &allow-other-keys) |
| 80 | nil) |
| 81 | |
| 82 | (defun promote-command (wm client x y) |
| 83 | "Make the client under the pointer the master for master layouts. |
| 84 | Expects TILING-MIXIN. |
| 85 | Respects POINTER-KEYBINDS-MIXIN convention." |
| 86 | (declare (ignore x y)) |
| 87 | (when client |
| 88 | (setf (tile-order wm) |
| 89 | (cons client (remove client (tile-order wm)))) |
| 90 | (retile wm))) |