Add function to deal with modifier state info

This commit is contained in:
Sasha Koshka 2023-06-08 00:02:14 -04:00
parent 0009d2d1d0
commit e114c6d700

View File

@ -48,6 +48,34 @@ func Initialize (connection *xgbutil.XUtil) {
modifierMasks.alt = KeysymToMask(0xffe9)
}
// Modifiers lists which modifier keys are toggled on or being pressed.
type Modifiers struct {
CapsLock bool
ShiftLock bool
NumLock bool
ModeSwitch bool
Alt bool
Meta bool
Super bool
Hyper bool
}
// StateToModifiers converts a modifier state given by a keyboard or mouse event
// to a Modifiers struct.
func StateToModifiers (state uint16) Modifiers {
return Modifiers {
CapsLock: 0 < state & modifierMasks.capsLock,
ShiftLock: 0 < state & modifierMasks.shiftLock,
NumLock: 0 < state & modifierMasks.numLock,
ModeSwitch: 0 < state & modifierMasks.modeSwitch,
Alt: 0 < state & modifierMasks.alt,
Meta: 0 < state & modifierMasks.meta,
Super: 0 < state & modifierMasks.super,
Hyper: 0 < state & modifierMasks.hyper,
}
}
// KeysymToKeycode converts an X keysym to an X keycode, instead of the other
// way around.
func KeysymToKeycode (