detect and discard modifier-only key events
for recognising key sequences, we only want to look at events containing non-modifier keystrokes
This commit is contained in:
parent
cc2caae372
commit
69d8aa4131
45
keymap.fnl
45
keymap.fnl
@ -1,6 +1,24 @@
|
|||||||
(local { : Gdk } (require :lgi))
|
(local { : Gdk } (require :lgi))
|
||||||
(local { : view } (require :fennel))
|
(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]
|
(fn keychord->spec [keychord]
|
||||||
(let [Mod Gdk.ModifierType
|
(let [Mod Gdk.ModifierType
|
||||||
symbol (keychord:match "(%w+)$")
|
symbol (keychord:match "(%w+)$")
|
||||||
@ -44,19 +62,20 @@
|
|||||||
{
|
{
|
||||||
:accept-event
|
:accept-event
|
||||||
(fn [_ e]
|
(fn [_ e]
|
||||||
(let [c (event->index e)
|
(when (not (modifier? e.keyval))
|
||||||
v (. m c)]
|
(let [c (event->index e)
|
||||||
(if v
|
v (. m c)]
|
||||||
(if (designates-command? v)
|
(if v
|
||||||
(do
|
(if (designates-command? v)
|
||||||
(set m keymap)
|
(do
|
||||||
v)
|
(set m keymap)
|
||||||
(do
|
v)
|
||||||
(set m v)
|
(do
|
||||||
(values nil (.. c " "))))
|
(set m v)
|
||||||
(do
|
(values nil (.. c " "))))
|
||||||
(set m keymap)
|
(do
|
||||||
(values nil (.. "No binding for " (view e) " "))))))
|
(set m keymap)
|
||||||
|
(values nil (.. "No binding for " (view e) " ")))))))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user