Skip to content

Commit

Permalink
Merge pull request #7 from cyrinux/fix/pause
Browse files Browse the repository at this point in the history
fix: dont return error if polling stuck pause
  • Loading branch information
cyrinux authored Oct 31, 2023
2 parents 1c821f0 + e40b2f1 commit 2af4ab2
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/libinput/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::{
atomic::{AtomicBool, Ordering},
Arc,
},
thread, time,
};
use xkbcommon::xkb;
use xkbcommon::xkb::Keysym;
Expand Down Expand Up @@ -75,26 +74,34 @@ impl Controller {
loop {
unsafe {
if libc::poll(fds.as_mut_ptr(), 1, poll_timeout) < 0 {
// on pause signal send, libc abort polling and
// receive EINTR error
if *libc::__errno_location() == libc::EINTR {
continue;
}
return Err("Unable to poll libinput, aborting".into());
}
}

libinput_context.dispatch()?;

if sig_pause.swap(false, Ordering::Relaxed) {
is_running = !is_running;
info!(
"Received SIGUSR1 signal, {}",
if is_running { "resuming" } else { "pausing" }
)
}
);

if !is_running {
thread::sleep(time::Duration::from_secs(1));
continue;
// ignore final events that happened just before the resume signal
if is_running {
libinput_context.by_ref().for_each(drop);
}
}

libinput_context.dispatch()?;
for event in libinput_context.by_ref() {
self.handle(event, tx.clone())?;
if is_running {
self.handle(event, tx.clone())?;
}
}
}
}
Expand Down

0 comments on commit 2af4ab2

Please sign in to comment.