forge
Explore
Log in

Don't you dare go Hollow

Keep track of output and window in PointerFocus separately

Browse files at this commit

d970abead82abab8ac2596662bc4d8e41a53e003Ivan MolodetskikhParent: 4f6ed9d
src/input.rsmodified+15 -26
@@ -778,12 +778,11 @@ impl State {
778778
779779 // Check if we have an active pointer constraint.
780780 let mut pointer_confined = None;
781- if let Some(focus) = self.niri.pointer_focus.as_ref() {
782- let focus_surface_loc = focus.surface.1;
783- let pos_within_surface = pos.to_i32_round() - focus_surface_loc;
781+ if let Some(focus) = &self.niri.pointer_focus.surface {
782+ let pos_within_surface = pos.to_i32_round() - focus.1;
784783
785784 let mut pointer_locked = false;
786- with_pointer_constraint(&focus.surface.0, &pointer, |constraint| {
785+ with_pointer_constraint(&focus.0, &pointer, |constraint| {
787786 let Some(constraint) = constraint else { return };
788787 if !constraint.is_active() {
789788 return;
@@ -801,7 +800,7 @@ impl State {
801800 pointer_locked = true;
802801 }
803802 PointerConstraint::Confined(confine) => {
804- pointer_confined = Some((focus.surface.clone(), confine.region().cloned()));
803+ pointer_confined = Some((focus.clone(), confine.region().cloned()));
805804 }
806805 }
807806 });
@@ -810,7 +809,7 @@ impl State {
810809 if pointer_locked {
811810 pointer.relative_motion(
812811 self,
813- Some(focus.surface.clone()),
812+ Some(focus.clone()),
814813 &RelativeMotionEvent {
815814 delta: event.delta(),
816815 delta_unaccel: event.delta_unaccel(),
@@ -875,7 +874,7 @@ impl State {
875874 let mut prevent = false;
876875
877876 // Prevent the pointer from leaving the focused surface.
878- if Some(&focus_surface.0) != under.as_ref().map(|x| &x.surface.0) {
877+ if Some(&focus_surface.0) != under.surface.as_ref().map(|(s, _)| s) {
879878 prevent = true;
880879 }
881880
@@ -908,11 +907,10 @@ impl State {
908907 self.niri.maybe_activate_pointer_constraint(new_pos, &under);
909908
910909 self.niri.pointer_focus.clone_from(&under);
911- let under = under.map(|u| u.surface);
912910
913911 pointer.motion(
914912 self,
915- under.clone(),
913+ under.surface.clone(),
916914 &MotionEvent {
917915 location: new_pos,
918916 serial,
@@ -922,7 +920,7 @@ impl State {
922920
923921 pointer.relative_motion(
924922 self,
925- under,
923+ under.surface,
926924 &RelativeMotionEvent {
927925 delta: event.delta(),
928926 delta_unaccel: event.delta_unaccel(),
@@ -971,11 +969,10 @@ impl State {
971969 let under = self.niri.surface_under_and_global_space(pos);
972970 self.niri.maybe_activate_pointer_constraint(pos, &under);
973971 self.niri.pointer_focus.clone_from(&under);
974- let under = under.map(|u| u.surface);
975972
976973 pointer.motion(
977974 self,
978- under,
975+ under.surface,
979976 &MotionEvent {
980977 location: pos,
981978 serial,
@@ -1113,7 +1110,6 @@ impl State {
11131110 };
11141111
11151112 let under = self.niri.surface_under_and_global_space(pos);
1116- let under = under.map(|u| u.surface);
11171113
11181114 let tablet_seat = self.niri.seat.tablet_seat();
11191115 let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device()));
@@ -1140,7 +1136,7 @@ impl State {
11401136
11411137 tool.motion(
11421138 pos,
1143- under,
1139+ under.surface,
11441140 &tablet,
11451141 SERIAL_COUNTER.next_serial(),
11461142 event.time_msec(),
@@ -1195,7 +1191,6 @@ impl State {
11951191 };
11961192
11971193 let under = self.niri.surface_under_and_global_space(pos);
1198- let under = under.map(|u| u.surface);
11991194
12001195 let tablet_seat = self.niri.seat.tablet_seat();
12011196 let tool = tablet_seat.add_tool::<Self>(&self.niri.display_handle, &event.tool());
@@ -1203,7 +1198,7 @@ impl State {
12031198 if let Some(tablet) = tablet {
12041199 match event.state() {
12051200 ProximityState::In => {
1206- if let Some(under) = under {
1201+ if let Some(under) = under.surface {
12071202 tool.proximity_in(
12081203 pos,
12091204 under,
@@ -1538,13 +1533,10 @@ impl State {
15381533 };
15391534
15401535 let serial = SERIAL_COUNTER.next_serial();
1541- let under = self
1542- .niri
1543- .surface_under_and_global_space(touch_location)
1544- .map(|under| under.surface);
1536+ let under = self.niri.surface_under_and_global_space(touch_location);
15451537 handle.down(
15461538 self,
1547- under,
1539+ under.surface,
15481540 &DownEvent {
15491541 slot: evt.slot(),
15501542 location: touch_location,
@@ -1574,13 +1566,10 @@ impl State {
15741566 let Some(touch_location) = self.compute_touch_location(&evt) else {
15751567 return;
15761568 };
1577- let under = self
1578- .niri
1579- .surface_under_and_global_space(touch_location)
1580- .map(|under| under.surface);
1569+ let under = self.niri.surface_under_and_global_space(touch_location);
15811570 handle.motion(
15821571 self,
1583- under,
1572+ under.surface,
15841573 &TouchMotionEvent {
15851574 slot: evt.slot(),
15861575 location: touch_location,
src/niri.rsmodified+50 -35
@@ -201,7 +201,7 @@ pub struct Niri {
201201 pub cursor_texture_cache: CursorTextureCache,
202202 pub cursor_shape_manager_state: CursorShapeManagerState,
203203 pub dnd_icon: Option<WlSurface>,
204- pub pointer_focus: Option<PointerFocus>,
204+ pub pointer_focus: PointerFocus,
205205 pub tablet_cursor_location: Option<Point<f64, Logical>>,
206206 pub gesture_swipe_3f_cumulative: Option<(f64, f64)>,
207207
@@ -292,10 +292,14 @@ pub enum KeyboardFocus {
292292 ScreenshotUi,
293293 }
294294
295-#[derive(Clone, PartialEq, Eq)]
295+#[derive(Default, Clone, PartialEq, Eq)]
296296 pub struct PointerFocus {
297- pub output: Output,
298- pub surface: (WlSurface, Point<i32, Logical>),
297+ // Output under pointer.
298+ pub output: Option<Output>,
299+ // Surface under pointer and its location in global coordinate space.
300+ pub surface: Option<(WlSurface, Point<i32, Logical>)>,
301+ // If surface belongs to a window, this is that window.
302+ pub window: Option<Window>,
299303 }
300304
301305 #[derive(Default)]
@@ -421,12 +425,11 @@ impl State {
421425 self.niri
422426 .maybe_activate_pointer_constraint(location, &under);
423427 self.niri.pointer_focus.clone_from(&under);
424- let under = under.map(|u| u.surface);
425428
426429 let pointer = &self.niri.seat.get_pointer().unwrap();
427430 pointer.motion(
428431 self,
429- under,
432+ under.surface,
430433 &MotionEvent {
431434 location,
432435 serial: SERIAL_COUNTER.next_serial(),
@@ -560,11 +563,10 @@ impl State {
560563 .maybe_activate_pointer_constraint(location, &under);
561564
562565 self.niri.pointer_focus.clone_from(&under);
563- let under = under.map(|u| u.surface);
564566
565567 pointer.motion(
566568 self,
567- under,
569+ under.surface,
568570 &MotionEvent {
569571 location,
570572 serial: SERIAL_COUNTER.next_serial(),
@@ -1225,7 +1227,7 @@ impl Niri {
12251227 cursor_texture_cache: Default::default(),
12261228 cursor_shape_manager_state,
12271229 dnd_icon: None,
1228- pointer_focus: None,
1230+ pointer_focus: PointerFocus::default(),
12291231 tablet_cursor_location: None,
12301232 gesture_swipe_3f_cumulative: None,
12311233
@@ -1622,32 +1624,39 @@ impl Niri {
16221624 /// Pointer needs location in global space, and focused window location compatible with that
16231625 /// global space. We don't have a global space for all windows, but this function converts the
16241626 /// window location temporarily to the current global space.
1625- pub fn surface_under_and_global_space(
1626- &mut self,
1627- pos: Point<f64, Logical>,
1628- ) -> Option<PointerFocus> {
1629- let (output, pos_within_output) = self.output_under(pos)?;
1627+ pub fn surface_under_and_global_space(&mut self, pos: Point<f64, Logical>) -> PointerFocus {
1628+ let mut rv = PointerFocus::default();
1629+
1630+ let Some((output, pos_within_output)) = self.output_under(pos) else {
1631+ return rv;
1632+ };
1633+ rv.output = Some(output.clone());
16301634 let output_pos_in_global_space = self.global_space.output_geometry(output).unwrap().loc;
16311635
16321636 if self.is_locked() {
1633- let state = self.output_state.get(output)?;
1634- let surface = state.lock_surface.as_ref()?;
1635- // We put lock surfaces at (0, 0).
1636- let point = pos_within_output;
1637- let (surface, point) = under_from_surface_tree(
1637+ let Some(state) = self.output_state.get(output) else {
1638+ return rv;
1639+ };
1640+ let Some(surface) = state.lock_surface.as_ref() else {
1641+ return rv;
1642+ };
1643+
1644+ rv.surface = under_from_surface_tree(
16381645 surface.wl_surface(),
1639- point,
1646+ pos_within_output,
1647+ // We put lock surfaces at (0, 0).
16401648 (0, 0),
16411649 WindowSurfaceType::ALL,
1642- )?;
1643- return Some(PointerFocus {
1644- output: output.clone(),
1645- surface: (surface, point + output_pos_in_global_space),
1650+ )
1651+ .map(|(surface, pos_within_output)| {
1652+ (surface, pos_within_output + output_pos_in_global_space)
16461653 });
1654+
1655+ return rv;
16471656 }
16481657
16491658 if self.screenshot_ui.is_open() {
1650- return None;
1659+ return rv;
16511660 }
16521661
16531662 let layers = layer_map_for_output(output);
@@ -1665,6 +1674,7 @@ impl Niri {
16651674 (surface, pos_within_layer + layer_pos_within_output)
16661675 })
16671676 })
1677+ .map(|s| (s, None))
16681678 };
16691679
16701680 let window_under = || {
@@ -1680,6 +1690,7 @@ impl Niri {
16801690 .map(|(s, pos_within_window)| {
16811691 (s, pos_within_window + win_pos_within_output)
16821692 })
1693+ .map(|s| (s, Some(window.clone())))
16831694 })
16841695 };
16851696
@@ -1697,16 +1708,18 @@ impl Niri {
16971708 .or_else(window_under);
16981709 }
16991710
1700- let (surface, surface_pos_within_output) = under
1711+ let Some(((surface, surface_pos_within_output), window)) = under
17011712 .or_else(|| layer_surface_under(Layer::Bottom))
1702- .or_else(|| layer_surface_under(Layer::Background))?;
1713+ .or_else(|| layer_surface_under(Layer::Background))
1714+ else {
1715+ return rv;
1716+ };
17031717
17041718 let surface_loc_in_global_space = surface_pos_within_output + output_pos_in_global_space;
17051719
1706- Some(PointerFocus {
1707- output: output.clone(),
1708- surface: (surface, surface_loc_in_global_space),
1709- })
1720+ rv.surface = Some((surface, surface_loc_in_global_space));
1721+ rv.window = window;
1722+ rv
17101723 }
17111724
17121725 pub fn output_under_cursor(&self) -> Option<Output> {
@@ -3231,11 +3244,13 @@ impl Niri {
32313244 pub fn maybe_activate_pointer_constraint(
32323245 &self,
32333246 new_pos: Point<f64, Logical>,
3234- new_under: &Option<PointerFocus>,
3247+ new_under: &PointerFocus,
32353248 ) {
3236- let Some(under) = new_under else { return };
3249+ let Some((surface, surface_loc)) = &new_under.surface else {
3250+ return;
3251+ };
32373252 let pointer = &self.seat.get_pointer().unwrap();
3238- with_pointer_constraint(&under.surface.0, pointer, |constraint| {
3253+ with_pointer_constraint(surface, pointer, |constraint| {
32393254 let Some(constraint) = constraint else { return };
32403255 if constraint.is_active() {
32413256 return;
@@ -3243,7 +3258,7 @@ impl Niri {
32433258
32443259 // Constraint does not apply if not within region.
32453260 if let Some(region) = constraint.region() {
3246- let new_pos_within_surface = new_pos.to_i32_round() - under.surface.1;
3261+ let new_pos_within_surface = new_pos.to_i32_round() - *surface_loc;
32473262 if !region.contains(new_pos_within_surface) {
32483263 return;
32493264 }