Added only secondary screen option
This commit is contained in:
parent
26d56d7b92
commit
db7e6bfa42
28
src/lib.rs
28
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.
|
||||
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()?
|
||||
|
|
|
@ -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(())
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue