diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-08-26 21:07:29 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-08-26 21:08:17 +0300 |
| commit | 43638df235ae7ce91a8afc318bc86a34089d3870 (patch) | |
| tree | d0a7121e16309c6be77b9feccb8a78cc5315e8d8 /src | |
| parent | 4ba79d94ac9013630a4944a0dc89e2172656268f (diff) | |
| download | niri-43638df235ae7ce91a8afc318bc86a34089d3870.tar.gz niri-43638df235ae7ce91a8afc318bc86a34089d3870.tar.bz2 niri-43638df235ae7ce91a8afc318bc86a34089d3870.zip | |
Save & restore num lock across layout changes
In particular, this makes the numlock option work with locale1.
Diffstat (limited to 'src')
| -rw-r--r-- | src/niri.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/niri.rs b/src/niri.rs index 504afe59..3f99b640 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -45,7 +45,7 @@ use smithay::desktop::{ find_popup_root_surface, layer_map_for_output, LayerMap, LayerSurface, PopupGrab, PopupManager, PopupUngrabStrategy, Space, Window, WindowSurfaceType, }; -use smithay::input::keyboard::Layout as KeyboardLayout; +use smithay::input::keyboard::{Layout as KeyboardLayout, XkbConfig}; use smithay::input::pointer::{ CursorIcon, CursorImageStatus, CursorImageSurfaceData, Focus, GrabStartData as PointerGrabStartData, MotionEvent, @@ -1326,6 +1326,22 @@ impl State { } } + fn set_xkb_config(&mut self, xkb: XkbConfig) { + let keyboard = self.niri.seat.get_keyboard().unwrap(); + let num_lock = keyboard.modifier_state().num_lock; + if let Err(err) = keyboard.set_xkb_config(self, xkb) { + warn!("error updating xkb config: {err:?}"); + return; + } + + // Restore num lock to its previous value. + let mut mods_state = keyboard.modifier_state(); + if mods_state.num_lock != num_lock { + mods_state.num_lock = num_lock; + keyboard.set_modifier_state(mods_state); + } + } + pub fn reload_config(&mut self, config: Result<Config, ()>) { let _span = tracy_client::span!("State::reload_config"); @@ -1531,10 +1547,7 @@ impl State { xkb = self.niri.xkb_from_locale1.clone().unwrap_or_default(); } - let keyboard = self.niri.seat.get_keyboard().unwrap(); - if let Err(err) = keyboard.set_xkb_config(self, xkb.to_xkb_config()) { - warn!("error updating xkb config: {err:?}"); - } + self.set_xkb_config(xkb.to_xkb_config()); } self.ipc_keyboard_layouts_changed(); @@ -2271,11 +2284,7 @@ impl State { } let xkb = xkb.clone(); - let keyboard = self.niri.seat.get_keyboard().unwrap(); - if let Err(err) = keyboard.set_xkb_config(self, xkb.to_xkb_config()) { - warn!("error updating xkb config: {err:?}"); - } - + self.set_xkb_config(xkb.to_xkb_config()); self.ipc_keyboard_layouts_changed(); } } |
