Skip to content

Commit a659a34

Browse files
committed
fix: use change_keymap to allow WM handle keycode with the correct keymap
1 parent 0cd72d1 commit a659a34

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

examples/minimal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ pub fn run_winit() -> Result<(), Box<dyn std::error::Error>> {
184184
//
185185
FilterResult::Forward
186186
},
187+
false,
187188
);
188189
}
189190
InputEvent::PointerMotionAbsolute { .. } => {

examples/seat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7272
FilterResult::Forward
7373
}
7474
},
75+
false,
7576
);
7677

7778
keyboard.set_focus(&mut state, Option::<WlSurface>::None, 0.into());

src/desktop/wayland/popup/grab.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ where
447447
modifiers: Option<ModifiersState>,
448448
serial: Serial,
449449
time: u32,
450+
ignore_keymap: bool,
450451
) {
451452
// Check if the grab changed and update the focus
452453
// If the grab has ended this will return the root
@@ -459,7 +460,7 @@ where
459460
handle.unset_grab(self, data, serial, false);
460461
}
461462

462-
handle.input(data, keycode, state, modifiers, serial, time)
463+
handle.input(data, keycode, state, modifiers, serial, time, ignore_keymap)
463464
}
464465

465466
fn set_focus(

src/input/keyboard/mod.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ pub trait KeyboardGrab<D: SeatHandler>: Downcast {
606606
modifiers: Option<ModifiersState>,
607607
serial: Serial,
608608
time: u32,
609+
ignore_keymap: bool,
609610
);
610611

611612
/// A focus change was requested.
@@ -934,7 +935,8 @@ impl<D: SeatHandler + 'static> KeyboardHandle<D> {
934935
/// Handle a keystroke
935936
///
936937
/// All keystrokes from the input backend should be fed _in order_ to this method of the
937-
/// keyboard handler. It will internally track the state of the keymap.
938+
/// keyboard handler. It will internally track the state of the keymap. But you could ignore
939+
/// it by setting ignore_keymap true.
938940
///
939941
/// The `filter` argument is expected to be a closure which will peek at the generated input
940942
/// as interpreted by the keymap before it is forwarded to the focused client. If this closure
@@ -953,6 +955,7 @@ impl<D: SeatHandler + 'static> KeyboardHandle<D> {
953955
serial: Serial,
954956
time: u32,
955957
filter: F,
958+
ignore_keymap: bool,
956959
) -> Option<T>
957960
where
958961
F: FnOnce(&mut D, &ModifiersState, KeysymHandle<'_>) -> FilterResult<T>,
@@ -964,7 +967,7 @@ impl<D: SeatHandler + 'static> KeyboardHandle<D> {
964967
return Some(val);
965968
}
966969

967-
self.input_forward(data, keycode, state, serial, time, mods_changed);
970+
self.input_forward(data, keycode, state, serial, time, mods_changed, ignore_keymap);
968971
None
969972
}
970973

@@ -1018,6 +1021,7 @@ impl<D: SeatHandler + 'static> KeyboardHandle<D> {
10181021
serial: Serial,
10191022
time: u32,
10201023
mods_changed: bool,
1024+
ignore_keymap: bool,
10211025
) {
10221026
let mut guard = self.arc.internal.lock().unwrap();
10231027
match state {
@@ -1033,7 +1037,16 @@ impl<D: SeatHandler + 'static> KeyboardHandle<D> {
10331037
let seat = self.get_seat(data);
10341038
let modifiers = mods_changed.then_some(guard.mods_state);
10351039
guard.with_grab(data, &seat, |data, handle, grab| {
1036-
grab.input(data, handle, keycode, state, modifiers, serial, time);
1040+
grab.input(
1041+
data,
1042+
handle,
1043+
keycode,
1044+
state,
1045+
modifiers,
1046+
serial,
1047+
time,
1048+
ignore_keymap,
1049+
);
10371050
});
10381051
if guard.focus.is_some() {
10391052
trace!("Input forwarded to client");
@@ -1270,6 +1283,7 @@ impl<D: SeatHandler + 'static> KeyboardInnerHandle<'_, D> {
12701283
modifiers: Option<ModifiersState>,
12711284
serial: Serial,
12721285
time: u32,
1286+
ignore_keymap: bool,
12731287
) {
12741288
let (focus, _) = match self.inner.focus.as_mut() {
12751289
Some(focus) => focus,
@@ -1278,10 +1292,12 @@ impl<D: SeatHandler + 'static> KeyboardInnerHandle<'_, D> {
12781292

12791293
// Ensure keymap is up to date.
12801294
#[cfg(feature = "wayland_frontend")]
1281-
if let Some(keyboard_handle) = self.seat.get_keyboard() {
1282-
let keymap_file = keyboard_handle.arc.keymap.lock().unwrap();
1283-
let mods = self.inner.mods_state;
1284-
keyboard_handle.send_keymap(data, &Some(focus), &keymap_file, mods);
1295+
if !ignore_keymap {
1296+
if let Some(keyboard_handle) = self.seat.get_keyboard() {
1297+
let keymap_file = keyboard_handle.arc.keymap.lock().unwrap();
1298+
let mods = self.inner.mods_state;
1299+
keyboard_handle.send_keymap(data, &Some(focus), &keymap_file, mods);
1300+
}
12851301
}
12861302

12871303
// key event must be sent before modifiers event for libxkbcommon
@@ -1381,8 +1397,9 @@ impl<D: SeatHandler + 'static> KeyboardGrab<D> for DefaultGrab {
13811397
modifiers: Option<ModifiersState>,
13821398
serial: Serial,
13831399
time: u32,
1400+
ignore_keymap: bool,
13841401
) {
1385-
handle.input(data, keycode, state, modifiers, serial, time)
1402+
handle.input(data, keycode, state, modifiers, serial, time, ignore_keymap)
13861403
}
13871404

13881405
fn set_focus(

src/wayland/input_method/input_method_keyboard_grab.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ where
4949
modifiers: Option<ModifiersState>,
5050
serial: Serial,
5151
time: u32,
52+
_ignore_keymap: bool,
5253
) {
5354
let inner = self.inner.lock().unwrap();
5455
let keyboard = inner.grab.as_ref().unwrap();

src/wayland/virtual_keyboard/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
//! # fn client_compositor_state<'a>(&self, client: &'a Client) -> &'a CompositorClientState { unimplemented!() }
5252
//! # fn commit(&mut self, surface: &WlSurface) {}
5353
//! # }
54+
//! // Set ignore_keymap true while using KeyboardHandle::input
5455
//! impl VirtualKeyboardHandler for State {
5556
//! fn on_keyboard_event(
5657
//! &mut self,

src/wayland/xwayland_keyboard_grab.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,15 @@ impl<D: XWaylandKeyboardGrabHandler + 'static> KeyboardGrab<D> for XWaylandKeybo
113113
modifiers: Option<keyboard::ModifiersState>,
114114
serial: Serial,
115115
time: u32,
116+
ignore_keymap: bool,
116117
) {
117118
handle.set_focus(data, self.start_data.focus.clone(), serial);
118119

119120
if !self.grab.is_alive() {
120121
handle.unset_grab(self, data, serial, false);
121122
}
122123

123-
handle.input(data, keycode, state, modifiers, serial, time)
124+
handle.input(data, keycode, state, modifiers, serial, time, ignore_keymap)
124125
}
125126

126127
fn set_focus(

0 commit comments

Comments
 (0)