Added only secondary screen option

This commit is contained in:
Thomas Forgione 2019-04-08 09:53:53 +02:00
parent 26d56d7b92
commit db7e6bfa42
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
2 changed files with 28 additions and 3 deletions

View File

@ -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.
pub fn only_primary(&self) -> Result<(), Error> {
self.run_command(self.only_primary_args())
@ -325,7 +341,16 @@ impl MultiScreen {
/// Calls the xrandr program to set two screens.
pub fn two_screens(&self, side: Side) -> Result<(), Error> {
if let Some(args) = self.two_screen_args(side){
if let Some(args) = self.two_screen_args(side) {
self.run_command(args)
} else {
Err(Error::NoScreenDetected)
}
}
/// 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)
@ -334,7 +359,6 @@ impl MultiScreen {
/// Run an xrandr command with its args.
pub fn run_command(&self, args: Vec<String>) -> Result<(), Error> {
Command::new("xrandr")
.args(args)
.spawn()?

View File

@ -10,7 +10,7 @@ fn main() {
.help("Action to do")
.takes_value(true)
.value_name("ACTION")
.possible_values(&["disable", "duplicate", "enable"])
.possible_values(&["disable", "duplicate", "enable","only-secondary"])
.required(true))
.arg(Arg::with_name("position")
.help("Specify the position of the second screen")
@ -35,6 +35,7 @@ fn main() {
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(())
};