mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-14 08:01:14 +01:00
Add idle inhibit
This commit is contained in:
parent
bfce194c0b
commit
4e796ce8f6
1 changed files with 46 additions and 0 deletions
46
src/handlers/idle.rs
Normal file
46
src/handlers/idle.rs
Normal file
|
@ -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<Self> {
|
||||||
|
&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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue