Merge pull request #495 from mahkoh/jorth/position-hint
pointer-constraints: always apply position hints asynchronously
This commit is contained in:
commit
70912b47e4
8 changed files with 88 additions and 63 deletions
|
|
@ -30,6 +30,7 @@ use {
|
||||||
ifs::{
|
ifs::{
|
||||||
jay_screencast::{perform_screencast_realloc, perform_toplevel_screencasts},
|
jay_screencast::{perform_screencast_realloc, perform_toplevel_screencasts},
|
||||||
wl_output::{OutputId, PersistentOutputState, WlOutputGlobal},
|
wl_output::{OutputId, PersistentOutputState, WlOutputGlobal},
|
||||||
|
wl_seat::handle_position_hint_requests,
|
||||||
wl_surface::{NoneSurfaceExt, zwp_input_popup_surface_v2::input_popup_positioning},
|
wl_surface::{NoneSurfaceExt, zwp_input_popup_surface_v2::input_popup_positioning},
|
||||||
workspace_manager::workspace_manager_done,
|
workspace_manager::workspace_manager_done,
|
||||||
},
|
},
|
||||||
|
|
@ -334,6 +335,8 @@ fn start_compositor2(
|
||||||
tl_matcher_manager: TlMatcherManager::new(&crit_ids),
|
tl_matcher_manager: TlMatcherManager::new(&crit_ids),
|
||||||
caps_thread,
|
caps_thread,
|
||||||
toplevel_managers: Default::default(),
|
toplevel_managers: Default::default(),
|
||||||
|
node_at_tree: Default::default(),
|
||||||
|
position_hint_requests: Default::default(),
|
||||||
});
|
});
|
||||||
state.tracker.register(ClientId::from_raw(0));
|
state.tracker.register(ClientId::from_raw(0));
|
||||||
create_dummy_output(&state);
|
create_dummy_output(&state);
|
||||||
|
|
@ -521,6 +524,10 @@ fn start_global_event_handlers(
|
||||||
Phase::Layout,
|
Phase::Layout,
|
||||||
handle_tl_just_mapped(state.clone()),
|
handle_tl_just_mapped(state.clone()),
|
||||||
),
|
),
|
||||||
|
eng.spawn(
|
||||||
|
"position hint requests",
|
||||||
|
handle_position_hint_requests(state.clone()),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,9 @@ use {
|
||||||
rect::Rect,
|
rect::Rect,
|
||||||
state::{DeviceHandlerData, State},
|
state::{DeviceHandlerData, State},
|
||||||
tree::{
|
tree::{
|
||||||
ContainerNode, ContainerSplit, Direction, FoundNode, Node, OutputNode, ToplevelNode,
|
ContainerNode, ContainerSplit, Direction, FoundNode, Node, NodeId, OutputNode,
|
||||||
WorkspaceNode, generic_node_visitor, toplevel_create_split, toplevel_parent_container,
|
ToplevelNode, WorkspaceNode, generic_node_visitor, toplevel_create_split,
|
||||||
toplevel_set_floating, toplevel_set_workspace,
|
toplevel_parent_container, toplevel_set_floating, toplevel_set_workspace,
|
||||||
},
|
},
|
||||||
utils::{
|
utils::{
|
||||||
asyncevent::AsyncEvent, bindings::PerClientBindings, clonecell::CloneCell,
|
asyncevent::AsyncEvent, bindings::PerClientBindings, clonecell::CloneCell,
|
||||||
|
|
@ -432,7 +432,7 @@ impl WlSeatGlobal {
|
||||||
|
|
||||||
pub fn disable_pointer_constraint(&self) {
|
pub fn disable_pointer_constraint(&self) {
|
||||||
if let Some(constraint) = self.constraint.get() {
|
if let Some(constraint) = self.constraint.get() {
|
||||||
constraint.deactivate(true, true);
|
constraint.deactivate(true);
|
||||||
if constraint.status.get() == SeatConstraintStatus::Inactive {
|
if constraint.status.get() == SeatConstraintStatus::Inactive {
|
||||||
constraint
|
constraint
|
||||||
.status
|
.status
|
||||||
|
|
@ -1348,3 +1348,26 @@ impl DeviceHandlerData {
|
||||||
state.root.extents.get()
|
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);
|
let (x, y) = self.set_pointer_cursor_position(x, y);
|
||||||
if let Some(c) = self.constraint.get() {
|
if let Some(c) = self.constraint.get() {
|
||||||
if c.ty == ConstraintType::Lock || !c.contains(x.round_down(), y.round_down()) {
|
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| {
|
self.state.for_each_seat_tester(|t| {
|
||||||
|
|
@ -1289,7 +1289,7 @@ impl WlSeatGlobal {
|
||||||
pub fn leave_surface(&self, n: &WlSurface) {
|
pub fn leave_surface(&self, n: &WlSurface) {
|
||||||
let serial = n.client.next_serial();
|
let serial = n.client.next_serial();
|
||||||
for (_, constraint) in &n.constraints {
|
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_event(Version::ALL, n, |p| p.send_leave(serial, n.id));
|
||||||
self.surface_pointer_frame(n);
|
self.surface_pointer_frame(n);
|
||||||
|
|
|
||||||
|
|
@ -547,21 +547,11 @@ impl PointerOwner for DndPointerOwner {
|
||||||
|
|
||||||
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>) {
|
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>) {
|
||||||
let (x, y) = seat.pointer_cursor.position();
|
let (x, y) = seat.pointer_cursor.position();
|
||||||
let (x_int, y_int) = (x.round_down(), y.round_down());
|
let FoundNode {
|
||||||
let (node, x_int, y_int) = {
|
node,
|
||||||
let mut found_tree = seat.found_tree.borrow_mut();
|
x: x_int,
|
||||||
found_tree.push(FoundNode {
|
y: y_int,
|
||||||
node: seat.state.root.clone(),
|
} = seat.state.node_at(x.round_down(), y.round_down());
|
||||||
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 (x, y) = (x.apply_fract(x_int), y.apply_fract(y_int));
|
let (x, y) = (x.apply_fract(x_int), y.apply_fract(y_int));
|
||||||
let mut target = self.target.get();
|
let mut target = self.target.get();
|
||||||
if node.node_id() != target.node_id() {
|
if node.node_id() != target.node_id() {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use {
|
||||||
crate::{
|
crate::{
|
||||||
fixed::Fixed,
|
fixed::Fixed,
|
||||||
ifs::wl_seat::WlSeatGlobal,
|
ifs::wl_seat::WlSeatGlobal,
|
||||||
tree::{FindTreeUsecase, FoundNode, Node},
|
tree::Node,
|
||||||
utils::{clonecell::CloneCell, smallmap::SmallMap},
|
utils::{clonecell::CloneCell, smallmap::SmallMap},
|
||||||
},
|
},
|
||||||
std::rc::Rc,
|
std::rc::Rc,
|
||||||
|
|
@ -69,29 +69,14 @@ trait TouchOwner {
|
||||||
|
|
||||||
impl TouchOwner for DefaultTouchOwner {
|
impl TouchOwner for DefaultTouchOwner {
|
||||||
fn down(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, id: i32, x: Fixed, y: Fixed) {
|
fn down(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, id: i32, x: Fixed, y: Fixed) {
|
||||||
let mut found_tree = seat.found_tree.borrow_mut();
|
let node = seat.state.node_at(x.round_down(), y.round_down());
|
||||||
let x_int = x.round_down();
|
node.node.node_seat_state().touch_begin(seat);
|
||||||
let y_int = y.round_down();
|
let owner = Rc::new(GrabTouchOwner {
|
||||||
found_tree.push(FoundNode {
|
node: node.node,
|
||||||
node: seat.state.root.clone(),
|
down_ids: Default::default(),
|
||||||
x: x_int,
|
|
||||||
y: y_int,
|
|
||||||
});
|
});
|
||||||
seat.state
|
seat.touch_owner.owner.set(owner.clone());
|
||||||
.root
|
owner.down(seat, time_usec, id, x, y);
|
||||||
.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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn up(&self, _seat: &Rc<WlSeatGlobal>, _time_usec: u64, _id: i32) {
|
fn up(&self, _seat: &Rc<WlSeatGlobal>, _time_usec: u64, _id: i32) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use {
|
||||||
globals::{Global, GlobalName},
|
globals::{Global, GlobalName},
|
||||||
ifs::{
|
ifs::{
|
||||||
wl_seat::{
|
wl_seat::{
|
||||||
WlSeatGlobal,
|
PositionHintRequest, WlSeatGlobal,
|
||||||
zwp_pointer_constraints_v1::zwp_confined_pointer_v1::ZwpConfinedPointerV1,
|
zwp_pointer_constraints_v1::zwp_confined_pointer_v1::ZwpConfinedPointerV1,
|
||||||
},
|
},
|
||||||
wl_surface::WlSurface,
|
wl_surface::WlSurface,
|
||||||
|
|
@ -65,10 +65,10 @@ pub struct SeatConstraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
if self.status.get() == SeatConstraintStatus::Active {
|
||||||
self.seat.constraint.take();
|
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() {
|
if let Some(owner) = self.owner.get() {
|
||||||
owner.send_disabled();
|
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 {
|
let Some((x, y)) = self.position_hint.take() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -89,15 +89,15 @@ impl SeatConstraint {
|
||||||
}
|
}
|
||||||
let buffer = self.surface.buffer_abs_pos.get();
|
let buffer = self.surface.buffer_abs_pos.get();
|
||||||
let (x_int, y_int) = buffer.translate_inv(x.round_down(), y.round_down());
|
let (x_int, y_int) = buffer.translate_inv(x.round_down(), y.round_down());
|
||||||
if !buffer.contains(x_int, y_int) {
|
self.client
|
||||||
return;
|
.state
|
||||||
}
|
.position_hint_requests
|
||||||
self.seat.motion_event_abs(
|
.push(PositionHintRequest {
|
||||||
self.client.state.now_usec(),
|
seat: self.seat.clone(),
|
||||||
x.apply_fract(x_int),
|
node: self.surface.node_id.into(),
|
||||||
y.apply_fract(y_int),
|
old_pos: self.seat.pointer_cursor.position(),
|
||||||
defer,
|
new_pos: (x.apply_fract(x_int), y.apply_fract(y_int)),
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains(&self, x: i32, y: i32) -> bool {
|
pub fn contains(&self, x: i32, y: i32) -> bool {
|
||||||
|
|
@ -141,7 +141,7 @@ impl SeatConstraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detach(&self) {
|
fn detach(&self) {
|
||||||
self.deactivate(true, false);
|
self.deactivate(true);
|
||||||
self.owner.take();
|
self.owner.take();
|
||||||
self.surface.constraints.remove(&self.seat.id);
|
self.surface.constraints.remove(&self.seat.id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1630,7 +1630,7 @@ impl WlSurface {
|
||||||
|
|
||||||
pub fn detach_node(&self, set_invisible: bool) {
|
pub fn detach_node(&self, set_invisible: bool) {
|
||||||
for (_, constraint) in &self.constraints {
|
for (_, constraint) in &self.constraints {
|
||||||
constraint.deactivate(true, true);
|
constraint.deactivate(true);
|
||||||
}
|
}
|
||||||
for (_, inhibitor) in &self.idle_inhibitors {
|
for (_, inhibitor) in &self.idle_inhibitors {
|
||||||
inhibitor.deactivate();
|
inhibitor.deactivate();
|
||||||
|
|
|
||||||
28
src/state.rs
28
src/state.rs
|
|
@ -50,7 +50,8 @@ use {
|
||||||
wl_drm::WlDrmGlobal,
|
wl_drm::WlDrmGlobal,
|
||||||
wl_output::{OutputGlobalOpt, OutputId, PersistentOutputState},
|
wl_output::{OutputGlobalOpt, OutputId, PersistentOutputState},
|
||||||
wl_seat::{
|
wl_seat::{
|
||||||
PhysicalKeyboardId, PhysicalKeyboardIds, SeatIds, WlSeatGlobal,
|
PhysicalKeyboardId, PhysicalKeyboardIds, PositionHintRequest, SeatIds,
|
||||||
|
WlSeatGlobal,
|
||||||
tablet::{TabletIds, TabletInit, TabletPadIds, TabletPadInit, TabletToolIds},
|
tablet::{TabletIds, TabletInit, TabletPadIds, TabletPadInit, TabletToolIds},
|
||||||
},
|
},
|
||||||
wl_surface::{
|
wl_surface::{
|
||||||
|
|
@ -83,9 +84,10 @@ use {
|
||||||
theme::{Color, Theme},
|
theme::{Color, Theme},
|
||||||
time::Time,
|
time::Time,
|
||||||
tree::{
|
tree::{
|
||||||
ContainerNode, ContainerSplit, Direction, DisplayNode, FloatNode, LatchListener, Node,
|
ContainerNode, ContainerSplit, Direction, DisplayNode, FindTreeUsecase, FloatNode,
|
||||||
NodeIds, NodeVisitorBase, OutputNode, PlaceholderNode, TearingMode, ToplevelData,
|
FoundNode, LatchListener, Node, NodeIds, NodeVisitorBase, OutputNode, PlaceholderNode,
|
||||||
ToplevelNode, ToplevelNodeBase, VrrMode, WorkspaceNode, generic_node_visitor,
|
TearingMode, ToplevelData, ToplevelNode, ToplevelNodeBase, VrrMode, WorkspaceNode,
|
||||||
|
generic_node_visitor,
|
||||||
},
|
},
|
||||||
utils::{
|
utils::{
|
||||||
activation_token::ActivationToken, asyncevent::AsyncEvent, bindings::Bindings,
|
activation_token::ActivationToken, asyncevent::AsyncEvent, bindings::Bindings,
|
||||||
|
|
@ -251,6 +253,8 @@ pub struct State {
|
||||||
pub cl_matcher_manager: ClMatcherManager,
|
pub cl_matcher_manager: ClMatcherManager,
|
||||||
pub tl_matcher_manager: TlMatcherManager,
|
pub tl_matcher_manager: TlMatcherManager,
|
||||||
pub caps_thread: Option<PrCapsThread>,
|
pub caps_thread: Option<PrCapsThread>,
|
||||||
|
pub node_at_tree: RefCell<Vec<FoundNode>>,
|
||||||
|
pub position_hint_requests: AsyncQueue<PositionHintRequest>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl Drop for State {
|
// impl Drop for State {
|
||||||
|
|
@ -975,6 +979,8 @@ impl State {
|
||||||
self.workspace_managers.clear();
|
self.workspace_managers.clear();
|
||||||
self.cl_matcher_manager.clear();
|
self.cl_matcher_manager.clear();
|
||||||
self.tl_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) {
|
pub fn remove_toplevel_id(&self, id: ToplevelIdentifier) {
|
||||||
|
|
@ -1400,6 +1406,20 @@ impl State {
|
||||||
pub fn initial_tile_state(&self, data: &ToplevelData) -> Option<TileState> {
|
pub fn initial_tile_state(&self, data: &ToplevelData) -> Option<TileState> {
|
||||||
self.config.get()?.initial_tile_state(data)
|
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)]
|
#[derive(Debug, Error)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue