From e1970e4d52b08e02dfc453166e7a10bf91e63cc2 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Mon, 19 Feb 2024 08:48:16 +0000 Subject: [PATCH] Keyboard: don't crash when coming from a different tty It didn't occur to me that this is a completely valid case when a key release event is received even though there was no press event known to river. (I've also just had this same crash on something else, but i don't understand what the cause could be.) --- river/Keyboard.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/river/Keyboard.zig b/river/Keyboard.zig index d46dd07..9b3a5ac 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -177,7 +177,10 @@ fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboa const consumer: KeyConsumer = blk: { // Decision is made on press; release only follows it - if (released) break :blk self.pressed.remove(event.keycode).?; + if (released) break :blk self.pressed.remove(event.keycode) orelse { + // This can happen for example when switching from a different tty + return; + }; if (self.device.seat.hasMapping(keycode, modifiers, released, xkb_state)) { // The key must be added to the set of pressed keys with the correct consumer before