adding keyboard deactivation upon rotation

This commit is contained in:
Derrick McKee 2019-12-27 10:03:55 -05:00
parent 41fb696fb0
commit 4dd544fb41
2 changed files with 31 additions and 6 deletions

View File

@ -55,5 +55,6 @@ there are the following args.
--sleep // Set sleep millis (500) --sleep // Set sleep millis (500)
--display // Set Display Device (eDP-1) --display // Set Display Device (eDP-1)
--touchscreen // Set Touchscreen Device X11 (ELAN0732:00 04F3:22E1) --touchscreen // Set Touchscreen Device X11 (ELAN0732:00 04F3:22E1)
--keyboard // Set keyboard to deactivate upon rotation
``` ```

View File

@ -89,6 +89,7 @@ fn main() -> Result<(), 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 mut keyboard_state: &str;
let backend = if String::from_utf8(Command::new("pidof").arg("sway").output().unwrap().stdout) let backend = if String::from_utf8(Command::new("pidof").arg("sway").output().unwrap().stdout)
.unwrap() .unwrap()
@ -132,10 +133,18 @@ fn main() -> Result<(), String> {
.help("Set Touchscreen Device (X11)") .help("Set Touchscreen Device (X11)")
.takes_value(true), .takes_value(true),
) )
.arg(
Arg::with_name("keyboard")
.long("keyboard")
.value_name("KEYBOARD")
.help("Disable keyboard for tablet modes")
.takes_value(true),
)
.get_matches(); .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");
let keyboard = matches.value_of("keyboard").unwrap_or("default.conf");
let old_state_owned = get_window_server_rotation_state(display, &backend)?; let old_state_owned = get_window_server_rotation_state(display, &backend)?;
let mut old_state = old_state_owned.as_str(); let mut old_state = old_state_owned.as_str();
@ -165,10 +174,12 @@ fn main() -> Result<(), String> {
if x < -500000 { if x < -500000 {
if y > 500000 { if y > 500000 {
new_state = "180"; new_state = "180";
keyboard_state = "disabled";
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"; new_state = "90";
keyboard_state = "disabled";
x_state = "right"; x_state = "right";
matrix = ["0", "-1", "1", "1", "0", "0", "0", "0", "1"]; matrix = ["0", "-1", "1", "1", "0", "0", "0", "0", "1"];
} }
@ -176,19 +187,23 @@ fn main() -> Result<(), String> {
if y > 500000 { if y > 500000 {
new_state = "180"; new_state = "180";
x_state = "inverted"; x_state = "inverted";
keyboard_state = "disabled";
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";
keyboard_state = "disabled";
x_state = "left"; x_state = "left";
matrix = ["0", "1", "0", "-1", "0", "1", "0", "0", "1"]; matrix = ["0", "1", "0", "-1", "0", "1", "0", "0", "1"];
} }
} else { } else {
if y > 500000 { if y > 500000 {
new_state = "180"; new_state = "180";
keyboard_state = "disabled";
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";
keyboard_state = "enabled";
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"];
} }
@ -206,6 +221,15 @@ fn main() -> Result<(), String> {
.expect("Swaymsg rotate command failed to start") .expect("Swaymsg rotate command failed to start")
.wait() .wait()
.expect("Swaymsg rotate command wait failed"); .expect("Swaymsg rotate command wait failed");
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");
} }
Backend::Xorg => { Backend::Xorg => {
Command::new("xrandr") Command::new("xrandr")