diff options
| -rw-r--r-- | niri-config/src/lib.rs | 1207 |
1 files changed, 853 insertions, 354 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index c692844b..6a705226 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -3494,18 +3494,17 @@ mod tests { use super::*; #[track_caller] - fn check(text: &str, expected: Config) { + fn do_parse(text: &str) -> Config { let _ = set_miette_hook(); - let parsed = Config::parse("test.kdl", text) + Config::parse("test.kdl", text) .map_err(miette::Report::new) - .unwrap(); - assert_eq!(parsed, expected); + .unwrap() } #[test] fn parse() { - check( + let parsed = do_parse( r##" input { keyboard { @@ -3748,17 +3747,25 @@ mod tests { workspace "workspace-2" workspace "workspace-3" "##, + ); + + assert_debug_snapshot!(parsed, @r#" Config { input: Input { keyboard: Keyboard { xkb: Xkb { - layout: "us,ru".to_owned(), - options: Some("grp:win_space_toggle".to_owned()), - ..Default::default() + rules: "", + model: "", + layout: "us,ru", + variant: "", + options: Some( + "grp:win_space_toggle", + ), + file: None, }, repeat_delay: 600, repeat_rate: 25, - track_layout: TrackLayout::Window, + track_layout: Window, }, touchpad: Touchpad { off: false, @@ -3766,169 +3773,380 @@ mod tests { dwt: true, dwtp: true, drag_lock: false, - click_method: Some(ClickMethod::Clickfinger), natural_scroll: false, + click_method: Some( + Clickfinger, + ), accel_speed: 0.2, - accel_profile: Some(AccelProfile::Flat), - scroll_method: Some(ScrollMethod::TwoFinger), - scroll_button: Some(272), - tap_button_map: Some(TapButtonMap::LeftMiddleRight), + accel_profile: Some( + Flat, + ), + scroll_method: Some( + TwoFinger, + ), + scroll_button: Some( + 272, + ), + tap_button_map: Some( + LeftMiddleRight, + ), left_handed: false, disabled_on_external_mouse: true, middle_emulation: false, - scroll_factor: Some(FloatOrInt(0.9)), + scroll_factor: Some( + FloatOrInt( + 0.9, + ), + ), }, mouse: Mouse { off: false, natural_scroll: true, accel_speed: 0.4, - accel_profile: Some(AccelProfile::Flat), - scroll_method: Some(ScrollMethod::NoScroll), - scroll_button: Some(273), + accel_profile: Some( + Flat, + ), + scroll_method: Some( + NoScroll, + ), + scroll_button: Some( + 273, + ), left_handed: false, middle_emulation: true, - scroll_factor: Some(FloatOrInt(0.2)), + scroll_factor: Some( + FloatOrInt( + 0.2, + ), + ), }, trackpoint: Trackpoint { off: true, natural_scroll: true, accel_speed: 0.0, - accel_profile: Some(AccelProfile::Flat), - scroll_method: Some(ScrollMethod::OnButtonDown), - scroll_button: Some(274), + accel_profile: Some( + Flat, + ), + scroll_method: Some( + OnButtonDown, + ), + scroll_button: Some( + 274, + ), middle_emulation: false, }, trackball: Trackball { off: true, natural_scroll: true, accel_speed: 0.0, - accel_profile: Some(AccelProfile::Flat), - scroll_method: Some(ScrollMethod::Edge), - scroll_button: Some(275), + accel_profile: Some( + Flat, + ), + scroll_method: Some( + Edge, + ), + scroll_button: Some( + 275, + ), left_handed: true, middle_emulation: true, }, tablet: Tablet { off: false, - calibration_matrix: Some(vec![1., 2., 3., - 4., 5., 6.]), - map_to_output: Some("eDP-1".to_owned()), + calibration_matrix: Some( + [ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + ], + ), + map_to_output: Some( + "eDP-1", + ), left_handed: false, }, touch: Touch { - map_to_output: Some("eDP-1".to_owned()), + map_to_output: Some( + "eDP-1", + ), }, disable_power_key_handling: true, warp_mouse_to_focus: true, - focus_follows_mouse: Some(FocusFollowsMouse { - max_scroll_amount: None, - }), + focus_follows_mouse: Some( + FocusFollowsMouse { + max_scroll_amount: None, + }, + ), workspace_auto_back_and_forth: true, }, - outputs: Outputs(vec![Output { - off: false, - name: "eDP-1".to_owned(), - scale: Some(FloatOrInt(2.)), - transform: Transform::Flipped90, - position: Some(Position { x: 10, y: 20 }), - mode: Some(ConfiguredMode { - width: 1920, - height: 1080, - refresh: Some(144.), - }), - variable_refresh_rate: Some(Vrr { on_demand: true }), - background_color: Color::from_rgba8_unpremul(25, 25, 102, 255), - }]), + outputs: Outputs( + [ + Output { + off: false, + name: "eDP-1", + scale: Some( + FloatOrInt( + 2.0, + ), + ), + transform: Flipped90, + position: Some( + Position { + x: 10, + y: 20, + }, + ), + mode: Some( + ConfiguredMode { + width: 1920, + height: 1080, + refresh: Some( + 144.0, + ), + }, + ), + variable_refresh_rate: Some( + Vrr { + on_demand: true, + }, + ), + background_color: Color { + r: 0.09803922, + g: 0.09803922, + b: 0.4, + a: 1.0, + }, + }, + ], + ), + spawn_at_startup: [ + SpawnAtStartup { + command: [ + "alacritty", + "-e", + "fish", + ], + }, + ], layout: Layout { focus_ring: FocusRing { off: false, - width: FloatOrInt(5.), - active_color: Color::from_rgba8_unpremul(0, 100, 200, 255), - inactive_color: Color::from_rgba8_unpremul(255, 200, 100, 0), - active_gradient: Some(Gradient { - from: Color::from_rgba8_unpremul(10, 20, 30, 255), - to: Color::from_rgba8_unpremul(0, 128, 255, 255), - angle: 180, - relative_to: GradientRelativeTo::WorkspaceView, - in_: GradientInterpolation { - color_space: GradientColorSpace::Srgb, - hue_interpolation: HueInterpolation::Shorter, + width: FloatOrInt( + 5.0, + ), + active_color: Color { + r: 0.0, + g: 0.39215687, + b: 0.78431374, + a: 1.0, + }, + inactive_color: Color { + r: 1.0, + g: 0.78431374, + b: 0.39215687, + a: 0.0, + }, + active_gradient: Some( + Gradient { + from: Color { + r: 0.039215688, + g: 0.078431375, + b: 0.11764706, + a: 1.0, + }, + to: Color { + r: 0.0, + g: 0.5019608, + b: 1.0, + a: 1.0, + }, + angle: 180, + relative_to: WorkspaceView, + in_: GradientInterpolation { + color_space: Srgb, + hue_interpolation: Shorter, + }, }, - }), + ), inactive_gradient: None, }, border: Border { off: false, - width: FloatOrInt(3.), - active_color: Color::from_rgba8_unpremul(255, 200, 127, 255), - inactive_color: Color::from_rgba8_unpremul(255, 200, 100, 0), + width: FloatOrInt( + 3.0, + ), + active_color: Color { + r: 1.0, + g: 0.78431374, + b: 0.49803922, + a: 1.0, + }, + inactive_color: Color { + r: 1.0, + g: 0.78431374, + b: 0.39215687, + a: 0.0, + }, active_gradient: None, inactive_gradient: None, }, shadow: Shadow { + on: false, offset: ShadowOffset { - x: FloatOrInt(10.), - y: FloatOrInt(-20.), + x: FloatOrInt( + 10.0, + ), + y: FloatOrInt( + -20.0, + ), }, - ..Default::default() + softness: FloatOrInt( + 30.0, + ), + spread: FloatOrInt( + 5.0, + ), + draw_behind_window: false, + color: Color { + r: 0.0, + g: 0.0, + b: 0.0, + a: 0.4392157, + }, + inactive_color: None, }, tab_indicator: TabIndicator { - width: FloatOrInt(10.), - position: TabIndicatorPosition::Top, - ..Default::default() + off: false, + hide_when_single_tab: false, + place_within_column: false, + gap: FloatOrInt( + 5.0, + ), + width: FloatOrInt( + 10.0, + ), + length: TabIndicatorLength { + total_proportion: Some( + 0.5, + ), + }, + position: Top, + gaps_between_tabs: FloatOrInt( + 0.0, + ), + corner_radius: FloatOrInt( + 0.0, + ), + active_color: None, + inactive_color: None, + active_gradient: None, + inactive_gradient: None, }, insert_hint: InsertHint { off: false, - color: Color::from_rgba8_unpremul(255, 200, 127, 255), - gradient: Some(Gradient { - from: Color::from_rgba8_unpremul(10, 20, 30, 255), - to: Color::from_rgba8_unpremul(0, 128, 255, 255), - angle: 180, - relative_to: GradientRelativeTo::WorkspaceView, - in_: GradientInterpolation { - color_space: GradientColorSpace::Srgb, - hue_interpolation: HueInterpolation::Shorter, + color: Color { + r: 1.0, + g: 0.78431374, + b: 0.49803922, + a: 1.0, + }, + gradient: Some( + Gradient { + from: Color { + r: 0.039215688, + g: 0.078431375, + b: 0.11764706, + a: 1.0, + }, + to: Color { + r: 0.0, + g: 0.5019608, + b: 1.0, + a: 1.0, + }, + angle: 180, + relative_to: WorkspaceView, + in_: GradientInterpolation { + color_space: Srgb, + hue_interpolation: Shorter, + }, }, - }), + ), }, - preset_column_widths: vec![ - PresetSize::Proportion(0.25), - PresetSize::Proportion(0.5), - PresetSize::Fixed(960), - PresetSize::Fixed(1280), + preset_column_widths: [ + Proportion( + 0.25, + ), + Proportion( + 0.5, + ), + Fixed( + 960, + ), + Fixed( + 1280, + ), ], - default_column_width: Some(DefaultPresetSize(Some(PresetSize::Proportion( - 0.25, - )))), - preset_window_heights: vec![ - PresetSize::Proportion(0.25), - PresetSize::Proportion(0.5), - PresetSize::Fixed(960), - PresetSize::Fixed(1280), + default_column_width: Some( + DefaultPresetSize( + Some( + Proportion( + 0.25, + ), + ), + ), + ), + preset_window_heights: [ + Proportion( + 0.25, + ), + Proportion( + 0.5, + ), + Fixed( + 960, + ), + Fixed( + 1280, + ), ], - gaps: FloatOrInt(8.), - struts: Struts { - left: FloatOrInt(1.), - right: FloatOrInt(2.), - top: FloatOrInt(3.), - bottom: FloatOrInt(0.), - }, - center_focused_column: CenterFocusedColumn::OnOverflow, - default_column_display: ColumnDisplay::Tabbed, + center_focused_column: OnOverflow, always_center_single_column: false, empty_workspace_above_first: false, + default_column_display: Tabbed, + gaps: FloatOrInt( + 8.0, + ), + struts: Struts { + left: FloatOrInt( + 1.0, + ), + right: FloatOrInt( + 2.0, + ), + top: FloatOrInt( + 3.0, + ), + bottom: FloatOrInt( + 0.0, + ), + }, }, - spawn_at_startup: vec![SpawnAtStartup { - command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()], - }], prefer_no_csd: true, cursor: Cursor { - xcursor_theme: String::from("breeze_cursors"), + xcursor_theme: "breeze_cursors", xcursor_size: 16, hide_when_typing: true, - hide_after_inactive_ms: Some(3000), + hide_after_inactive_ms: Some( + 3000, + ), }, - screenshot_path: Some(String::from("~/Screenshots/screenshot.png")), + screenshot_path: Some( + "~/Screenshots/screenshot.png", + ), clipboard: Clipboard { disable_primary: true, }, @@ -3936,289 +4154,570 @@ mod tests { skip_at_startup: true, }, animations: Animations { - slowdown: 2., - workspace_switch: WorkspaceSwitchAnim(Animation { - off: false, - kind: AnimationKind::Spring(SpringParams { - damping_ratio: 1., - stiffness: 1000, - epsilon: 0.0001, - }), - }), - horizontal_view_movement: HorizontalViewMovementAnim(Animation { - off: false, - kind: AnimationKind::Easing(EasingParams { - duration_ms: 100, - curve: AnimationCurve::EaseOutExpo, - }), - }), + off: false, + slowdown: 2.0, + workspace_switch: WorkspaceSwitchAnim( + Animation { + off: false, + kind: Spring( + SpringParams { + damping_ratio: 1.0, + stiffness: 1000, + epsilon: 0.0001, + }, + ), + }, + ), window_open: WindowOpenAnim { anim: Animation { off: true, - ..WindowOpenAnim::default().anim + kind: Easing( + EasingParams { + duration_ms: 150, + curve: EaseOutExpo, + }, + ), }, custom_shader: None, }, - ..Default::default() - }, - environment: Environment(vec![ - EnvironmentVariable { - name: String::from("QT_QPA_PLATFORM"), - value: Some(String::from("wayland")), + window_close: WindowCloseAnim { + anim: Animation { + off: false, + kind: Easing( + EasingParams { + duration_ms: 150, + curve: EaseOutQuad, + }, + ), + }, + custom_shader: None, }, - EnvironmentVariable { - name: String::from("DISPLAY"), - value: None, + horizontal_view_movement: HorizontalViewMovementAnim( + Animation { + off: false, + kind: Easing( + EasingParams { + duration_ms: 100, + curve: EaseOutExpo, + }, + ), + }, + ), + window_movement: WindowMovementAnim( + Animation { + off: false, + kind: Spring( + SpringParams { + damping_ratio: 1.0, + stiffness: 800, + epsilon: 0.0001, + }, + ), + }, + ), + window_resize: WindowResizeAnim { + anim: Animation { + off: false, + kind: Spring( + SpringParams { + damping_ratio: 1.0, + stiffness: 800, + epsilon: 0.0001, + }, + ), + }, + custom_shader: None, }, - ]), - window_rules: vec![WindowRule { - matches: vec![Match { - app_id: Some(RegexEq::from_str(".*alacritty").unwrap()), - title: None, - is_active: None, - is_focused: None, - is_active_in_column: None, - is_floating: None, - is_window_cast_target: None, - at_startup: None, - }], - excludes: vec![ - Match { - app_id: None, - title: Some(RegexEq::from_str("~").unwrap()), - is_active: None, - is_focused: None, - is_active_in_column: None, - is_floating: None, - is_window_cast_target: None, - at_startup: None, + config_notification_open_close: ConfigNotificationOpenCloseAnim( + Animation { + off: false, + kind: Spring( + SpringParams { + damping_ratio: 0.6, + stiffness: 1000, + epsilon: 0.001, + }, + ), }, - Match { - app_id: None, - title: None, - is_active: Some(true), - is_focused: Some(false), - is_active_in_column: None, - is_floating: None, - is_window_cast_target: None, - at_startup: None, + ), + screenshot_ui_open: ScreenshotUiOpenAnim( + Animation { + off: false, + kind: Easing( + EasingParams { + duration_ms: 200, + curve: EaseOutQuad, + }, + ), + }, + ), + }, + environment: Environment( + [ + EnvironmentVariable { + name: "QT_QPA_PLATFORM", + value: Some( + "wayland", + ), + }, + EnvironmentVariable { + name: "DISPLAY", + value: None, }, ], - open_on_output: Some("eDP-1".to_owned()), - open_maximized: Some(true), - open_fullscreen: Some(false), - open_floating: Some(false), - open_focused: Some(true), - default_window_height: Some(DefaultPresetSize(Some(PresetSize::Fixed(500)))), - default_column_display: Some(ColumnDisplay::Tabbed), - default_floating_position: Some(FloatingPosition { - x: FloatOrInt(100.), - y: FloatOrInt(-200.), - relative_to: RelativeTo::BottomLeft, - }), - focus_ring: BorderRule { - off: true, - width: Some(FloatOrInt(3.)), - ..Default::default() - }, - border: BorderRule { - on: true, - width: Some(FloatOrInt(8.5)), - ..Default::default() - }, - tab_indicator: TabIndicatorRule { - active_color: Some(Color::from_rgba8_unpremul(255, 0, 0, 255)), - ..Default::default() + ), + window_rules: [ + WindowRule { + matches: [ + Match { + app_id: Some( + RegexEq( + Regex( + ".*alacritty", + ), + ), + ), + title: None, + is_active: None, + is_focused: None, + is_active_in_column: None, + is_floating: None, + is_window_cast_target: None, + at_startup: None, + }, + ], + excludes: [ + Match { + app_id: None, + title: Some( + RegexEq( + Regex( + "~", + ), + ), + ), + is_active: None, + is_focused: None, + is_active_in_column: None, + is_floating: None, + is_window_cast_target: None, + at_startup: None, + }, + Match { + app_id: None, + title: None, + is_active: Some( + true, + ), + is_focused: Some( + false, + ), + is_active_in_column: None, + is_floating: None, + is_window_cast_target: None, + at_startup: None, + }, + ], + default_column_width: None, + default_window_height: Some( + DefaultPresetSize( + Some( + Fixed( + 500, + ), + ), + ), + ), + open_on_output: Some( + "eDP-1", + ), + open_on_workspace: None, + open_maximized: Some( + true, + ), + open_fullscreen: Some( + false, + ), + open_floating: Some( + false, + ), + open_focused: Some( + true, + ), + min_width: None, + min_height: None, + max_width: None, + max_height: None, + focus_ring: BorderRule { + off: true, + on: false, + width: Some( + FloatOrInt( + 3.0, + ), + ), + active_color: None, + inactive_color: None, + active_gradient: None, + inactive_gradient: None, + }, + border: BorderRule { + off: false, + on: true, + width: Some( + FloatOrInt( + 8.5, + ), + ), + active_color: None, + inactive_color: None, + active_gradient: None, + inactive_gradient: None, + }, + shadow: ShadowRule { + off: false, + on: false, + offset: None, + softness: None, + spread: None, + draw_behind_window: None, + color: None, + inactive_color: None, + }, + tab_indicator: TabIndicatorRule { + active_color: Some( + Color { + r: 1.0, + g: 0.0, + b: 0.0, + a: 1.0, + }, + ), + inactive_color: None, + active_gradient: None, + inactive_gradient: None, + }, + draw_border_with_background: None, + opacity: None, + geometry_corner_radius: None, + clip_to_geometry: None, + baba_is_float: None, + block_out_from: None, + variable_refresh_rate: None, + default_column_display: Some( + Tabbed, + ), + default_floating_position: Some( + FloatingPosition { + x: FloatOrInt( + 100.0, + ), + y: FloatOrInt( + -200.0, + ), + relative_to: BottomLeft, + }, + ), + scroll_factor: None, }, - ..Default::default() - }], - layer_rules: vec![ + ], + layer_rules: [ LayerRule { - matches: vec![layer_rule::Match { - namespace: Some(RegexEq::from_str("^notifications$").unwrap()), - at_startup: None, - }], - excludes: vec![], + matches: [ + Match { + namespace: Some( + RegexEq( + Regex( + "^notifications$", + ), + ), + ), + at_startup: None, + }, + ], + excludes: [], opacity: None, - block_out_from: Some(BlockOutFrom::Screencast), - shadow: ShadowRule::default(), + block_out_from: Some( + Screencast, + ), + shadow: ShadowRule { + off: false, + on: false, + offset: None, + softness: None, + spread: None, + draw_behind_window: None, + color: None, + inactive_color: None, + }, geometry_corner_radius: None, - } - ], - workspaces: vec