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

clear the modifier keys on exiting the focused window #519

Merged
merged 3 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ pub trait EventHandler {

fn key_down_event(&mut self, _keycode: KeyCode, _keymods: KeyMods, _repeat: bool) {}

/// Note: you are not always guaranteed to receive a key_up event. For example on
/// Wayland when leaving the focused window, the key_up event will not be caught.
fn key_up_event(&mut self, _keycode: KeyCode, _keymods: KeyMods) {}

/// Default implementation emulates mouse clicks
Expand Down
9 changes: 8 additions & 1 deletion src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,18 @@
// Ignore this for now.
}
unsafe extern "C" fn keyboard_handle_leave(
_data: *mut ::core::ffi::c_void,
data: *mut ::core::ffi::c_void,
_wl_keyboard: *mut wl_keyboard,
_serial: u32,
_surface: *mut wl_surface,
) {
// Clear modifiers
let display: &mut WaylandPayload = &mut *(data as *mut _);
(display.xkb.xkb_state_update_mask)(display.xkb_state, 0, 0, 0, 0, 0, 0);
EVENTS.push(WaylandEvent::KeyboardLeave);
}
unsafe extern "C" fn keyboard_handle_key(
data: *mut ::core::ffi::c_void,

Check warning on line 203 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 203 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 203 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,
Expand Down Expand Up @@ -808,6 +811,10 @@
match event {
WaylandEvent::KeyboardLeave => {
repeated_keys.clear();
keymods.shift = false;
keymods.ctrl = false;
keymods.logo = false;
keymods.alt = false;
}
WaylandEvent::KeyboardKey(key, state) => {
// https://wayland-book.com/seat/keyboard.html
Expand Down
Loading