app/internal/xkb: ensure things don't panic

If there's no keyboard attached we don't want to panic
when querying modifiers.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2023-06-16 12:41:38 +03:00
committed by Elias Naur
parent 2327604f58
commit 49bb767048
+7
View File
@@ -136,6 +136,10 @@ func (x *Context) LoadKeymap(format int, fd int, size int) error {
func (x *Context) Modifiers() key.Modifiers { func (x *Context) Modifiers() key.Modifiers {
var mods key.Modifiers var mods key.Modifiers
if x.state == nil {
return mods
}
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_CTRL[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 { if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_CTRL[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
mods |= key.ModCtrl mods |= key.ModCtrl
} }
@@ -219,6 +223,9 @@ func (x *Context) charsForKeycode(keyCode C.xkb_keycode_t) []byte {
} }
func (x *Context) IsRepeatKey(keyCode uint32) bool { func (x *Context) IsRepeatKey(keyCode uint32) bool {
if x.state == nil {
return false
}
kc := C.xkb_keycode_t(keyCode) kc := C.xkb_keycode_t(keyCode)
return C.xkb_keymap_key_repeats(x.keyMap, kc) == 1 return C.xkb_keymap_key_repeats(x.keyMap, kc) == 1
} }