at commit a82c185d
| 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)))) |