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.
This commit is contained in:
Isaac Freund 2022-07-26 16:25:04 +02:00
parent 7443e1377a
commit d4b2f2b0fc
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11

View File

@ -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);