diff --git a/src/bin/xidlehook-client.rs b/src/bin/xidlehook-client.rs new file mode 100644 index 0000000..56a34e0 --- /dev/null +++ b/src/bin/xidlehook-client.rs @@ -0,0 +1,60 @@ +#[macro_use] extern crate clap; +extern crate failure; + +use clap::{App as ClapApp, Arg}; +use failure::Error; +use std::{io::Write, os::unix::net::UnixStream}; + +fn main() -> Result<(), Error> { + let clap_app = ClapApp::new(crate_name!()) + .author(crate_authors!()) + .version(crate_version!()) + // Flags + .arg( + Arg::with_name("disable") + .help("Disable xidlehook timers.") + .long("disable") + .required_unless_one(&["enable", "trigger"]), + ) + .arg( + Arg::with_name("enable") + .help("Enable xidlehook timers.") + .long("enable") + .required_unless_one(&["disable", "trigger"]), + ) + .arg( + Arg::with_name("trigger") + .help("Execute the primary timer immediately.") + .long("trigger") + .required_unless_one(&["disable", "enable"]), + ) + // Options + .arg( + Arg::with_name("socket") + .long_help( + "\ + Listen to events over a specified unix socket.\n\ + Events are as following:\n\ + \t0x0 - Disable xidlehook\n\ + \t0x1 - Re-enable xidlehook\n\ + \t0x2 - Trigger the timer immediately\n\ + ", + ) + .long("socket") + .takes_value(true) + .required(true), + ); + let matches = clap_app.get_matches(); + // socket necessarily exists as it is a required param + let socket = matches.value_of("socket").unwrap(); + let mut socket = UnixStream::connect(&socket)?; + let control_byte = if matches.is_present("disable") { + b"\x00" + } else if matches.is_present("enable") { + b"\x01" + } else { + b"\x02" + }; + socket.write_all(control_byte)?; + return Ok(()); +} diff --git a/src/main.rs b/src/bin/xidlehook.rs similarity index 99% rename from src/main.rs rename to src/bin/xidlehook.rs index 691e1df..c13b9cc 100644 --- a/src/main.rs +++ b/src/bin/xidlehook.rs @@ -31,8 +31,8 @@ use std::{ }; use x11::xss::{XScreenSaverAllocInfo, XScreenSaverInfo}; -#[cfg(feature = "pulse")] mod pulse; -mod x11api; +extern crate xidlehook; +use xidlehook::*; #[cfg(feature = "pulse")] use pulse::PulseAudio; use x11api::{XDisplay, XPtr}; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..0071c21 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ +#[macro_use] extern crate failure; +#[cfg(feature = "pulse")] extern crate libpulse_sys; +extern crate x11; + +#[cfg(feature = "pulse")] pub mod pulse; +pub mod x11api; + +#[derive(Debug, Fail)] +pub enum MyError { + #[fail(display = "failed to open x display")] + XDisplay, + #[fail(display = "failed to query for screen saver info")] + XScreenSaver +}