at commit 01002255
| 1 | ;;;; common lisp window manager |
| 2 | ;;;; |
| 3 | ;;;; mouse bindings |
| 4 | ;;;; the convention is (lambda (wm client x y) ...) |
| 5 | ;;;; possibly returning a (lambda (x y) ...) |
| 6 | ;;;; which is called on every move until the interaction ends |
| 7 | |
| 8 | (in-package #:clwm-ext) |
| 9 | |
| 10 | (defclass mousebinds-mixin (interaction-mixin) () |
| 11 | (:documentation "Buttons (and modifiers) grabbed on the root |
| 12 | to execute forms.")) |
| 13 | |
| 14 | (defclass drag (interaction) |
| 15 | ((function :initarg :function :reader drag-function)) |
| 16 | (:documentation "Call a function on pointer motion until release.")) |
| 17 | |
| 18 | (defgeneric mouse-bindings (wm) |
| 19 | (:documentation "Bindings of (modifiers... button) to functions.") |
| 20 | (:method-combination append)) |
| 21 | (defgeneric grab-buttons (wm) |
| 22 | (:documentation |
| 23 | "Grab the buttons of the mouse bindings on the root.")) |
| 24 | |
| 25 | (defmethod mouse-bindings append ((wm mousebinds-mixin)) '()) |
| 26 | |
| 27 | (defmethod grab-buttons ((wm mousebinds-mixin)) |
| 28 | (xlib:ungrab-button (root wm) :any :modifiers :any) |
| 29 | (loop for (spec) in (mouse-bindings wm) |
| 30 | do (dolist (mask (binding-grab-masks spec)) |
| 31 | (xlib:grab-button (root wm) (binding-key spec) |
| 32 | '(:button-press :button-release |
| 33 | :pointer-motion) |
| 34 | :modifiers mask)))) |
| 35 | |
| 36 | (defmethod initialize-wm :after ((wm mousebinds-mixin)) |
| 37 | (grab-buttons wm)) |
| 38 | |
| 39 | (defmethod handle-client-event |
| 40 | ((wm mousebinds-mixin) client (event-key (eql :button-press)) |
| 41 | &key code state root-x root-y) |
| 42 | (let ((command (find-binding (mouse-bindings wm) state code))) |
| 43 | (if command |
| 44 | (let ((function (funcall command wm client root-x root-y))) |
| 45 | (when (functionp function) |
| 46 | (start-interaction |
| 47 | wm |
| 48 | (make-instance 'drag :client client :function function)))) |
| 49 | (call-next-method)))) |
| 50 | |
| 51 | (defmethod interaction-event |
| 52 | ((wm interaction-mixin) (drag drag) (event-key (eql :motion-notify)) |
| 53 | &key root-x root-y) |
| 54 | (funcall (drag-function drag) root-x root-y) |
| 55 | t) |
| 56 | |
| 57 | (defmethod interaction-event |
| 58 | ((wm interaction-mixin) (drag drag) |
| 59 | (event-key (eql :button-release)) &key) |
| 60 | (stop-interaction wm drag) |
| 61 | t) |