diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-09-30 09:23:51 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-10-02 09:38:17 +0300 |
| commit | c0f19d48fa9c43895cfee8e3166f0d2b15ca13f6 (patch) | |
| tree | f5fb0b827960b835408855a68f3a7764867ea460 | |
| parent | 31f9577df92d79ded3e60cea54cd56f61a9bd470 (diff) | |
| download | niri-c0f19d48fa9c43895cfee8e3166f0d2b15ca13f6.tar.gz niri-c0f19d48fa9c43895cfee8e3166f0d2b15ca13f6.tar.bz2 niri-c0f19d48fa9c43895cfee8e3166f0d2b15ca13f6.zip | |
config: Add merging for Input
| -rw-r--r-- | niri-config/src/input.rs | 117 | ||||
| -rw-r--r-- | niri-config/src/lib.rs | 3 |
2 files changed, 91 insertions, 29 deletions
diff --git a/niri-config/src/input.rs b/niri-config/src/input.rs index b81b304a..cf3df973 100644 --- a/niri-config/src/input.rs +++ b/niri-config/src/input.rs @@ -5,51 +5,91 @@ use smithay::input::keyboard::XkbConfig; use smithay::reexports::input; use crate::binds::Modifiers; -use crate::utils::Percent; +use crate::utils::{Flag, MergeWith, Percent}; use crate::FloatOrInt; -#[derive(knuffel::Decode, Debug, Default, PartialEq)] +#[derive(Debug, Default, PartialEq)] pub struct Input { - #[knuffel(child, default)] pub keyboard: Keyboard, - #[knuffel(child, default)] pub touchpad: Touchpad, - #[knuffel(child, default)] pub mouse: Mouse, - #[knuffel(child, default)] pub trackpoint: Trackpoint, - #[knuffel(child, default)] pub trackball: Trackball, - #[knuffel(child, default)] pub tablet: Tablet, - #[knuffel(child, default)] pub touch: Touch, - #[knuffel(child)] pub disable_power_key_handling: bool, + pub warp_mouse_to_focus: Option<WarpMouseToFocus>, + pub focus_follows_mouse: Option<FocusFollowsMouse>, + pub workspace_auto_back_and_forth: bool, + pub mod_key: Option<ModKey>, + pub mod_key_nested: Option<ModKey>, +} + +#[derive(knuffel::Decode, Debug, Default, PartialEq)] +pub struct InputPart { + #[knuffel(child)] + pub keyboard: Option<KeyboardPart>, + #[knuffel(child)] + pub touchpad: Option<Touchpad>, + #[knuffel(child)] + pub mouse: Option<Mouse>, + #[knuffel(child)] + pub trackpoint: Option<Trackpoint>, + #[knuffel(child)] + pub trackball: Option<Trackball>, + #[knuffel(child)] + pub tablet: Option<Tablet>, + #[knuffel(child)] + pub touch: Option<Touch>, + #[knuffel(child)] + pub disable_power_key_handling: Option<Flag>, #[knuffel(child)] pub warp_mouse_to_focus: Option<WarpMouseToFocus>, #[knuffel(child)] pub focus_follows_mouse: Option<FocusFollowsMouse>, #[knuffel(child)] - pub workspace_auto_back_and_forth: bool, + pub workspace_auto_back_and_forth: Option<Flag>, #[knuffel(child, unwrap(argument, str))] pub mod_key: Option<ModKey>, #[knuffel(child, unwrap(argument, str))] pub mod_key_nested: Option<ModKey>, } -#[derive(knuffel::Decode, Debug, PartialEq, Eq)] +impl MergeWith<InputPart> for Input { + fn merge_with(&mut self, part: &InputPart) { + merge!( + (self, part), + keyboard, + disable_power_key_handling, + workspace_auto_back_and_forth, + ); + + merge_clone!( + (self, part), + touchpad, + mouse, + trackpoint, + trackball, + tablet, + touch, + ); + + merge_clone_opt!( + (self, part), + warp_mouse_to_focus, + focus_follows_mouse, + mod_key, + mod_key_nested, + ); + } +} + +#[derive(Debug, PartialEq, Eq)] pub struct Keyboard { - #[knuffel(child, default)] pub xkb: Xkb, - // The defaults were chosen to match wlroots and sway. - #[knuffel(child, unwrap(argument), default = Self::default().repeat_delay)] pub repeat_delay: u16, - #[knuffel(child, unwrap(argument), default = Self::default().repeat_rate)] pub repeat_rate: u8, - #[knuffel(child, unwrap(argument), default)] pub track_layout: TrackLayout, - #[knuffel(child)] pub numlock: bool, } @@ -57,6 +97,7 @@ impl Default for Keyboard { fn default() -> Self { Self { xkb: Default::default(), + // The defaults were chosen to match wlroots and sway. repeat_delay: 600, repeat_rate: 25, track_layout: Default::default(), @@ -65,6 +106,27 @@ impl Default for Keyboard { } } +#[derive(knuffel::Decode, Debug, PartialEq, Eq)] +pub struct KeyboardPart { + #[knuffel(child)] + pub xkb: Option<Xkb>, + #[knuffel(child, unwrap(argument))] + pub repeat_delay: Option<u16>, + #[knuffel(child, unwrap(argument))] + pub repeat_rate: Option<u8>, + #[knuffel(child, unwrap(argument))] + pub track_layout: Option<TrackLayout>, + #[knuffel(child)] + pub numlock: Option<Flag>, +} + +impl MergeWith<KeyboardPart> for Keyboard { + fn merge_with(&mut self, part: &KeyboardPart) { + merge_clone!((self, part), xkb, repeat_delay, repeat_rate, track_layout); + merge!((self, part), numlock); + } +} + #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq, Clone)] pub struct Xkb { #[knuffel(child, unwrap(argument), default)] @@ -93,7 +155,7 @@ impl Xkb { } } -#[derive(knuffel::DecodeScalar, Debug, Default, PartialEq, Eq)] +#[derive(knuffel::DecodeScalar, Debug, Default, Clone, Copy, PartialEq, Eq)] pub enum TrackLayout { /// The layout change is global. #[default] @@ -121,7 +183,7 @@ impl ScrollFactor { } } -#[derive(knuffel::Decode, Debug, Default, PartialEq)] +#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] pub struct Touchpad { #[knuffel(child)] pub off: bool, @@ -161,7 +223,7 @@ pub struct Touchpad { pub scroll_factor: Option<ScrollFactor>, } -#[derive(knuffel::Decode, Debug, Default, PartialEq)] +#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] pub struct Mouse { #[knuffel(child)] pub off: bool, @@ -185,7 +247,7 @@ pub struct Mouse { pub scroll_factor: Option<ScrollFactor>, } -#[derive(knuffel::Decode, Debug, Default, PartialEq)] +#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] pub struct Trackpoint { #[knuffel(child)] pub off: bool, @@ -207,7 +269,7 @@ pub struct Trackpoint { pub middle_emulation: bool, } -#[derive(knuffel::Decode, Debug, Default, PartialEq)] +#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] pub struct Trackball { #[knuffel(child)] pub off: bool, @@ -293,7 +355,7 @@ impl From<TapButtonMap> for input::TapButtonMap { } } -#[derive(knuffel::Decode, Debug, Default, PartialEq)] +#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] pub struct Tablet { #[knuffel(child)] pub off: bool, @@ -305,7 +367,7 @@ pub struct Tablet { pub left_handed: bool, } -#[derive(knuffel::Decode, Debug, Default, PartialEq)] +#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] pub struct Touch { #[knuffel(child)] pub off: bool, @@ -450,9 +512,10 @@ mod tests { #[track_caller] fn do_parse(text: &str) -> Input { - knuffel::parse("test.kdl", text) + let part = knuffel::parse("test.kdl", text) .map_err(miette::Report::new) - .unwrap() + .unwrap(); + Input::from_part(&part) } #[test] diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 18f52a95..e0dfcf6c 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -185,8 +185,7 @@ where } match name { - // TODO: most (all?) of these need to be merged instead - "input" => m_replace!(input), + "input" => m_merge!(input), "cursor" => m_merge!(cursor), "clipboard" => m_merge!(clipboard), "hotkey-overlay" => m_merge!(hotkey_overlay), |
