Skip to content

Commit

Permalink
wayland.idle_notify: Update to version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Dec 26, 2024
1 parent 2eddf12 commit d7fa8ae
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
44 changes: 40 additions & 4 deletions src/wayland/idle_notify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ pub struct IdleNotificationUserData {
is_idle: AtomicBool,
timeout: Duration,
timer_token: Mutex<Option<RegistrationToken>>,

/// If listener was created with `get_input_idle_notification`
ignore_inhibitor: bool,
}

impl IdleNotificationUserData {
Expand Down Expand Up @@ -131,9 +134,13 @@ impl<D: IdleNotifierHandler> IdleNotifierState<D> {
self.is_inhibited = is_inhibited;

for notification in self.notifications() {
if is_inhibited {
let data = notification.data::<IdleNotificationUserData>().unwrap();
let data = notification.data::<IdleNotificationUserData>().unwrap();

if data.ignore_inhibitor {
continue;
}

if is_inhibited {
if data.is_idle() {
notification.resumed();
data.set_idle(false);
Expand Down Expand Up @@ -189,7 +196,7 @@ impl<D: IdleNotifierHandler> IdleNotifierState<D> {
self.loop_handle.remove(token);
}

if self.is_inhibited {
if !data.ignore_inhibitor && self.is_inhibited {
return;
}

Expand All @@ -200,7 +207,10 @@ impl<D: IdleNotifierHandler> IdleNotifierState<D> {
move |_, _, state| {
let data = idle_notification.data::<IdleNotificationUserData>().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);
}
Expand Down Expand Up @@ -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,
},
);

Expand Down

0 comments on commit d7fa8ae

Please sign in to comment.