Added only secondary screen option
This commit is contained in:
parent
26d56d7b92
commit
db7e6bfa42
26
src/lib.rs
26
src/lib.rs
|
@ -309,6 +309,22 @@ impl MultiScreen {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the arguments for enabling only the second screen.
|
||||||
|
pub fn only_secondary_args(&self) -> Option<Vec<String>> {
|
||||||
|
if let Some((ref main, ref second)) = self.main_screens() {
|
||||||
|
Some(vec![
|
||||||
|
"--output".to_owned(),
|
||||||
|
main.name.clone(),
|
||||||
|
"--off".to_owned(),
|
||||||
|
"--output".to_owned(),
|
||||||
|
second.name.clone(),
|
||||||
|
"--auto".to_owned(),
|
||||||
|
])
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Calls the xrandr program to disable all screens except the primary.
|
/// Calls the xrandr program to disable all screens except the primary.
|
||||||
pub fn only_primary(&self) -> Result<(), Error> {
|
pub fn only_primary(&self) -> Result<(), Error> {
|
||||||
self.run_command(self.only_primary_args())
|
self.run_command(self.only_primary_args())
|
||||||
|
@ -332,9 +348,17 @@ impl MultiScreen {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Calls the xrandr program to enable only the second screen.
|
||||||
|
pub fn only_secondary(&self) -> Result<(), Error> {
|
||||||
|
if let Some(args) = self.only_secondary_args() {
|
||||||
|
self.run_command(args)
|
||||||
|
} else {
|
||||||
|
Err(Error::NoScreenDetected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Run an xrandr command with its args.
|
/// Run an xrandr command with its args.
|
||||||
pub fn run_command(&self, args: Vec<String>) -> Result<(), Error> {
|
pub fn run_command(&self, args: Vec<String>) -> Result<(), Error> {
|
||||||
|
|
||||||
Command::new("xrandr")
|
Command::new("xrandr")
|
||||||
.args(args)
|
.args(args)
|
||||||
.spawn()?
|
.spawn()?
|
||||||
|
|
|
@ -10,7 +10,7 @@ fn main() {
|
||||||
.help("Action to do")
|
.help("Action to do")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("ACTION")
|
.value_name("ACTION")
|
||||||
.possible_values(&["disable", "duplicate", "enable"])
|
.possible_values(&["disable", "duplicate", "enable","only-secondary"])
|
||||||
.required(true))
|
.required(true))
|
||||||
.arg(Arg::with_name("position")
|
.arg(Arg::with_name("position")
|
||||||
.help("Specify the position of the second screen")
|
.help("Specify the position of the second screen")
|
||||||
|
@ -35,6 +35,7 @@ fn main() {
|
||||||
let side = matches.value_of("position").unwrap().parse().unwrap();
|
let side = matches.value_of("position").unwrap().parse().unwrap();
|
||||||
screens.two_screens(side)
|
screens.two_screens(side)
|
||||||
},
|
},
|
||||||
|
Some("only-secondary") => screens.only_secondary(),
|
||||||
// Can never happen, clap will crash before this
|
// Can never happen, clap will crash before this
|
||||||
_ => Ok(())
|
_ => Ok(())
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue