From b5812c001daeeaff1f259031661e47f3a612220c Mon Sep 17 00:00:00 2001 From: John Gebbie Date: Sun, 5 Nov 2023 16:34:27 +0000 Subject: [PATCH] prefer keys on lower levels for realsies --- dotool.go | 2 ++ keys.go | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dotool.go b/dotool.go index dbdc88d..056fc47 100644 --- a/dotool.go +++ b/dotool.go @@ -62,6 +62,8 @@ func log(err error) { type Chord struct { Super, AltGr, Ctrl, Alt, Shift bool Key int + + level uint32 // just for initKeys } func parseChord(keymap *xkb.Keymap, chord string) (Chord, error) { diff --git a/keys.go b/keys.go index 5b1346c..fc303f5 100644 --- a/keys.go +++ b/keys.go @@ -607,11 +607,14 @@ var DeadKeyResults = []DeadKeyResult{ {"dead_tilde", "Y", 'Ỹ'}, } -func newChord(keymap *xkb.Keymap, mask, code uint32) Chord{ +func newChord(keymap *xkb.Keymap, code, level uint32) Chord { altGrMask := uint32(1) << keymap.ModGetIndex("Mod5") ctrlMask := uint32(1) << keymap.ModGetIndex(xkb.ModNameCtrl) altMask := uint32(1) << keymap.ModGetIndex(xkb.ModNameAlt) shiftMask := uint32(1) << keymap.ModGetIndex(xkb.ModNameShift) + + // TODO support layouts other than 0 + mask := keymap.KeyGetMod(code, 0, level) return Chord{ false, (mask & altGrMask) != 0, @@ -619,6 +622,7 @@ func newChord(keymap *xkb.Keymap, mask, code uint32) Chord{ (mask & altMask) != 0, (mask & shiftMask) != 0, int(code) - 8, + level, } } @@ -628,16 +632,16 @@ func initKeys(keymap *xkb.Keymap) { numLevels := keymap.NumLevelsForKey(code, 0) for level := uint32(0); level < numLevels; level++ { for _, sym := range keymap.KeyGetSymsByLevel(code, 0, level) { - chord := newChord(keymap, keymap.KeyGetMod(code, 0, level), code) + chord := newChord(keymap, code, level) for name, s := range linuxXSyms { if s == sym { - if _, ok := LinuxKeys[name]; !ok { + if l, ok := LinuxKeys[name]; !ok || level < l.level { LinuxKeys[name] = chord } } } name := xkb.KeysymGetName(sym) - if _, ok := XKeys[name]; !ok { + if x, ok := XKeys[name]; !ok || level < x.level { XKeys[name] = chord } } @@ -657,7 +661,7 @@ func getChord(keymap *xkb.Keymap, keysym uint32) Chord { for level := uint32(0); level < numLevels; level++ { for _, sym := range keymap.KeyGetSymsByLevel(code, 0, level) { if sym == keysym { - return newChord(keymap, keymap.KeyGetMod(code, 0, level), code) + return newChord(keymap, code, level) } } }