This commit is contained in:
commit
0752aaf28e
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
**/*.rs.bk
|
|
@ -0,0 +1,32 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "glob"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "input-sys"
|
||||||
|
version = "1.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.55"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rot8"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"input-sys 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||||
|
"checksum input-sys 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae2b64cf99b6fecd206430ffc32d9055a83db4b186c8d7901d8f51aa4f1b7878"
|
||||||
|
"checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880"
|
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "rot8"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["efernau <e.fernau@efero.de>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
glob = "0.3"
|
||||||
|
input-sys = "1.9"
|
|
@ -0,0 +1,20 @@
|
||||||
|
# rot8
|
||||||
|
|
||||||
|
## Automatic Display rotation
|
||||||
|
|
||||||
|
Automatic rotate modern Linux desktop screen and input devices. Handy for
|
||||||
|
convertible touchscreen notebooks like the Kaby Lake model of the HP Spectre x360.
|
||||||
|
|
||||||
|
Rust language and the cargo package manager are required to build the binary.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ git clone https://github.com/efernau/rot8
|
||||||
|
$ cd rot8 && cargo build --release
|
||||||
|
$ cp target/release/rot8 /usr/bin/rot8
|
||||||
|
```
|
||||||
|
|
||||||
|
Call Rote8 from from sway configuration file ~/.config/sway/config:
|
||||||
|
|
||||||
|
```
|
||||||
|
exec rot8
|
||||||
|
```
|
|
@ -0,0 +1,81 @@
|
||||||
|
extern crate glob;
|
||||||
|
extern crate input_sys;
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
use std::process::Command;
|
||||||
|
use glob::glob;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut old_state = "normal";
|
||||||
|
let mut new_state: &str;
|
||||||
|
let mut path_x: String = "".to_string();
|
||||||
|
let mut path_y: String = "".to_string();
|
||||||
|
for entry in glob("/sys/bus/iio/devices/iio:device*/in_accel_*_raw").unwrap(){
|
||||||
|
match entry {
|
||||||
|
Ok(path) => {
|
||||||
|
if path.to_str().unwrap().contains("x_raw"){
|
||||||
|
path_x = path.to_str().unwrap().to_owned();
|
||||||
|
} else if path.to_str().unwrap().contains("y_raw"){
|
||||||
|
path_y = path.to_str().unwrap().to_owned();
|
||||||
|
} else if path.to_str().unwrap().contains("z_raw"){
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
println!("{:?}", path);
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => println!("{:?}",e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let x_raw = fs::read_to_string(path_x.as_str()).unwrap();
|
||||||
|
let y_raw = fs::read_to_string(path_y.as_str()).unwrap();
|
||||||
|
let x = x_raw.trim_end_matches('\n').parse::<i32>().unwrap_or(0);
|
||||||
|
let y = y_raw.trim_end_matches('\n').parse::<i32>().unwrap_or(0);
|
||||||
|
|
||||||
|
if x < -500000 {
|
||||||
|
if y > 500000 {
|
||||||
|
new_state = "180";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
new_state = "90";
|
||||||
|
}
|
||||||
|
} else if x > 500000 {
|
||||||
|
if y > 500000 {
|
||||||
|
new_state = "180";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_state = "270";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if y > 500000 {
|
||||||
|
new_state = "180";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_state = "normal";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if new_state != old_state {
|
||||||
|
|
||||||
|
Command::new("swaymsg")
|
||||||
|
.arg("output")
|
||||||
|
.arg("eDP-1")
|
||||||
|
.arg("transform")
|
||||||
|
.arg(new_state)
|
||||||
|
.spawn()
|
||||||
|
.expect("rotate command failed to start");
|
||||||
|
|
||||||
|
old_state = new_state;
|
||||||
|
}
|
||||||
|
thread::sleep(Duration::from_millis(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue