From 4e796ce8f6d75ab10bbf8e08e99741fb5bfb0ffa Mon Sep 17 00:00:00 2001 From: Ottatop Date: Thu, 30 May 2024 19:58:26 -0500 Subject: [PATCH] Add idle inhibit --- src/handlers/idle.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/handlers/idle.rs diff --git a/src/handlers/idle.rs b/src/handlers/idle.rs new file mode 100644 index 0000000..e4b6cf5 --- /dev/null +++ b/src/handlers/idle.rs @@ -0,0 +1,46 @@ +use smithay::{ + delegate_idle_notify, + desktop::utils::surface_primary_scanout_output, + reexports::wayland_server::protocol::wl_surface::WlSurface, + utils::IsAlive, + wayland::{ + compositor, + idle_inhibit::IdleInhibitHandler, + idle_notify::{IdleNotifierHandler, IdleNotifierState}, + }, +}; + +use crate::state::{Pinnacle, State}; + +impl IdleNotifierHandler for State { + fn idle_notifier_state(&mut self) -> &mut IdleNotifierState { + &mut self.pinnacle.idle_notifier_state + } +} +delegate_idle_notify!(State); + +impl IdleInhibitHandler for State { + fn inhibit(&mut self, surface: WlSurface) { + self.pinnacle.idle_inhibiting_surfaces.insert(surface); + self.pinnacle.idle_notifier_state.set_is_inhibited(true); + } + + fn uninhibit(&mut self, surface: WlSurface) { + self.pinnacle.idle_inhibiting_surfaces.remove(&surface); + self.pinnacle.refresh_idle_inhibit(); + } +} + +impl Pinnacle { + pub fn refresh_idle_inhibit(&mut self) { + self.idle_inhibiting_surfaces.retain(|s| s.alive()); + + let is_inhibited = self.idle_inhibiting_surfaces.iter().any(|surface| { + compositor::with_states(surface, |states| { + surface_primary_scanout_output(surface, states).is_some() + }) + }); + + self.idle_notifier_state.set_is_inhibited(is_inhibited); + } +}