Keyboard: eat key release event for mappings

Until now, only the event (press/release) for which a mapping was
present got eaten, and the other was passed to the client. From this
commit, a press mapping eats both events and a release mapping eats
nothing (and a press+release combo eats both).

This fixes behavior of some clients that do not make a difference
between press and release (e.g. Firefox with a fullscreen video
exiting fullscreen even on an Esc release event).
This commit is contained in:
tiosgz
2022-05-28 15:18:00 +00:00
committed by Isaac Freund
parent 706dca9b1a
commit 6d6646febe
2 changed files with 62 additions and 6 deletions
+10 -6
View File
@@ -24,6 +24,7 @@ const xkb = @import("xkbcommon");
const server = &@import("main.zig").server;
const util = @import("util.zig");
const KeycodeSet = @import("KeycodeSet.zig");
const Seat = @import("Seat.zig");
const log = std.log.scoped(.keyboard);
@@ -31,6 +32,9 @@ const log = std.log.scoped(.keyboard);
seat: *Seat,
input_device: *wlr.InputDevice,
/// Pressed keys for which a mapping was triggered on press
eaten_keycodes: KeycodeSet = .{},
key: wl.Listener(*wlr.Keyboard.event.Key) = wl.Listener(*wlr.Keyboard.event.Key).init(handleKey),
modifiers: wl.Listener(*wlr.Keyboard) = wl.Listener(*wlr.Keyboard).init(handleModifiers),
destroy: wl.Listener(*wlr.Keyboard) = wl.Listener(*wlr.Keyboard).init(handleDestroy),
@@ -108,12 +112,12 @@ fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboa
}
// Handle user-defined mapping
if (!self.seat.handleMapping(
keycode,
modifiers,
released,
xkb_state,
)) {
const mapped = self.seat.handleMapping(keycode, modifiers, released, xkb_state);
if (mapped and !released) self.eaten_keycodes.add(event.keycode);
const eaten = if (released) self.eaten_keycodes.remove(event.keycode) else mapped;
if (!eaten) {
// If key was not handled, we pass it along to the client.
const wlr_seat = self.seat.wlr_seat;
wlr_seat.setKeyboard(self.input_device);