pointer-constraints: always apply position hints asynchronously
This commit is contained in:
parent
bae92d90d0
commit
4d9dde7927
6 changed files with 54 additions and 22 deletions
|
|
@ -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,
|
||||
},
|
||||
|
|
@ -335,6 +336,7 @@ fn start_compositor2(
|
|||
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);
|
||||
|
|
@ -522,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()),
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<WlSeatGlobal>,
|
||||
node: NodeId,
|
||||
old_pos: (Fixed, Fixed),
|
||||
new_pos: (Fixed, Fixed),
|
||||
}
|
||||
|
||||
pub async fn handle_position_hint_requests(state: Rc<State>) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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::{
|
||||
|
|
@ -253,6 +254,7 @@ pub struct State {
|
|||
pub tl_matcher_manager: TlMatcherManager,
|
||||
pub caps_thread: Option<PrCapsThread>,
|
||||
pub node_at_tree: RefCell<Vec<FoundNode>>,
|
||||
pub position_hint_requests: AsyncQueue<PositionHintRequest>,
|
||||
}
|
||||
|
||||
// impl Drop for State {
|
||||
|
|
@ -978,6 +980,7 @@ impl State {
|
|||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue