Skip to content

Commit

Permalink
Implement xidlehook-client for communicating over daemon socket
Browse files Browse the repository at this point in the history
  • Loading branch information
yashsriv committed Mar 26, 2019
1 parent 1de9de5 commit 7d9ce50
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
60 changes: 60 additions & 0 deletions src/bin/xidlehook-client.rs
Original file line number Diff line number Diff line change
@@ -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(());
}
4 changes: 2 additions & 2 deletions src/main.rs → src/bin/xidlehook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7d9ce50

Please sign in to comment.