1
0
Fork 0
forked from wry/wry

pointer-constraints: implement cursor position hint

This commit is contained in:
Julian Orth 2025-05-28 12:11:51 +02:00
parent 90f791f772
commit 7405e04937
5 changed files with 34 additions and 7 deletions

View file

@ -61,12 +61,14 @@ pub struct SeatConstraint {
pub one_shot: bool,
pub status: Cell<SeatConstraintStatus>,
pub ty: ConstraintType,
pub position_hint: Cell<Option<(Fixed, Fixed)>>,
}
impl SeatConstraint {
pub fn deactivate(&self) {
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);
if let Some(owner) = self.owner.get() {
owner.send_disabled();
}
@ -78,6 +80,25 @@ impl SeatConstraint {
}
}
fn handle_position_hint(&self, apply: bool) {
let Some((x, y)) = self.position_hint.take() else {
return;
};
if !apply {
return;
}
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),
);
}
pub fn contains(&self, x: i32, y: i32) -> bool {
let region = self.region.get();
if let Some(region) = region {
@ -119,7 +140,7 @@ impl SeatConstraint {
}
fn detach(&self) {
self.deactivate();
self.deactivate(true);
self.owner.take();
self.surface.constraints.remove(&self.seat.id);
}
@ -221,6 +242,7 @@ impl ZwpPointerConstraintsV1 {
one_shot,
status: Cell::new(SeatConstraintStatus::Inactive),
ty,
position_hint: Default::default(),
}))
}
}