From d7fa8aeeb6f28fb17219361f828b74350baa9d21 Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Thu, 26 Dec 2024 02:20:18 +0100 Subject: [PATCH] wayland.idle_notify: Update to version 2 --- Cargo.toml | 11 +++++++++ src/wayland/idle_notify/mod.rs | 44 ++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4c6da0e4d75e..fca8a94290cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,6 +71,17 @@ profiling = "1.0.13" smallvec = "1.11" pixman = { version = "0.2.0", features = ["drm-fourcc", "sync"], optional = true } +[patch.crates-io] +wayland-egl = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } +wayland-protocols = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } +wayland-protocols-wlr = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } +wayland-protocols-misc = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } +wayland-server = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } +wayland-cursor = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } +wayland-client = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } +wayland-sys = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } +wayland-backend = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } +wayland-scanner = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "ext-idle-notify-2" } [dev-dependencies] clap = { version = "4", features = ["derive"] } diff --git a/src/wayland/idle_notify/mod.rs b/src/wayland/idle_notify/mod.rs index f64e5fd09c86..42de0e1b9012 100644 --- a/src/wayland/idle_notify/mod.rs +++ b/src/wayland/idle_notify/mod.rs @@ -74,6 +74,9 @@ pub struct IdleNotificationUserData { is_idle: AtomicBool, timeout: Duration, timer_token: Mutex>, + + /// If listener was created with `get_input_idle_notification` + ignore_inhibitor: bool, } impl IdleNotificationUserData { @@ -131,9 +134,13 @@ impl IdleNotifierState { self.is_inhibited = is_inhibited; for notification in self.notifications() { - if is_inhibited { - let data = notification.data::().unwrap(); + let data = notification.data::().unwrap(); + + if data.ignore_inhibitor { + continue; + } + if is_inhibited { if data.is_idle() { notification.resumed(); data.set_idle(false); @@ -189,7 +196,7 @@ impl IdleNotifierState { self.loop_handle.remove(token); } - if self.is_inhibited { + if !data.ignore_inhibitor && self.is_inhibited { return; } @@ -200,7 +207,10 @@ impl IdleNotifierState { move |_, _, state| { let data = idle_notification.data::().unwrap(); - if !state.idle_notifier_state().is_inhibited && !data.is_idle() { + let is_inhibited = !data.ignore_inhibitor && state.idle_notifier_state().is_inhibited; + let is_idle_already = data.is_idle(); + + if !is_inhibited && !is_idle_already { idle_notification.idled(); data.set_idle(true); } @@ -275,6 +285,32 @@ where is_idle: AtomicBool::new(false), timeout, timer_token: Mutex::new(None), + ignore_inhibitor: false, + }, + ); + + idle_notifier_state.reinsert_timer(&idle_notification); + + state + .idle_notifier_state() + .notifications + .entry(seat) + .or_default() + .push(idle_notification); + } + ext_idle_notifier_v1::Request::GetInputIdleNotification { id, timeout, seat } => { + let timeout = Duration::from_millis(timeout as u64); + + let idle_notifier_state = state.idle_notifier_state(); + + let idle_notification = data_init.init( + id, + IdleNotificationUserData { + seat: seat.clone(), + is_idle: AtomicBool::new(false), + timeout, + timer_token: Mutex::new(None), + ignore_inhibitor: true, }, );