Skip to content

Commit f960dd6

Browse files
committed
Correct last input for idle timeout for Wayland handlers
1 parent be59315 commit f960dd6

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

watchers/src/watchers/wl_ext_idle_notify.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct IdleState {
1919
last_input_time: DateTime<Utc>,
2020
is_idle: bool,
2121
is_changed: bool,
22+
idle_timeout: Duration,
2223
}
2324

2425
impl Drop for IdleState {
@@ -29,18 +30,20 @@ impl Drop for IdleState {
2930
}
3031

3132
impl IdleState {
32-
fn new(idle_notification: ExtIdleNotificationV1) -> Self {
33+
fn new(idle_notification: ExtIdleNotificationV1, idle_timeout: Duration) -> Self {
3334
Self {
3435
idle_notification,
3536
last_input_time: Utc::now(),
3637
is_idle: false,
3738
is_changed: false,
39+
idle_timeout,
3840
}
3941
}
4042

4143
fn idle(&mut self) {
4244
self.is_idle = true;
4345
self.is_changed = true;
46+
self.last_input_time -= self.idle_timeout;
4447
debug!("Idle");
4548
}
4649

@@ -138,6 +141,7 @@ impl Watcher for IdleWatcher {
138141
connection
139142
.get_ext_idle_notification(timeout.unwrap())
140143
.unwrap(),
144+
Duration::from_std(client.config.idle_timeout).unwrap(),
141145
);
142146
connection.event_queue.roundtrip(&mut idle_state).unwrap();
143147

watchers/src/watchers/wl_kwin_idle.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,35 @@ use wayland_protocols_plasma::idle::client::org_kde_kwin_idle_timeout::{
1616
};
1717

1818
struct IdleState {
19-
idle_timeout: OrgKdeKwinIdleTimeout,
19+
kwin_idle_timeout: OrgKdeKwinIdleTimeout,
2020
last_input_time: DateTime<Utc>,
2121
is_idle: bool,
2222
is_changed: bool,
23+
idle_timeout: Duration,
2324
}
2425

2526
impl Drop for IdleState {
2627
fn drop(&mut self) {
2728
info!("Releasing idle timeout");
28-
self.idle_timeout.release();
29+
self.kwin_idle_timeout.release();
2930
}
3031
}
3132

3233
impl IdleState {
33-
fn new(idle_timeout: OrgKdeKwinIdleTimeout) -> Self {
34+
fn new(kwin_idle_timeout: OrgKdeKwinIdleTimeout, idle_timeout: Duration) -> Self {
3435
Self {
35-
idle_timeout,
36+
kwin_idle_timeout,
3637
last_input_time: Utc::now(),
3738
is_idle: false,
3839
is_changed: false,
40+
idle_timeout,
3941
}
4042
}
4143

4244
fn idle(&mut self) {
4345
self.is_idle = true;
4446
self.is_changed = true;
47+
self.last_input_time -= self.idle_timeout;
4548
debug!("Idle");
4649
}
4750

@@ -135,8 +138,10 @@ impl Watcher for IdleWatcher {
135138
connection.get_kwin_idle()?;
136139

137140
let timeout = u32::try_from(client.config.idle_timeout.as_secs() * 1000);
138-
let mut idle_state =
139-
IdleState::new(connection.get_kwin_idle_timeout(timeout.unwrap()).unwrap());
141+
let mut idle_state = IdleState::new(
142+
connection.get_kwin_idle_timeout(timeout.unwrap()).unwrap(),
143+
Duration::from_std(client.config.idle_timeout).unwrap(),
144+
);
140145
connection.event_queue.roundtrip(&mut idle_state).unwrap();
141146

142147
Ok(Self {

0 commit comments

Comments
 (0)