Fix numlock in wayland
This commit is contained in:
parent
071720fe8b
commit
7c2f26eab2
@ -820,10 +820,7 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let mut to_release = Vec::new();
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let mut has_cap = false;
|
||||
#[cfg(windows)]
|
||||
let mut has_numlock = false;
|
||||
|
||||
if evt.down {
|
||||
let ck = if let Some(key_event::Union::ControlKey(ck)) = evt.union {
|
||||
ck.value()
|
||||
@ -846,45 +843,19 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
if key == &Key::CapsLock {
|
||||
has_cap = true;
|
||||
} else if key == &Key::NumLock {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
has_numlock = true;
|
||||
}
|
||||
if !get_modifier_state(key.clone(), &mut en) {
|
||||
if *IS_X11.lock().unwrap() {
|
||||
tfc_key_down_or_up(key.clone(), true, false);
|
||||
} else {
|
||||
if !get_modifier_state(key.clone(), &mut en) {
|
||||
if *IS_X11.lock().unwrap() {
|
||||
tfc_key_down_or_up(key.clone(), true, false);
|
||||
} else {
|
||||
en.key_down(key.clone()).ok();
|
||||
}
|
||||
modifier_sleep();
|
||||
to_release.push(key);
|
||||
}
|
||||
en.key_down(key.clone()).ok();
|
||||
}
|
||||
modifier_sleep();
|
||||
to_release.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
if has_cap != en.get_key_state(Key::CapsLock) {
|
||||
if *IS_X11.lock().unwrap() {
|
||||
tfc_key_down_or_up(Key::CapsLock, true, true);
|
||||
} else {
|
||||
en.key_down(Key::CapsLock).ok();
|
||||
en.key_up(Key::CapsLock);
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
if crate::common::valid_for_numlock(evt) {
|
||||
if has_numlock != en.get_key_state(Key::NumLock) {
|
||||
en.key_down(Key::NumLock).ok();
|
||||
en.key_up(Key::NumLock);
|
||||
}
|
||||
}
|
||||
|
||||
match evt.union {
|
||||
Some(key_event::Union::ControlKey(ck)) => {
|
||||
if let Some(key) = KEY_MAP.get(&ck.value()) {
|
||||
@ -979,11 +950,6 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
|
||||
en.key_up(key.clone());
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
if disable_numlock {
|
||||
en.key_down(Key::NumLock).ok();
|
||||
en.key_up(Key::NumLock);
|
||||
}
|
||||
}
|
||||
|
||||
fn translate_keyboard_mode(evt: &KeyEvent) {
|
||||
|
@ -314,7 +314,7 @@ pub mod service {
|
||||
|
||||
fn map_key(key: &enigo::Key) -> ResultType<evdev::Key> {
|
||||
if let Some(k) = KEY_MAP.get(&key) {
|
||||
log::info!("mapkey {:?}, get {:?}", &key, &k);
|
||||
log::trace!("mapkey {:?}, get {:?}", &key, &k);
|
||||
return Ok(k.clone());
|
||||
} else {
|
||||
match key {
|
||||
@ -351,12 +351,10 @@ pub mod service {
|
||||
// ignore
|
||||
}
|
||||
DataKeyboard::KeyDown(enigo::Key::Raw(code)) => {
|
||||
log::info!("keycode {:?}", *code - 8);
|
||||
let down_event = InputEvent::new(EventType::KEY, *code - 8, 1);
|
||||
allow_err!(keyboard.emit(&[down_event]));
|
||||
}
|
||||
DataKeyboard::KeyUp(enigo::Key::Raw(code)) => {
|
||||
log::info!("keycode {:?}", *code - 8);
|
||||
let down_event = InputEvent::new(EventType::KEY, *code - 8, 0);
|
||||
allow_err!(keyboard.emit(&[down_event]));
|
||||
}
|
||||
@ -388,6 +386,14 @@ pub mod service {
|
||||
false
|
||||
}
|
||||
}
|
||||
} else if enigo::Key::NumLock == *key {
|
||||
match keyboard.get_led_state() {
|
||||
Ok(leds) => leds.contains(evdev::LedType::LED_NUML),
|
||||
Err(_e) => {
|
||||
// log::debug!("Failed to get led state {}", &_e);
|
||||
false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
match keyboard.get_key_state() {
|
||||
Ok(keys) => match key {
|
||||
@ -403,7 +409,6 @@ pub mod service {
|
||||
keys.contains(evdev::Key::KEY_LEFTALT)
|
||||
|| keys.contains(evdev::Key::KEY_RIGHTALT)
|
||||
}
|
||||
enigo::Key::NumLock => keys.contains(evdev::Key::KEY_NUMLOCK),
|
||||
enigo::Key::Meta => {
|
||||
keys.contains(evdev::Key::KEY_LEFTMETA)
|
||||
|| keys.contains(evdev::Key::KEY_RIGHTMETA)
|
||||
|
Loading…
Reference in New Issue
Block a user