anvil: perform cursor x and y movements separately
This commit is contained in:
parent
2fab511f55
commit
f6d7e9dc65
2 changed files with 54 additions and 27 deletions
|
|
@ -933,27 +933,41 @@ impl AnvilState<UdevData> {
|
|||
return;
|
||||
}
|
||||
|
||||
pointer_location += evt.delta();
|
||||
// Clamp delta, such that the pointer never moves out of bounds
|
||||
let mut delta = self.clamp_coords(pointer_location + evt.delta()) - pointer_location;
|
||||
|
||||
// clamp to screen limits
|
||||
// this event is never generated by winit
|
||||
pointer_location = self.clamp_coords(pointer_location);
|
||||
// Clamp the individual x and y components of delta to respect confinement regions
|
||||
if pointer_confined {
|
||||
if let Some((_, surface_loc)) = &under {
|
||||
if let Some(region) = &confine_region {
|
||||
// Clamp delta.x
|
||||
if !region.contains(
|
||||
(pointer_location + Point::new(delta.x, 0f64) - *surface_loc).to_i32_round(),
|
||||
) {
|
||||
delta.x = 0f64;
|
||||
}
|
||||
|
||||
// Clamp delta.y
|
||||
if !region.contains(
|
||||
(pointer_location + Point::new(0f64, delta.y) - *surface_loc).to_i32_round(),
|
||||
) {
|
||||
delta.y = 0f64;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pointer_location += delta;
|
||||
|
||||
let new_under = self.surface_under(pointer_location);
|
||||
|
||||
// If confined, don't move pointer if it would go outside surface or region
|
||||
// If confined, don't move pointer if it would go outside surface
|
||||
if pointer_confined {
|
||||
if let Some((surface, surface_loc)) = &under {
|
||||
if let Some((surface, _)) = &under {
|
||||
if new_under.as_ref().and_then(|(under, _)| under.wl_surface()) != surface.wl_surface() {
|
||||
pointer.frame(self);
|
||||
return;
|
||||
}
|
||||
if let Some(region) = confine_region {
|
||||
if !region.contains((pointer_location - *surface_loc).to_i32_round()) {
|
||||
pointer.frame(self);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,6 +153,34 @@ impl WindowHandler for App {
|
|||
self.first_configure = false;
|
||||
self.draw(conn, qh);
|
||||
}
|
||||
|
||||
if let Some(confined_pointer) = &self.confined_pointer {
|
||||
confined_pointer.destroy();
|
||||
self.confined_pointer = None;
|
||||
}
|
||||
|
||||
if let Some(pointer) = &self.pointer {
|
||||
let region = self.compositor_state.wl_compositor().create_region(qh, ());
|
||||
let w = self.width as i32;
|
||||
let h = self.height as i32;
|
||||
|
||||
region.add(0, 0, w, h);
|
||||
region.subtract(w / 2, h / 2, w / 2, h / 2);
|
||||
region.subtract(0, 0, w / 4, h / 4);
|
||||
|
||||
let confined_pointer = self
|
||||
.pointer_constraint_state
|
||||
.confine_pointer(
|
||||
self.window.wl_surface(),
|
||||
&pointer,
|
||||
Some(®ion),
|
||||
zwp_pointer_constraints_v1::Lifetime::Persistent,
|
||||
qh,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
self.confined_pointer = Some(confined_pointer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -214,22 +242,7 @@ impl SeatHandler for App {
|
|||
.get_pointer(qh, &seat)
|
||||
.expect("Failed to create pointer");
|
||||
|
||||
let region = self.compositor_state.wl_compositor().create_region(qh, ());
|
||||
region.add(0, 0, 64, 64);
|
||||
|
||||
let confined_pointer = self
|
||||
.pointer_constraint_state
|
||||
.confine_pointer(
|
||||
self.window.wl_surface(),
|
||||
&pointer,
|
||||
Some(®ion),
|
||||
zwp_pointer_constraints_v1::Lifetime::Persistent,
|
||||
qh,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
self.pointer = Some(pointer);
|
||||
self.confined_pointer = Some(confined_pointer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue