From e588d7d7911ac203e37ba0338989694e0ba8dc03 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 24 Nov 2022 22:16:22 -0500 Subject: [PATCH] Modifier states returned from x backend should be 100% correct now --- backends/x/event.go | 15 ++++++++------- backends/x/factory.go | 5 +++++ backends/x/x.go | 5 +++++ examples/printbuttons/main.go | 14 ++++++++++++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/backends/x/event.go b/backends/x/event.go index 442eff1..74918b8 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -113,13 +113,14 @@ func (backend *Backend) handleKeyPress ( keyEvent := *event.KeyPressEvent button, num := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) backend.callbackManager.RunPress (button, stone.Modifiers { - // FIXME these may not be correct in all cases - Shift: (keyEvent.State & xproto.ModMaskShift) > 0, - Control: (keyEvent.State & xproto.ModMaskControl) > 0, - Alt: (keyEvent.State & xproto.ModMask1) > 0, - // Meta: (keyEvent.State & xproto.??) > 0, - Super: (keyEvent.State & xproto.ModMask4) > 0, - // Hyper: (keyEvent.State & xproto.??) > 0, + Shift: + (keyEvent.State & xproto.ModMaskShift) > 0 || + (keyEvent.State & backend.modifierMasks.shiftLock) > 0, + Control: (keyEvent.State & xproto.ModMaskControl) > 0, + Alt: (keyEvent.State & backend.modifierMasks.alt) > 0, + Meta: (keyEvent.State & backend.modifierMasks.meta) > 0, + Super: (keyEvent.State & backend.modifierMasks.super) > 0, + Hyper: (keyEvent.State & backend.modifierMasks.hyper) > 0, NumberPad: num, }) } diff --git a/backends/x/factory.go b/backends/x/factory.go index 21ff165..b9bdfdf 100644 --- a/backends/x/factory.go +++ b/backends/x/factory.go @@ -81,6 +81,11 @@ func factory ( backend.modifierMasks.shiftLock = backend.keysymToMask(0xFFE6) backend.modifierMasks.numLock = backend.keysymToMask(0xFF7F) backend.modifierMasks.modeSwitch = backend.keysymToMask(0xFF7E) + + backend.modifierMasks.hyper = backend.keysymToMask(0xffed) + backend.modifierMasks.super = backend.keysymToMask(0xffeb) + backend.modifierMasks.meta = backend.keysymToMask(0xffe7) + backend.modifierMasks.alt = backend.keysymToMask(0xffe9) // create the window backend.window.Create ( diff --git a/backends/x/x.go b/backends/x/x.go index 67e764b..a3abf09 100644 --- a/backends/x/x.go +++ b/backends/x/x.go @@ -48,6 +48,11 @@ type Backend struct { shiftLock uint16 numLock uint16 modeSwitch uint16 + + alt uint16 + meta uint16 + super uint16 + hyper uint16 } windowBoundsClean bool diff --git a/examples/printbuttons/main.go b/examples/printbuttons/main.go index 88439f0..cfef8c1 100644 --- a/examples/printbuttons/main.go +++ b/examples/printbuttons/main.go @@ -1,6 +1,7 @@ package main import "os" +import "fmt" import "image" import _ "image/png" import "git.tebibyte.media/sashakoshka/stone" @@ -33,9 +34,18 @@ func main () { } func onPress (button stone.Button, modifiers stone.Modifiers) { - println("press", button) + fmt.Printf ( + "=>>\t0x%X\tsh: %t\tctrl: %t\talt: %t\tm: %t\ts: %t \th: %t\tnumpad: %t\n", + button, + modifiers.Shift, + modifiers.Control, + modifiers.Alt, + modifiers.Meta, + modifiers.Super, + modifiers.Hyper, + modifiers.NumberPad) } func onRelease (button stone.Button) { - println("release", button) + fmt.Printf("<--\t0x%X\n", button) }