pynput run as user

This commit is contained in:
rustdesk
2022-03-08 15:42:58 +08:00
parent 6c5b7b3b89
commit ffb0fa4349
5 changed files with 30 additions and 8 deletions

View File

@@ -243,7 +243,7 @@ pub fn start_os_service() {
log::info!("Exit");
}
fn get_active_userid() -> String {
pub fn get_active_userid() -> String {
get_value_of_seat0(1)
}

View File

@@ -165,7 +165,16 @@ fn run_cursor(sp: MouseCursorService, state: &mut StateCursor) -> ResultType<()>
}
lazy_static::lazy_static! {
static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new()));
static ref ENIGO: Arc<Mutex<Enigo>> = {
#[cfg(target_os = "linux")]
{
if crate::platform::is_root() {
std::env::set_var("PYNPUT_USERNAME", crate::platform::linux::get_active_username());
std::env::set_var("PYNPUT_USERID", crate::platform::linux::get_active_userid());
}
}
Arc::new(Mutex::new(Enigo::new()))
};
static ref KEYS_DOWN: Arc<Mutex<HashMap<u64, Instant>>> = Default::default();
static ref LATEST_INPUT: Arc<Mutex<Input>> = Default::default();
}

View File

@@ -353,7 +353,7 @@ impl Handler {
Key::Kp8 => Some(ControlKey::Numpad8),
Key::Kp9 => Some(ControlKey::Numpad9),
Key::KpDivide => Some(ControlKey::Divide),
Key::KpMultiply => Some(ControlKey::Subtract),
Key::KpMultiply => Some(ControlKey::Multiply),
Key::KpDecimal => Some(ControlKey::Decimal),
Key::KpMinus => Some(ControlKey::Subtract),
Key::KpPlus => Some(ControlKey::Add),