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
89
src/main.rs
89
src/main.rs
|
@ -7,8 +7,12 @@ use std::process::Command;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
fn main() {
|
enum BackendMode {
|
||||||
let mut mode = "";
|
Sway,
|
||||||
|
Xorg,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<(), String> {
|
||||||
let mut old_state = "normal";
|
let mut old_state = "normal";
|
||||||
let mut new_state: &str;
|
let mut new_state: &str;
|
||||||
let mut path_x: String = "".to_string();
|
let mut path_x: String = "".to_string();
|
||||||
|
@ -16,17 +20,21 @@ fn main() {
|
||||||
let mut matrix: [&str; 9];
|
let mut matrix: [&str; 9];
|
||||||
let mut x_state: &str;
|
let mut x_state: &str;
|
||||||
|
|
||||||
let sway_pid =
|
let mode = if String::from_utf8(Command::new("pidof").arg("sway").output().unwrap().stdout)
|
||||||
String::from_utf8(Command::new("pidof").arg("sway").output().unwrap().stdout).unwrap();
|
.unwrap()
|
||||||
|
.len()
|
||||||
let x_pid = String::from_utf8(Command::new("pidof").arg("x").output().unwrap().stdout).unwrap();
|
>= 1
|
||||||
|
{
|
||||||
if sway_pid.len() >= 1 {
|
BackendMode::Sway
|
||||||
mode = "sway";
|
} else if String::from_utf8(Command::new("pidof").arg("Xorg").output().unwrap().stdout)
|
||||||
}
|
.unwrap()
|
||||||
if x_pid.len() >= 1 {
|
.len()
|
||||||
mode = "x";
|
>= 1
|
||||||
}
|
{
|
||||||
|
BackendMode::Xorg
|
||||||
|
} else {
|
||||||
|
return Err("Unable to find Sway or Xorg procceses".to_owned());
|
||||||
|
};
|
||||||
|
|
||||||
let matches = App::new("rot8")
|
let matches = App::new("rot8")
|
||||||
.version("0.1.1")
|
.version("0.1.1")
|
||||||
|
@ -116,36 +124,35 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if new_state != old_state {
|
if new_state != old_state {
|
||||||
if mode == "sway" {
|
match mode {
|
||||||
Command::new("swaymsg")
|
BackendMode::Sway => {
|
||||||
.arg("output")
|
Command::new("swaymsg")
|
||||||
.arg(display)
|
.arg("output")
|
||||||
.arg("transform")
|
.arg(display)
|
||||||
.arg(new_state)
|
.arg("transform")
|
||||||
.spawn()
|
.arg(new_state)
|
||||||
.expect("rotate command failed to start");
|
.spawn()
|
||||||
|
.expect("rotate command failed to start");
|
||||||
|
}
|
||||||
|
BackendMode::Xorg => {
|
||||||
|
Command::new("xrandr")
|
||||||
|
.arg("-o")
|
||||||
|
.arg(x_state)
|
||||||
|
.spawn()
|
||||||
|
.expect("rotate command failed to start");
|
||||||
|
|
||||||
old_state = new_state;
|
Command::new("xinput")
|
||||||
}
|
.arg("set-prop")
|
||||||
if mode == "x" {
|
.arg(touchscreen)
|
||||||
Command::new("xrandr")
|
.arg("Coordinate")
|
||||||
.arg("-o")
|
.arg("Transformation")
|
||||||
.arg(x_state)
|
.arg("Matrix")
|
||||||
.spawn()
|
.args(&matrix)
|
||||||
.expect("rotate command failed to start");
|
.spawn()
|
||||||
|
.expect("rotate command failed to start");
|
||||||
Command::new("xinput")
|
}
|
||||||
.arg("set-prop")
|
|
||||||
.arg(touchscreen)
|
|
||||||
.arg("Coordinate")
|
|
||||||
.arg("Transformation")
|
|
||||||
.arg("Matrix")
|
|
||||||
.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)));
|
thread::sleep(Duration::from_millis(sleep.parse::<u64>().unwrap_or(0)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue