git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit9a77a6cfded16c513023a172c5877f51c91756f7
parent87340e6bf4
authorIsaac Freund <[email protected]>
date2023-02-28 14:40
Keyboard: fix keyboard-layout mapping crash

 river/Keyboard.zig | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/river/Keyboard.zig b/river/Keyboard.zig
index 55efde8..4b5afce 100644
--- a/river/Keyboard.zig
+++ b/river/Keyboard.zig
@@ -85,7 +85,10 @@ fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboa
     const modifiers = wlr_keyboard.getModifiers();
     const released = event.state == .released;
 
-    const xkb_state = wlr_keyboard.xkb_state orelse return;
+    // We must ref() the state here as a mapping could change the keyboard layout.
+    const xkb_state = (wlr_keyboard.xkb_state orelse return).ref();
+    defer xkb_state.unref();
+
     const keysyms = xkb_state.keyGetSyms(keycode);
 
     // Hide cursor when typing