aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/handlers/mod.rs21
-rw-r--r--src/input/mod.rs38
-rw-r--r--src/niri.rs39
3 files changed, 56 insertions, 42 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs
index ed9f224c..a60de97f 100644
--- a/src/handlers/mod.rs
+++ b/src/handlers/mod.rs
@@ -140,7 +140,7 @@ impl PointerConstraintsHandler for State {
fn new_constraint(&mut self, _surface: &WlSurface, pointer: &PointerHandle<Self>) {
self.niri.maybe_activate_pointer_constraint(
pointer.current_location(),
- &self.niri.pointer_focus,
+ &self.niri.pointer_contents,
);
}
@@ -158,19 +158,20 @@ impl PointerConstraintsHandler for State {
return;
}
- // Logically the following two checks should always succeed (so, they should print
- // error!()s if they fail). However, currently both can fail because niri's pointer focus
- // doesn't take pointer grabs into account. So if you start, say, a middle-drag in Blender,
- // then touchpad-swipe the window away, the niri pointer focus will change, even though the
- // real pointer focus remains on the Blender surface due to the click grab.
+ // Note: this is surface under pointer, not pointer focus. So if you start, say, a
+ // middle-drag in Blender, then touchpad-swipe the window away, the surface under pointer
+ // will change, even though the real pointer focus remains on the Blender surface due to
+ // the click grab.
//
- // FIXME: add error!()s when niri pointer focus takes grabs into account. Alternatively,
- // recompute the surface origin here (but that is a bit clunky).
- let Some((ref focused_surface, origin)) = self.niri.pointer_focus.surface else {
+ // Ideally we would just use the constraint surface, but we need its origin. So this is
+ // more of a hack because pointer contents has the surface origin available.
+ //
+ // FIXME: use the constraint surface somehow, don't use pointer contents.
+ let Some((ref surface_under_pointer, origin)) = self.niri.pointer_contents.surface else {
return;
};
- if focused_surface != surface {
+ if surface_under_pointer != surface {
return;
}
diff --git a/src/input/mod.rs b/src/input/mod.rs
index 167c43cc..24d72bc0 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -1321,11 +1321,11 @@ impl State {
// Check if we have an active pointer constraint.
let mut pointer_confined = None;
- if let Some(focus) = &self.niri.pointer_focus.surface {
- let pos_within_surface = pos - focus.1;
+ if let Some(under) = &self.niri.pointer_contents.surface {
+ let pos_within_surface = pos - under.1;
let mut pointer_locked = false;
- with_pointer_constraint(&focus.0, &pointer, |constraint| {
+ with_pointer_constraint(&under.0, &pointer, |constraint| {
let Some(constraint) = constraint else { return };
if !constraint.is_active() {
return;
@@ -1343,7 +1343,7 @@ impl State {
pointer_locked = true;
}
PointerConstraint::Confined(confine) => {
- pointer_confined = Some((focus.clone(), confine.region().cloned()));
+ pointer_confined = Some((under.clone(), confine.region().cloned()));
}
}
});
@@ -1352,7 +1352,7 @@ impl State {
if pointer_locked {
pointer.relative_motion(
self,
- Some(focus.clone()),
+ Some(under.clone()),
&RelativeMotionEvent {
delta: event.delta(),
delta_unaccel: event.delta_unaccel(),
@@ -1451,7 +1451,7 @@ impl State {
// Activate a new confinement if necessary.
self.niri.maybe_activate_pointer_constraint(new_pos, &under);
- self.niri.pointer_focus.clone_from(&under);
+ self.niri.pointer_contents.clone_from(&under);
pointer.motion(
self,
@@ -1514,7 +1514,7 @@ impl State {
self.niri.handle_focus_follows_mouse(&under);
self.niri.maybe_activate_pointer_constraint(pos, &under);
- self.niri.pointer_focus.clone_from(&under);
+ self.niri.pointer_contents.clone_from(&under);
pointer.motion(
self,
@@ -1693,11 +1693,11 @@ impl State {
}
};
- self.update_pointer_focus();
+ self.update_pointer_contents();
if ButtonState::Pressed == button_state {
- let layer_focus = self.niri.pointer_focus.layer.clone();
- self.niri.focus_layer_surface_if_on_demand(layer_focus);
+ let layer_under = self.niri.pointer_contents.layer.clone();
+ self.niri.focus_layer_surface_if_on_demand(layer_under);
}
if let Some(button) = event.button() {
@@ -1914,7 +1914,7 @@ impl State {
}
}
- self.update_pointer_focus();
+ self.update_pointer_contents();
let pointer = &self.niri.seat.get_pointer().unwrap();
pointer.axis(self, frame);
@@ -2077,7 +2077,7 @@ impl State {
let serial = SERIAL_COUNTER.next_serial();
let pointer = self.niri.seat.get_pointer().unwrap();
- if self.update_pointer_focus() {
+ if self.update_pointer_contents() {
pointer.frame(self);
}
@@ -2168,7 +2168,7 @@ impl State {
let pointer = self.niri.seat.get_pointer().unwrap();
- if self.update_pointer_focus() {
+ if self.update_pointer_contents() {
pointer.frame(self);
}
@@ -2211,7 +2211,7 @@ impl State {
let serial = SERIAL_COUNTER.next_serial();
let pointer = self.niri.seat.get_pointer().unwrap();
- if self.update_pointer_focus() {
+ if self.update_pointer_contents() {
pointer.frame(self);
}
@@ -2229,7 +2229,7 @@ impl State {
let serial = SERIAL_COUNTER.next_serial();
let pointer = self.niri.seat.get_pointer().unwrap();
- if self.update_pointer_focus() {
+ if self.update_pointer_contents() {
pointer.frame(self);
}
@@ -2246,7 +2246,7 @@ impl State {
fn on_gesture_pinch_update<I: InputBackend>(&mut self, event: I::GesturePinchUpdateEvent) {
let pointer = self.niri.seat.get_pointer().unwrap();
- if self.update_pointer_focus() {
+ if self.update_pointer_contents() {
pointer.frame(self);
}
@@ -2265,7 +2265,7 @@ impl State {
let serial = SERIAL_COUNTER.next_serial();
let pointer = self.niri.seat.get_pointer().unwrap();
- if self.update_pointer_focus() {
+ if self.update_pointer_contents() {
pointer.frame(self);
}
@@ -2283,7 +2283,7 @@ impl State {
let serial = SERIAL_COUNTER.next_serial();
let pointer = self.niri.seat.get_pointer().unwrap();
- if self.update_pointer_focus() {
+ if self.update_pointer_contents() {
pointer.frame(self);
}
@@ -2301,7 +2301,7 @@ impl State {
let serial = SERIAL_COUNTER.next_serial();
let pointer = self.niri.seat.get_pointer().unwrap();
- if self.update_pointer_focus() {
+ if self.update_pointer_contents() {
pointer.frame(self);
}
diff --git a/src/niri.rs b/src/niri.rs
index 161933f7..5f0dbfb5 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -262,7 +262,20 @@ pub struct Niri {
pub cursor_texture_cache: CursorTextureCache,
pub cursor_shape_manager_state: CursorShapeManagerState,
pub dnd_icon: Option<DndIcon>,
- pub pointer_focus: PointContents,
+ /// Contents under pointer.
+ ///
+ /// Periodically updated: on motion and other events and in the loop callback. If you require
+ /// the real up-to-date contents somewhere, it's better to recompute on the spot.
+ ///
+ /// This is not pointer focus. I.e. during a click grab, the pointer focus remains on the
+ /// client with the grab, but this field will keep updating to the latest contents as if no
+ /// grab was active.
+ ///
+ /// This is primarily useful for emitting pointer motion events for surfaces that move
+ /// underneath the cursor on their own (i.e. when the tiling layout moves). In this case, not
+ /// taking grabs into account is expected, because we pass the information to pointer.motion()
+ /// which passes it down through grabs, which decide what to do with it as they see fit.
+ pub pointer_contents: PointContents,
/// Whether the pointer is hidden, for example due to a previous touch input.
///
/// When this happens, the pointer also loses any focus. This is so that touch can prevent
@@ -553,7 +566,7 @@ impl State {
self.niri.refresh_pointer_outputs();
self.niri.global_space.refresh();
self.niri.refresh_idle_inhibit();
- self.refresh_pointer_focus();
+ self.refresh_pointer_contents();
foreign_toplevel::refresh(self);
self.niri.refresh_window_rules();
self.refresh_ipc_outputs();
@@ -577,7 +590,7 @@ impl State {
let under = self.niri.contents_under(location);
self.niri
.maybe_activate_pointer_constraint(location, &under);
- self.niri.pointer_focus.clone_from(&under);
+ self.niri.pointer_contents.clone_from(&under);
let pointer = &self.niri.seat.get_pointer().unwrap();
pointer.motion(
@@ -676,8 +689,8 @@ impl State {
self.move_cursor_to_focused_tile(CenterCoords::Both)
}
- pub fn refresh_pointer_focus(&mut self) {
- let _span = tracy_client::span!("Niri::refresh_pointer_focus");
+ pub fn refresh_pointer_contents(&mut self) {
+ let _span = tracy_client::span!("Niri::refresh_pointer_contents");
let pointer = &self.niri.seat.get_pointer().unwrap();
let location = pointer.current_location();
@@ -692,7 +705,7 @@ impl State {
}
}
- if !self.update_pointer_focus() {
+ if !self.update_pointer_contents() {
return;
}
@@ -701,8 +714,8 @@ impl State {
self.niri.queue_redraw_all();
}
- pub fn update_pointer_focus(&mut self) -> bool {
- let _span = tracy_client::span!("Niri::update_pointer_focus");
+ pub fn update_pointer_contents(&mut self) -> bool {
+ let _span = tracy_client::span!("Niri::update_pointer_contents");
let pointer = &self.niri.seat.get_pointer().unwrap();
let location = pointer.current_location();
@@ -712,16 +725,16 @@ impl State {
self.niri.contents_under(location)
};
- // We're not changing the global cursor location here, so if the focus did not change, then
- // nothing changed.
- if self.niri.pointer_focus == under {
+ // We're not changing the global cursor location here, so if the contents did not change,
+ // then nothing changed.
+ if self.niri.pointer_contents == under {
return false;
}
self.niri
.maybe_activate_pointer_constraint(location, &under);
- self.niri.pointer_focus.clone_from(&under);
+ self.niri.pointer_contents.clone_from(&under);
pointer.motion(
self,
@@ -1858,7 +1871,7 @@ impl Niri {
cursor_texture_cache: Default::default(),
cursor_shape_manager_state,
dnd_icon: None,
- pointer_focus: PointContents::default(),
+ pointer_contents: PointContents::default(),
pointer_hidden: false,
pointer_inactivity_timer: None,
pointer_grab_ongoing: false,