pub struct Xidlehook<T, M>{ /* private fields */ }
Expand description
The main xidlehook instance that allows you to schedule things
Implementations§
Source§impl<T, M> Xidlehook<T, M>
impl<T, M> Xidlehook<T, M>
Sourcepub fn with_module<N: Module>(self, other: N) -> Xidlehook<T, N>
pub fn with_module<N: Module>(self, other: N) -> Xidlehook<T, N>
Return this xidlehook instance but with this module replaced.
Sourcepub fn register<N: Module>(self, other: N) -> Xidlehook<T, (M, N)>
pub fn register<N: Module>(self, other: N) -> Xidlehook<T, (M, N)>
Return this xidlehook instance but with an additional module activated. This works using the
timer impl for (A, B)
to get a fixed-size list of modules at compile time.
Sourcepub fn set_detect_sleep(&mut self, value: bool)
pub fn set_detect_sleep(&mut self, value: bool)
Set whether or not we reset the idle timer once a suspend was detected. This only affects main/main_async.
Sourcepub fn detect_sleep(&self) -> bool
pub fn detect_sleep(&self) -> bool
Get whether or not we reset the idle timer once a suspend was detected
Sourcepub fn with_detect_sleep(self, value: bool) -> Self
pub fn with_detect_sleep(self, value: bool) -> Self
Set whether or not we reset the idle timer once a suspend was detected. This only affects
main/main_async. This is the chainable version of set_detect_sleep
.
Sourcepub fn timers_mut(&mut self) -> Result<&mut Vec<T>>
pub fn timers_mut(&mut self) -> Result<&mut Vec<T>>
Returns a mutable list of all timers. Use this to add or remove timers as you wish. This will abort the idle chain as that may otherwise panic.
Sourcepub fn abort(&mut self) -> Result<()>
pub fn abort(&mut self) -> Result<()>
Calls the abortion function on the current timer and stops pursuing the chain
Sourcepub fn reset(&mut self, absolute_time: Duration) -> Result<()>
pub fn reset(&mut self, absolute_time: Duration) -> Result<()>
Calls the abortion functions on the current timer and restarts from index zero. Just like
with the poll
function, continued usage after an error discouraged.
Sourcepub fn trigger(
&mut self,
index: usize,
absolute_time: Duration,
force: bool,
) -> Result<Progress>
pub fn trigger( &mut self, index: usize, absolute_time: Duration, force: bool, ) -> Result<Progress>
Skip ahead to the selected timer. Timers leading up to this point will not be ran. If you
pass force
, modules will not even be able to prevent this from happening (all requests
pre-timer would be ignored). Post-timer requests are fully complied with.
Whatever the return value is, it’s already been handled. If the return value is Err(...)
,
that means this function invoked the module’s warning
function and that still wanted to
propagate the error. If the return value is Ok(Progress::Abort)
, never mind it. The
self.abort()
function has already been invoked - it’s all cool.
§Panics
- If the index is out of bounds
Sourcepub fn poll(&mut self, absolute_time: Duration) -> Result<Action>
pub fn poll(&mut self, absolute_time: Duration) -> Result<Action>
Polls the scheduler for any activated timers. On success, returns the max amount of time a program can sleep for. Only fatal errors cause this function to return, and at that point, the state of xidlehook is undefined so it should not be used.
Sourcepub fn main_sync<F>(self, xcb: &Xcb, callback: F) -> Result<()>
pub fn main_sync<F>(self, xcb: &Xcb, callback: F) -> Result<()>
Runs a standard poll-sleep-repeat loop.
static EXITED: AtomicBool = AtomicBool::new(false);
extern "C" fn exit_handler(_signo: libc::c_int) {
EXITED.store(true, Ordering::SeqCst);
}
unsafe {
signal::sigaction(
signal::Signal::SIGINT,
&signal::SigAction::new(
signal::SigHandler::Handler(exit_handler),
signal::SaFlags::empty(),
signal::SigSet::empty(),
),
)?;
}
xidlehook.main_sync(&xcb, || EXITED.load(Ordering::SeqCst));