commit a81d9d4d4c9ba83e721c6075ff9a4ab1abb4e17c
parent 3fac6a2601016dae3a976ebdbcc5c021a54ab56b
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 1 Jan 2023 11:27:33 +0000
remove hardcoded keyvals
Diffstat:
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/frame.fnl b/frame.fnl
@@ -46,7 +46,7 @@
[name params] (commander:invoke-interactively name params)
(nil prompt) (print "prompted" prompt)))
(when (and (commander:active?)
- (= (Gdk.keyval_name event.keyval) "Escape"))
+ (= keymap.keyval.Escape event.keyval))
(commander:deactivate))
(when (and event.state.MOD1_MASK
diff --git a/keymap.fnl b/keymap.fnl
@@ -2,19 +2,26 @@
(local { : view } (require :fennel))
(local modifier-keyvals
- {
- ;; These aren't canonical or official, this is just the
- ;; result of pressing keys on my keyboard. If Gtk/Gdk/GI
- ;; implemented KeyEvent.is_modifier we wouldn't have to
- ;; do this
- 65507 :control_l
- 65505 :shift_l
- 269025067 :fn
- 65515 :windows
- 65513 :alt_l
- 65027 :alt_gr
- 65508 :control_r
- })
+ ;; we need to detect and discard modifier-only key events when
+ ;; looking for the next key in a key sequence. Gtk/Gdk
+ ;; allegedly has KeyEvent.is_modifier to do this but it's always
+ ;; 0 because GI doesn't expose it.
+ (let [names
+ [
+ :Control_L
+ :Control_R
+ :Control
+ :Shift_L
+ :Shift_R
+ :WakeUp ; labelled "Fn"
+ :Super_L ; labelled with Windows logo
+ :Super_R ; menu key? not on my keyboard
+ :Alt_L
+ :Alt_R
+ :ISO_Level3_Shift ; AltGr
+ ]]
+ (collect [_ n (ipairs names)]
+ (values (Gdk.keyval_from_name n) n))))
(fn modifier? [keyval]
(. modifier-keyvals keyval))
@@ -85,6 +92,9 @@
{ : recogniser
+ :keyval {
+ :Escape (Gdk.keyval_from_name "Escape")
+ }
:_ {
;; symbols in _ are exported only for testing
: keychord->spec