Merge pull request #474 from mahkoh/jorth/cursor-position-hint
pointer-constraints: implement cursor position hint
This commit is contained in:
commit
3be8534683
5 changed files with 34 additions and 7 deletions
|
|
@ -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();
|
constraint.deactivate(true);
|
||||||
if constraint.status.get() == SeatConstraintStatus::Inactive {
|
if constraint.status.get() == SeatConstraintStatus::Inactive {
|
||||||
constraint
|
constraint
|
||||||
.status
|
.status
|
||||||
|
|
@ -465,6 +465,7 @@ impl WlSeatGlobal {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
candidate.status.set(SeatConstraintStatus::Active);
|
candidate.status.set(SeatConstraintStatus::Active);
|
||||||
|
candidate.position_hint.take();
|
||||||
if let Some(owner) = candidate.owner.get() {
|
if let Some(owner) = candidate.owner.get() {
|
||||||
owner.send_enabled();
|
owner.send_enabled();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
c.deactivate(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.state.for_each_seat_tester(|t| {
|
self.state.for_each_seat_tester(|t| {
|
||||||
|
|
@ -1285,7 +1285,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();
|
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);
|
||||||
|
|
|
||||||
|
|
@ -61,12 +61,14 @@ pub struct SeatConstraint {
|
||||||
pub one_shot: bool,
|
pub one_shot: bool,
|
||||||
pub status: Cell<SeatConstraintStatus>,
|
pub status: Cell<SeatConstraintStatus>,
|
||||||
pub ty: ConstraintType,
|
pub ty: ConstraintType,
|
||||||
|
pub position_hint: Cell<Option<(Fixed, Fixed)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SeatConstraint {
|
impl SeatConstraint {
|
||||||
pub fn deactivate(&self) {
|
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);
|
||||||
if let Some(owner) = self.owner.get() {
|
if let Some(owner) = self.owner.get() {
|
||||||
owner.send_disabled();
|
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 {
|
pub fn contains(&self, x: i32, y: i32) -> bool {
|
||||||
let region = self.region.get();
|
let region = self.region.get();
|
||||||
if let Some(region) = region {
|
if let Some(region) = region {
|
||||||
|
|
@ -119,7 +140,7 @@ impl SeatConstraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detach(&self) {
|
fn detach(&self) {
|
||||||
self.deactivate();
|
self.deactivate(true);
|
||||||
self.owner.take();
|
self.owner.take();
|
||||||
self.surface.constraints.remove(&self.seat.id);
|
self.surface.constraints.remove(&self.seat.id);
|
||||||
}
|
}
|
||||||
|
|
@ -221,6 +242,7 @@ impl ZwpPointerConstraintsV1 {
|
||||||
one_shot,
|
one_shot,
|
||||||
status: Cell::new(SeatConstraintStatus::Inactive),
|
status: Cell::new(SeatConstraintStatus::Inactive),
|
||||||
ty,
|
ty,
|
||||||
|
position_hint: Default::default(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,13 @@ impl ZwpLockedPointerV1RequestHandler for ZwpLockedPointerV1 {
|
||||||
|
|
||||||
fn set_cursor_position_hint(
|
fn set_cursor_position_hint(
|
||||||
&self,
|
&self,
|
||||||
_req: SetCursorPositionHint,
|
req: SetCursorPositionHint,
|
||||||
_slf: &Rc<Self>,
|
_slf: &Rc<Self>,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
|
let mut x = req.surface_x;
|
||||||
|
let mut y = req.surface_y;
|
||||||
|
client_wire_scale_to_logical!(self.constraint.client, x, y);
|
||||||
|
self.constraint.position_hint.set(Some((x, y)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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();
|
constraint.deactivate(true);
|
||||||
}
|
}
|
||||||
for (_, inhibitor) in &self.idle_inhibitors {
|
for (_, inhibitor) in &self.idle_inhibitors {
|
||||||
inhibitor.deactivate();
|
inhibitor.deactivate();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue