Apply suggested formatting from rustfmt

This commit is contained in:
mnussbaum 2019-09-05 17:28:50 -07:00
parent 19c65e6c7a
commit 25860caa84
1 changed files with 70 additions and 77 deletions

View File

@ -1,11 +1,11 @@
extern crate glob;
extern crate clap; extern crate clap;
use clap::{Arg, App}; extern crate glob;
use clap::{App, Arg};
use glob::glob;
use std::fs; use std::fs;
use std::process::Command;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use std::process::Command;
use glob::glob;
fn main() { fn main() {
let mut mode = ""; let mut mode = "";
@ -13,68 +13,67 @@ fn main() {
let mut new_state: &str; let mut new_state: &str;
let mut path_x: String = "".to_string(); let mut path_x: String = "".to_string();
let mut path_y: String = "".to_string(); let mut path_y: String = "".to_string();
let mut matrix: [&str;9]; let mut matrix: [&str; 9];
let mut x_state: &str; let mut x_state: &str;
let sway_pid = String::from_utf8(Command::new("pidof") let sway_pid =
.arg("sway") String::from_utf8(Command::new("pidof").arg("sway").output().unwrap().stdout).unwrap();
.output()
.unwrap()
.stdout).unwrap();
let x_pid = String::from_utf8(Command::new("pidof") let x_pid = String::from_utf8(Command::new("pidof").arg("x").output().unwrap().stdout).unwrap();
.arg("x")
.output()
.unwrap()
.stdout).unwrap();
if sway_pid.len() >= 1 { if sway_pid.len() >= 1 {
mode = "sway"; mode = "sway";
} }
if x_pid.len() >= 1 { if x_pid.len() >= 1 {
mode = "x"; mode = "x";
} }
let matches = App::new("rot8") let matches = App::new("rot8")
.version("0.1.1") .version("0.1.1")
.arg(Arg::with_name("sleep") .arg(
.default_value("500") Arg::with_name("sleep")
.long("sleep") .default_value("500")
.value_name("SLEEP") .long("sleep")
.help("Set sleep millis") .value_name("SLEEP")
.takes_value(true)) .help("Set sleep millis")
.arg(Arg::with_name("display") .takes_value(true),
.default_value("eDP-1") )
.long("display") .arg(
.value_name("DISPLAY") Arg::with_name("display")
.help("Set Display Device") .default_value("eDP-1")
.takes_value(true)) .long("display")
.arg(Arg::with_name("touchscreen") .value_name("DISPLAY")
.default_value("ELAN0732:00 04F3:22E1") .help("Set Display Device")
.long("touchscreen") .takes_value(true),
.value_name("TOUCHSCREEN") )
.help("Set Touchscreen Device (X11)") .arg(
.takes_value(true)) Arg::with_name("touchscreen")
.get_matches(); .default_value("ELAN0732:00 04F3:22E1")
.long("touchscreen")
.value_name("TOUCHSCREEN")
.help("Set Touchscreen Device (X11)")
.takes_value(true),
)
.get_matches();
let sleep = matches.value_of("sleep").unwrap_or("default.conf"); let sleep = matches.value_of("sleep").unwrap_or("default.conf");
let display = matches.value_of("display").unwrap_or("default.conf"); let display = matches.value_of("display").unwrap_or("default.conf");
let touchscreen = matches.value_of("touchscreen").unwrap_or("default.conf"); let touchscreen = matches.value_of("touchscreen").unwrap_or("default.conf");
for entry in glob("/sys/bus/iio/devices/iio:device*/in_accel_*_raw").unwrap(){ for entry in glob("/sys/bus/iio/devices/iio:device*/in_accel_*_raw").unwrap() {
match entry { match entry {
Ok(path) => { Ok(path) => {
if path.to_str().unwrap().contains("x_raw"){ if path.to_str().unwrap().contains("x_raw") {
path_x = path.to_str().unwrap().to_owned(); path_x = path.to_str().unwrap().to_owned();
} else if path.to_str().unwrap().contains("y_raw"){ } else if path.to_str().unwrap().contains("y_raw") {
path_y = path.to_str().unwrap().to_owned(); path_y = path.to_str().unwrap().to_owned();
} else if path.to_str().unwrap().contains("z_raw"){ } else if path.to_str().unwrap().contains("z_raw") {
continue; continue;
} else { } else {
println!("{:?}", path); println!("{:?}", path);
panic!(); panic!();
} }
}, }
Err(e) => println!("{:?}",e) Err(e) => println!("{:?}", e),
} }
} }
@ -89,20 +88,17 @@ fn main() {
new_state = "180"; new_state = "180";
x_state = "normal"; x_state = "normal";
matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"]; matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"];
} } else {
else { new_state = "90";
x_state = "left";
new_state = "90"; matrix = ["0", "-1", "1", "1", "0", "0", "0", "0", "1"];
x_state = "left";
matrix = ["0", "-1", "1", "1", "0", "0", "0", "0", "1"];
} }
} else if x > 500000 { } else if x > 500000 {
if y > 500000 { if y > 500000 {
new_state = "180"; new_state = "180";
x_state = "inverted"; x_state = "inverted";
matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"]; matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"];
} } else {
else {
new_state = "270"; new_state = "270";
x_state = "right"; x_state = "right";
matrix = ["0", "1", "0", "-1", "0", "1", "0", "0", "1"]; matrix = ["0", "1", "0", "-1", "0", "1", "0", "0", "1"];
@ -112,8 +108,7 @@ fn main() {
new_state = "180"; new_state = "180";
x_state = "inverted"; x_state = "inverted";
matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"]; matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"];
} } else {
else {
new_state = "normal"; new_state = "normal";
x_state = "normal"; x_state = "normal";
matrix = ["1", "0", "0", "0", "1", "0", "0", "0", "1"]; matrix = ["1", "0", "0", "0", "1", "0", "0", "0", "1"];
@ -121,33 +116,33 @@ fn main() {
} }
if new_state != old_state { if new_state != old_state {
if mode == "sway" { if mode == "sway" {
Command::new("swaymsg") Command::new("swaymsg")
.arg("output") .arg("output")
.arg(display) .arg(display)
.arg("transform") .arg("transform")
.arg(new_state) .arg(new_state)
.spawn() .spawn()
.expect("rotate command failed to start"); .expect("rotate command failed to start");
old_state = new_state; old_state = new_state;
} }
if mode == "x" { if mode == "x" {
Command::new("xrandr") Command::new("xrandr")
.arg("-o") .arg("-o")
.arg(x_state) .arg(x_state)
.spawn() .spawn()
.expect("rotate command failed to start"); .expect("rotate command failed to start");
Command::new("xinput") Command::new("xinput")
.arg("set-prop") .arg("set-prop")
.arg(touchscreen) .arg(touchscreen)
.arg("Coordinate") .arg("Coordinate")
.arg("Transformation") .arg("Transformation")
.arg("Matrix") .arg("Matrix")
.args(&matrix) .args(&matrix)
.spawn() .spawn()
.expect("rotate command failed to start"); .expect("rotate command failed to start");
old_state = new_state; old_state = new_state;
} }
@ -155,5 +150,3 @@ fn main() {
thread::sleep(Duration::from_millis(sleep.parse::<u64>().unwrap_or(0))); thread::sleep(Duration::from_millis(sleep.parse::<u64>().unwrap_or(0)));
} }
} }