add function

relogin required if current is wayland
This commit is contained in:
desertstsung
2021-09-09 15:07:09 +08:00
parent d369955790
commit 1009eabdfe
3 changed files with 104 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ use std::{
type Xdo = *const c_void;
pub const PA_SAMPLE_RATE: u32 = 24000;
static mut UNMODIFIED: bool = true;
thread_local! {
static XDO: RefCell<Xdo> = RefCell::new(unsafe { xdo_new(std::ptr::null()) });
@@ -432,6 +433,72 @@ pub fn fix_login_wayland() {
}
}
pub fn current_is_wayland() -> bool {
let dtype = get_display_server();
return "wayland" == dtype && unsafe{UNMODIFIED};
}
pub fn modify_default_login() -> String {
let dsession = std::env::var("DESKTOP_SESSION").unwrap();
let user_name = std::env::var("USERNAME").unwrap();
if let Ok(Some(x)) = run_cmds("ls /usr/share/* | grep ${DESKTOP_SESSION}-xorg.desktop".to_owned()) {
if x.trim_end().to_string() != "" {
match std::process::Command::new("pkexec")
.args(vec![
"sed",
"-i",
&format!("s/={0}$/={0}-xorg/g", &dsession),
&format!("/var/lib/AccountsService/users/{}", &user_name)
])
.output()
{
Ok(x) => {
let x = String::from_utf8_lossy(&x.stderr);
if !x.is_empty() {
log::error!("modify_default_login failed: {}", x);
return "Fix failed! Please re-login with X server manually".to_owned();
} else {
unsafe {UNMODIFIED = false;}
return "".to_owned();
}
}
Err(err) => {
log::error!("modify_default_login failed: {}", err);
return "Fix failed! Please re-login with X server manually".to_owned();
}
}
} else if let Ok(Some(z)) = run_cmds("ls /usr/share/* | grep ${DESKTOP_SESSION:0:-8}.desktop".to_owned()) {
if z.trim_end().to_string() != "" {
match std::process::Command::new("pkexec")
.args(vec![
"sed",
"-i",
&format!("s/={}$/={}/g", &dsession, &dsession[..dsession.len()-8]),
&format!("/var/lib/AccountsService/users/{}", &user_name)
])
.output()
{
Ok(x) => {
let x = String::from_utf8_lossy(&x.stderr);
if !x.is_empty() {
log::error!("modify_default_login failed: {}", x);
return "Fix failed! Please re-login with X server manually".to_owned();
} else {
unsafe {UNMODIFIED = false;}
return "".to_owned();
}
}
Err(err) => {
log::error!("modify_default_login failed: {}", err);
return "Fix failed! Please re-login with X server manually".to_owned();
}
}
}
}
}
return "Fix failed! Please re-login with X server manually".to_owned();
}
// to-do: test the other display manager
fn _get_display_manager() -> String {
if let Ok(x) = std::fs::read_to_string("/etc/X11/default-display-manager") {