Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux_wayland: fix bug where shift+i, release shift, release i sends repeated I events #515

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,14 @@
) {
}
unsafe extern "C" fn keyboard_handle_key(
data: *mut ::core::ffi::c_void,

Check warning on line 196 in src/native/linux_wayland.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `data`

Check warning on line 196 in src/native/linux_wayland.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, armv7-unknown-linux-gnueabihf)

unused variable: `data`

Check warning on line 196 in src/native/linux_wayland.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu)

unused variable: `data`
_wl_keyboard: *mut wl_keyboard,
_serial: u32,
_time: u32,
key: u32,
state: u32,
) {
let display: &mut WaylandPayload = &mut *(data as *mut _);
// https://wayland-book.com/seat/keyboard.html
// To translate this to an XKB scancode, you must add 8 to the evdev scancode.
let keysym = (display.xkb.xkb_state_key_get_one_sym)(display.xkb_state, key + 8);
EVENTS.push(WaylandEvent::KeyboardKey(keysym, state == 1));
EVENTS.push(WaylandEvent::KeyboardKey(key, state == 1));
}
unsafe extern "C" fn keyboard_handle_modifiers(
data: *mut ::core::ffi::c_void,
Expand Down Expand Up @@ -765,11 +761,14 @@
(client.wl_display_dispatch_pending)(wdisplay);

if let Some(ref mut event_handler) = display.event_handler {
for keysym in &repeated_keys {
let keycode = keycodes::translate(*keysym);
for key in &repeated_keys {
let keysym =
(display.xkb.xkb_state_key_get_one_sym)(display.xkb_state, key + 8);
let keycode = keycodes::translate(keysym);

event_handler.key_down_event(keycode.clone(), keymods, true);

let chr = keycodes::keysym_to_unicode(&mut display.xkb, *keysym);
let chr = keycodes::keysym_to_unicode(&mut display.xkb, keysym);
if chr > 0 {
if let Some(chr) = char::from_u32(chr as u32) {
event_handler.char_event(chr, keymods, true);
Expand Down Expand Up @@ -803,8 +802,13 @@

for event in EVENTS.drain(..) {
match event {
WaylandEvent::KeyboardKey(keysym, state) => {
WaylandEvent::KeyboardKey(key, state) => {
// https://wayland-book.com/seat/keyboard.html
// To translate this to an XKB scancode, you must add 8 to the evdev scancode.
let keysym =
(display.xkb.xkb_state_key_get_one_sym)(display.xkb_state, key + 8);
let keycode = keycodes::translate(keysym);

match keycode {
KeyCode::LeftShift | KeyCode::RightShift => keymods.shift = state,
KeyCode::LeftControl | KeyCode::RightControl => {
Expand All @@ -817,7 +821,7 @@

if state {
event_handler.key_down_event(keycode, keymods, false);
repeated_keys.insert(keysym);
repeated_keys.insert(key);

let chr = keycodes::keysym_to_unicode(&mut display.xkb, keysym);
if chr > 0 {
Expand All @@ -827,7 +831,7 @@
}
} else {
event_handler.key_up_event(keycode, keymods);
repeated_keys.remove(&keysym);
repeated_keys.remove(&key);
}
}
WaylandEvent::PointerMotion(x, y) => {
Expand Down
Loading