Refresh pointer focus continuously
Browse files at this commitda59dfc5b4b6046475c36a377be661fbf3351bd0Parent: 67ea3782 changed files +68 -4
- src/input.rs +8 -0
- src/niri.rs +60 -4
src/input.rsmodified+8 -0
| @@ -394,6 +394,8 @@ impl State { | |||
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | let under = self.niri.surface_under_and_global_space(new_pos); | 396 | let under = self.niri.surface_under_and_global_space(new_pos); |
| 397 | + self.niri.pointer_focus = under.clone(); | ||
| 398 | + let under = under.map(|u| u.surface); | ||
| 397 | 399 | ||
| 398 | pointer.motion( | 400 | pointer.motion( |
| 399 | self, | 401 | self, |
| @@ -435,6 +437,8 @@ impl State { | |||
| 435 | let pointer = self.niri.seat.get_pointer().unwrap(); | 437 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 436 | 438 | ||
| 437 | let under = self.niri.surface_under_and_global_space(pos); | 439 | let under = self.niri.surface_under_and_global_space(pos); |
| 440 | + self.niri.pointer_focus = under.clone(); | ||
| 441 | + let under = under.map(|u| u.surface); | ||
| 438 | 442 | ||
| 439 | pointer.motion( | 443 | pointer.motion( |
| 440 | self, | 444 | self, |
| @@ -534,6 +538,8 @@ impl State { | |||
| 534 | let pointer = self.niri.seat.get_pointer().unwrap(); | 538 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 535 | 539 | ||
| 536 | let under = self.niri.surface_under_and_global_space(pos); | 540 | let under = self.niri.surface_under_and_global_space(pos); |
| 541 | + self.niri.pointer_focus = under.clone(); | ||
| 542 | + let under = under.map(|u| u.surface); | ||
| 537 | 543 | ||
| 538 | pointer.motion( | 544 | pointer.motion( |
| 539 | self, | 545 | self, |
| @@ -621,6 +627,8 @@ impl State { | |||
| 621 | let pointer = self.niri.seat.get_pointer().unwrap(); | 627 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 622 | 628 | ||
| 623 | let under = self.niri.surface_under_and_global_space(pos); | 629 | let under = self.niri.surface_under_and_global_space(pos); |
| 630 | + self.niri.pointer_focus = under.clone(); | ||
| 631 | + let under = under.map(|u| u.surface); | ||
| 624 | 632 | ||
| 625 | pointer.motion( | 633 | pointer.motion( |
| 626 | self, | 634 | self, |
src/niri.rsmodified+60 -4
| @@ -136,6 +136,7 @@ pub struct Niri { | |||
| 136 | pub default_cursor: Cursor, | 136 | pub default_cursor: Cursor, |
| 137 | pub cursor_image: CursorImageStatus, | 137 | pub cursor_image: CursorImageStatus, |
| 138 | pub dnd_icon: Option<WlSurface>, | 138 | pub dnd_icon: Option<WlSurface>, |
| 139 | + pub pointer_focus: Option<PointerFocus>, | ||
| 139 | 140 | ||
| 140 | #[cfg(feature = "dbus")] | 141 | #[cfg(feature = "dbus")] |
| 141 | pub dbus: Option<crate::dbus::DBusServers>, | 142 | pub dbus: Option<crate::dbus::DBusServers>, |
| @@ -179,6 +180,12 @@ pub enum RedrawState { | |||
| 179 | WaitingForEstimatedVBlankAndQueued((RegistrationToken, Idle<'static>)), | 180 | WaitingForEstimatedVBlankAndQueued((RegistrationToken, Idle<'static>)), |
| 180 | } | 181 | } |
| 181 | 182 | ||
| 183 | +#[derive(Clone, PartialEq, Eq)] | ||
| 184 | +pub struct PointerFocus { | ||
| 185 | + pub output: Output, | ||
| 186 | + pub surface: (WlSurface, Point<i32, Logical>), | ||
| 187 | +} | ||
| 188 | + | ||
| 182 | // Not related to the one in Smithay. | 189 | // Not related to the one in Smithay. |
| 183 | // | 190 | // |
| 184 | // This state keeps track of when a surface last received a frame callback. | 191 | // This state keeps track of when a surface last received a frame callback. |
| @@ -234,6 +241,7 @@ impl State { | |||
| 234 | self.niri.refresh_pointer_outputs(); | 241 | self.niri.refresh_pointer_outputs(); |
| 235 | self.niri.popups.cleanup(); | 242 | self.niri.popups.cleanup(); |
| 236 | self.update_focus(); | 243 | self.update_focus(); |
| 244 | + self.refresh_cursor_focus(); | ||
| 237 | 245 | ||
| 238 | { | 246 | { |
| 239 | let _span = tracy_client::span!("flush_clients"); | 247 | let _span = tracy_client::span!("flush_clients"); |
| @@ -243,6 +251,9 @@ impl State { | |||
| 243 | 251 | ||
| 244 | pub fn move_cursor(&mut self, location: Point<f64, Logical>) { | 252 | pub fn move_cursor(&mut self, location: Point<f64, Logical>) { |
| 245 | let under = self.niri.surface_under_and_global_space(location); | 253 | let under = self.niri.surface_under_and_global_space(location); |
| 254 | + self.niri.pointer_focus = under.clone(); | ||
| 255 | + let under = under.map(|u| u.surface); | ||
| 256 | + | ||
| 246 | let pointer = &self.niri.seat.get_pointer().unwrap(); | 257 | let pointer = &self.niri.seat.get_pointer().unwrap(); |
| 247 | pointer.motion( | 258 | pointer.motion( |
| 248 | self, | 259 | self, |
| @@ -258,6 +269,45 @@ impl State { | |||
| 258 | self.niri.queue_redraw_all(); | 269 | self.niri.queue_redraw_all(); |
| 259 | } | 270 | } |
| 260 | 271 | ||
| 272 | + pub fn refresh_cursor_focus(&mut self) { | ||
| 273 | + let _span = tracy_client::span!("Niri::refresh_cursor_focus"); | ||
| 274 | + | ||
| 275 | + let pointer = &self.niri.seat.get_pointer().unwrap(); | ||
| 276 | + let location = pointer.current_location(); | ||
| 277 | + | ||
| 278 | + let under = self.niri.surface_under_and_global_space(location); | ||
| 279 | + | ||
| 280 | + // We're not changing the global cursor location here, so if the focus did not change, then | ||
| 281 | + // nothing changed. | ||
| 282 | + if self.niri.pointer_focus == under { | ||
| 283 | + return; | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + // Don't refresh cursor focus during animations. | ||
| 287 | + if let Some(PointerFocus { output, .. }) = &under { | ||
| 288 | + let monitor = self.niri.layout.monitor_for_output(output).unwrap(); | ||
| 289 | + if monitor.are_animations_ongoing() { | ||
| 290 | + return; | ||
| 291 | + } | ||
| 292 | + } | ||
| 293 | + | ||
| 294 | + self.niri.pointer_focus = under.clone(); | ||
| 295 | + let under = under.map(|u| u.surface); | ||
| 296 | + | ||
| 297 | + pointer.motion( | ||
| 298 | + self, | ||
| 299 | + under, | ||
| 300 | + &MotionEvent { | ||
| 301 | + location, | ||
| 302 | + serial: SERIAL_COUNTER.next_serial(), | ||
| 303 | + time: get_monotonic_time().as_millis() as u32, | ||
| 304 | + }, | ||
| 305 | + ); | ||
| 306 | + pointer.frame(self); | ||
| 307 | + // FIXME: granular | ||
| 308 | + self.niri.queue_redraw_all(); | ||
| 309 | + } | ||
| 310 | + | ||
| 261 | pub fn move_cursor_to_output(&mut self, output: &Output) { | 311 | pub fn move_cursor_to_output(&mut self, output: &Output) { |
| 262 | let geo = self.niri.global_space.output_geometry(output).unwrap(); | 312 | let geo = self.niri.global_space.output_geometry(output).unwrap(); |
| 263 | self.move_cursor(center(geo).to_f64()); | 313 | self.move_cursor(center(geo).to_f64()); |
| @@ -538,6 +588,7 @@ impl Niri { | |||
| 538 | default_cursor, | 588 | default_cursor, |
| 539 | cursor_image: CursorImageStatus::default_named(), | 589 | cursor_image: CursorImageStatus::default_named(), |
| 540 | dnd_icon: None, | 590 | dnd_icon: None, |
| 591 | + pointer_focus: None, | ||
| 541 | 592 | ||
| 542 | #[cfg(feature = "dbus")] | 593 | #[cfg(feature = "dbus")] |
| 543 | dbus: None, | 594 | dbus: None, |
| @@ -740,10 +791,12 @@ impl Niri { | |||
| 740 | pub fn surface_under_and_global_space( | 791 | pub fn surface_under_and_global_space( |
| 741 | &mut self, | 792 | &mut self, |
| 742 | pos: Point<f64, Logical>, | 793 | pos: Point<f64, Logical>, |
| 743 | - ) -> Option<(WlSurface, Point<i32, Logical>)> { | 794 | + ) -> Option<PointerFocus> { |
| 744 | let (output, pos_within_output) = self.output_under(pos)?; | 795 | let (output, pos_within_output) = self.output_under(pos)?; |
| 796 | + let output = output.clone(); | ||
| 797 | + | ||
| 745 | let (window, win_pos_within_output) = | 798 | let (window, win_pos_within_output) = |
| 746 | - self.layout.window_under(output, pos_within_output)?; | 799 | + self.layout.window_under(&output, pos_within_output)?; |
| 747 | 800 | ||
| 748 | let (surface, surface_pos_within_output) = window | 801 | let (surface, surface_pos_within_output) = window |
| 749 | .surface_under( | 802 | .surface_under( |
| @@ -751,10 +804,13 @@ impl Niri { | |||
| 751 | WindowSurfaceType::ALL, | 804 | WindowSurfaceType::ALL, |
| 752 | ) | 805 | ) |
| 753 | .map(|(s, pos_within_window)| (s, pos_within_window + win_pos_within_output))?; | 806 | .map(|(s, pos_within_window)| (s, pos_within_window + win_pos_within_output))?; |
| 754 | - let output_pos_in_global_space = self.global_space.output_geometry(output).unwrap().loc; | 807 | + let output_pos_in_global_space = self.global_space.output_geometry(&output).unwrap().loc; |
| 755 | let surface_loc_in_global_space = surface_pos_within_output + output_pos_in_global_space; | 808 | let surface_loc_in_global_space = surface_pos_within_output + output_pos_in_global_space; |
| 756 | 809 | ||
| 757 | - Some((surface, surface_loc_in_global_space)) | 810 | + Some(PointerFocus { |
| 811 | + output, | ||
| 812 | + surface: (surface, surface_loc_in_global_space), | ||
| 813 | + }) | ||
| 758 | } | 814 | } |
| 759 | 815 | ||
| 760 | pub fn output_under_cursor(&self) -> Option<Output> { | 816 | pub fn output_under_cursor(&self) -> Option<Output> { |