linux_wayland_support: dup detecting function of x11 or wayland

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2022-07-20 10:44:27 -07:00
parent 634cb5ef1a
commit 00dc473703
12 changed files with 130 additions and 155 deletions

View File

@@ -3,35 +3,3 @@ mod pynput;
mod xdo;
pub use self::nix_impl::Enigo;
/// Check if display manager is x11.
pub fn is_x11() -> bool {
let stdout =
match std::process::Command::new("sh")
.arg("-c")
.arg("loginctl show-session $(loginctl | awk '/tty/ {print $1}') -p Type | awk -F= '{print $2}'")
.output() {
Ok(output) => {
output.stdout
},
Err(_) => {
match std::process::Command::new("sh")
.arg("-c")
.arg("echo $XDG_SESSION_TYPE")
.output() {
Ok(output) => {
output.stdout
},
Err(_) => {
return false;
}
}
}
};
if let Ok(display_manager) = std::str::from_utf8(&stdout) {
display_manager.trim() == "x11"
} else {
false
}
}