forge
Explore
Log in

Don't you dare go Hollow

Add 'input.keyboard.track_layout' config option

Browse files at this commit

907e0a03efcce6ba35aa6405e130f316bc217c5aKirill ChibisovParent: eb7d20c
Track layout for each window individually when user requested `Window`
tracking mode, keeping the default as global.
resources/default-config.kdlmodified+5 -0
@@ -16,6 +16,11 @@ input {
16 // Delay is in milliseconds before the repeat starts. Rate is in characters per second.16 // Delay is in milliseconds before the repeat starts. Rate is in characters per second.
17 // repeat-delay 60017 // repeat-delay 600
18 // repeat-rate 2518 // repeat-rate 25
19+
20+ // Niri can remember the keyboard layout globally (the default) or per-window.
21+ // - "global" - layout change is global for all windows.
22+ // - "window" - layout is tracked for each window individually.
23+ // track-layout "global"
19 }24 }
20 25
21 // Next sections include libinput settings.26 // Next sections include libinput settings.
src/config.rsmodified+13 -0
@@ -62,6 +62,8 @@ pub struct Keyboard {
62 pub repeat_delay: u16,62 pub repeat_delay: u16,
63 #[knuffel(child, unwrap(argument), default = 25)]63 #[knuffel(child, unwrap(argument), default = 25)]
64 pub repeat_rate: u8,64 pub repeat_rate: u8,
65+ #[knuffel(child, unwrap(argument), default)]
66+ pub track_layout: TrackLayout,
65 }67 }
66 68
67 #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)]69 #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)]
@@ -78,6 +80,15 @@ pub struct Xkb {
78 pub options: Option<String>,80 pub options: Option<String>,
79 }81 }
80 82
83+#[derive(knuffel::DecodeScalar, Debug, Default, PartialEq, Eq)]
84+pub enum TrackLayout {
85+ /// The layout change is global.
86+ #[default]
87+ Global,
88+ /// The layout change is window local.
89+ Window,
90+}
91+
81 // FIXME: Add the rest of the settings.92 // FIXME: Add the rest of the settings.
82 #[derive(knuffel::Decode, Debug, Default, PartialEq)]93 #[derive(knuffel::Decode, Debug, Default, PartialEq)]
83 pub struct Touchpad {94 pub struct Touchpad {
@@ -514,6 +525,7 @@ mod tests {
514 keyboard {525 keyboard {
515 repeat-delay 600526 repeat-delay 600
516 repeat-rate 25527 repeat-rate 25
528+ track-layout "window"
517 xkb {529 xkb {
518 layout "us,ru"530 layout "us,ru"
519 options "grp:win_space_toggle"531 options "grp:win_space_toggle"
@@ -587,6 +599,7 @@ mod tests {
587 },599 },
588 repeat_delay: 600,600 repeat_delay: 600,
589 repeat_rate: 25,601 repeat_rate: 25,
602+ track_layout: TrackLayout::Window,
590 },603 },
591 touchpad: Touchpad {604 touchpad: Touchpad {
592 tap: true,605 tap: true,
src/niri.rsmodified+39 -4
@@ -1,4 +1,4 @@
1-use std::cell::RefCell;1+use std::cell::{Cell, RefCell};
2 use std::collections::{HashMap, HashSet};2 use std::collections::{HashMap, HashSet};
3 use std::ffi::OsString;3 use std::ffi::OsString;
4 use std::path::PathBuf;4 use std::path::PathBuf;
@@ -29,7 +29,7 @@ use smithay::desktop::utils::{
29 under_from_surface_tree, update_surface_primary_scanout_output, OutputPresentationFeedback,29 under_from_surface_tree, update_surface_primary_scanout_output, OutputPresentationFeedback,
30 };30 };
31 use smithay::desktop::{layer_map_for_output, PopupManager, Space, Window, WindowSurfaceType};31 use smithay::desktop::{layer_map_for_output, PopupManager, Space, Window, WindowSurfaceType};
32-use smithay::input::keyboard::XkbConfig;32+use smithay::input::keyboard::{Layout as KeyboardLayout, XkbConfig, XkbContextHandler};
33 use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent};33 use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent};
34 use smithay::input::{Seat, SeatState};34 use smithay::input::{Seat, SeatState};
35 use smithay::output::Output;35 use smithay::output::Output;
@@ -76,7 +76,7 @@ use smithay::wayland::text_input::TextInputManagerState;
76 use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;76 use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
77 77
78 use crate::backend::{Backend, RenderResult, Tty, Winit};78 use crate::backend::{Backend, RenderResult, Tty, Winit};
79-use crate::config::Config;79+use crate::config::{Config, TrackLayout};
80 use crate::cursor::{CursorManager, CursorTextureCache, RenderCursor, XCursor};80 use crate::cursor::{CursorManager, CursorTextureCache, RenderCursor, XCursor};
81 #[cfg(feature = "dbus")]81 #[cfg(feature = "dbus")]
82 use crate::dbus::gnome_shell_screenshot::{NiriToScreenshot, ScreenshotToNiri};82 use crate::dbus::gnome_shell_screenshot::{NiriToScreenshot, ScreenshotToNiri};
@@ -382,8 +382,43 @@ impl State {
382 };382 };
383 383
384 let keyboard = self.niri.seat.get_keyboard().unwrap();384 let keyboard = self.niri.seat.get_keyboard().unwrap();
385- if keyboard.current_focus() != focus {385+ let current_focus = keyboard.current_focus();
386+ if current_focus != focus {
387+ if self.niri.config.borrow().input.keyboard.track_layout == TrackLayout::Window {
388+ let current_layout =
389+ keyboard.with_kkb_state(self, |context| context.active_layout());
390+
391+ let mut new_layout = current_layout;
392+ // Store the currently active layout for the surface.
393+ if let Some(current_focus) = current_focus.as_ref() {
394+ with_states(current_focus, |data| {
395+ let cell = data
396+ .data_map
397+ .get_or_insert::<Cell<KeyboardLayout>, _>(Cell::default);
398+ cell.set(current_layout);
399+ });
400+ }
401+
402+ if let Some(focus) = focus.as_ref() {
403+ new_layout = with_states(focus, |data| {
404+ let cell = data.data_map.get_or_insert::<Cell<KeyboardLayout>, _>(|| {
405+ // The default layout is effectively the first layout in the
406+ // keymap, so use it for new windows.
407+ Cell::new(KeyboardLayout::default())
408+ });
409+ cell.get()
410+ });
411+ }
412+ if new_layout != current_layout && focus.is_some() {
413+ keyboard.set_focus(self, None, SERIAL_COUNTER.next_serial());
414+ keyboard.with_kkb_state(self, |mut context| {
415+ context.set_layout(new_layout);
416+ });
417+ }
418+ }
419+
386 keyboard.set_focus(self, focus, SERIAL_COUNTER.next_serial());420 keyboard.set_focus(self, focus, SERIAL_COUNTER.next_serial());
421+
387 // FIXME: can be more granular.422 // FIXME: can be more granular.
388 self.niri.queue_redraw_all();423 self.niri.queue_redraw_all();
389 }424 }