From 69d8aa4131b496ed3c6cbca3128af494988d474a Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 31 Dec 2022 15:47:18 +0000 Subject: [PATCH] detect and discard modifier-only key events for recognising key sequences, we only want to look at events containing non-modifier keystrokes --- keymap.fnl | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/keymap.fnl b/keymap.fnl index 252cb30..f0c8571 100644 --- a/keymap.fnl +++ b/keymap.fnl @@ -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) " "))))))) }))