Use Xorg process to determine if on X backend
I believe the old process name "x" was incorrect. This also moves the list of backends to an enum instead of a string.
This commit is contained in:
parent
25860caa84
commit
1e0cc3ed57
45
src/main.rs
45
src/main.rs
|
@ -7,8 +7,12 @@ use std::process::Command;
|
|||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
let mut mode = "";
|
||||
enum BackendMode {
|
||||
Sway,
|
||||
Xorg,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), String> {
|
||||
let mut old_state = "normal";
|
||||
let mut new_state: &str;
|
||||
let mut path_x: String = "".to_string();
|
||||
|
@ -16,17 +20,21 @@ fn main() {
|
|||
let mut matrix: [&str; 9];
|
||||
let mut x_state: &str;
|
||||
|
||||
let sway_pid =
|
||||
String::from_utf8(Command::new("pidof").arg("sway").output().unwrap().stdout).unwrap();
|
||||
|
||||
let x_pid = String::from_utf8(Command::new("pidof").arg("x").output().unwrap().stdout).unwrap();
|
||||
|
||||
if sway_pid.len() >= 1 {
|
||||
mode = "sway";
|
||||
}
|
||||
if x_pid.len() >= 1 {
|
||||
mode = "x";
|
||||
}
|
||||
let mode = if String::from_utf8(Command::new("pidof").arg("sway").output().unwrap().stdout)
|
||||
.unwrap()
|
||||
.len()
|
||||
>= 1
|
||||
{
|
||||
BackendMode::Sway
|
||||
} else if String::from_utf8(Command::new("pidof").arg("Xorg").output().unwrap().stdout)
|
||||
.unwrap()
|
||||
.len()
|
||||
>= 1
|
||||
{
|
||||
BackendMode::Xorg
|
||||
} else {
|
||||
return Err("Unable to find Sway or Xorg procceses".to_owned());
|
||||
};
|
||||
|
||||
let matches = App::new("rot8")
|
||||
.version("0.1.1")
|
||||
|
@ -116,7 +124,8 @@ fn main() {
|
|||
}
|
||||
|
||||
if new_state != old_state {
|
||||
if mode == "sway" {
|
||||
match mode {
|
||||
BackendMode::Sway => {
|
||||
Command::new("swaymsg")
|
||||
.arg("output")
|
||||
.arg(display)
|
||||
|
@ -124,10 +133,8 @@ fn main() {
|
|||
.arg(new_state)
|
||||
.spawn()
|
||||
.expect("rotate command failed to start");
|
||||
|
||||
old_state = new_state;
|
||||
}
|
||||
if mode == "x" {
|
||||
BackendMode::Xorg => {
|
||||
Command::new("xrandr")
|
||||
.arg("-o")
|
||||
.arg(x_state)
|
||||
|
@ -143,10 +150,10 @@ fn main() {
|
|||
.args(&matrix)
|
||||
.spawn()
|
||||
.expect("rotate command failed to start");
|
||||
|
||||
old_state = new_state;
|
||||
}
|
||||
}
|
||||
old_state = new_state;
|
||||
}
|
||||
thread::sleep(Duration::from_millis(sleep.parse::<u64>().unwrap_or(0)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue