detect and discard modifier-only key events

for recognising key sequences, we only want  to look at
events containing non-modifier keystrokes
main
Daniel Barlow 2022-12-31 15:47:18 +00:00
parent cc2caae372
commit 69d8aa4131
1 changed files with 32 additions and 13 deletions

View File

@ -1,6 +1,24 @@
(local { : Gdk } (require :lgi))
(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
})
(fn modifier? [keyval]
(. modifier-keyvals keyval))
(fn keychord->spec [keychord]
(let [Mod Gdk.ModifierType
symbol (keychord:match "(%w+)$")
@ -44,19 +62,20 @@
{
:accept-event
(fn [_ e]
(let [c (event->index e)
v (. m c)]
(if v
(if (designates-command? v)
(do
(set m keymap)
v)
(do
(set m v)
(values nil (.. c " "))))
(do
(set m keymap)
(values nil (.. "No binding for " (view e) " "))))))
(when (not (modifier? e.keyval))
(let [c (event->index e)
v (. m c)]
(if v
(if (designates-command? v)
(do
(set m keymap)
v)
(do
(set m v)
(values nil (.. c " "))))
(do
(set m keymap)
(values nil (.. "No binding for " (view e) " ")))))))
}))