Compare
3dcbd3de2e2a446dd8915d1e083263e2322af3ab..7587ba78f149af280764285a570bf51e34e905dd
Merge branch 'ray/readme-md-to-org' into autoseen
# By Raymond E. Pasco # Via Raymond E. Pasco * branch 'ray/readme-md-to-org': readme: convert from markdown to org
Merge Base <git-operations@merge-base.internal> · 2026-11-13 12:32 UTC
8 files changed,
+744
−3
- README.org
- clwm-ext.lisp
- clwm-ext/ewmh-maximize-mixin.lisp
- clwm-ext/ewmh-mixin.lisp
- clwm-ext/reparenting-mixin.lisp
- clwm-ext/tiling-mixin.lisp
- clwm.asd
- example-init.lisp
added README.org mode 100644
| @@ -0,0 +1,41 @@ | |||
| 1 | + | #+TITLE: Common Lisp Window Manager | |
| 2 | + | ||
| 3 | + | Extensible Common Lisp window manager. | |
| 4 | + | ||
| 5 | + | How extensible? It's made out of extensions to itself, which is the only | |
| 6 | + | way to ensure extensibility. | |
| 7 | + | ||
| 8 | + | The base WM class, =CLWM:WM=, implements a vaguely ICCCM-compliant | |
| 9 | + | window manager that does more or less nothing. All other functionality | |
| 10 | + | is implemented as extensions in =CLWM-EXT=; these are all mixin classes | |
| 11 | + | a final WM class should inherit from along with =WM=. Because there's no | |
| 12 | + | =DEFWM= macro (yet), you have to take a bit of care to have a valid | |
| 13 | + | class precedence list, since some mixins do inherit from others. | |
| 14 | + | ||
| 15 | + | To use it, define your own WM class in the =CLWM-USER= package, then | |
| 16 | + | invoke =RUN-WM= on it; this spawns a thread. You might want to use | |
| 17 | + | =XLIB:WITH-SERVER-GRABBED= if you plan to send any X events from the | |
| 18 | + | REPL. | |
| 19 | + | ||
| 20 | + | =sbcl --non-interactive --load binary.lisp= assumes you have Quicklisp; | |
| 21 | + | if you do, it builds a =clwm= binary with =CLWM-USER::MAIN= as the entry | |
| 22 | + | point. You can pass it a user init file as the only argument, this is | |
| 23 | + | loaded in the =CLWM-USER= package. You can invoke the =START-SLYNK= | |
| 24 | + | helper in this file to start a Slynk server and =M-x sly-connect= to | |
| 25 | + | your running WM. | |
| 26 | + | ||
| 27 | + | The running WM, if any, is in =*THE-WM*=. If you need a destructive | |
| 28 | + | restart from the REPL, there's =RESTART-WM=. Other special variables in | |
| 29 | + | =CLWM= turn the debugger back on or print various things for your | |
| 30 | + | hacking convenience. | |
| 31 | + | ||
| 32 | + | The example WM is a cwm-like, though not up to parity yet. Fans of other | |
| 33 | + | types of WM might be interested in the barebones =REPARENTING-MIXIN= and | |
| 34 | + | =TILING-MIXIN= extensions, but they aren't really usable as-is, they're | |
| 35 | + | just examples. | |
| 36 | + | ||
| 37 | + | The key thing which makes =clwm= possible is CLOS: if a program is made | |
| 38 | + | out of generic functions, every generic function is an extension point. | |
| 39 | + | Of course, the provider of the generic functions can arrange them to | |
| 40 | + | facilitate extensibility, and the architecture herein likely still has | |
| 41 | + | flaws. | |
modified clwm-ext.lisp
| @@ -60,4 +60,14 @@ | |||
| 60 | 60 | #:menu #:menu-prompt #:menu-items #:menu-input #:menu-selection | |
| 61 | 61 | #:menu-matches #:run-menu | |
| 62 | 62 | #:menu-font-name #:menu-colors | |
| 63 | - | #:exec-menu-command #:window-menu-command)) | |
| 63 | + | #:exec-menu-command #:window-menu-command | |
| 64 | + | ;; ewmh-mixin | |
| 65 | + | #:ewmh-mixin #:ewmh-supported | |
| 66 | + | ;; ewmh-maximize-mixin | |
| 67 | + | #:ewmh-maximize-mixin | |
| 68 | + | ;; example: reparenting mixin | |
| 69 | + | #:reparenting-mixin #:framed-client #:client-frame #:frame-font-name | |
| 70 | + | #:frame-colors | |
| 71 | + | ;; example: tiling mixin | |
| 72 | + | #:tiling-mixin #:tile-order #:master-fraction #:layout-clients | |
| 73 | + | #:retile #:promote-command)) | |
added clwm-ext/ewmh-maximize-mixin.lisp mode 100644
| @@ -0,0 +1,87 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; ewmh maximize mixin | |
| 4 | + | ;;;; experimental way to have mixins interact | |
| 5 | + | ||
| 6 | + | (in-package #:clwm-ext) | |
| 7 | + | ||
| 8 | + | (defclass ewmh-maximize-mixin (ewmh-mixin maximize-mixin) () | |
| 9 | + | (:documentation "Publish EWMH maximize states and maximize when | |
| 10 | + | requested by EWMH docks or the like.")) | |
| 11 | + | ||
| 12 | + | (defparameter *maximize-states* | |
| 13 | + | '((:horizontal . :_NET_WM_STATE_MAXIMIZED_HORZ) | |
| 14 | + | (:vertical . :_NET_WM_STATE_MAXIMIZED_VERT)) | |
| 15 | + | "Map our simple symbols to EWMH's long ones.") | |
| 16 | + | ||
| 17 | + | (defun axes-states (axes) | |
| 18 | + | "Helper to get the EWMH atoms for our states." | |
| 19 | + | (loop for (axis . atom) in *maximize-states* | |
| 20 | + | when (member axis axes) collect atom)) | |
| 21 | + | ||
| 22 | + | (defun state-axes (atoms) | |
| 23 | + | "Helper to get our states from EWMH atoms." | |
| 24 | + | (loop for (axis . atom) in *maximize-states* | |
| 25 | + | when (member atom atoms) collect axis)) | |
| 26 | + | ||
| 27 | + | (defun client-state-axes (client) | |
| 28 | + | "Helper to get the maximized state in _NET_WM_STATE." | |
| 29 | + | (state-axes (window-atoms (client-window client) :_NET_WM_STATE))) | |
| 30 | + | ||
| 31 | + | (defmethod ewmh-supported append ((wm ewmh-maximize-mixin)) | |
| 32 | + | (axes-states '(:horizontal :vertical))) | |
| 33 | + | ||
| 34 | + | (defmethod maximize-state-changed :after | |
| 35 | + | ((wm ewmh-maximize-mixin) client) | |
| 36 | + | (update-window-atoms | |
| 37 | + | (client-window client) :_NET_WM_STATE | |
| 38 | + | (lambda (states) | |
| 39 | + | (append (set-difference states (axes-states '(:horizontal | |
| 40 | + | :vertical))) | |
| 41 | + | (axes-states (maximized-axes client)))))) | |
| 42 | + | ||
| 43 | + | ;; hack to pick up already-maximized windows on startup | |
| 44 | + | ;; we don't know any restore geometry though | |
| 45 | + | (defvar *adopting* nil) | |
| 46 | + | ||
| 47 | + | (defun note-maximized (wm client axes) | |
| 48 | + | "Helper to note a client as maximized when we don't know any restore | |
| 49 | + | geometry, so we just use its current geometry." | |
| 50 | + | (multiple-value-call #'remember-axes client axes (client-geometry wm client)) | |
| 51 | + | (when axes | |
| 52 | + | (maximize-state-changed wm client))) | |
| 53 | + | ||
| 54 | + | (defmethod manage-all-windows :around ((wm ewmh-maximize-mixin)) | |
| 55 | + | (let ((*adopting* t)) | |
| 56 | + | (call-next-method))) | |
| 57 | + | ||
| 58 | + | (defmethod manage-client :after ((wm ewmh-maximize-mixin) client) | |
| 59 | + | (when *adopting* | |
| 60 | + | (note-maximized wm client (client-state-axes client)))) | |
| 61 | + | ||
| 62 | + | (defmethod place-client :after ((wm ewmh-maximize-mixin) client) | |
| 63 | + | (when-let ((axes (client-state-axes client))) | |
| 64 | + | (maximize-axes wm client axes))) | |
| 65 | + | ||
| 66 | + | (defmethod handle-client-event | |
| 67 | + | ((wm ewmh-maximize-mixin) client (event-key (eql :client-message)) | |
| 68 | + | &key type data) | |
| 69 | + | (when (eql type :_NET_WM_STATE) | |
| 70 | + | (let* ((display (display wm)) | |
| 71 | + | (axes (state-axes | |
| 72 | + | (loop for id across (subseq data 1 3) | |
| 73 | + | unless (zerop id) | |
| 74 | + | collect (xlib:atom-name display id)))) | |
| 75 | + | (maximized (maximized-axes client))) | |
| 76 | + | (flet ((maximize (axes) | |
| 77 | + | (maximize-axes wm client | |
| 78 | + | (set-difference axes maximized))) | |
| 79 | + | (restore (axes) | |
| 80 | + | (restore-axes wm client | |
| 81 | + | (intersection axes maximized)))) | |
| 82 | + | (case (aref data 0) | |
| 83 | + | (0 (restore axes)) | |
| 84 | + | (1 (maximize axes)) | |
| 85 | + | (2 (restore axes) | |
| 86 | + | (maximize axes)))))) | |
| 87 | + | (call-next-method)) | |
added clwm-ext/ewmh-mixin.lisp mode 100644
| @@ -0,0 +1,278 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; EWMH support | |
| 4 | + | ;;;; todo: split into more mixins, don't hardcode 1 desktop | |
| 5 | + | ||
| 6 | + | (in-package #:clwm-ext) | |
| 7 | + | ||
| 8 | + | (defclass ewmh-mixin (screen-geometry-mixin | |
| 9 | + | ignored-clients-mixin | |
| 10 | + | focus-tracking-mixin) | |
| 11 | + | ((check-window :initform nil :accessor ewmh-check-window | |
| 12 | + | :documentation | |
| 13 | + | "_NET_SUPPORTING_WM_CHECK window.") | |
| 14 | + | (client-order :initform '() :accessor ewmh-client-order | |
| 15 | + | :documentation | |
| 16 | + | "Clients in the order they were managed.") | |
| 17 | + | (docks :initform '() :accessor ewmh-docks | |
| 18 | + | :documentation "Dock windows we're not managing.")) | |
| 19 | + | (:documentation | |
| 20 | + | "Partial EWMH support for pagers, docks, taskbars, &c.")) | |
| 21 | + | ||
| 22 | + | (defgeneric ewmh-supported (wm) | |
| 23 | + | (:documentation "The EWMH features to advertise support for.") | |
| 24 | + | (:method-combination append)) | |
| 25 | + | ||
| 26 | + | (defmethod ewmh-supported append ((wm ewmh-mixin)) | |
| 27 | + | '(:_NET_SUPPORTED :_NET_SUPPORTING_WM_CHECK :_NET_WM_NAME | |
| 28 | + | :_NET_CLIENT_LIST :_NET_CLIENT_LIST_STACKING :_NET_ACTIVE_WINDOW | |
| 29 | + | :_NET_NUMBER_OF_DESKTOPS :_NET_CURRENT_DESKTOP :_NET_DESKTOP_NAMES | |
| 30 | + | :_NET_DESKTOP_GEOMETRY :_NET_DESKTOP_VIEWPORT :_NET_WORKAREA | |
| 31 | + | :_NET_WM_DESKTOP :_NET_WM_STATE :_NET_WM_STATE_HIDDEN | |
| 32 | + | :_NET_CLOSE_WINDOW :_NET_WM_WINDOW_TYPE :_NET_WM_WINDOW_TYPE_DOCK | |
| 33 | + | :_NET_WM_STRUT :_NET_WM_STRUT_PARTIAL)) | |
| 34 | + | ||
| 35 | + | ;; todo: check mixin-accuracy | |
| 36 | + | (defparameter *ewmh-root-properties* | |
| 37 | + | '(:_NET_SUPPORTED :_NET_SUPPORTING_WM_CHECK :_NET_CLIENT_LIST | |
| 38 | + | :_NET_CLIENT_LIST_STACKING :_NET_ACTIVE_WINDOW | |
| 39 | + | :_NET_NUMBER_OF_DESKTOPS :_NET_CURRENT_DESKTOP :_NET_DESKTOP_NAMES | |
| 40 | + | :_NET_DESKTOP_GEOMETRY :_NET_DESKTOP_VIEWPORT :_NET_WORKAREA) | |
| 41 | + | "Root properties to clear on exit.") | |
| 42 | + | ||
| 43 | + | (defun set-cardinals (window property values) | |
| 44 | + | "Helper to set window cardinals." | |
| 45 | + | (xlib:change-property window property values :CARDINAL 32)) | |
| 46 | + | ||
| 47 | + | (defun set-windows (window property windows) | |
| 48 | + | "Helper to set window associated windows." | |
| 49 | + | (xlib:change-property window property | |
| 50 | + | (mapcar #'xlib:window-id windows) | |
| 51 | + | :WINDOW 32)) | |
| 52 | + | ||
| 53 | + | ;; todo: move utf8 helpers to their own thing (fonts?) | |
| 54 | + | ;; todo: non sb-ext? | |
| 55 | + | (defun utf8-octets (string &key null-terminate) | |
| 56 | + | "Helper to coerce a string to UTF-8 octets." | |
| 57 | + | (coerce (sb-ext:string-to-octets string | |
| 58 | + | :external-format :utf-8 | |
| 59 | + | :null-terminate null-terminate) | |
| 60 | + | 'list)) | |
| 61 | + | ||
| 62 | + | (defun set-utf8-string (window property string) | |
| 63 | + | "Helper to set a property to a UTF-8 string." | |
| 64 | + | (xlib:change-property window property | |
| 65 | + | (utf8-octets string) :UTF8_STRING 8)) | |
| 66 | + | ||
| 67 | + | (defun set-utf8-strings (window property strings) | |
| 68 | + | "Helper to set a property to a list of UTF-8 strings." | |
| 69 | + | (xlib:change-property window property | |
| 70 | + | (loop for string in strings | |
| 71 | + | append (utf8-octets string | |
| 72 | + | :null-terminate t)) | |
| 73 | + | :UTF8_STRING 8)) | |
| 74 | + | ||
| 75 | + | (defun window-atoms (window property) | |
| 76 | + | "Helper to get atom list properties." | |
| 77 | + | (let ((display (xlib:window-display window))) | |
| 78 | + | (mapcar (lambda (id) (xlib:atom-name display id)) | |
| 79 | + | (xlib:get-property window property :type :ATOM)))) | |
| 80 | + | ||
| 81 | + | (defun set-window-atoms (window property atoms) | |
| 82 | + | "Helper to set atom list properties." | |
| 83 | + | (let ((display (xlib:window-display window))) | |
| 84 | + | (xlib:change-property window property | |
| 85 | + | (mapcar (lambda (atom) | |
| 86 | + | (xlib:intern-atom display atom)) | |
| 87 | + | atoms) | |
| 88 | + | :ATOM 32))) | |
| 89 | + | ||
| 90 | + | (defun update-window-atoms (window property function) | |
| 91 | + | "Call FUNCTION to update an atom list property." | |
| 92 | + | (set-window-atoms window property | |
| 93 | + | (funcall function (window-atoms window property)))) | |
| 94 | + | ||
| 95 | + | (defun update-client-lists (wm) | |
| 96 | + | "Update the EWMH _NET_CLIENT_LIST and _NET_CLIENT_LIST_STACKING." | |
| 97 | + | (let ((stacking (loop for window in (xlib:query-tree (root wm)) | |
| 98 | + | for client = (find-client wm window) | |
| 99 | + | when client collect (client-window client)))) | |
| 100 | + | (set-windows (root wm) :_NET_CLIENT_LIST | |
| 101 | + | (mapcar #'client-window (ewmh-client-order wm))) | |
| 102 | + | (set-windows (root wm) :_NET_CLIENT_LIST_STACKING | |
| 103 | + | (remove-duplicates stacking :test #'xlib:window-equal | |
| 104 | + | :from-end t)))) | |
| 105 | + | ||
| 106 | + | (defun update-active-window (wm) | |
| 107 | + | "Update _NET_ACTIVE_WINDOW with the focused client." | |
| 108 | + | (let ((client (focused-client wm))) | |
| 109 | + | (xlib:change-property (root wm) :_NET_ACTIVE_WINDOW | |
| 110 | + | (list | |
| 111 | + | (if client | |
| 112 | + | (xlib:window-id (client-window client)) | |
| 113 | + | 0)) | |
| 114 | + | :WINDOW 32))) | |
| 115 | + | ||
| 116 | + | (defmethod initialize-wm :after ((wm ewmh-mixin)) | |
| 117 | + | (let* ((root (root wm)) | |
| 118 | + | (screen (screen wm)) | |
| 119 | + | (width (xlib:screen-width screen)) | |
| 120 | + | (height (xlib:screen-height screen)) | |
| 121 | + | (check (xlib:create-window :parent root :x -1 :y -1 | |
| 122 | + | :width 1 :height 1 | |
| 123 | + | :override-redirect :on))) | |
| 124 | + | (setf (ewmh-check-window wm) check) | |
| 125 | + | (set-windows check :_NET_SUPPORTING_WM_CHECK (list check)) | |
| 126 | + | (set-utf8-string check :_NET_WM_NAME "clwm") | |
| 127 | + | (set-windows root :_NET_SUPPORTING_WM_CHECK (list check)) | |
| 128 | + | (set-window-atoms root :_NET_SUPPORTED (ewmh-supported wm)) | |
| 129 | + | (set-cardinals root :_NET_NUMBER_OF_DESKTOPS '(1)) | |
| 130 | + | (set-cardinals root :_NET_CURRENT_DESKTOP '(0)) | |
| 131 | + | (set-utf8-strings root :_NET_DESKTOP_NAMES '("1")) | |
| 132 | + | (set-cardinals root :_NET_DESKTOP_GEOMETRY (list width height)) | |
| 133 | + | (set-cardinals root :_NET_DESKTOP_VIEWPORT '(0 0)) | |
| 134 | + | (update-docks wm) | |
| 135 | + | (update-client-lists wm) | |
| 136 | + | (update-active-window wm))) | |
| 137 | + | ||
| 138 | + | (defun remove-ewmh (wm) | |
| 139 | + | "Helper to remove EWMH on uninitalize or shutdown." | |
| 140 | + | (when-let ((check (shiftf (ewmh-check-window wm) nil))) | |
| 141 | + | (dolist (property *ewmh-root-properties*) | |
| 142 | + | (xlib:delete-property (root wm) property)) | |
| 143 | + | (xlib:destroy-window check))) | |
| 144 | + | ||
| 145 | + | (defmethod uninitialize-wm :after ((wm ewmh-mixin)) | |
| 146 | + | (remove-ewmh wm)) | |
| 147 | + | ||
| 148 | + | (defmethod shutdown-wm :before ((wm ewmh-mixin)) | |
| 149 | + | (remove-ewmh wm)) | |
| 150 | + | ||
| 151 | + | (defmethod manage-client :after ((wm ewmh-mixin) client) | |
| 152 | + | (appendf (ewmh-client-order wm) (list client)) | |
| 153 | + | (set-cardinals (client-window client) :_NET_WM_DESKTOP '(0)) | |
| 154 | + | (update-client-lists wm)) | |
| 155 | + | ||
| 156 | + | (defmethod unmanage-client :after ((wm ewmh-mixin) client) | |
| 157 | + | (removef (ewmh-client-order wm) client) | |
| 158 | + | (update-client-lists wm)) | |
| 159 | + | ||
| 160 | + | (defmethod withdraw-client :before ((wm ewmh-mixin) client) | |
| 161 | + | (xlib:delete-property (client-window client) :_NET_WM_STATE) | |
| 162 | + | (xlib:delete-property (client-window client) :_NET_WM_DESKTOP)) | |
| 163 | + | ||
| 164 | + | (defmethod configure-client :after ((wm ewmh-mixin) client | |
| 165 | + | &key stack-mode &allow-other-keys) | |
| 166 | + | (when stack-mode | |
| 167 | + | (raise-docks wm) | |
| 168 | + | (update-client-lists wm))) | |
| 169 | + | ||
| 170 | + | (defmethod show-client :after ((wm ewmh-mixin) client) | |
| 171 | + | (raise-docks wm) | |
| 172 | + | (update-window-atoms (client-window client) :_NET_WM_STATE | |
| 173 | + | (lambda (states) | |
| 174 | + | (remove :_NET_WM_STATE_HIDDEN states)))) | |
| 175 | + | ||
| 176 | + | (defmethod hide-client :after ((wm ewmh-mixin) client) | |
| 177 | + | (update-window-atoms (client-window client) :_NET_WM_STATE | |
| 178 | + | (lambda (states) | |
| 179 | + | (adjoin :_NET_WM_STATE_HIDDEN states)))) | |
| 180 | + | ||
| 181 | + | (defmethod (setf focused-client) :after (client (wm ewmh-mixin)) | |
| 182 | + | (declare (ignore client)) | |
| 183 | + | (update-active-window wm)) | |
| 184 | + | ||
| 185 | + | (defmethod handle-client-event | |
| 186 | + | ((wm ewmh-mixin) client (event-key (eql :client-message)) | |
| 187 | + | &key type) | |
| 188 | + | (case type | |
| 189 | + | (:_NET_ACTIVE_WINDOW | |
| 190 | + | (show-client wm client) | |
| 191 | + | (configure-client wm client :stack-mode :above) | |
| 192 | + | (focus-client wm client)) | |
| 193 | + | (:_NET_CLOSE_WINDOW | |
| 194 | + | (close-client wm client)) | |
| 195 | + | (t (call-next-method)))) | |
| 196 | + | ||
| 197 | + | (defun dock-p (window) | |
| 198 | + | "Helper to check if a window is a dock (if it vanishes before we can | |
| 199 | + | ask, say no)." | |
| 200 | + | (handler-case (member :_NET_WM_WINDOW_TYPE_DOCK | |
| 201 | + | (window-atoms window :_NET_WM_WINDOW_TYPE)) | |
| 202 | + | (xlib:window-error () nil))) | |
| 203 | + | ||
| 204 | + | (defmethod ignore-window-p or ((wm ewmh-mixin) window) | |
| 205 | + | (dock-p window)) | |
| 206 | + | ||
| 207 | + | (defun dock-strut (window) | |
| 208 | + | "Helper to get a dock window's reserved l/r/t/b strut, or NIL | |
| 209 | + | if we can't." | |
| 210 | + | (let ((strut (or (xlib:get-property window :_NET_WM_STRUT_PARTIAL | |
| 211 | + | :type :CARDINAL) | |
| 212 | + | (xlib:get-property window :_NET_WM_STRUT | |
| 213 | + | :type :CARDINAL)))) | |
| 214 | + | (and (>= (length strut) 4) | |
| 215 | + | (subseq strut 0 4)))) | |
| 216 | + | ||
| 217 | + | (defmethod reserved-edges append ((wm ewmh-mixin)) | |
| 218 | + | (remove nil (mapcar #'dock-strut (ewmh-docks wm)))) | |
| 219 | + | ||
| 220 | + | (defun raise-docks (wm) | |
| 221 | + | "Helper to raise dock windows." | |
| 222 | + | (dolist (dock (ewmh-docks wm)) | |
| 223 | + | (setf (xlib:window-priority dock) :above))) | |
| 224 | + | ||
| 225 | + | (defun update-docks (wm) | |
| 226 | + | "Helper to update our knowledge of docks and grab masks to | |
| 227 | + | get updates on them." | |
| 228 | + | (setf (ewmh-docks wm) | |
| 229 | + | (loop for window in (xlib:query-tree (root wm)) | |
| 230 | + | when (and (eql (xlib:window-map-state window) :viewable) | |
| 231 | + | (not (find-client wm window)) | |
| 232 | + | (dock-p window)) | |
| 233 | + | collect window)) | |
| 234 | + | (dolist (dock (ewmh-docks wm)) | |
| 235 | + | (setf (xlib:window-event-mask dock) | |
| 236 | + | (xlib:make-event-mask :property-change))) | |
| 237 | + | (raise-docks wm) | |
| 238 | + | (screen-geometry-changed wm)) | |
| 239 | + | ||
| 240 | + | (defun tracked-dock-p (wm window) | |
| 241 | + | "Helper to check if a window is one of the docks we know about." | |
| 242 | + | (member window (ewmh-docks wm) :test #'xlib:window-equal)) | |
| 243 | + | ||
| 244 | + | (defmethod screen-geometry-changed :after ((wm ewmh-mixin)) | |
| 245 | + | (multiple-value-bind (x y width height) | |
| 246 | + | (work-area wm (first (screen-areas wm))) | |
| 247 | + | (set-cardinals (root wm) :_NET_WORKAREA (list x y width height)))) | |
| 248 | + | ||
| 249 | + | ;;; steal all dock events | |
| 250 | + | ||
| 251 | + | (defmethod handle-event | |
| 252 | + | ((wm ewmh-mixin) (event-key (eql :map-notify)) &key window) | |
| 253 | + | (unless (or (find-client wm window) (tracked-dock-p wm window)) | |
| 254 | + | (when (dock-p window) | |
| 255 | + | (update-docks wm))) | |
| 256 | + | (call-next-method)) | |
| 257 | + | ||
| 258 | + | (defmethod handle-event | |
| 259 | + | ((wm ewmh-mixin) (event-key (eql :unmap-notify)) &key window) | |
| 260 | + | (when (tracked-dock-p wm window) | |
| 261 | + | (update-docks wm)) | |
| 262 | + | (call-next-method)) | |
| 263 | + | ||
| 264 | + | (defmethod handle-event | |
| 265 | + | ((wm ewmh-mixin) (event-key (eql :destroy-notify)) &key window) | |
| 266 | + | (when (tracked-dock-p wm window) | |
| 267 | + | (removef (ewmh-docks wm) window :test #'xlib:window-equal) | |
| 268 | + | (raise-docks wm) | |
| 269 | + | (screen-geometry-changed wm)) | |
| 270 | + | (call-next-method)) | |
| 271 | + | ||
| 272 | + | (defmethod handle-event | |
| 273 | + | ((wm ewmh-mixin) (event-key (eql :property-notify)) | |
| 274 | + | &key window atom) | |
| 275 | + | (when (and (member atom '(:_NET_WM_STRUT :_NET_WM_STRUT_PARTIAL)) | |
| 276 | + | (tracked-dock-p wm window)) | |
| 277 | + | (screen-geometry-changed wm)) | |
| 278 | + | (call-next-method)) | |
added clwm-ext/reparenting-mixin.lisp mode 100644
| @@ -0,0 +1,229 @@ | |||
| 1 | + | ;;;; common lisp window manager | |
| 2 | + | ;;;; | |
| 3 | + | ;;;; an EXAMPLE reparenting mixin | |
| 4 | + | ;;;; not suitable for real use | |
| 5 | + | ||
| 6 | + | (in-package #:clwm-ext) | |
| 7 | + | ||
| 8 | + | (defclass reparenting-mixin (interaction-mixin) | |
| 9 | + | ((font :initform nil :accessor frame-font) | |
| 10 | + | (gcontext :initform nil :accessor frame-gcontext)) | |
| 11 | + | (:documentation | |
| 12 | + | "Draw frame windows around clients.")) | |
| 13 | + | ||
| 14 | + | (defclass framed-client () | |
| 15 | + | ((frame :initform nil :accessor client-frame | |
| 16 | + | :documentation "The frame window the client's window is in.") | |
| 17 | + | (original-border :initform 0 :accessor client-original-border | |
| 18 | + | :documentation | |
| 19 | + | "The client window's border width before framing.")) | |
| 20 | + | (:documentation "A client in a frame window.")) | |
| 21 | + | ||
| 22 | + | (defmethod client-mixins append ((wm reparenting-mixin)) | |
| 23 | + | '(framed-client)) | |
| 24 | + | ||
| 25 | + | (defgeneric frame-font-name (wm) | |
| 26 | + | (:documentation "The core X font titles are drawn in.") | |
| 27 | + | (:method ((wm reparenting-mixin)) "fixed")) | |
| 28 | + | (defgeneric frame-colors (wm) | |
| 29 | + | (:documentation | |
| 30 | + | "Color names for frames: title bar, text, frame border, frame.") | |
| 31 | + | (:method ((wm reparenting-mixin)) | |
| 32 | + | (values "#336699" "white" "black" "#cccccc"))) | |
| 33 | + | ||
| 34 | + | ;;; sizes | |
| 35 | + | ||
| 36 | + | ;; defconstant because this is just an example | |
| 37 | + | (defconstant +frame-border+ 1 | |
| 38 | + | "The frame window's X border width.") | |
| 39 | + | (defconstant +frame-margin+ 4 | |
| 40 | + | "The frame's edges beside and below the client.") | |
| 41 | + | ||
| 42 | + | (defun ensure-frame-resources (wm) | |
| 43 | + | "Helper to set up the title font and the graphics context | |
| 44 | + | for drawing frames." | |
| 45 | + | (unless (frame-gcontext wm) | |
| 46 | + | (setf (frame-font wm) (xlib:open-font (display wm) | |
| 47 | + | (frame-font-name wm)) | |
| 48 | + | (frame-gcontext wm) (xlib:create-gcontext | |
| 49 | + | :drawable (root wm) | |
| 50 | + | :font (frame-font wm))))) | |
| 51 | + | ||
| 52 | + | (defun title-height (wm) | |
| 53 | + | "Helper to figure out the height of the window title." | |
| 54 | + | (ensure-frame-resources wm) | |
| 55 | + | (+ (xlib:font-ascent (frame-font wm)) | |
| 56 | + | (xlib:font-descent (frame-font wm)) 4)) | |
| 57 | + | ||
| 58 | + | (defmethod manage-client :before ((wm reparenting-mixin) client) | |
| 59 | + | (let* ((window (client-window client)) | |
| 60 | + | (title (title-height wm))) | |
| 61 | + | (multiple-value-bind | |
| 62 | + | (title-color text-color border-color background) | |
| 63 | + | (frame-colors wm) | |
| 64 | + | (declare (ignore title-color text-color)) | |
| 65 | + | (xlib:with-state (window) | |
| 66 | + | (let ((frame | |
| 67 | + | (xlib:create-window | |
| 68 | + | :parent (root wm) | |
| 69 | + | :x (xlib:drawable-x window) | |
| 70 | + | :y (xlib:drawable-y window) | |
| 71 | + | :width (+ (xlib:drawable-width window) | |
| 72 | + | (* 2 +frame-margin+)) | |
| 73 | + | :height (+ (xlib:drawable-height window) | |
| 74 | + | title | |
| 75 | + | +frame-margin+) | |
| 76 | + | :border-width +frame-border+ | |
| 77 | + | :border (color wm border-color) | |
| 78 | + | :background (color wm background) | |
| 79 | + | :override-redirect :on | |
| 80 | + | :event-mask (xlib:make-event-mask | |
| 81 | + | :substructure-redirect | |
| 82 | + | :substructure-notify | |
| 83 | + | :exposure :enter-window | |
| 84 | + | :button-press :button-release | |
| 85 | + | :button-motion)))) | |
| 86 | + | (setf (client-frame client) frame | |
| 87 | + | (client-original-border client) | |
| 88 | + | (xlib:drawable-border-width window)) | |
| 89 | + | (unless (eql (xlib:window-map-state window) :unmapped) | |
| 90 | + | (incf (pending-unmaps client))) | |
| 91 | + | (setf (xlib:drawable-border-width window) 0) | |
| 92 | + | (xlib:reparent-window window frame +frame-margin+ title) | |
| 93 | + | ;; save the original window | |
| 94 | + | (xlib:add-to-save-set window)))))) | |
| 95 | + | ||
| 96 | + | (defmethod client-windows append ((wm reparenting-mixin) client) | |
| 97 | + | (list (client-frame client))) | |
| 98 | + | ||
| 99 | + | (defmethod unmanage-client :after ((wm reparenting-mixin) client) | |
| 100 | + | (let ((window (client-window client)) | |
| 101 | + | (frame (client-frame client))) | |
| 102 | + | (xlib:with-state (frame) | |
| 103 | + | (xlib:reparent-window window (root wm) | |
| 104 | + | (xlib:drawable-x frame) | |
| 105 | + | (xlib:drawable-y frame))) | |
| 106 | + | (setf (xlib:drawable-border-width window) | |
| 107 | + | (client-original-border client)) | |
| 108 | + | (xlib:remove-from-save-set window) | |
| 109 | + | (xlib:destroy-window frame))) | |
| 110 | + | ||
| 111 | + | (defmethod show-client :after ((wm reparenting-mixin) client) | |
| 112 | + | (xlib:map-window (client-frame client))) | |
| 113 | + | ||
| 114 | + | (defmethod hide-client :after ((wm reparenting-mixin) client) | |
| 115 | + | (xlib:unmap-window (client-frame client))) | |
| 116 | + | ||
| 117 | + | ;;; use frame geometry for everything that cares about our geometry | |
| 118 | + | ||
| 119 | + | (defmethod client-geometry ((wm reparenting-mixin) client) | |
| 120 | + | (let ((frame (client-frame client))) | |
| 121 | + | (xlib:with-state (frame) | |
| 122 | + | (values (xlib:drawable-x frame) (xlib:drawable-y frame) | |
| 123 | + | (+ (xlib:drawable-width frame) (* 2 +frame-border+)) | |
| 124 | + | (+ (xlib:drawable-height frame) (* 2 +frame-border+)))))) | |
| 125 | + | ||
| 126 | + | (defmethod client-decoration-extents ((wm reparenting-mixin) client) | |
| 127 | + | (let ((side (+ +frame-border+ +frame-margin+))) | |
| 128 | + | (values side (+ +frame-border+ (title-height wm)) side side))) | |
| 129 | + | ||
| 130 | + | (defmethod apply-client-geometry | |
| 131 | + | ((wm reparenting-mixin) client | |
| 132 | + | &key x y width height stack-mode sibling) | |
| 133 | + | (flet ((inside (size thickness) | |
| 134 | + | (and size (max 1 (- size thickness))))) | |
| 135 | + | (configure-window (client-frame client) | |
| 136 | + | :x x :y y | |
| 137 | + | :width (inside width (* 2 +frame-border+)) | |
| 138 | + | :height (inside height (* 2 +frame-border+)) | |
| 139 | + | :stack-mode stack-mode | |
| 140 | + | :sibling (and sibling (client-frame sibling))) | |
| 141 | + | (multiple-value-bind (left top right bottom) | |
| 142 | + | (client-decoration-extents wm client) | |
| 143 | + | (configure-window (client-window client) | |
| 144 | + | :width (inside width (+ left right)) | |
| 145 | + | :height (inside height (+ top bottom)))))) | |
| 146 | + | ||
| 147 | + | ;; moving the frame doesn't move the client in its parent, so X won't | |
| 148 | + | ;; tell it on its own; ICCCM says this is our responsibility | |
| 149 | + | (defmethod apply-client-geometry :after ((wm reparenting-mixin) client | |
| 150 | + | &key x y &allow-other-keys) | |
| 151 | + | (when (or x y) | |
| 152 | + | (send-configure-notify wm client))) | |
| 153 | + | ||
| 154 | + | ;;; actually draw very simple frames | |
| 155 | + | ;;; todo: define some dumb widgets to avoid this spaghetti | |
| 156 | + | ||
| 157 | + | (defun draw-frame (wm client) | |
| 158 | + | "Draw a client's title bar: its name, and a close box at the right. | |
| 159 | + | Expects REPARENTING-MIXIN." | |
| 160 | + | (ensure-frame-resources wm) | |
| 161 | + | (let* ((frame (client-frame client)) | |
| 162 | + | (gcontext (frame-gcontext wm)) | |
| 163 | + | (font (frame-font wm)) | |
| 164 | + | (title (title-height wm)) | |
| 165 | + | (width (xlib:drawable-width frame)) | |
| 166 | + | (name (drawable-text | |
| 167 | + | (or (xlib:wm-name (client-window client)) "")))) | |
| 168 | + | (multiple-value-bind (title-color text-color) (frame-colors wm) | |
| 169 | + | (setf (xlib:gcontext-foreground gcontext) (color wm title-color)) | |
| 170 | + | (xlib:draw-rectangle frame gcontext 0 0 width title t) | |
| 171 | + | (setf (xlib:gcontext-foreground gcontext) (color wm text-color) | |
| 172 | + | (xlib:gcontext-background gcontext) (color wm title-color)) | |
| 173 | + | (xlib:draw-glyphs frame gcontext +frame-margin+ | |
| 174 | + | (+ 2 (xlib:font-ascent font)) name) | |
| 175 | + | ;; the close box: a square with an X in it | |
| 176 | + | (let* ((size (- title 6)) | |
| 177 | + | (left (- width size 3)) | |
| 178 | + | (top 3)) | |
| 179 | + | (xlib:draw-rectangle frame gcontext left top size size) | |
| 180 | + | (xlib:draw-line | |
| 181 | + | frame gcontext left top (+ left size) (+ top size)) | |
| 182 | + | (xlib:draw-line | |
| 183 | + | frame gcontext left (+ top size) (+ left size) top))))) | |
| 184 | + | ||
| 185 | + | (defun close-box-p (wm client x y) | |
| 186 | + | "Helper to check if a point in a client's frame is in its close box." | |
| 187 | + | (let ((title (title-height wm))) | |
| 188 | + | (and (< y title) | |
| 189 | + | (>= x | |
| 190 | + | (- (xlib:drawable-width (client-frame client)) title))))) | |
| 191 | + | ||
| 192 | + | ;;; handle events on frames | |
| 193 | + | ||
| 194 | + | (defun frame-event-p (client window) | |
| 195 | + | (and window (xlib:window-equal window (client-frame client)))) | |
| 196 | + | ||
| 197 | + | (defmethod handle-client-event | |
| 198 | + | ((wm reparenting-mixin) client (event-key (eql :exposure)) | |
| 199 | + | &key window count) | |
| 200 | + | (if (frame-event-p client window) | |
| 201 | + | (when (zerop count) | |
| 202 | + | (draw-frame wm client)) | |
| 203 | + | (call-next-method))) | |
| 204 | + | ||
| 205 | + | (defmethod handle-client-event | |
| 206 | + | ((wm reparenting-mixin) client (event-key (eql :property-notify)) | |
| 207 | + | &key atom) | |
| 208 | + | (when (member atom '(:WM_NAME :_NET_WM_NAME)) | |
| 209 | + | (draw-frame wm client)) | |
| 210 | + | (call-next-method)) | |
| 211 | + | ||
| 212 | + | ;; close on close button click, drag otherwise | |
| 213 | + | (defmethod handle-client-event | |
| 214 | + | ((wm reparenting-mixin) client (event-key (eql :button-press)) | |
| 215 | + | &key window child code x y root-x root-y) | |
| 216 | + | (if (and (frame-event-p client window) (null child) (= code 1)) | |
| 217 | + | (cond ((close-box-p wm client x y) | |
| 218 | + | (close-client wm client)) | |
| 219 | + | (t | |
| 220 | + | (let ((function | |
| 221 | + | (if (< y (title-height wm)) | |
| 222 | + | (drag-move wm client root-x root-y) | |
| 223 | + | (drag-resize wm client root-x root-y)))) | |
| 224 | + | (start-interaction | |
| 225 | + | wm | |
| 226 | + | (make-instance 'drag | |
| 227 | + | :client client | |
| 228 | + | :function function))))) | |
| 229 | + | (call-next-method))) | |
added clwm-ext/tiling-mixin.lisp mode 100644
| @@ -0,0 +1,90 @@ | |||
| 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))) | |
modified clwm.asd
| @@ -30,5 +30,9 @@ | |||
| 30 | 30 | (:file "pointer-placement-mixin") | |
| 31 | 31 | (:file "maximize-mixin") | |
| 32 | 32 | (:file "drawing") | |
| 33 | - | (:file "modal-commands-mixin"))) | |
| 33 | + | (:file "modal-commands-mixin") | |
| 34 | + | (:file "ewmh-mixin") | |
| 35 | + | (:file "ewmh-maximize-mixin") | |
| 36 | + | (:file "reparenting-mixin") | |
| 37 | + | (:file "tiling-mixin"))) | |
| 34 | 38 | (:file "clwm-user"))) | |
modified example-init.lisp
| @@ -4,7 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | 5 | (in-package #:clwm-user) | |
| 6 | 6 | ||
| 7 | - | (defclass my-wm (modal-commands-mixin | |
| 7 | + | (defclass my-wm (ewmh-maximize-mixin | |
| 8 | + | ewmh-mixin | |
| 9 | + | modal-commands-mixin | |
| 8 | 10 | maximize-mixin | |
| 9 | 11 | pointer-placement-mixin | |
| 10 | 12 | screen-geometry-mixin | |