diff --git a/src/compositor.rs b/src/compositor.rs index 37c2b001..1d7c85c2 100644 --- a/src/compositor.rs +++ b/src/compositor.rs @@ -30,6 +30,7 @@ use { ifs::{ jay_screencast::{perform_screencast_realloc, perform_toplevel_screencasts}, wl_output::{OutputId, PersistentOutputState, WlOutputGlobal}, + wl_seat::handle_position_hint_requests, wl_surface::{NoneSurfaceExt, zwp_input_popup_surface_v2::input_popup_positioning}, workspace_manager::workspace_manager_done, }, @@ -334,6 +335,8 @@ fn start_compositor2( tl_matcher_manager: TlMatcherManager::new(&crit_ids), caps_thread, toplevel_managers: Default::default(), + node_at_tree: Default::default(), + position_hint_requests: Default::default(), }); state.tracker.register(ClientId::from_raw(0)); create_dummy_output(&state); @@ -521,6 +524,10 @@ fn start_global_event_handlers( Phase::Layout, handle_tl_just_mapped(state.clone()), ), + eng.spawn( + "position hint requests", + handle_position_hint_requests(state.clone()), + ), ] } diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index f296891e..daada2c6 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -78,9 +78,9 @@ use { rect::Rect, state::{DeviceHandlerData, State}, tree::{ - ContainerNode, ContainerSplit, Direction, FoundNode, Node, OutputNode, ToplevelNode, - WorkspaceNode, generic_node_visitor, toplevel_create_split, toplevel_parent_container, - toplevel_set_floating, toplevel_set_workspace, + ContainerNode, ContainerSplit, Direction, FoundNode, Node, NodeId, OutputNode, + ToplevelNode, WorkspaceNode, generic_node_visitor, toplevel_create_split, + toplevel_parent_container, toplevel_set_floating, toplevel_set_workspace, }, utils::{ asyncevent::AsyncEvent, bindings::PerClientBindings, clonecell::CloneCell, @@ -432,7 +432,7 @@ impl WlSeatGlobal { pub fn disable_pointer_constraint(&self) { if let Some(constraint) = self.constraint.get() { - constraint.deactivate(true, true); + constraint.deactivate(true); if constraint.status.get() == SeatConstraintStatus::Inactive { constraint .status @@ -1348,3 +1348,26 @@ impl DeviceHandlerData { state.root.extents.get() } } + +pub struct PositionHintRequest { + seat: Rc, + node: NodeId, + old_pos: (Fixed, Fixed), + new_pos: (Fixed, Fixed), +} + +pub async fn handle_position_hint_requests(state: Rc) { + loop { + let req = state.position_hint_requests.pop().await; + let (x, y) = (req.new_pos.0.round_down(), req.new_pos.1.round_down()); + if state.node_at(x, y).node.node_id() != req.node { + continue; + } + let current_pos = req.seat.pointer_cursor.position(); + let (x, y) = ( + req.new_pos.0 + (current_pos.0 - req.old_pos.0), + req.new_pos.1 + (current_pos.1 - req.old_pos.1), + ); + req.seat.motion_event_abs(state.now_usec(), x, y, false); + } +} diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 02b02f6b..561ed80e 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -526,7 +526,7 @@ impl WlSeatGlobal { let (x, y) = self.set_pointer_cursor_position(x, y); if let Some(c) = self.constraint.get() { if c.ty == ConstraintType::Lock || !c.contains(x.round_down(), y.round_down()) { - c.deactivate(false, false); + c.deactivate(false); } } self.state.for_each_seat_tester(|t| { @@ -1289,7 +1289,7 @@ impl WlSeatGlobal { pub fn leave_surface(&self, n: &WlSurface) { let serial = n.client.next_serial(); for (_, constraint) in &n.constraints { - constraint.deactivate(true, true); + constraint.deactivate(true); } self.surface_pointer_event(Version::ALL, n, |p| p.send_leave(serial, n.id)); self.surface_pointer_frame(n); diff --git a/src/ifs/wl_seat/pointer_owner.rs b/src/ifs/wl_seat/pointer_owner.rs index 3de37e08..53c0d440 100644 --- a/src/ifs/wl_seat/pointer_owner.rs +++ b/src/ifs/wl_seat/pointer_owner.rs @@ -547,21 +547,11 @@ impl PointerOwner for DndPointerOwner { fn apply_changes(&self, seat: &Rc) { let (x, y) = seat.pointer_cursor.position(); - let (x_int, y_int) = (x.round_down(), y.round_down()); - let (node, x_int, y_int) = { - let mut found_tree = seat.found_tree.borrow_mut(); - found_tree.push(FoundNode { - node: seat.state.root.clone(), - x: x_int, - y: y_int, - }); - seat.state - .root - .node_find_tree_at(x_int, y_int, &mut found_tree, FindTreeUsecase::None); - let FoundNode { node, x, y } = found_tree.pop().unwrap(); - found_tree.clear(); - (node, x, y) - }; + let FoundNode { + node, + x: x_int, + y: y_int, + } = seat.state.node_at(x.round_down(), y.round_down()); let (x, y) = (x.apply_fract(x_int), y.apply_fract(y_int)); let mut target = self.target.get(); if node.node_id() != target.node_id() { diff --git a/src/ifs/wl_seat/touch_owner.rs b/src/ifs/wl_seat/touch_owner.rs index c3d61205..5d7a04a7 100644 --- a/src/ifs/wl_seat/touch_owner.rs +++ b/src/ifs/wl_seat/touch_owner.rs @@ -2,7 +2,7 @@ use { crate::{ fixed::Fixed, ifs::wl_seat::WlSeatGlobal, - tree::{FindTreeUsecase, FoundNode, Node}, + tree::Node, utils::{clonecell::CloneCell, smallmap::SmallMap}, }, std::rc::Rc, @@ -69,29 +69,14 @@ trait TouchOwner { impl TouchOwner for DefaultTouchOwner { fn down(&self, seat: &Rc, time_usec: u64, id: i32, x: Fixed, y: Fixed) { - let mut found_tree = seat.found_tree.borrow_mut(); - let x_int = x.round_down(); - let y_int = y.round_down(); - found_tree.push(FoundNode { - node: seat.state.root.clone(), - x: x_int, - y: y_int, + let node = seat.state.node_at(x.round_down(), y.round_down()); + node.node.node_seat_state().touch_begin(seat); + let owner = Rc::new(GrabTouchOwner { + node: node.node, + down_ids: Default::default(), }); - seat.state - .root - .node_find_tree_at(x_int, y_int, &mut found_tree, FindTreeUsecase::None); - let node = found_tree.pop(); - found_tree.clear(); - drop(found_tree); - if let Some(node) = node { - node.node.node_seat_state().touch_begin(seat); - let owner = Rc::new(GrabTouchOwner { - node: node.node, - down_ids: Default::default(), - }); - seat.touch_owner.owner.set(owner.clone()); - owner.down(seat, time_usec, id, x, y); - } + seat.touch_owner.owner.set(owner.clone()); + owner.down(seat, time_usec, id, x, y); } fn up(&self, _seat: &Rc, _time_usec: u64, _id: i32) { diff --git a/src/ifs/wl_seat/zwp_pointer_constraints_v1.rs b/src/ifs/wl_seat/zwp_pointer_constraints_v1.rs index b58e5412..aebb5cd0 100644 --- a/src/ifs/wl_seat/zwp_pointer_constraints_v1.rs +++ b/src/ifs/wl_seat/zwp_pointer_constraints_v1.rs @@ -5,7 +5,7 @@ use { globals::{Global, GlobalName}, ifs::{ wl_seat::{ - WlSeatGlobal, + PositionHintRequest, WlSeatGlobal, zwp_pointer_constraints_v1::zwp_confined_pointer_v1::ZwpConfinedPointerV1, }, wl_surface::WlSurface, @@ -65,10 +65,10 @@ pub struct SeatConstraint { } impl SeatConstraint { - pub fn deactivate(&self, apply_position_hint: bool, defer: bool) { + pub fn deactivate(&self, apply_position_hint: bool) { if self.status.get() == SeatConstraintStatus::Active { self.seat.constraint.take(); - self.handle_position_hint(apply_position_hint, defer); + self.handle_position_hint(apply_position_hint); if let Some(owner) = self.owner.get() { owner.send_disabled(); } @@ -80,7 +80,7 @@ impl SeatConstraint { } } - fn handle_position_hint(&self, apply: bool, defer: bool) { + fn handle_position_hint(&self, apply: bool) { let Some((x, y)) = self.position_hint.take() else { return; }; @@ -89,15 +89,15 @@ impl SeatConstraint { } let buffer = self.surface.buffer_abs_pos.get(); let (x_int, y_int) = buffer.translate_inv(x.round_down(), y.round_down()); - if !buffer.contains(x_int, y_int) { - return; - } - self.seat.motion_event_abs( - self.client.state.now_usec(), - x.apply_fract(x_int), - y.apply_fract(y_int), - defer, - ); + self.client + .state + .position_hint_requests + .push(PositionHintRequest { + seat: self.seat.clone(), + node: self.surface.node_id.into(), + old_pos: self.seat.pointer_cursor.position(), + new_pos: (x.apply_fract(x_int), y.apply_fract(y_int)), + }); } pub fn contains(&self, x: i32, y: i32) -> bool { @@ -141,7 +141,7 @@ impl SeatConstraint { } fn detach(&self) { - self.deactivate(true, false); + self.deactivate(true); self.owner.take(); self.surface.constraints.remove(&self.seat.id); } diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index f227b80a..299199ad 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -1630,7 +1630,7 @@ impl WlSurface { pub fn detach_node(&self, set_invisible: bool) { for (_, constraint) in &self.constraints { - constraint.deactivate(true, true); + constraint.deactivate(true); } for (_, inhibitor) in &self.idle_inhibitors { inhibitor.deactivate(); diff --git a/src/state.rs b/src/state.rs index 8dc58b59..b043568c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -50,7 +50,8 @@ use { wl_drm::WlDrmGlobal, wl_output::{OutputGlobalOpt, OutputId, PersistentOutputState}, wl_seat::{ - PhysicalKeyboardId, PhysicalKeyboardIds, SeatIds, WlSeatGlobal, + PhysicalKeyboardId, PhysicalKeyboardIds, PositionHintRequest, SeatIds, + WlSeatGlobal, tablet::{TabletIds, TabletInit, TabletPadIds, TabletPadInit, TabletToolIds}, }, wl_surface::{ @@ -83,9 +84,10 @@ use { theme::{Color, Theme}, time::Time, tree::{ - ContainerNode, ContainerSplit, Direction, DisplayNode, FloatNode, LatchListener, Node, - NodeIds, NodeVisitorBase, OutputNode, PlaceholderNode, TearingMode, ToplevelData, - ToplevelNode, ToplevelNodeBase, VrrMode, WorkspaceNode, generic_node_visitor, + ContainerNode, ContainerSplit, Direction, DisplayNode, FindTreeUsecase, FloatNode, + FoundNode, LatchListener, Node, NodeIds, NodeVisitorBase, OutputNode, PlaceholderNode, + TearingMode, ToplevelData, ToplevelNode, ToplevelNodeBase, VrrMode, WorkspaceNode, + generic_node_visitor, }, utils::{ activation_token::ActivationToken, asyncevent::AsyncEvent, bindings::Bindings, @@ -251,6 +253,8 @@ pub struct State { pub cl_matcher_manager: ClMatcherManager, pub tl_matcher_manager: TlMatcherManager, pub caps_thread: Option, + pub node_at_tree: RefCell>, + pub position_hint_requests: AsyncQueue, } // impl Drop for State { @@ -975,6 +979,8 @@ impl State { self.workspace_managers.clear(); self.cl_matcher_manager.clear(); self.tl_matcher_manager.clear(); + self.node_at_tree.borrow_mut().clear(); + self.position_hint_requests.clear(); } pub fn remove_toplevel_id(&self, id: ToplevelIdentifier) { @@ -1400,6 +1406,20 @@ impl State { pub fn initial_tile_state(&self, data: &ToplevelData) -> Option { self.config.get()?.initial_tile_state(data) } + + pub fn node_at(&self, x: i32, y: i32) -> FoundNode { + let mut found_tree = self.node_at_tree.borrow_mut(); + found_tree.push(FoundNode { + node: self.root.clone(), + x, + y, + }); + self.root + .node_find_tree_at(x, y, &mut found_tree, FindTreeUsecase::None); + let node = found_tree.pop().unwrap(); + found_tree.clear(); + node + } } #[derive(Debug, Error)]