Skip to content

Commit f351958

Browse files
committed
fix: adapt to newer virtual_keyboard
1 parent d7184a0 commit f351958

File tree

3 files changed

+17
-59
lines changed

3 files changed

+17
-59
lines changed

src/input/mod.rs

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use std::time::Duration;
77
use calloop::timer::{TimeoutAction, Timer};
88
use input::event::gesture::GestureEventCoordinates as _;
99
use niri_config::{
10-
Action, Bind, Binds, Config, Key, ModKey, Modifiers, MruDirection, SwitchBinds, Trigger, Xkb,
10+
Action, Bind, Binds, Config, Key, ModKey, Modifiers, MruDirection, SwitchBinds, Trigger,
1111
};
1212
use niri_ipc::LayoutSwitchTarget;
1313
use smithay::backend::input::{
1414
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
1515
GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _,
16-
InputEvent, KeyState, KeyboardKeyEvent, Keycode, MouseButton, PointerAxisEvent,
17-
PointerButtonEvent, PointerMotionEvent, ProximityState, Switch, SwitchState, SwitchToggleEvent,
16+
InputEvent, KeyState, KeyboardKeyEvent, MouseButton, PointerAxisEvent, PointerButtonEvent,
17+
PointerMotionEvent, ProximityState, Switch, SwitchState, SwitchToggleEvent,
1818
TabletToolButtonEvent, TabletToolEvent, TabletToolProximityEvent, TabletToolTipEvent,
1919
TabletToolTipState, TouchEvent,
2020
};
@@ -48,7 +48,6 @@ use crate::dbus::freedesktop_a11y::KbMonBlock;
4848
use crate::layout::scrolling::ScrollDirection;
4949
use crate::layout::{ActivateWindow, LayoutElement as _};
5050
use crate::niri::{CastTarget, PointerVisibility, State};
51-
use crate::protocols::virtual_keyboard::VirtualKeyboard;
5251
use crate::ui::mru::{WindowMru, WindowMruUi};
5352
use crate::ui::screenshot_ui::ScreenshotUi;
5453
use crate::utils::spawning::{spawn, spawn_sh};
@@ -368,29 +367,6 @@ impl State {
368367
) where
369368
I::Device: 'static,
370369
{
371-
// Reset the keymap when handling a physical keyboard after a virtual one.
372-
if self.niri.reset_keymap {
373-
let device = event.device();
374-
let is_virtual_keyboard = (&device as &dyn Any)
375-
.downcast_ref::<VirtualKeyboard>()
376-
.is_some();
377-
if !is_virtual_keyboard {
378-
self.niri.reset_keymap = false;
379-
380-
let config = self.niri.config.borrow();
381-
let xkb_config = config.input.keyboard.xkb.clone();
382-
std::mem::drop(config);
383-
384-
if xkb_config != Xkb::default() {
385-
self.set_xkb_config(xkb_config.to_xkb_config());
386-
} else {
387-
// Use locale1 settings if xkb config is unset.
388-
let xkb = self.niri.xkb_from_locale1.clone().unwrap_or_default();
389-
self.set_xkb_config(xkb.to_xkb_config());
390-
}
391-
}
392-
}
393-
394370
let mod_key = self.backend.mod_key(&self.niri.config.borrow());
395371

396372
let serial = SERIAL_COUNTER.next_serial();
@@ -448,7 +424,6 @@ impl State {
448424
serial,
449425
time,
450426
|this, mods, keysym| {
451-
let key_code = event.key_code();
452427
let modified = keysym.modified_sym();
453428
let raw = keysym.raw_latin_sym_or_raw_current_sym();
454429
let modifiers = modifiers_from_state(*mods);
@@ -498,7 +473,7 @@ impl State {
498473
}
499474

500475
// Don't send this press to any clients.
501-
this.niri.suppressed_keys.insert(key_code);
476+
this.niri.suppressed_keys.insert(modified);
502477
return FilterResult::Intercept(None);
503478
}
504479

@@ -507,7 +482,7 @@ impl State {
507482
if this.niri.window_mru_ui.is_open() && !pressed && modifiers.is_empty() {
508483
this.do_action(Action::MruConfirm, false);
509484

510-
if this.niri.suppressed_keys.remove(&key_code) {
485+
if this.niri.suppressed_keys.remove(&modified) {
511486
return FilterResult::Intercept(None);
512487
} else {
513488
return FilterResult::Forward;
@@ -525,7 +500,7 @@ impl State {
525500
.get_pointer()
526501
.unwrap()
527502
.unset_grab(this, serial, time);
528-
this.niri.suppressed_keys.insert(key_code);
503+
this.niri.suppressed_keys.insert(modified);
529504
return FilterResult::Intercept(None);
530505
}
531506

@@ -542,7 +517,6 @@ impl State {
542517
&mut this.niri.suppressed_keys,
543518
bindings,
544519
mod_key,
545-
key_code,
546520
modified,
547521
raw,
548522
pressed,
@@ -558,7 +532,7 @@ impl State {
558532
if this.niri.keyboard_focus.is_overview() && pressed {
559533
if let Some(bind) = raw.and_then(|raw| hardcoded_overview_bind(raw, *mods))
560534
{
561-
this.niri.suppressed_keys.insert(key_code);
535+
this.niri.suppressed_keys.insert(modified);
562536
return FilterResult::Intercept(Some(bind));
563537
}
564538
}
@@ -4329,10 +4303,9 @@ impl State {
43294303
/// to them from being delivered.
43304304
#[allow(clippy::too_many_arguments)]
43314305
fn should_intercept_key<'a>(
4332-
suppressed_keys: &mut HashSet<Keycode>,
4306+
suppressed_keys: &mut HashSet<Keysym>,
43334307
bindings: impl IntoIterator<Item = &'a Bind>,
43344308
mod_key: ModKey,
4335-
key_code: Keycode,
43364309
modified: Keysym,
43374310
raw: Option<Keysym>,
43384311
pressed: bool,
@@ -4344,7 +4317,7 @@ fn should_intercept_key<'a>(
43444317
// Actions are only triggered on presses, release of the key
43454318
// shouldn't try to intercept anything unless we have marked
43464319
// the key to suppress.
4347-
if !pressed && !suppressed_keys.contains(&key_code) {
4320+
if !pressed && !suppressed_keys.contains(&modified) {
43484321
return FilterResult::Forward;
43494322
}
43504323

@@ -4395,7 +4368,7 @@ fn should_intercept_key<'a>(
43954368
if is_inhibiting_shortcuts && bind.allow_inhibiting {
43964369
FilterResult::Forward
43974370
} else {
4398-
suppressed_keys.insert(key_code);
4371+
suppressed_keys.insert(modified);
43994372
FilterResult::Intercept(Some(bind))
44004373
}
44014374
}
@@ -4405,7 +4378,7 @@ fn should_intercept_key<'a>(
44054378
// But we don't need to check for shortcuts inhibition here, because
44064379
// if it was inhibited on press (forwarded to the client), it wouldn't be suppressed,
44074380
// so the release would already have been forwarded at the start of this function.
4408-
suppressed_keys.remove(&key_code);
4381+
suppressed_keys.remove(&modified);
44094382
FilterResult::Intercept(None)
44104383
}
44114384
(None, true) => FilterResult::Forward,
@@ -4466,7 +4439,6 @@ fn find_configured_bind<'a>(
44664439
) -> Option<Bind> {
44674440
// Handle configured binds.
44684441
let mut modifiers = modifiers_from_state(mods);
4469-
44704442
let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());
44714443
if mod_down {
44724444
modifiers |= Modifiers::COMPOSITOR;
@@ -5115,13 +5087,11 @@ mod tests {
51155087
// The key_code we pick is arbitrary, the only thing
51165088
// that matters is that they are different between cases.
51175089

5118-
let close_key_code = Keycode::from(close_keysym.raw() + 8u32);
5119-
let close_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| {
5090+
let close_key_event = |suppr: &mut HashSet<Keysym>, mods: ModifiersState, pressed| {
51205091
should_intercept_key(
51215092
suppr,
51225093
&bindings.0,
51235094
comp_mod,
5124-
close_key_code,
51255095
close_keysym,
51265096
Some(close_keysym),
51275097
pressed,
@@ -5133,12 +5103,11 @@ mod tests {
51335103
};
51345104

51355105
// Key event with the code which can't trigger any action.
5136-
let none_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| {
5106+
let none_key_event = |suppr: &mut HashSet<Keysym>, mods: ModifiersState, pressed| {
51375107
should_intercept_key(
51385108
suppr,
51395109
&bindings.0,
51405110
comp_mod,
5141-
Keycode::from(Keysym::l.raw() + 8),
51425111
Keysym::l,
51435112
Some(Keysym::l),
51445113
pressed,
@@ -5165,7 +5134,7 @@ mod tests {
51655134
..
51665135
}))
51675136
));
5168-
assert!(suppressed_keys.contains(&close_key_code));
5137+
assert!(suppressed_keys.contains(&close_keysym));
51695138

51705139
let filter = close_key_event(&mut suppressed_keys, mods, false);
51715140
assert!(matches!(filter, FilterResult::Intercept(None)));
@@ -5266,7 +5235,7 @@ mod tests {
52665235
..
52675236
}))
52685237
));
5269-
assert!(suppressed_keys.contains(&close_key_code));
5238+
assert!(suppressed_keys.contains(&close_keysym));
52705239

52715240
is_inhibiting_shortcuts.set(true);
52725241

src/niri.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use niri_config::{
1919
WorkspaceReference, Xkb,
2020
};
2121
use smithay::backend::allocator::Fourcc;
22-
use smithay::backend::input::Keycode;
2322
use smithay::backend::renderer::damage::OutputDamageTracker;
2423
use smithay::backend::renderer::element::memory::MemoryRenderBufferRenderElement;
2524
use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
@@ -44,7 +43,7 @@ use smithay::desktop::{
4443
find_popup_root_surface, layer_map_for_output, LayerMap, LayerSurface, PopupGrab, PopupManager,
4544
PopupUngrabStrategy, Space, Window, WindowSurfaceType,
4645
};
47-
use smithay::input::keyboard::{Layout as KeyboardLayout, XkbConfig};
46+
use smithay::input::keyboard::{Keysym, Layout as KeyboardLayout, XkbConfig};
4847
use smithay::input::pointer::{
4948
CursorIcon, CursorImageStatus, CursorImageSurfaceData, Focus,
5049
GrabStartData as PointerGrabStartData, MotionEvent,
@@ -317,7 +316,7 @@ pub struct Niri {
317316

318317
pub seat: Seat<State>,
319318
/// Scancodes of the keys to suppress.
320-
pub suppressed_keys: HashSet<Keycode>,
319+
pub suppressed_keys: HashSet<Keysym>,
321320
/// Button codes of the mouse buttons to suppress.
322321
pub suppressed_buttons: HashSet<u32>,
323322
pub bind_cooldown_timers: HashMap<Key, RegistrationToken>,
@@ -331,11 +330,6 @@ pub struct Niri {
331330
/// Most recent XKB settings from org.freedesktop.locale1.
332331
pub xkb_from_locale1: Option<Xkb>,
333332

334-
/// Whether to reset the keymap on the next physical keyboard event.
335-
///
336-
/// Set to true when handling virtual keyboard events which override the keymap.
337-
pub reset_keymap: bool,
338-
339333
pub cursor_manager: CursorManager,
340334
pub cursor_texture_cache: CursorTextureCache,
341335
pub cursor_shape_manager_state: CursorShapeManagerState,
@@ -2510,7 +2504,6 @@ impl Niri {
25102504
is_fdo_idle_inhibited: Arc::new(AtomicBool::new(false)),
25112505
keyboard_shortcuts_inhibiting_surfaces: HashMap::new(),
25122506
xkb_from_locale1: None,
2513-
reset_keymap: false,
25142507
cursor_manager,
25152508
cursor_texture_cache: Default::default(),
25162509
cursor_shape_manager_state,

src/protocols/virtual_keyboard.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ impl VirtualKeyboardHandler for State {
107107
time: u32,
108108
_keyboard: KeyboardHandle<Self>,
109109
) {
110-
// The virtual keyboard impl in Smithay changes the keymap, so we'll need to reset it on
111-
// the next real keyboard event.
112-
self.niri.reset_keymap = true;
113-
114110
let event = VirtualKeyboardKeyEvent {
115111
keycode,
116112
state,

0 commit comments

Comments
 (0)