Skip to content

Commit

Permalink
Correct last input for idle timeout for Wayland handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
2e3s committed May 16, 2024
1 parent be59315 commit f960dd6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion watchers/src/watchers/wl_ext_idle_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct IdleState {
last_input_time: DateTime<Utc>,
is_idle: bool,
is_changed: bool,
idle_timeout: Duration,
}

impl Drop for IdleState {
Expand All @@ -29,18 +30,20 @@ impl Drop for IdleState {
}

impl IdleState {
fn new(idle_notification: ExtIdleNotificationV1) -> Self {
fn new(idle_notification: ExtIdleNotificationV1, idle_timeout: Duration) -> Self {
Self {
idle_notification,
last_input_time: Utc::now(),
is_idle: false,
is_changed: false,
idle_timeout,
}
}

fn idle(&mut self) {
self.is_idle = true;
self.is_changed = true;
self.last_input_time -= self.idle_timeout;
debug!("Idle");
}

Expand Down Expand Up @@ -138,6 +141,7 @@ impl Watcher for IdleWatcher {
connection
.get_ext_idle_notification(timeout.unwrap())
.unwrap(),
Duration::from_std(client.config.idle_timeout).unwrap(),
);
connection.event_queue.roundtrip(&mut idle_state).unwrap();

Expand Down
17 changes: 11 additions & 6 deletions watchers/src/watchers/wl_kwin_idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,35 @@ use wayland_protocols_plasma::idle::client::org_kde_kwin_idle_timeout::{
};

struct IdleState {
idle_timeout: OrgKdeKwinIdleTimeout,
kwin_idle_timeout: OrgKdeKwinIdleTimeout,
last_input_time: DateTime<Utc>,
is_idle: bool,
is_changed: bool,
idle_timeout: Duration,
}

impl Drop for IdleState {
fn drop(&mut self) {
info!("Releasing idle timeout");
self.idle_timeout.release();
self.kwin_idle_timeout.release();
}
}

impl IdleState {
fn new(idle_timeout: OrgKdeKwinIdleTimeout) -> Self {
fn new(kwin_idle_timeout: OrgKdeKwinIdleTimeout, idle_timeout: Duration) -> Self {
Self {
idle_timeout,
kwin_idle_timeout,
last_input_time: Utc::now(),
is_idle: false,
is_changed: false,
idle_timeout,
}
}

fn idle(&mut self) {
self.is_idle = true;
self.is_changed = true;
self.last_input_time -= self.idle_timeout;
debug!("Idle");
}

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

let timeout = u32::try_from(client.config.idle_timeout.as_secs() * 1000);
let mut idle_state =
IdleState::new(connection.get_kwin_idle_timeout(timeout.unwrap()).unwrap());
let mut idle_state = IdleState::new(
connection.get_kwin_idle_timeout(timeout.unwrap()).unwrap(),
Duration::from_std(client.config.idle_timeout).unwrap(),
);
connection.event_queue.roundtrip(&mut idle_state).unwrap();

Ok(Self {
Expand Down

0 comments on commit f960dd6

Please sign in to comment.