Modifier states returned from x backend should be 100% correct now

This commit is contained in:
Sasha Koshka 2022-11-24 22:16:22 -05:00
parent 941a78eaf1
commit e588d7d791
4 changed files with 30 additions and 9 deletions

View File

@ -113,13 +113,14 @@ func (backend *Backend) handleKeyPress (
keyEvent := *event.KeyPressEvent keyEvent := *event.KeyPressEvent
button, num := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) button, num := backend.keycodeToButton(keyEvent.Detail, keyEvent.State)
backend.callbackManager.RunPress (button, stone.Modifiers { backend.callbackManager.RunPress (button, stone.Modifiers {
// FIXME these may not be correct in all cases Shift:
Shift: (keyEvent.State & xproto.ModMaskShift) > 0, (keyEvent.State & xproto.ModMaskShift) > 0 ||
Control: (keyEvent.State & xproto.ModMaskControl) > 0, (keyEvent.State & backend.modifierMasks.shiftLock) > 0,
Alt: (keyEvent.State & xproto.ModMask1) > 0, Control: (keyEvent.State & xproto.ModMaskControl) > 0,
// Meta: (keyEvent.State & xproto.??) > 0, Alt: (keyEvent.State & backend.modifierMasks.alt) > 0,
Super: (keyEvent.State & xproto.ModMask4) > 0, Meta: (keyEvent.State & backend.modifierMasks.meta) > 0,
// Hyper: (keyEvent.State & xproto.??) > 0, Super: (keyEvent.State & backend.modifierMasks.super) > 0,
Hyper: (keyEvent.State & backend.modifierMasks.hyper) > 0,
NumberPad: num, NumberPad: num,
}) })
} }

View File

@ -81,6 +81,11 @@ func factory (
backend.modifierMasks.shiftLock = backend.keysymToMask(0xFFE6) backend.modifierMasks.shiftLock = backend.keysymToMask(0xFFE6)
backend.modifierMasks.numLock = backend.keysymToMask(0xFF7F) backend.modifierMasks.numLock = backend.keysymToMask(0xFF7F)
backend.modifierMasks.modeSwitch = backend.keysymToMask(0xFF7E) 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 // create the window
backend.window.Create ( backend.window.Create (

View File

@ -48,6 +48,11 @@ type Backend struct {
shiftLock uint16 shiftLock uint16
numLock uint16 numLock uint16
modeSwitch uint16 modeSwitch uint16
alt uint16
meta uint16
super uint16
hyper uint16
} }
windowBoundsClean bool windowBoundsClean bool

View File

@ -1,6 +1,7 @@
package main package main
import "os" import "os"
import "fmt"
import "image" import "image"
import _ "image/png" import _ "image/png"
import "git.tebibyte.media/sashakoshka/stone" import "git.tebibyte.media/sashakoshka/stone"
@ -33,9 +34,18 @@ func main () {
} }
func onPress (button stone.Button, modifiers stone.Modifiers) { 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) { func onRelease (button stone.Button) {
println("release", button) fmt.Printf("<--\t0x%X\n", button)
} }