add X11 support

This commit is contained in:
e3b 2019-05-19 05:41:30 +02:00
parent 0752aaf28e
commit 74cd1cd438
4 changed files with 221 additions and 32 deletions

138
Cargo.lock generated
View File

@ -1,32 +1,146 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "atty"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clap"
version = "2.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "glob" name = "glob"
version = "0.3.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" 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]] [[package]]
name = "libc" name = "libc"
version = "0.2.55" version = "0.2.55"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "rot8" name = "numtoa"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_syscall"
version = "0.1.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
"input-sys 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "rot8"
version = "0.1.1"
dependencies = [
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "termion"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
"numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-width"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vec_map"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata] [metadata]
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" "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" "checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880"
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -1,9 +1,9 @@
[package] [package]
name = "rot8" name = "rot8"
version = "0.1.0" version = "0.1.1"
authors = ["efernau <e.fernau@efero.de>"] authors = ["efernau <e.fernau@efero.de>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
glob = "0.3" glob = "0.3"
input-sys = "1.9" clap = "2.33"

View File

@ -1,6 +1,6 @@
# rot8 # rot8
## Automatic Display rotation ## automatic display rotation
Automatic rotate modern Linux desktop screen and input devices. Handy for Automatic rotate modern Linux desktop screen and input devices. Handy for
convertible touchscreen notebooks like the Kaby Lake model of the HP Spectre x360. convertible touchscreen notebooks like the Kaby Lake model of the HP Spectre x360.
@ -13,7 +13,7 @@ $ cd rot8 && cargo build --release
$ cp target/release/rot8 /usr/bin/rot8 $ cp target/release/rot8 /usr/bin/rot8
``` ```
Call Rote8 from from sway configuration file ~/.config/sway/config: Call Rote8 from sway configuration file ~/.config/sway/config:
``` ```
exec rot8 exec rot8

View File

@ -1,17 +1,60 @@
extern crate glob; extern crate glob;
extern crate input_sys; extern crate clap;
use clap::{Arg, App};
use std::fs; use std::fs;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use std::process::Command; use std::process::Command;
use glob::glob; use glob::glob;
fn main() { fn main() {
let mut mode = "";
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();
let mut path_y: String = "".to_string(); let mut path_y: String = "".to_string();
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 matches = App::new("rot8")
.version("0.1.1")
.arg(Arg::with_name("display")
.default_value("eDP-1")
.long("display")
.value_name("DISPLAY")
.help("Set Display Device")
.takes_value(true))
.arg(Arg::with_name("touchscreen")
.default_value("eDP-1")
.long("touchscreen")
.value_name("TOUCHSCREEN")
.help("Set Touchscreen Device")
.takes_value(true))
.get_matches();
let display = matches.value_of("display").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) => {
@ -39,32 +82,44 @@ fn main() {
if x < -500000 { if x < -500000 {
if y > 500000 { if y > 500000 {
new_state = "180"; new_state = "180";
x_state = "normal";
matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"];
} }
else { else {
new_state = "90"; new_state = "90";
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";
matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"];
} }
else { else {
new_state = "270"; new_state = "270";
x_state = "right";
matrix = ["0", "1", "0", "-1", "0", "1", "0", "0", "1"];
} }
} else { } else {
if y > 500000 { if y > 500000 {
new_state = "180"; new_state = "180";
x_state = "inverted";
matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"];
} }
else { else {
new_state = "normal"; new_state = "normal";
x_state = "normal";
matrix = ["1", "0", "0", "0", "1", "0", "0", "0", "1"];
} }
} }
if new_state != old_state { if new_state != old_state {
if mode == "sway" {
Command::new("swaymsg") Command::new("swaymsg")
.arg("output") .arg("output")
.arg("eDP-1") .arg(display)
.arg("transform") .arg("transform")
.arg(new_state) .arg(new_state)
.spawn() .spawn()
@ -72,10 +127,30 @@ fn main() {
old_state = new_state; old_state = new_state;
} }
thread::sleep(Duration::from_millis(1000)); if mode == "x" {
}
Command::new("xrandr")
.arg("-o")
.arg(x_state)
.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;
}
}
thread::sleep(Duration::from_millis(500));
}
} }