-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathevents.lisp
39 lines (32 loc) · 1.2 KB
/
events.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(in-package :lispkit)
(defparameter *previous-event* nil)
(defun strip-irrelevant-mods (keys)
(remove-if
(lambda (elt) (member elt '(:mod2-mask :shift-mask)))
keys))
(let ((mod-map '((:mod1-mask . "M")
(:control-mask . "C"))))
(defun mod->string (mod)
(cdr (assoc mod mod-map :test #'equal))))
(defun mods->string (s)
(mapcar #'mod->string (strip-irrelevant-mods s)))
(defun duplicated-event? (event)
(when (and *previous-event* event)
(= (gdk:GDK-EVENT-KEY-TIME event)
(gdk:GDK-EVENT-KEY-TIME *previous-event*))))
(defun parse-event (event)
(with-gdk-event-slots (state keyval) event
(let ((key (keysym->keysym-name keyval))
(mod-str (mods->string state)))
(values key mod-str))))
(defun event-as-string (event)
(with-gdk-event-slots (state keyval) event
(let ((key (keysym->keysym-name keyval))
(mod-str (mods->string state)))
(unwind-protect
(when (and (not (duplicated-event? event))
(not (modifier? keyval)))
(if (consp mod-str)
(format nil "~{~a~^-~}-~a" mod-str key)
(format nil "~a" key)))
(setq *previous-event* event)))))