Struct Xidlehook

Source
pub struct Xidlehook<T, M>
where T: Timer, M: Module,
{ /* private fields */ }
Expand description

The main xidlehook instance that allows you to schedule things

Implementations§

Source§

impl<T: Timer> Xidlehook<T, ()>

Source

pub fn new(timers: Vec<T>) -> Self

An empty instance without any modules

Source§

impl<T, M> Xidlehook<T, M>
where T: Timer, M: Module,

Source

pub fn with_module<N: Module>(self, other: N) -> Xidlehook<T, N>

Return this xidlehook instance but with this module replaced.

Source

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.

Source

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.

Source

pub fn detect_sleep(&self) -> bool

Get whether or not we reset the idle timer once a suspend was detected

Source

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.

Source

pub fn timers(&self) -> &Vec<T>

Returns an immutable list of all timers

Source

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.

Source

pub fn abort(&mut self) -> Result<()>

Calls the abortion function on the current timer and stops pursuing the chain

Source

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.

Source

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
Source

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.

Source

pub fn main_sync<F>(self, xcb: &Xcb, callback: F) -> Result<()>
where F: FnMut() -> bool,

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));

Trait Implementations§

Source§

impl<T, M> Debug for Xidlehook<T, M>
where T: Timer, M: Module + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, M> Freeze for Xidlehook<T, M>
where M: Freeze,

§

impl<T, M> RefUnwindSafe for Xidlehook<T, M>

§

impl<T, M> Send for Xidlehook<T, M>
where M: Send, T: Send,

§

impl<T, M> Sync for Xidlehook<T, M>
where M: Sync, T: Sync,

§

impl<T, M> Unpin for Xidlehook<T, M>
where M: Unpin, T: Unpin,

§

impl<T, M> UnwindSafe for Xidlehook<T, M>
where M: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.