Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

wayland.idle_notify: Update to version 2 #1618

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 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 @@ -113,7 +116,7 @@ impl<D: IdleNotifierHandler> IdleNotifierState<D> {
D: IdleNotifierHandler,
D: 'static,
{
let global = display.create_global::<D, ExtIdleNotifierV1, _>(1, ());
let global = display.create_global::<D, ExtIdleNotifierV1, _>(2, ());
Self {
global,
notifications: HashMap::new(),
Expand All @@ -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
Loading