51 lines
1.7 KiB
Rust
51 lines
1.7 KiB
Rust
use clap::{Arg, App};
|
|
use tvrs::MultiScreen;
|
|
|
|
fn main() {
|
|
|
|
let matches = App::new("tvrs")
|
|
.author("Thomas Forgione <thomas@forgione.fr>")
|
|
.version("0.1.0")
|
|
.arg(Arg::with_name("action")
|
|
.help("Action to do")
|
|
.takes_value(true)
|
|
.value_name("ACTION")
|
|
.possible_values(&["disable", "duplicate", "enable","only-secondary"])
|
|
.required(true))
|
|
.arg(Arg::with_name("position")
|
|
.help("Specify the position of the second screen")
|
|
.possible_values(&["left", "right", "above", "below"])
|
|
.required_if("action", "enable"))
|
|
.arg(Arg::with_name("sound")
|
|
.help("Outputs the sound to the HDMI (requires pulseaudio)")
|
|
.short("s")
|
|
.long("sound"))
|
|
.get_matches();
|
|
|
|
let screens = MultiScreen::detect()
|
|
.expect("An error happened while finding screens");
|
|
|
|
let sound = matches.occurrences_of("sound") > 0;
|
|
|
|
let result = match matches.value_of("action") {
|
|
Some("disable") => screens.only_primary(),
|
|
Some("duplicate") => screens.duplicate(),
|
|
Some("enable") => {
|
|
// Can never fail, clap will crash before this
|
|
let side = matches.value_of("position").unwrap().parse().unwrap();
|
|
screens.two_screens(side)
|
|
},
|
|
Some("only-secondary") => screens.only_secondary(),
|
|
// Can never happen, clap will crash before this
|
|
_ => Ok(())
|
|
};
|
|
|
|
if sound {
|
|
if let Err(e) = screens.enable_hdmi_sound_if_present() {
|
|
eprintln!("Error: couldn't set hdmi sound: {:?}", e);
|
|
}
|
|
}
|
|
|
|
result.expect("An error happenned while executing the command");
|
|
}
|