Make idle notify lazy
Browse files at this commitd27d6a504d9d59ffcf01ea9a1ee0668f1c6d3eefParent: ec5144f4 changed files +23 -11
- src/backend/tty.rs +1 -1
- src/handlers/mod.rs +1 -3
- src/input/mod.rs +2 -7
- src/niri.rs +19 -0
src/backend/tty.rsmodified+1 -1
| @@ -478,7 +478,7 @@ impl Tty { | |||
| 478 | 478 | ||
| 479 | self.refresh_ipc_outputs(niri); | 479 | self.refresh_ipc_outputs(niri); |
| 480 | 480 | ||
| 481 | - niri.idle_notifier_state.notify_activity(&niri.seat); | 481 | + niri.notify_activity(); |
| 482 | niri.monitors_active = true; | 482 | niri.monitors_active = true; |
| 483 | self.set_monitors_active(true); | 483 | self.set_monitors_active(true); |
| 484 | niri.queue_redraw_all(); | 484 | niri.queue_redraw_all(); |
src/handlers/mod.rsmodified+1 -3
| @@ -451,9 +451,7 @@ impl SessionLockHandler for State { | |||
| 451 | fn unlock(&mut self) { | 451 | fn unlock(&mut self) { |
| 452 | self.niri.unlock(); | 452 | self.niri.unlock(); |
| 453 | self.niri.activate_monitors(&mut self.backend); | 453 | self.niri.activate_monitors(&mut self.backend); |
| 454 | - self.niri | 454 | + self.niri.notify_activity(); |
| 455 | - .idle_notifier_state | ||
| 456 | - .notify_activity(&self.niri.seat); | ||
| 457 | } | 455 | } |
| 458 | 456 | ||
| 459 | fn new_surface(&mut self, surface: LockSurface, output: WlOutput) { | 457 | fn new_surface(&mut self, surface: LockSurface, output: WlOutput) { |
src/input/mod.rsmodified+2 -7
| @@ -97,10 +97,7 @@ impl State { | |||
| 97 | if self.niri.monitors_active { | 97 | if self.niri.monitors_active { |
| 98 | // Notify the idle-notifier of activity. | 98 | // Notify the idle-notifier of activity. |
| 99 | if should_notify_activity(&event) { | 99 | if should_notify_activity(&event) { |
| 100 | - let _span = tracy_client::span!("IdleNotifierState::notify_activity"); | 100 | + self.niri.notify_activity(); |
| 101 | - self.niri | ||
| 102 | - .idle_notifier_state | ||
| 103 | - .notify_activity(&self.niri.seat); | ||
| 104 | } | 101 | } |
| 105 | } else { | 102 | } else { |
| 106 | // Power on monitors if they were off. | 103 | // Power on monitors if they were off. |
| @@ -109,9 +106,7 @@ impl State { | |||
| 109 | 106 | ||
| 110 | // Notify the idle-notifier of activity only if we're also powering on the | 107 | // Notify the idle-notifier of activity only if we're also powering on the |
| 111 | // monitors. | 108 | // monitors. |
| 112 | - self.niri | 109 | + self.niri.notify_activity(); |
| 113 | - .idle_notifier_state | ||
| 114 | - .notify_activity(&self.niri.seat); | ||
| 115 | } | 110 | } |
| 116 | } | 111 | } |
| 117 | 112 | ||
src/niri.rsmodified+19 -0
| @@ -334,6 +334,11 @@ pub struct Niri { | |||
| 334 | /// Used for limiting the reset to once per iteration, so that it's not spammed with high | 334 | /// Used for limiting the reset to once per iteration, so that it's not spammed with high |
| 335 | /// resolution mice. | 335 | /// resolution mice. |
| 336 | pub pointer_inactivity_timer_got_reset: bool, | 336 | pub pointer_inactivity_timer_got_reset: bool, |
| 337 | + /// Whether the (idle notifier) activity was notified this event loop iteration. | ||
| 338 | + /// | ||
| 339 | + /// Used for limiting the notify to once per iteration, so that it's not spammed with high | ||
| 340 | + /// resolution mice. | ||
| 341 | + pub notified_activity_this_iteration: bool, | ||
| 337 | pub tablet_cursor_location: Option<Point<f64, Logical>>, | 342 | pub tablet_cursor_location: Option<Point<f64, Logical>>, |
| 338 | pub gesture_swipe_3f_cumulative: Option<(f64, f64)>, | 343 | pub gesture_swipe_3f_cumulative: Option<(f64, f64)>, |
| 339 | pub vertical_wheel_tracker: ScrollTracker, | 344 | pub vertical_wheel_tracker: ScrollTracker, |
| @@ -627,6 +632,7 @@ impl State { | |||
| 627 | // Clear the time so it's fetched afresh next iteration. | 632 | // Clear the time so it's fetched afresh next iteration. |
| 628 | self.niri.clock.clear(); | 633 | self.niri.clock.clear(); |
| 629 | self.niri.pointer_inactivity_timer_got_reset = false; | 634 | self.niri.pointer_inactivity_timer_got_reset = false; |
| 635 | + self.niri.notified_activity_this_iteration = false; | ||
| 630 | } | 636 | } |
| 631 | 637 | ||
| 632 | fn refresh(&mut self) { | 638 | fn refresh(&mut self) { |
| @@ -2146,6 +2152,7 @@ impl Niri { | |||
| 2146 | pointer_hidden: false, | 2152 | pointer_hidden: false, |
| 2147 | pointer_inactivity_timer: None, | 2153 | pointer_inactivity_timer: None, |
| 2148 | pointer_inactivity_timer_got_reset: false, | 2154 | pointer_inactivity_timer_got_reset: false, |
| 2155 | + notified_activity_this_iteration: false, | ||
| 2149 | tablet_cursor_location: None, | 2156 | tablet_cursor_location: None, |
| 2150 | gesture_swipe_3f_cumulative: None, | 2157 | gesture_swipe_3f_cumulative: None, |
| 2151 | vertical_wheel_tracker: ScrollTracker::new(120), | 2158 | vertical_wheel_tracker: ScrollTracker::new(120), |
| @@ -5293,6 +5300,18 @@ impl Niri { | |||
| 5293 | 5300 | ||
| 5294 | self.pointer_inactivity_timer_got_reset = true; | 5301 | self.pointer_inactivity_timer_got_reset = true; |
| 5295 | } | 5302 | } |
| 5303 | + | ||
| 5304 | + pub fn notify_activity(&mut self) { | ||
| 5305 | + if self.notified_activity_this_iteration { | ||
| 5306 | + return; | ||
| 5307 | + } | ||
| 5308 | + | ||
| 5309 | + let _span = tracy_client::span!("Niri::notify_activity"); | ||
| 5310 | + | ||
| 5311 | + self.idle_notifier_state.notify_activity(&self.seat); | ||
| 5312 | + | ||
| 5313 | + self.notified_activity_this_iteration = true; | ||
| 5314 | + } | ||
| 5296 | } | 5315 | } |
| 5297 | 5316 | ||
| 5298 | pub struct NewClient { | 5317 | pub struct NewClient { |