at commit a0296e8f
| 1 | ;;;; common lisp window manager |
| 2 | ;;;; |
| 3 | ;;;; modal interactions that get all events |
| 4 | |
| 5 | (in-package #:clwm-ext) |
| 6 | |
| 7 | (defclass interaction-mixin () |
| 8 | ((interaction :initform nil :accessor current-interaction |
| 9 | :documentation "The current modal interaction or NIL.")) |
| 10 | (:documentation |
| 11 | "Allow a single modal interaction, which may get first refusal on |
| 12 | all events.")) |
| 13 | |
| 14 | (defclass interaction () |
| 15 | ((client :initarg :client :initform nil :reader interaction-client)) |
| 16 | (:documentation |
| 17 | "A modal interaction which may get first refusal on all events.")) |
| 18 | |
| 19 | (defgeneric start-interaction (wm interaction) |
| 20 | (:documentation "Make an interaction the WM's current interaction.")) |
| 21 | (defgeneric stop-interaction (wm interaction) |
| 22 | (:documentation "Stop an interaction if it's the current one.")) |
| 23 | (defgeneric interaction-event |
| 24 | (wm interaction event-key &key &allow-other-keys) |
| 25 | (:documentation "Offer an event to an interaction. |
| 26 | Non-NIL return consumes the event.") |
| 27 | (:method (wm interaction event-key &key) nil)) |
| 28 | |
| 29 | (defun stop-current-interaction (wm) |
| 30 | "End the current interaction, whatever it may or may not be. |
| 31 | Expects INTERACTION-MIXIN." |
| 32 | (when-let ((interaction (current-interaction wm))) |
| 33 | (stop-interaction wm interaction))) |
| 34 | |
| 35 | (defmethod start-interaction |
| 36 | ((wm interaction-mixin) (interaction interaction)) |
| 37 | (stop-current-interaction wm) |
| 38 | (setf (current-interaction wm) interaction)) |
| 39 | (defmethod stop-interaction |
| 40 | ((wm interaction-mixin) (interaction interaction)) |
| 41 | (when (eql interaction (current-interaction wm)) |
| 42 | (setf (current-interaction wm) nil))) |
| 43 | |
| 44 | (defmethod handle-event :around |
| 45 | ((wm interaction-mixin) event-key &rest e &key) |
| 46 | (let ((interaction (current-interaction wm))) |
| 47 | (unless (and interaction |
| 48 | (apply #'interaction-event wm interaction event-key e)) |
| 49 | (call-next-method)))) |
| 50 | |
| 51 | (defmethod unmanage-client :before ((wm interaction-mixin) client) |
| 52 | (let ((interaction (current-interaction wm))) |
| 53 | (when (and interaction |
| 54 | (eql client (interaction-client interaction))) |
| 55 | (stop-interaction wm interaction)))) |
| 56 | |
| 57 | (defmethod uninitialize-wm :before ((wm interaction-mixin)) |
| 58 | (stop-current-interaction wm)) |
| 59 | |
| 60 | (defmethod shutdown-wm :before ((wm interaction-mixin)) |
| 61 | (stop-current-interaction wm)) |