Skip to content

Commit

Permalink
linux_wayland: do not send repeated keys events when focus is lost fr…
Browse files Browse the repository at this point in the history
…om the window.
  • Loading branch information
jkds authored and not-fl3 committed Jan 20, 2025
1 parent 2f716f5 commit 8b8dc62
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ unsafe extern "C" fn seat_handle_capabilities(
}

enum WaylandEvent {
KeyboardLeave,
KeyboardKey(u32, bool),
PointerMotion(f32, f32),
PointerButton(MouseButton, bool),
Expand Down Expand Up @@ -184,13 +185,16 @@ unsafe extern "C" fn keyboard_handle_enter(
_surface: *mut wl_surface,
_keys: *mut wl_array,
) {
// We can capture held keys when window is refocused.
// Ignore this for now.
}
unsafe extern "C" fn keyboard_handle_leave(
_data: *mut ::core::ffi::c_void,
_wl_keyboard: *mut wl_keyboard,
_serial: u32,
_surface: *mut wl_surface,
) {
EVENTS.push(WaylandEvent::KeyboardLeave);
}
unsafe extern "C" fn keyboard_handle_key(
data: *mut ::core::ffi::c_void,

Check warning on line 200 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 200 in src/native/linux_wayland.rs

View workflow job for this annotation

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

unused variable: `data`

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

View workflow job for this annotation

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

unused variable: `data`
Expand Down Expand Up @@ -802,6 +806,9 @@ where

for event in EVENTS.drain(..) {
match event {
WaylandEvent::KeyboardLeave => {
repeated_keys.clear();
}
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.
Expand Down

0 comments on commit 8b8dc62

Please sign in to comment.