[cfg-breaking] Move layout settings into their own scope
Browse files at this commit4e0aa391137a53180783ab3d2d0ff0cc6311b23bParent: dcb80ef3 changed files +160 -145
- resources/default-config.kdl +58 -56
- src/config.rs +95 -83
- src/layout/mod.rs +7 -6
resources/default-config.kdlmodified+58 -56
| @@ -75,37 +75,72 @@ input { | |||
| 75 | position x=1280 y=0 | 75 | position x=1280 y=0 |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | -// Add lines like this to spawn processes at startup. | 78 | +layout { |
| 79 | -// Note that running niri as a session supports xdg-desktop-autostart, | 79 | + // You can change how the focus ring looks. |
| 80 | -// which may be more convenient to use. | 80 | + focus-ring { |
| 81 | -// spawn-at-startup "alacritty" "-e" "fish" | 81 | + // Uncomment this line to disable the focus ring. |
| 82 | + // off | ||
| 82 | 83 | ||
| 83 | -// You can change how the focus ring looks. | 84 | + // How many logical pixels the ring extends out from the windows. |
| 84 | -focus-ring { | 85 | + width 4 |
| 85 | - // Uncomment this line to disable the focus ring. | ||
| 86 | - // off | ||
| 87 | 86 | ||
| 88 | - // How many logical pixels the ring extends out from the windows. | 87 | + // Color of the ring on the active monitor: red, green, blue, alpha. |
| 89 | - width 4 | 88 | + active-color 127 200 255 255 |
| 90 | 89 | ||
| 91 | - // Color of the ring on the active monitor: red, green, blue, alpha. | 90 | + // Color of the ring on inactive monitors: red, green, blue, alpha. |
| 92 | - active-color 127 200 255 255 | 91 | + inactive-color 80 80 80 255 |
| 92 | + } | ||
| 93 | 93 | ||
| 94 | - // Color of the ring on inactive monitors: red, green, blue, alpha. | 94 | + // You can also add a border. It's similar to the focus ring, but always visible. |
| 95 | - inactive-color 80 80 80 255 | 95 | + border { |
| 96 | -} | 96 | + // The settings are the same as for the focus ring. |
| 97 | + // If you enable the border, you probably want to disable the focus ring. | ||
| 98 | + off | ||
| 97 | 99 | ||
| 98 | -// You can also add a border. It's similar to the focus ring, but always visible. | 100 | + width 4 |
| 99 | -border { | 101 | + active-color 255 200 127 255 |
| 100 | - // The settings are the same as for the focus ring. | 102 | + inactive-color 80 80 80 255 |
| 101 | - // If you enable the border, you probably want to disable the focus ring. | 103 | + } |
| 102 | - off | 104 | + |
| 105 | + // You can customize the widths that "switch-preset-column-width" (Mod+R) toggles between. | ||
| 106 | + preset-column-widths { | ||
| 107 | + // Proportion sets the width as a fraction of the output width, taking gaps into account. | ||
| 108 | + // For example, you can perfectly fit four windows sized "proportion 0.25" on an output. | ||
| 109 | + // The default preset widths are 1/3, 1/2 and 2/3 of the output. | ||
| 110 | + proportion 0.333 | ||
| 111 | + proportion 0.5 | ||
| 112 | + proportion 0.667 | ||
| 113 | + | ||
| 114 | + // Fixed sets the width in logical pixels exactly. | ||
| 115 | + // fixed 1920 | ||
| 116 | + } | ||
| 103 | 117 | ||
| 104 | - width 4 | 118 | + // You can change the default width of the new windows. |
| 105 | - active-color 255 200 127 255 | 119 | + default-column-width { proportion 0.5; } |
| 106 | - inactive-color 80 80 80 255 | 120 | + // If you leave the brackets empty, the windows themselves will decide their initial width. |
| 121 | + // default-column-width {} | ||
| 122 | + | ||
| 123 | + // Set gaps around windows in logical pixels. | ||
| 124 | + gaps 16 | ||
| 125 | + | ||
| 126 | + // Struts shrink the area occupied by windows, similarly to layer-shell panels. | ||
| 127 | + // You can think of them as a kind of outer gaps. They are set in logical pixels. | ||
| 128 | + // Left and right struts will cause the next window to the side to always be visible. | ||
| 129 | + // Top and bottom struts will simply add outer gaps in addition to the area occupied by | ||
| 130 | + // layer-shell panels and regular gaps. | ||
| 131 | + struts { | ||
| 132 | + // left 64 | ||
| 133 | + // right 64 | ||
| 134 | + // top 64 | ||
| 135 | + // bottom 64 | ||
| 136 | + } | ||
| 107 | } | 137 | } |
| 108 | 138 | ||
| 139 | +// Add lines like this to spawn processes at startup. | ||
| 140 | +// Note that running niri as a session supports xdg-desktop-autostart, | ||
| 141 | +// which may be more convenient to use. | ||
| 142 | +// spawn-at-startup "alacritty" "-e" "fish" | ||
| 143 | + | ||
| 109 | cursor { | 144 | cursor { |
| 110 | // Change the theme and size of the cursor as well as set the | 145 | // Change the theme and size of the cursor as well as set the |
| 111 | // `XCURSOR_THEME` and `XCURSOR_SIZE` env variables. | 146 | // `XCURSOR_THEME` and `XCURSOR_SIZE` env variables. |
| @@ -118,39 +153,6 @@ cursor { | |||
| 118 | // Additionally, clients will be informed that they are tiled, removing some rounded corners. | 153 | // Additionally, clients will be informed that they are tiled, removing some rounded corners. |
| 119 | // prefer-no-csd | 154 | // prefer-no-csd |
| 120 | 155 | ||
| 121 | -// You can customize the widths that "switch-preset-column-width" (Mod+R) toggles between. | ||
| 122 | -preset-column-widths { | ||
| 123 | - // Proportion sets the width as a fraction of the output width, taking gaps into account. | ||
| 124 | - // For example, you can perfectly fit four windows sized "proportion 0.25" on an output. | ||
| 125 | - // The default preset widths are 1/3, 1/2 and 2/3 of the output. | ||
| 126 | - proportion 0.333 | ||
| 127 | - proportion 0.5 | ||
| 128 | - proportion 0.667 | ||
| 129 | - | ||
| 130 | - // Fixed sets the width in logical pixels exactly. | ||
| 131 | - // fixed 1920 | ||
| 132 | -} | ||
| 133 | - | ||
| 134 | -// You can change the default width of the new windows. | ||
| 135 | -default-column-width { proportion 0.5; } | ||
| 136 | -// If you leave the brackets empty, the windows themselves will decide their initial width. | ||
| 137 | -// default-column-width {} | ||
| 138 | - | ||
| 139 | -// Set gaps around windows in logical pixels. | ||
| 140 | -gaps 16 | ||
| 141 | - | ||
| 142 | -// Struts shrink the area occupied by windows, similarly to layer-shell panels. | ||
| 143 | -// You can think of them as a kind of outer gaps. They are set in logical pixels. | ||
| 144 | -// Left and right struts will cause the next window to the side to always be visible. | ||
| 145 | -// Top and bottom struts will simply add outer gaps in addition to the area occupied by | ||
| 146 | -// layer-shell panels and regular gaps. | ||
| 147 | -struts { | ||
| 148 | - // left 64 | ||
| 149 | - // right 64 | ||
| 150 | - // top 64 | ||
| 151 | - // bottom 64 | ||
| 152 | -} | ||
| 153 | - | ||
| 154 | // You can change the path where screenshots are saved. | 156 | // You can change the path where screenshots are saved. |
| 155 | // A ~ at the front will be expanded to the home directory. | 157 | // A ~ at the front will be expanded to the home directory. |
| 156 | // The path is formatted with strftime(3) to give you the screenshot date and time. | 158 | // The path is formatted with strftime(3) to give you the screenshot date and time. |
src/config.rsmodified+95 -83
| @@ -17,21 +17,11 @@ pub struct Config { | |||
| 17 | #[knuffel(children(name = "spawn-at-startup"))] | 17 | #[knuffel(children(name = "spawn-at-startup"))] |
| 18 | pub spawn_at_startup: Vec<SpawnAtStartup>, | 18 | pub spawn_at_startup: Vec<SpawnAtStartup>, |
| 19 | #[knuffel(child, default)] | 19 | #[knuffel(child, default)] |
| 20 | - pub focus_ring: FocusRing, | 20 | + pub layout: Layout, |
| 21 | - #[knuffel(child, default = default_border())] | ||
| 22 | - pub border: FocusRing, | ||
| 23 | #[knuffel(child, default)] | 21 | #[knuffel(child, default)] |
| 24 | pub prefer_no_csd: bool, | 22 | pub prefer_no_csd: bool, |
| 25 | #[knuffel(child, default)] | 23 | #[knuffel(child, default)] |
| 26 | pub cursor: Cursor, | 24 | pub cursor: Cursor, |
| 27 | - #[knuffel(child, unwrap(children), default)] | ||
| 28 | - pub preset_column_widths: Vec<PresetWidth>, | ||
| 29 | - #[knuffel(child)] | ||
| 30 | - pub default_column_width: Option<DefaultColumnWidth>, | ||
| 31 | - #[knuffel(child, unwrap(argument), default = 16)] | ||
| 32 | - pub gaps: u16, | ||
| 33 | - #[knuffel(child, default)] | ||
| 34 | - pub struts: Struts, | ||
| 35 | #[knuffel( | 25 | #[knuffel( |
| 36 | child, | 26 | child, |
| 37 | unwrap(argument), | 27 | unwrap(argument), |
| @@ -165,6 +155,22 @@ pub struct Mode { | |||
| 165 | pub refresh: Option<f64>, | 155 | pub refresh: Option<f64>, |
| 166 | } | 156 | } |
| 167 | 157 | ||
| 158 | +#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] | ||
| 159 | +pub struct Layout { | ||
| 160 | + #[knuffel(child, default)] | ||
| 161 | + pub focus_ring: FocusRing, | ||
| 162 | + #[knuffel(child, default = default_border())] | ||
| 163 | + pub border: FocusRing, | ||
| 164 | + #[knuffel(child, unwrap(children), default)] | ||
| 165 | + pub preset_column_widths: Vec<PresetWidth>, | ||
| 166 | + #[knuffel(child)] | ||
| 167 | + pub default_column_width: Option<DefaultColumnWidth>, | ||
| 168 | + #[knuffel(child, unwrap(argument), default = 16)] | ||
| 169 | + pub gaps: u16, | ||
| 170 | + #[knuffel(child, default)] | ||
| 171 | + pub struts: Struts, | ||
| 172 | +} | ||
| 173 | + | ||
| 168 | #[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)] | 174 | #[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)] |
| 169 | pub struct SpawnAtStartup { | 175 | pub struct SpawnAtStartup { |
| 170 | #[knuffel(arguments)] | 176 | #[knuffel(arguments)] |
| @@ -607,42 +613,44 @@ mod tests { | |||
| 607 | mode "1920x1080@144" | 613 | mode "1920x1080@144" |
| 608 | } | 614 | } |
| 609 | 615 | ||
| 610 | - spawn-at-startup "alacritty" "-e" "fish" | 616 | + layout { |
| 617 | + focus-ring { | ||
| 618 | + width 5 | ||
| 619 | + active-color 0 100 200 255 | ||
| 620 | + inactive-color 255 200 100 0 | ||
| 621 | + } | ||
| 611 | 622 | ||
| 612 | - focus-ring { | 623 | + border { |
| 613 | - width 5 | 624 | + width 3 |
| 614 | - active-color 0 100 200 255 | 625 | + active-color 0 100 200 255 |
| 615 | - inactive-color 255 200 100 0 | 626 | + inactive-color 255 200 100 0 |
| 616 | - } | 627 | + } |
| 617 | 628 | ||
| 618 | - border { | 629 | + preset-column-widths { |
| 619 | - width 3 | 630 | + proportion 0.25 |
| 620 | - active-color 0 100 200 255 | 631 | + proportion 0.5 |
| 621 | - inactive-color 255 200 100 0 | 632 | + fixed 960 |
| 622 | - } | 633 | + fixed 1280 |
| 634 | + } | ||
| 623 | 635 | ||
| 624 | - prefer-no-csd | 636 | + default-column-width { proportion 0.25; } |
| 625 | 637 | ||
| 626 | - cursor { | 638 | + gaps 8 |
| 627 | - xcursor-theme "breeze_cursors" | ||
| 628 | - xcursor-size 16 | ||
| 629 | - } | ||
| 630 | 639 | ||
| 631 | - preset-column-widths { | 640 | + struts { |
| 632 | - proportion 0.25 | 641 | + left 1 |
| 633 | - proportion 0.5 | 642 | + right 2 |
| 634 | - fixed 960 | 643 | + top 3 |
| 635 | - fixed 1280 | 644 | + } |
| 636 | } | 645 | } |
| 637 | 646 | ||
| 638 | - default-column-width { proportion 0.25; } | 647 | + spawn-at-startup "alacritty" "-e" "fish" |
| 639 | 648 | ||
| 640 | - gaps 8 | 649 | + prefer-no-csd |
| 641 | 650 | ||
| 642 | - struts { | 651 | + cursor { |
| 643 | - left 1 | 652 | + xcursor-theme "breeze_cursors" |
| 644 | - right 2 | 653 | + xcursor-size 16 |
| 645 | - top 3 | ||
| 646 | } | 654 | } |
| 647 | 655 | ||
| 648 | screenshot-path "~/Screenshots/screenshot.png" | 656 | screenshot-path "~/Screenshots/screenshot.png" |
| @@ -694,60 +702,64 @@ mod tests { | |||
| 694 | refresh: Some(144.), | 702 | refresh: Some(144.), |
| 695 | }), | 703 | }), |
| 696 | }], | 704 | }], |
| 697 | - spawn_at_startup: vec![SpawnAtStartup { | 705 | + layout: Layout { |
| 698 | - command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()], | 706 | + focus_ring: FocusRing { |
| 699 | - }], | 707 | + off: false, |
| 700 | - focus_ring: FocusRing { | 708 | + width: 5, |
| 701 | - off: false, | 709 | + active_color: Color { |
| 702 | - width: 5, | 710 | + r: 0, |
| 703 | - active_color: Color { | 711 | + g: 100, |
| 704 | - r: 0, | 712 | + b: 200, |
| 705 | - g: 100, | 713 | + a: 255, |
| 706 | - b: 200, | 714 | + }, |
| 707 | - a: 255, | 715 | + inactive_color: Color { |
| 708 | - }, | 716 | + r: 255, |
| 709 | - inactive_color: Color { | 717 | + g: 200, |
| 710 | - r: 255, | 718 | + b: 100, |
| 711 | - g: 200, | 719 | + a: 0, |
| 712 | - b: 100, | 720 | + }, |
| 713 | - a: 0, | ||
| 714 | }, | 721 | }, |
| 715 | - }, | 722 | + border: FocusRing { |
| 716 | - border: FocusRing { | 723 | + off: false, |
| 717 | - off: false, | 724 | + width: 3, |
| 718 | - width: 3, | 725 | + active_color: Color { |
| 719 | - active_color: Color { | 726 | + r: 0, |
| 720 | - r: 0, | 727 | + g: 100, |
| 721 | - g: 100, | 728 | + b: 200, |
| 722 | - b: 200, | 729 | + a: 255, |
| 723 | - a: 255, | 730 | + }, |
| 731 | + inactive_color: Color { | ||
| 732 | + r: 255, | ||
| 733 | + g: 200, | ||
| 734 | + b: 100, | ||
| 735 | + a: 0, | ||
| 736 | + }, | ||
| 724 | }, | 737 | }, |
| 725 | - inactive_color: Color { | 738 | + preset_column_widths: vec![ |
| 726 | - r: 255, | 739 | + PresetWidth::Proportion(0.25), |
| 727 | - g: 200, | 740 | + PresetWidth::Proportion(0.5), |
| 728 | - b: 100, | 741 | + PresetWidth::Fixed(960), |
| 729 | - a: 0, | 742 | + PresetWidth::Fixed(1280), |
| 743 | + ], | ||
| 744 | + default_column_width: Some(DefaultColumnWidth(vec![PresetWidth::Proportion( | ||
| 745 | + 0.25, | ||
| 746 | + )])), | ||
| 747 | + gaps: 8, | ||
| 748 | + struts: Struts { | ||
| 749 | + left: 1, | ||
| 750 | + right: 2, | ||
| 751 | + top: 3, | ||
| 752 | + bottom: 0, | ||
| 730 | }, | 753 | }, |
| 731 | }, | 754 | }, |
| 755 | + spawn_at_startup: vec![SpawnAtStartup { | ||
| 756 | + command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()], | ||
| 757 | + }], | ||
| 732 | prefer_no_csd: true, | 758 | prefer_no_csd: true, |
| 733 | cursor: Cursor { | 759 | cursor: Cursor { |
| 734 | xcursor_theme: String::from("breeze_cursors"), | 760 | xcursor_theme: String::from("breeze_cursors"), |
| 735 | xcursor_size: 16, | 761 | xcursor_size: 16, |
| 736 | }, | 762 | }, |
| 737 | - preset_column_widths: vec![ | ||
| 738 | - PresetWidth::Proportion(0.25), | ||
| 739 | - PresetWidth::Proportion(0.5), | ||
| 740 | - PresetWidth::Fixed(960), | ||
| 741 | - PresetWidth::Fixed(1280), | ||
| 742 | - ], | ||
| 743 | - default_column_width: Some(DefaultColumnWidth(vec![PresetWidth::Proportion(0.25)])), | ||
| 744 | - gaps: 8, | ||
| 745 | - struts: Struts { | ||
| 746 | - left: 1, | ||
| 747 | - right: 2, | ||
| 748 | - top: 3, | ||
| 749 | - bottom: 0, | ||
| 750 | - }, | ||
| 751 | screenshot_path: Some(String::from("~/Screenshots/screenshot.png")), | 763 | screenshot_path: Some(String::from("~/Screenshots/screenshot.png")), |
| 752 | binds: Binds(vec![ | 764 | binds: Binds(vec![ |
| 753 | Bind { | 765 | Bind { |
src/layout/mod.rsmodified+7 -6
| @@ -164,7 +164,8 @@ impl Default for Options { | |||
| 164 | 164 | ||
| 165 | impl Options { | 165 | impl Options { |
| 166 | fn from_config(config: &Config) -> Self { | 166 | fn from_config(config: &Config) -> Self { |
| 167 | - let preset_column_widths = &config.preset_column_widths; | 167 | + let layout = &config.layout; |
| 168 | + let preset_column_widths = &layout.preset_column_widths; | ||
| 168 | 169 | ||
| 169 | let preset_widths = if preset_column_widths.is_empty() { | 170 | let preset_widths = if preset_column_widths.is_empty() { |
| 170 | Options::default().preset_widths | 171 | Options::default().preset_widths |
| @@ -178,17 +179,17 @@ impl Options { | |||
| 178 | 179 | ||
| 179 | // Missing default_column_width maps to Some(ColumnWidth::Proportion(0.5)), | 180 | // Missing default_column_width maps to Some(ColumnWidth::Proportion(0.5)), |
| 180 | // while present, but empty, maps to None. | 181 | // while present, but empty, maps to None. |
| 181 | - let default_width = config | 182 | + let default_width = layout |
| 182 | .default_column_width | 183 | .default_column_width |
| 183 | .as_ref() | 184 | .as_ref() |
| 184 | .map(|w| w.0.first().copied().map(ColumnWidth::from)) | 185 | .map(|w| w.0.first().copied().map(ColumnWidth::from)) |
| 185 | .unwrap_or(Some(ColumnWidth::Proportion(0.5))); | 186 | .unwrap_or(Some(ColumnWidth::Proportion(0.5))); |
| 186 | 187 | ||
| 187 | Self { | 188 | Self { |
| 188 | - gaps: config.gaps.into(), | 189 | + gaps: layout.gaps.into(), |
| 189 | - struts: config.struts, | 190 | + struts: layout.struts, |
| 190 | - focus_ring: config.focus_ring, | 191 | + focus_ring: layout.focus_ring, |
| 191 | - border: config.border, | 192 | + border: layout.border, |
| 192 | preset_widths, | 193 | preset_widths, |
| 193 | default_width, | 194 | default_width, |
| 194 | } | 195 | } |