From d4b2f2b0fc5766c8ae14a6f42fe76d058bfb3505 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 26 Jul 2022 16:25:04 +0200 Subject: [PATCH] Seat: send enter event on keyboard device creation Currently we don't send an enter event when a new keyboard device is created which causes issues when switching ttys. On switching away the keyboard device is destroyed and leave is sent. Currently on switching back the keyboard device is re-created but no enter event is sent before we start sending key events, which is a violation of the protocol. --- river/Seat.zig | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/river/Seat.zig b/river/Seat.zig index c04e2eb..fcd3377 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -244,24 +244,7 @@ pub fn setFocusRaw(self: *Self, new_focus: FocusTarget) void { // Send keyboard enter/leave events and handle pointer constraints if (target_surface) |wlr_surface| { - if (self.wlr_seat.getKeyboard()) |wlr_keyboard| { - var keycodes = KeycodeSet{ - .items = wlr_keyboard.keycodes, - .len = wlr_keyboard.num_keycodes, - }; - - const keyboard = @intToPtr(*Keyboard, wlr_keyboard.data); - keycodes.subtract(keyboard.eaten_keycodes); - - self.wlr_seat.keyboardNotifyEnter( - wlr_surface, - &keycodes.items, - keycodes.len, - &wlr_keyboard.modifiers, - ); - } else { - self.wlr_seat.keyboardNotifyEnter(wlr_surface, null, 0, null); - } + self.keyboardNotifyEnter(wlr_surface); if (server.input_manager.pointer_constraints.constraintForSurface(wlr_surface, self.wlr_seat)) |constraint| { @intToPtr(*PointerConstraint, constraint.data).setAsActive(); @@ -286,6 +269,27 @@ pub fn setFocusRaw(self: *Self, new_focus: FocusTarget) void { while (it) |node| : (it = node.next) node.data.sendFocusedView(); } +fn keyboardNotifyEnter(self: *Self, wlr_surface: *wlr.Surface) void { + if (self.wlr_seat.getKeyboard()) |wlr_keyboard| { + var keycodes = KeycodeSet{ + .items = wlr_keyboard.keycodes, + .len = wlr_keyboard.num_keycodes, + }; + + const keyboard = @intToPtr(*Keyboard, wlr_keyboard.data); + keycodes.subtract(keyboard.eaten_keycodes); + + self.wlr_seat.keyboardNotifyEnter( + wlr_surface, + &keycodes.items, + keycodes.len, + &wlr_keyboard.modifiers, + ); + } else { + self.wlr_seat.keyboardNotifyEnter(wlr_surface, null, 0, null); + } +} + /// Focus the given output, notifying any listening clients of the change. pub fn focusOutput(self: *Self, output: *Output) void { if (self.focused_output == output) return; @@ -470,6 +474,12 @@ fn tryAddDevice(self: *Self, wlr_device: *wlr.InputDevice) !void { errdefer util.gpa.destroy(keyboard); try keyboard.init(self, wlr_device); + + self.wlr_seat.setKeyboard(keyboard.device.wlr_device); + if (self.wlr_seat.keyboard_state.focused_surface) |wlr_surface| { + self.wlr_seat.keyboardNotifyClearFocus(); + self.keyboardNotifyEnter(wlr_surface); + } }, .pointer, .touch => { const device = try util.gpa.create(InputDevice);