Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support platforms without KDE idle mechanism #39

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions src/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ pub fn get_current_afk_event() -> AwEvent {
}

pub fn assign_idle_timeout(globals: &wayland_client::GlobalManager,
timeout_ms: u32) -> () {
timeout_ms: u32) -> Result<(), String> {
init_afk_state(timeout_ms);
let seat = globals.instantiate_exact::<WlSeat>(1)
.expect("Wayland session does not expose a WlSeat object, \
this window manager is most likely not supported");
.map_err(|_|
String::from("Wayland session does not expose a WlSeat object, \
this window manager is most likely not supported")
)?;
let idle = globals.instantiate_exact::<Idle>(1)
.expect("Wayland session does not expose a Idle object, \
this window manager is most likely not supported");
.map_err(|_|
String::from("Wayland session does not expose a Idle object, this \
window manager is most likely not supported")
)?;
let idle_timeout = idle.get_idle_timeout(&seat, timeout_ms);
idle_timeout.assign_mono(|_idle_timeout, event| {
match event {
Expand All @@ -92,4 +96,5 @@ pub fn assign_idle_timeout(globals: &wayland_client::GlobalManager,
_ => panic!("Got unexpected timeout event"),
}
});
Ok(())
}
30 changes: 20 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ fn main() {
current_window::assign_toplevel_manager(&globals);

println!("### Setting up idle timeout");
idle::assign_idle_timeout(&globals, 120000);
let idle_result = idle::assign_idle_timeout(&globals, 120000);
let is_idle_active = match idle_result {
Ok(_) => true,
Err(err_str) => {
eprintln!("{}", err_str);
false
}
};

println!("### Syncing roundtrip");
event_queue
Expand Down Expand Up @@ -173,10 +180,12 @@ fn main() {
},
}

let afk_event = idle::get_current_afk_event();
if client.heartbeat(&afk_bucket, &afk_event, HEARTBEAT_INTERVAL_MARGIN_S).is_err() {
println!("Failed to send heartbeat");
break;
if is_idle_active {
let afk_event = idle::get_current_afk_event();
if client.heartbeat(&afk_bucket, &afk_event, HEARTBEAT_INTERVAL_MARGIN_S).is_err() {
println!("Failed to send heartbeat");
break;
}
}
},
TIMER => {
Expand All @@ -191,12 +200,13 @@ fn main() {
}
}

let afk_event = idle::get_current_afk_event();
if client.heartbeat(&afk_bucket, &afk_event, HEARTBEAT_INTERVAL_MARGIN_S).is_err() {
println!("Failed to send heartbeat");
break;
if is_idle_active {
let afk_event = idle::get_current_afk_event();
if client.heartbeat(&afk_bucket, &afk_event, HEARTBEAT_INTERVAL_MARGIN_S).is_err() {
println!("Failed to send heartbeat");
break;
}
}

},
_ => panic!("Invalid token!")
}
Expand Down
Loading