From 324540c41ee968d25a7d214b9b7919d62cf81f4a Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Thu, 17 Oct 2024 15:48:47 +0200 Subject: [PATCH] seat: keep track of focus serials --- src/ifs/wl_seat.rs | 2 ++ src/ifs/wl_seat/event_handling.rs | 17 +++++++++++++---- src/ifs/wl_seat/kb_owner.rs | 14 ++++++++------ src/ifs/wl_seat/tablet/tool.rs | 4 ++-- .../wl_surface/ext_session_lock_surface_v1.rs | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index df190682..409f8ea8 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -200,6 +200,7 @@ pub struct WlSeatGlobal { tablet: TabletSeatData, ei_seats: CopyHashMap<(ClientId, EiSeatId), Rc>, ui_drag_highlight: Cell>, + keyboard_node_serial: Cell, } const CHANGE_CURSOR_MOVED: u32 = 1 << 0; @@ -229,6 +230,7 @@ impl WlSeatGlobal { pointer_stack_modified: Cell::new(false), found_tree: RefCell::new(vec![]), keyboard_node: CloneCell::new(state.root.clone()), + keyboard_node_serial: Default::default(), bindings: Default::default(), x_data_devices: Default::default(), data_devices: RefCell::new(Default::default()), diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index cdc1ceb7..ea638a37 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -159,7 +159,8 @@ impl NodeSeatState { fn release_kb_focus2(&self, focus_last: bool) { self.release_kb_grab(); while let Some((_, seat)) = self.kb_foci.pop() { - seat.kb_owner.set_kb_node(&seat, seat.state.root.clone()); + seat.kb_owner + .set_kb_node(&seat, seat.state.root.clone(), seat.state.next_serial(None)); // log::info!("keyboard_node = root"); if focus_last { seat.get_output() @@ -935,7 +936,15 @@ impl WlSeatGlobal { } pub fn focus_node(self: &Rc, node: Rc) { - self.kb_owner.set_kb_node(self, node); + if self.keyboard_node.get().node_id() == node.node_id() { + return; + } + let serial = self.state.next_serial(node.node_client().as_deref()); + self.focus_node_with_serial(node, serial); + } + + pub fn focus_node_with_serial(self: &Rc, node: Rc, serial: u64) { + self.kb_owner.set_kb_node(self, node, serial); } pub(super) fn for_each_seat(&self, ver: Version, client: ClientId, mut f: C) @@ -1150,7 +1159,7 @@ impl WlSeatGlobal { self.surface_pointer_frame(surface); if pressed { if let Some(node) = surface.get_focus_node(self.id) { - self.focus_node(node); + self.focus_node_with_serial(node, serial); } } } @@ -1368,7 +1377,7 @@ impl WlSeatGlobal { t.send_down(serial, time, surface.id, id, x, y) }); if let Some(node) = surface.get_focus_node(self.id) { - self.focus_node(node); + self.focus_node_with_serial(node, serial); } } diff --git a/src/ifs/wl_seat/kb_owner.rs b/src/ifs/wl_seat/kb_owner.rs index 796aeb57..caf7048b 100644 --- a/src/ifs/wl_seat/kb_owner.rs +++ b/src/ifs/wl_seat/kb_owner.rs @@ -29,8 +29,8 @@ impl KbOwnerHolder { self.owner.get().ungrab(seat) } - pub fn set_kb_node(&self, seat: &Rc, node: Rc) { - self.owner.get().set_kb_node(seat, node); + pub fn set_kb_node(&self, seat: &Rc, node: Rc, serial: u64) { + self.owner.get().set_kb_node(seat, node, serial); } pub fn clear(&self) { @@ -45,12 +45,13 @@ struct GrabKbOwner; trait KbOwner { fn grab(&self, seat: &Rc, node: Rc) -> bool; fn ungrab(&self, seat: &Rc); - fn set_kb_node(&self, seat: &Rc, node: Rc); + fn set_kb_node(&self, seat: &Rc, node: Rc, serial: u64); } impl KbOwner for DefaultKbOwner { fn grab(&self, seat: &Rc, node: Rc) -> bool { - self.set_kb_node(seat, node); + let serial = seat.state.next_serial(node.node_client().as_deref()); + self.set_kb_node(seat, node, serial); seat.kb_owner.owner.set(Rc::new(GrabKbOwner)); true } @@ -59,7 +60,7 @@ impl KbOwner for DefaultKbOwner { // nothing } - fn set_kb_node(&self, seat: &Rc, node: Rc) { + fn set_kb_node(&self, seat: &Rc, node: Rc, serial: u64) { let old = seat.keyboard_node.get(); if old.node_id() == node.node_id() { return; @@ -78,6 +79,7 @@ impl KbOwner for DefaultKbOwner { } // log::info!("focus {}", node.node_id()); node.clone().node_on_focus(seat); + seat.keyboard_node_serial.set(serial); seat.keyboard_node.set(node.clone()); seat.tablet_on_keyboard_node_change(); } @@ -92,7 +94,7 @@ impl KbOwner for GrabKbOwner { seat.kb_owner.owner.set(seat.kb_owner.default.clone()); } - fn set_kb_node(&self, _seat: &Rc, _node: Rc) { + fn set_kb_node(&self, _seat: &Rc, _node: Rc, _serial: u64) { // nothing } } diff --git a/src/ifs/wl_seat/tablet/tool.rs b/src/ifs/wl_seat/tablet/tool.rs index 61fa6306..c8346781 100644 --- a/src/ifs/wl_seat/tablet/tool.rs +++ b/src/ifs/wl_seat/tablet/tool.rs @@ -212,7 +212,7 @@ impl TabletTool { }); if state == ToolButtonState::Pressed { if let Some(node) = n.get_focus_node(self.tablet.seat.id) { - self.tablet.seat.focus_node(node); + self.tablet.seat.focus_node_with_serial(node, serial.get()); } } } @@ -260,7 +260,7 @@ impl TabletTool { if let Some(changes) = changes { if changes.down == Some(true) { if let Some(node) = n.get_focus_node(self.tablet.seat.id) { - self.tablet.seat.focus_node(node); + self.tablet.seat.focus_node_with_serial(node, serial.get()); } } } diff --git a/src/ifs/wl_surface/ext_session_lock_surface_v1.rs b/src/ifs/wl_surface/ext_session_lock_surface_v1.rs index 78a39db3..ff429495 100644 --- a/src/ifs/wl_surface/ext_session_lock_surface_v1.rs +++ b/src/ifs/wl_surface/ext_session_lock_surface_v1.rs @@ -134,7 +134,7 @@ impl Node for ExtSessionLockSurfaceV1 { } fn node_on_pointer_enter(self: Rc, seat: &Rc, _x: Fixed, _y: Fixed) { - seat.focus_node(self.surface.clone()); + seat.focus_node_with_serial(self.surface.clone(), self.client.next_serial()); } }