Compare commits

...

35 Commits

Author SHA1 Message Date
Eduardo Cueto-Mendoza 2b631c80fc Changed URL 2021-10-24 08:21:59 +01:00
Eduardo Cueto-Mendoza 3cd18fbff5 Changed README 2021-10-19 19:15:59 +01:00
Eduardo Cueto-Mendoza 43a4c298a6 Changed orientation vectors for Dell Inspiron 7506 2n1 2021-10-19 19:13:21 +01:00
Esra Fernau 80431661d7
Merge pull request #20 from Vassili-Dev/variable_normalization_factor
Move normalization factor to cli argument
2021-08-17 21:17:12 +02:00
VassiliDev 9e0d2f986f Changed erroneous default.conf default 2021-08-17 06:36:20 -04:00
VassiliDev 6630edfebf Added short form arg and fixed feault value 2021-08-17 06:34:38 -04:00
VassiliDev 6035e39c05 Move normalization factor to cli argument 2021-08-12 19:45:07 -04:00
Esra Fernau b7b42d95a9
Merge pull request #17 from nicola-sorace/master
Adding name to Cargo.toml
2021-06-08 21:48:04 +02:00
Esra Fernau 9b341fc3ae
Merge pull request #18 from seandlg/patch-1
Update README.md
2021-06-08 21:39:31 +02:00
Sean Eulenberg c18eca4892
Update README.md
Fix swaymsg command
2021-06-08 15:32:21 +00:00
Nicola Sorace 54c781d60d Adding name to Cargo.toml 2020-11-02 16:53:24 +00:00
Esra Fernau 8f2128c172
Merge pull request #12 from vifino/master
Fix xinput rotation.
2020-03-05 23:46:27 +01:00
Adrian Pistol ebbea9e132 Fix xinput rotation.
Left/Right was swapped for the coordinate matrix as well.
2020-03-05 22:06:16 +01:00
e3b e8957f0c60 🔖 v0.1.3 2020-01-04 23:50:44 +01:00
e3b 2190524a38 adding short arguments 2020-01-04 23:40:30 +01:00
e3b 585dcab39b adding agrs 2020-01-04 23:27:54 +01:00
Esra Fernau a30f3233e8
Merge pull request #11 from deadly-platypus/algo-update
adding keyboard deactivation, improve rotation algorithm and introduce threshold
2020-01-04 23:21:29 +01:00
Derrick McKee 0b3b48967f incorporating rotation algorithm update 2019-12-31 16:39:09 -05:00
Derrick McKee a2ff5f6895 Merge remote-tracking branch 'fork/master' into algo-update
# Conflicts:
#	src/main.rs
2019-12-31 16:29:56 -05:00
Derrick McKee c654e80acc importing rotation algo update 2019-12-31 16:23:29 -05:00
Derrick McKee 571bd5897f automatically get all keyboards and disable them if desired 2019-12-29 18:13:41 -05:00
Derrick McKee 8036af4a4b adding name to Cargo.toml 2019-12-27 10:12:42 -05:00
Derrick McKee 4dd544fb41 adding keyboard deactivation upon rotation 2019-12-27 10:03:55 -05:00
e3b 41fb696fb0 🔖 v0.1.2 2019-09-14 17:52:59 +02:00
e3b 84d91e6130 📄 add AUR to readme 🔖 v0.1.2 2019-09-14 05:30:02 +02:00
Esra Fernau 910b1c8484
Merge pull request #3 from mnussbaum/fix-initial-state-detection
Fix initial state detection and Xorg interaction
2019-09-10 21:58:56 +02:00
mnussbaum 7832d2be2c Ensure no zombie processes are left behind
Dead subprocesses need an explicit wait before they're reaped
2019-09-06 00:22:08 -07:00
mnussbaum 2a548252d1 Fix inverted left/right rotation with Xorg backend
The accelerometer to Xorg orientation mapping had left and right
inverted, causing the output to flip opposite the desired direction when
used sideways.
2019-09-06 00:00:27 -07:00
mnussbaum 5ca46c50f8 Fix detection of initial rotation state
This ensures that if rot8 starts while the window server output is
rotated, but the physical device is in a "normal" position, rot8 will
detect the initial misalignment and rotate the window server's output to
reflect the device's physical state.

This scenario occurs if you frequently toggle rot8 on and off as form of
rotation lock, and you:

1. Use rot8 to rotate the output sideways
2. Turn rot8 off
3. Move the physical device back into a "normal" position
4. Turn rot8 back on
2019-09-06 00:00:12 -07:00
mnussbaum 1e0cc3ed57 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.
2019-09-05 17:30:15 -07:00
mnussbaum 25860caa84 Apply suggested formatting from rustfmt 2019-09-05 17:28:50 -07:00
e3b 19c65e6c7a 🔧 update metadata 2019-08-17 02:15:16 +02:00
e3b 7fd7f53d96 🔧 fix error 2019-08-17 02:07:30 +02:00
e3b fb1ec8ceca add sleep arg & update readme 2019-08-17 01:47:36 +02:00
Esra Fernau dbcebf433b
📋 add LICENSE
📋 add LICENSE
2019-08-16 20:25:35 +02:00
4 changed files with 478 additions and 149 deletions

173
Cargo.lock generated
View File

@ -1,26 +1,33 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[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)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "atty"
version = "0.2.11"
version = "0.2.13"
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)",
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.0.4"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -29,11 +36,11 @@ 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)",
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.1.0 (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)",
"unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -42,35 +49,100 @@ name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "itoa"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.55"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "numtoa"
version = "0.1.0"
name = "memchr"
version = "2.2.1"
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"
name = "proc-macro2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rot8"
version = "0.1.1"
version = "0.1.3"
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)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ryu"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde_derive 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive"
version = "1.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -79,14 +151,13 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "termion"
version = "1.5.2"
name = "syn"
version = "1.0.5"
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)",
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -94,12 +165,25 @@ 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)",
"unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-width"
version = "0.1.5"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -109,7 +193,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.7"
version = "0.3.8"
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)",
@ -127,20 +211,31 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
"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 atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
"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 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 itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e98a83a9f9b331f54b924e68a66acb1bb35cb01fb0a23645139967abefb697e8"
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
"checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd"
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
"checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
"checksum serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)" = "f4473e8506b213730ff2061073b48fa51dcc66349219e2e7c5608f0296a1d95a"
"checksum serde_derive 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)" = "11e410fde43e157d789fc290d26bc940778ad0fdd47836426fbac36573710dbb"
"checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704"
"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 syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
"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 thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"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 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
"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,18 @@
[package]
name = "rot8"
version = "0.1.1"
authors = ["efernau <e.fernau@efero.de>"]
version = "0.1.3"
authors = ["efernau <e.fernau@efero.de>", "deadly_platypus <mail@geth.systems>", "nicola-sorace"]
license = "MIT"
description = "automatic display rotation using built-in accelerometer"
homepage = "https://github.com/efernau/rot8"
documentation = "https://github.com/efernau/rot8"
repository = "https://github.com/efernau/rot8"
keywords = ["sway", "x11", "display", "rotation"]
edition = "2018"
[dependencies]
glob = "0.3"
clap = "2.33"
glob = "0.3"
regex = "1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -1,20 +1,59 @@
# rot8
## automatic display rotation
## automatic display rotation using built-in accelerometer
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 Dell Inspiron 7506 2n1.
Compatible with [sway](http://swaywm.org/) and [X11](https://www.x.org/wiki/Releases/7.7/).
Rust language and the cargo package manager are required to build the binary.
```
$ git clone https://github.com/efernau/rot8
$ git clone https://github.com/EddieCueto/rot8
$ cd rot8 && cargo build --release
$ cp target/release/rot8 /usr/bin/rot8
```
Call Rote8 from sway configuration file ~/.config/sway/config:
or
```
exec rot8
$ cargo install rot8
```
For Sway map your input to the output device:
```
$ swaymsg input <INPUTDEVICE> map_to_output <OUTPUTDEVICE>
```
Call rot8 from sway configuration file ~/.config/sway/config:
```
exec rot8
```
For X11 set Touchscreen Device
```
rot8 --touchscreen <TOUCHSCREEN>
```
there are the following args.
```
--sleep // Set sleep millis (500)
--display // Set Display Device (eDP-1)
--touchscreen // Set Touchscreen Device X11 (ELAN0732:00 04F3:22E1)
--keyboard // Set keyboard to deactivate upon rotation
--threshold // Set a rotation threshold between 0 and 1 (0.5)
```

View File

@ -1,156 +1,342 @@
extern crate glob;
extern crate clap;
use clap::{Arg, App};
extern crate glob;
extern crate regex;
use std::fs;
use std::process::Command;
use std::thread;
use std::time::Duration;
use std::process::Command;
use clap::{App, Arg};
use glob::glob;
use serde::Deserialize;
use serde_json::Value;
enum Backend {
Sway,
Xorg,
}
#[derive(Deserialize)]
struct SwayOutput {
name: String,
transform: String,
}
fn main() {
let mut mode = "";
let mut old_state = "normal";
fn get_keyboards(backend: &Backend) -> Result<Vec<String>, String> {
match backend {
Backend::Sway => {
let raw_inputs = String::from_utf8(
Command::new("swaymsg")
.arg("-t")
.arg("get_inputs")
.arg("--raw")
.output()
.expect("Swaymsg get inputs command failed")
.stdout,
)
.unwrap();
let mut keyboards = vec![];
let deserialized: Vec<Value> = serde_json::from_str(&raw_inputs)
.expect("Unable to deserialize swaymsg JSON output");
for output in deserialized {
let input_type = output["type"].as_str().unwrap();
if input_type == "keyboard" {
keyboards.push(output["identifier"].to_string());
}
}
return Ok(keyboards);
}
Backend::Xorg => {
return Ok(vec![]);
}
}
}
fn get_window_server_rotation_state(display: &str, backend: &Backend) -> Result<String, String> {
match backend {
Backend::Sway => {
let raw_rotation_state = String::from_utf8(
Command::new("swaymsg")
.arg("-t")
.arg("get_outputs")
.arg("--raw")
.output()
.expect("Swaymsg get outputs command failed to start")
.stdout,
)
.unwrap();
let deserialized: Vec<SwayOutput> = serde_json::from_str(&raw_rotation_state)
.expect("Unable to deserialize swaymsg JSON output");
for output in deserialized {
if output.name == display {
return Ok(output.transform);
}
}
return Err(format!(
"Unable to determine rotation state: display {} not found in 'swaymsg -t get_outputs'",
display
)
.to_owned());
}
Backend::Xorg => {
let raw_rotation_state = String::from_utf8(
Command::new("xrandr")
.output()
.expect("Xrandr get outputs command failed to start")
.stdout,
)
.unwrap();
let xrandr_output_pattern = regex::Regex::new(format!(
r"^{} connected .+? .+? (normal |inverted |left |right )?\(normal left inverted right x axis y axis\) .+$",
regex::escape(display),
).as_str()).unwrap();
for xrandr_output_line in raw_rotation_state.split("\n") {
if !xrandr_output_pattern.is_match(xrandr_output_line) {
continue;
}
let xrandr_output_captures =
xrandr_output_pattern.captures(xrandr_output_line).unwrap();
if let Some(transform) = xrandr_output_captures.get(1) {
return Ok(transform.as_str().to_owned());
} else {
return Ok("normal".to_owned());
}
}
return Err(format!(
"Unable to determine rotation state: display {} not found in xrandr output",
display
)
.to_owned());
}
}
}
struct Orientation {
vector: (f32, f32),
new_state: &'static str,
x_state: &'static str,
matrix: [&'static str; 9],
}
fn main() -> Result<(), String> {
let mut new_state: &str;
let mut path_x: 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 sway_pid = String::from_utf8(Command::new("pidof")
.arg("sway")
.output()
let backend = if String::from_utf8(Command::new("pidof").arg("sway").output().unwrap().stdout)
.unwrap()
.stdout).unwrap();
let x_pid = String::from_utf8(Command::new("pidof")
.arg("x")
.output()
.len()
>= 1
{
Backend::Sway
} else if String::from_utf8(Command::new("pidof").arg("Xorg").output().unwrap().stdout)
.unwrap()
.stdout).unwrap();
.len()
>= 1
{
Backend::Xorg
} else {
return Err("Unable to find Sway or Xorg procceses".to_owned());
};
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")
let mut args = vec![
Arg::with_name("sleep")
.default_value("500")
.long("sleep")
.short("s")
.value_name("SLEEP")
.help("Set sleep millis")
.takes_value(true),
Arg::with_name("display")
.default_value("eDP-1")
.long("display")
.short("d")
.value_name("DISPLAY")
.help("Set Display Device")
.takes_value(true))
.arg(Arg::with_name("touchscreen")
.default_value("eDP-1")
.takes_value(true),
Arg::with_name("touchscreen")
.default_value("ELAN0732:00 04F3:22E1")
.long("touchscreen")
.short("i")
.value_name("TOUCHSCREEN")
.help("Set Touchscreen Device")
.takes_value(true))
.get_matches();
.help("Set Touchscreen input Device (X11 only)")
.takes_value(true),
Arg::with_name("threshold")
.default_value("0.5")
.long("threshold")
.short("t")
.value_name("THRESHOLD")
.help("Set a rotation threshold between 0 and 1")
.takes_value(true),
Arg::with_name("normalization-factor")
.default_value("1e6")
.long("normalization-factor")
.short("n")
.value_name("NORMALIZATION_FACTOR")
.help("Set factor for sensor value normalization")
.takes_value(true),
];
match backend {
Backend::Sway => {
args.push(
Arg::with_name("keyboard")
.long("disable-keyboard")
.short("k")
.help("Disable keyboard for tablet modes (Sway only)")
.takes_value(false),
);
}
Backend::Xorg => { /* Keyboard disabling in Xorg is not supported yet */ }
}
let cmd_lines = App::new("rot8").version("0.1.3").args(&args);
let matches = cmd_lines.get_matches();
let sleep = matches.value_of("sleep").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 disable_keyboard = matches.is_present("keyboard");
let threshold = matches.value_of("threshold").unwrap_or("default.conf");
let old_state_owned = get_window_server_rotation_state(display, &backend)?;
let mut old_state = old_state_owned.as_str();
for entry in glob("/sys/bus/iio/devices/iio:device*/in_accel_*_raw").unwrap(){
let normalization_factor = matches.value_of("normalization-factor").unwrap_or("1e6");
let normalization_factor = normalization_factor.parse::<f32>().unwrap_or(1e6);
let keyboards = get_keyboards(&backend)?;
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"){
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"){
} 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"){
} else if path.to_str().unwrap().contains("z_raw") {
continue;
} else {
println!("{:?}", path);
panic!();
panic!("Unknown accelerometer device path {:?}", path);
}
}
Err(e) => println!("{:?}", e),
}
}
let orientations = [
Orientation {
vector: (0.0, 0.0),
new_state: "normal",
x_state: "normal",
matrix: ["1", "0", "0", "0", "1", "0", "0", "0", "1"],
},
Err(e) => println!("{:?}",e)
}
}
Orientation {
vector: (0.0, -1.0),
new_state: "180",
x_state: "inverted",
matrix: ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"],
},
Orientation {
vector: (-1.0, 0.0),
new_state: "90",
x_state: "right",
matrix: ["0", "1", "0", "-1", "0", "1", "0", "0", "1"],
},
Orientation {
vector: (1.0, 0.0),
new_state: "270",
x_state: "left",
matrix: ["0", "-1", "1", "1", "0", "0", "0", "0", "1"],
},
];
let mut current_orient: &Orientation = &orientations[0];
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);
let x_clean = x_raw.trim_end_matches('\n').parse::<i32>().unwrap_or(0);
let y_clean = y_raw.trim_end_matches('\n').parse::<i32>().unwrap_or(0);
if x < -500000 {
if y > 500000 {
new_state = "180";
x_state = "normal";
matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"];
}
else {
// Normalize vectors
let x: f32 = (x_clean as f32) / normalization_factor;
let y: f32 = (y_clean as f32) / normalization_factor;
new_state = "90";
x_state = "left";
matrix = ["0", "-1", "1", "1", "0", "0", "0", "0", "1"];
}
} else if x > 500000 {
if y > 500000 {
new_state = "180";
x_state = "inverted";
matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"];
}
else {
new_state = "270";
x_state = "right";
matrix = ["0", "1", "0", "-1", "0", "1", "0", "0", "1"];
}
} else {
if y > 500000 {
new_state = "180";
x_state = "inverted";
matrix = ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"];
}
else {
new_state = "normal";
x_state = "normal";
matrix = ["1", "0", "0", "0", "1", "0", "0", "0", "1"];
for (_i, orient) in orientations.iter().enumerate() {
let d = (x - orient.vector.0).powf(2.0) + (y - orient.vector.1).powf(2.0);
if d < threshold.parse::<f32>().unwrap_or(0.5) {
current_orient = &orient;
break;
}
}
new_state = current_orient.new_state;
x_state = current_orient.x_state;
matrix = current_orient.matrix;
if new_state != old_state {
if mode == "sway" {
let keyboard_state = if new_state == "normal" {
"enabled"
} else {
"disabled"
};
match backend {
Backend::Sway => {
Command::new("swaymsg")
.arg("output")
.arg(display)
.arg("transform")
.arg(new_state)
.spawn()
.expect("rotate command failed to start");
old_state = new_state;
.expect("Swaymsg rotate command failed to start")
.wait()
.expect("Swaymsg rotate command wait failed");
if disable_keyboard {
for keyboard in &keyboards {
// println!("swaymsg input {} events {}", keyboard, keyboard_state);
Command::new("swaymsg")
.arg("input")
.arg(keyboard)
.arg("events")
.arg(keyboard_state)
.spawn()
.expect("Swaymsg keyboard command failed to start")
.wait()
.expect("Swaymsg keyboard command wait failed");
}
if mode == "x" {
}
}
Backend::Xorg => {
Command::new("xrandr")
.arg("-o")
.arg(x_state)
.spawn()
.expect("rotate command failed to start");
.expect("Xrandr rotate command failed to start")
.wait()
.expect("Xrandr rotate command wait failed");
Command::new("xinput")
.arg("set-prop")
.arg(touchscreen)
.arg("Coordinate")
.arg("Transformation")
.arg("Matrix")
.arg("Coordinate Transformation Matrix")
.args(&matrix)
.spawn()
.expect("rotate command failed to start");
.expect("Xinput rotate command failed to start")
.wait()
.expect("Xinput rotate command wait failed");
}
}
old_state = new_state;
}
}
thread::sleep(Duration::from_millis(500));
thread::sleep(Duration::from_millis(sleep.parse::<u64>().unwrap_or(0)));
}
}