Add per-output layout config
Browse files at this commit09cf8402c3e25fbe4ab790cb997ae4033f9d30f3Parent: a5e28587 changed files +134 -18
- niri-config/src/lib.rs +1 -0
- niri-config/src/output.rs +5 -1
- niri-visual-tests/src/cases/layout.rs +1 -1
- src/layout/mod.rs +35 -8
- src/layout/monitor.rs +40 -4
- src/layout/tests.rs +23 -3
- src/niri.rs +29 -1
niri-config/src/lib.rsmodified+1 -0
| @@ -791,6 +791,7 @@ mod tests { | |||
| 791 | bottom_right: true, | 791 | bottom_right: true, |
| 792 | }, | 792 | }, |
| 793 | ), | 793 | ), |
| 794 | + layout: None, | ||
| 794 | }, | 795 | }, |
| 795 | ], | 796 | ], |
| 796 | ), | 797 | ), |
niri-config/src/output.rsmodified+5 -1
| @@ -1,7 +1,7 @@ | |||
| 1 | use niri_ipc::{ConfiguredMode, Transform}; | 1 | use niri_ipc::{ConfiguredMode, Transform}; |
| 2 | 2 | ||
| 3 | use crate::gestures::HotCorners; | 3 | use crate::gestures::HotCorners; |
| 4 | -use crate::{Color, FloatOrInt}; | 4 | +use crate::{Color, FloatOrInt, LayoutPart}; |
| 5 | 5 | ||
| 6 | #[derive(Debug, Default, Clone, PartialEq)] | 6 | #[derive(Debug, Default, Clone, PartialEq)] |
| 7 | pub struct Outputs(pub Vec<Output>); | 7 | pub struct Outputs(pub Vec<Output>); |
| @@ -24,12 +24,15 @@ pub struct Output { | |||
| 24 | pub variable_refresh_rate: Option<Vrr>, | 24 | pub variable_refresh_rate: Option<Vrr>, |
| 25 | #[knuffel(child)] | 25 | #[knuffel(child)] |
| 26 | pub focus_at_startup: bool, | 26 | pub focus_at_startup: bool, |
| 27 | + // Deprecated; use layout.background_color. | ||
| 27 | #[knuffel(child)] | 28 | #[knuffel(child)] |
| 28 | pub background_color: Option<Color>, | 29 | pub background_color: Option<Color>, |
| 29 | #[knuffel(child)] | 30 | #[knuffel(child)] |
| 30 | pub backdrop_color: Option<Color>, | 31 | pub backdrop_color: Option<Color>, |
| 31 | #[knuffel(child)] | 32 | #[knuffel(child)] |
| 32 | pub hot_corners: Option<HotCorners>, | 33 | pub hot_corners: Option<HotCorners>, |
| 34 | + #[knuffel(child)] | ||
| 35 | + pub layout: Option<LayoutPart>, | ||
| 33 | } | 36 | } |
| 34 | 37 | ||
| 35 | impl Output { | 38 | impl Output { |
| @@ -60,6 +63,7 @@ impl Default for Output { | |||
| 60 | background_color: None, | 63 | background_color: None, |
| 61 | backdrop_color: None, | 64 | backdrop_color: None, |
| 62 | hot_corners: None, | 65 | hot_corners: None, |
| 66 | + layout: None, | ||
| 63 | } | 67 | } |
| 64 | } | 68 | } |
| 65 | } | 69 | } |
niri-visual-tests/src/cases/layout.rsmodified+1 -1
| @@ -72,7 +72,7 @@ impl Layout { | |||
| 72 | ..Default::default() | 72 | ..Default::default() |
| 73 | }; | 73 | }; |
| 74 | let mut layout = niri::layout::Layout::with_options(clock.clone(), options); | 74 | let mut layout = niri::layout::Layout::with_options(clock.clone(), options); |
| 75 | - layout.add_output(output.clone()); | 75 | + layout.add_output(output.clone(), None); |
| 76 | 76 | ||
| 77 | let start_time = clock.now_unadjusted(); | 77 | let start_time = clock.now_unadjusted(); |
| 78 | 78 | ||
src/layout/mod.rsmodified+35 -8
| @@ -39,7 +39,7 @@ use std::time::Duration; | |||
| 39 | use monitor::{InsertHint, InsertPosition, InsertWorkspace, MonitorAddWindowTarget}; | 39 | use monitor::{InsertHint, InsertPosition, InsertWorkspace, MonitorAddWindowTarget}; |
| 40 | use niri_config::utils::MergeWith as _; | 40 | use niri_config::utils::MergeWith as _; |
| 41 | use niri_config::{ | 41 | use niri_config::{ |
| 42 | - Config, CornerRadius, PresetSize, Workspace as WorkspaceConfig, WorkspaceReference, | 42 | + Config, CornerRadius, LayoutPart, PresetSize, Workspace as WorkspaceConfig, WorkspaceReference, |
| 43 | }; | 43 | }; |
| 44 | use niri_ipc::{ColumnDisplay, PositionChange, SizeChange, WindowLayout}; | 44 | use niri_ipc::{ColumnDisplay, PositionChange, SizeChange, WindowLayout}; |
| 45 | use scrolling::{Column, ColumnWidth}; | 45 | use scrolling::{Column, ColumnWidth}; |
| @@ -380,6 +380,10 @@ struct InteractiveMoveData<W: LayoutElement> { | |||
| 380 | /// | 380 | /// |
| 381 | /// This helps the pointer remain inside the window as it resizes. | 381 | /// This helps the pointer remain inside the window as it resizes. |
| 382 | pub(self) pointer_ratio_within_window: (f64, f64), | 382 | pub(self) pointer_ratio_within_window: (f64, f64), |
| 383 | + /// Config overrides for the output where the window is currently located. | ||
| 384 | + /// | ||
| 385 | + /// Cached here to be accessible while an output is removed. | ||
| 386 | + pub(self) output_config: Option<niri_config::LayoutPart>, | ||
| 383 | /// Config overrides for the workspace where the window is currently located. | 387 | /// Config overrides for the workspace where the window is currently located. |
| 384 | /// | 388 | /// |
| 385 | /// To avoid sudden window changes when starting an interactive move, it will remember the | 389 | /// To avoid sudden window changes when starting an interactive move, it will remember the |
| @@ -658,7 +662,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 658 | } | 662 | } |
| 659 | } | 663 | } |
| 660 | 664 | ||
| 661 | - pub fn add_output(&mut self, output: Output) { | 665 | + pub fn add_output(&mut self, output: Output, layout_config: Option<LayoutPart>) { |
| 662 | self.monitor_set = match mem::take(&mut self.monitor_set) { | 666 | self.monitor_set = match mem::take(&mut self.monitor_set) { |
| 663 | MonitorSet::Normal { | 667 | MonitorSet::Normal { |
| 664 | mut monitors, | 668 | mut monitors, |
| @@ -700,7 +704,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 700 | // workspaces set up across multiple monitors. Without this check, the | 704 | // workspaces set up across multiple monitors. Without this check, the |
| 701 | // first monitor to connect can end up with the first empty workspace | 705 | // first monitor to connect can end up with the first empty workspace |
| 702 | // focused instead of the first named workspace. | 706 | // focused instead of the first named workspace. |
| 703 | - && !(self.options.layout.empty_workspace_above_first | 707 | + && !(primary.options.layout.empty_workspace_above_first |
| 704 | && primary.active_workspace_idx == 1) | 708 | && primary.active_workspace_idx == 1) |
| 705 | { | 709 | { |
| 706 | primary.active_workspace_idx = | 710 | primary.active_workspace_idx = |
| @@ -731,6 +735,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 731 | ws_id_to_activate, | 735 | ws_id_to_activate, |
| 732 | self.clock.clone(), | 736 | self.clock.clone(), |
| 733 | self.options.clone(), | 737 | self.options.clone(), |
| 738 | + layout_config, | ||
| 734 | ); | 739 | ); |
| 735 | monitor.overview_open = self.overview_open; | 740 | monitor.overview_open = self.overview_open; |
| 736 | monitor.set_overview_progress(self.overview_progress.as_ref()); | 741 | monitor.set_overview_progress(self.overview_progress.as_ref()); |
| @@ -751,6 +756,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 751 | ws_id_to_activate, | 756 | ws_id_to_activate, |
| 752 | self.clock.clone(), | 757 | self.clock.clone(), |
| 753 | self.options.clone(), | 758 | self.options.clone(), |
| 759 | + layout_config, | ||
| 754 | ); | 760 | ); |
| 755 | monitor.overview_open = self.overview_open; | 761 | monitor.overview_open = self.overview_open; |
| 756 | monitor.set_overview_progress(self.overview_progress.as_ref()); | 762 | monitor.set_overview_progress(self.overview_progress.as_ref()); |
| @@ -782,10 +788,16 @@ impl<W: LayoutElement> Layout<W> { | |||
| 782 | monitor.workspaces[monitor.active_workspace_idx].id(), | 788 | monitor.workspaces[monitor.active_workspace_idx].id(), |
| 783 | ); | 789 | ); |
| 784 | 790 | ||
| 785 | - let workspaces = monitor.into_workspaces(); | 791 | + let mut workspaces = monitor.into_workspaces(); |
| 786 | 792 | ||
| 787 | if monitors.is_empty() { | 793 | if monitors.is_empty() { |
| 788 | // Removed the last monitor. | 794 | // Removed the last monitor. |
| 795 | + | ||
| 796 | + for ws in &mut workspaces { | ||
| 797 | + // Reset base options to layout ones. | ||
| 798 | + ws.update_config(self.options.clone()); | ||
| 799 | + } | ||
| 800 | + | ||
| 789 | MonitorSet::NoOutputs { workspaces } | 801 | MonitorSet::NoOutputs { workspaces } |
| 790 | } else { | 802 | } else { |
| 791 | if primary_idx >= idx { | 803 | if primary_idx >= idx { |
| @@ -2310,6 +2322,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2310 | 2322 | ||
| 2311 | let scale = move_.output.current_scale().fractional_scale(); | 2323 | let scale = move_.output.current_scale().fractional_scale(); |
| 2312 | let options = Options::clone(&self.options) | 2324 | let options = Options::clone(&self.options) |
| 2325 | + .with_merged_layout(move_.output_config.as_ref()) | ||
| 2313 | .with_merged_layout(move_.workspace_config.as_ref().map(|(_, c)| c)) | 2326 | .with_merged_layout(move_.workspace_config.as_ref().map(|(_, c)| c)) |
| 2314 | .adjusted_for_scale(scale); | 2327 | .adjusted_for_scale(scale); |
| 2315 | assert_eq!( | 2328 | assert_eq!( |
| @@ -2409,8 +2422,8 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2409 | for (idx, monitor) in monitors.iter().enumerate() { | 2422 | for (idx, monitor) in monitors.iter().enumerate() { |
| 2410 | assert_eq!(self.clock, monitor.clock); | 2423 | assert_eq!(self.clock, monitor.clock); |
| 2411 | assert_eq!( | 2424 | assert_eq!( |
| 2412 | - monitor.options, self.options, | 2425 | + monitor.base_options, self.options, |
| 2413 | - "monitor options must be synchronized with layout" | 2426 | + "monitor base options must be synchronized with layout" |
| 2414 | ); | 2427 | ); |
| 2415 | 2428 | ||
| 2416 | assert_eq!(self.overview_open, monitor.overview_open); | 2429 | assert_eq!(self.overview_open, monitor.overview_open); |
| @@ -2863,6 +2876,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2863 | let view_size = output_size(&move_.output); | 2876 | let view_size = output_size(&move_.output); |
| 2864 | let scale = move_.output.current_scale().fractional_scale(); | 2877 | let scale = move_.output.current_scale().fractional_scale(); |
| 2865 | let options = Options::clone(&options) | 2878 | let options = Options::clone(&options) |
| 2879 | + .with_merged_layout(move_.output_config.as_ref()) | ||
| 2866 | .with_merged_layout(move_.workspace_config.as_ref().map(|(_, c)| c)) | 2880 | .with_merged_layout(move_.workspace_config.as_ref().map(|(_, c)| c)) |
| 2867 | .adjusted_for_scale(scale); | 2881 | .adjusted_for_scale(scale); |
| 2868 | move_.tile.update_config(view_size, scale, Rc::new(options)); | 2882 | move_.tile.update_config(view_size, scale, Rc::new(options)); |
| @@ -3786,6 +3800,11 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3786 | return true; | 3800 | return true; |
| 3787 | } | 3801 | } |
| 3788 | 3802 | ||
| 3803 | + let output_config = self | ||
| 3804 | + .monitors() | ||
| 3805 | + .find(|mon| mon.output() == &output) | ||
| 3806 | + .and_then(|mon| mon.layout_config().cloned()); | ||
| 3807 | + | ||
| 3789 | // If the pointer is currently on the window's own output, then we can animate the | 3808 | // If the pointer is currently on the window's own output, then we can animate the |
| 3790 | // window movement from its current (rubberbanded and possibly moved away) position | 3809 | // window movement from its current (rubberbanded and possibly moved away) position |
| 3791 | // to the pointer. Otherwise, we just teleport it as the layout code is not aware | 3810 | // to the pointer. Otherwise, we just teleport it as the layout code is not aware |
| @@ -3832,6 +3851,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3832 | let view_size = output_size(&output); | 3851 | let view_size = output_size(&output); |
| 3833 | let scale = output.current_scale().fractional_scale(); | 3852 | let scale = output.current_scale().fractional_scale(); |
| 3834 | let options = Options::clone(&self.options) | 3853 | let options = Options::clone(&self.options) |
| 3854 | + .with_merged_layout(output_config.as_ref()) | ||
| 3835 | .with_merged_layout(workspace_config.as_ref().map(|(_, c)| c)) | 3855 | .with_merged_layout(workspace_config.as_ref().map(|(_, c)| c)) |
| 3836 | .adjusted_for_scale(scale); | 3856 | .adjusted_for_scale(scale); |
| 3837 | tile.update_config(view_size, scale, Rc::new(options)); | 3857 | tile.update_config(view_size, scale, Rc::new(options)); |
| @@ -3887,6 +3907,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3887 | is_full_width, | 3907 | is_full_width, |
| 3888 | is_floating, | 3908 | is_floating, |
| 3889 | pointer_ratio_within_window, | 3909 | pointer_ratio_within_window, |
| 3910 | + output_config, | ||
| 3890 | workspace_config, | 3911 | workspace_config, |
| 3891 | }; | 3912 | }; |
| 3892 | 3913 | ||
| @@ -3930,6 +3951,11 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3930 | ); | 3951 | ); |
| 3931 | move_.output = output.clone(); | 3952 | move_.output = output.clone(); |
| 3932 | self.focus_output(&output); | 3953 | self.focus_output(&output); |
| 3954 | + | ||
| 3955 | + move_.output_config = self | ||
| 3956 | + .monitor_for_output(&output) | ||
| 3957 | + .and_then(|mon| mon.layout_config().cloned()); | ||
| 3958 | + | ||
| 3933 | update_config = true; | 3959 | update_config = true; |
| 3934 | } | 3960 | } |
| 3935 | 3961 | ||
| @@ -3937,6 +3963,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3937 | let view_size = output_size(&output); | 3963 | let view_size = output_size(&output); |
| 3938 | let scale = output.current_scale().fractional_scale(); | 3964 | let scale = output.current_scale().fractional_scale(); |
| 3939 | let options = Options::clone(&self.options) | 3965 | let options = Options::clone(&self.options) |
| 3966 | + .with_merged_layout(move_.output_config.as_ref()) | ||
| 3940 | .with_merged_layout(move_.workspace_config.as_ref().map(|(_, c)| c)) | 3967 | .with_merged_layout(move_.workspace_config.as_ref().map(|(_, c)| c)) |
| 3941 | .adjusted_for_scale(scale); | 3968 | .adjusted_for_scale(scale); |
| 3942 | move_.tile.update_config(view_size, scale, Rc::new(options)); | 3969 | move_.tile.update_config(view_size, scale, Rc::new(options)); |
| @@ -4125,7 +4152,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4125 | .position(|ws| ws.id() == ws_id) | 4152 | .position(|ws| ws.id() == ws_id) |
| 4126 | .unwrap(), | 4153 | .unwrap(), |
| 4127 | InsertWorkspace::NewAt(ws_idx) => { | 4154 | InsertWorkspace::NewAt(ws_idx) => { |
| 4128 | - if self.options.layout.empty_workspace_above_first && ws_idx == 0 { | 4155 | + if mon.options.layout.empty_workspace_above_first && ws_idx == 0 { |
| 4129 | // Reuse the top empty workspace. | 4156 | // Reuse the top empty workspace. |
| 4130 | 0 | 4157 | 0 |
| 4131 | } else if mon.workspaces.len() - 1 <= ws_idx { | 4158 | } else if mon.workspaces.len() - 1 <= ws_idx { |
| @@ -4454,7 +4481,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4454 | } = &mut self.monitor_set | 4481 | } = &mut self.monitor_set |
| 4455 | { | 4482 | { |
| 4456 | let monitor = &mut monitors[*active_monitor_idx]; | 4483 | let monitor = &mut monitors[*active_monitor_idx]; |
| 4457 | - if self.options.layout.empty_workspace_above_first | 4484 | + if monitor.options.layout.empty_workspace_above_first |
| 4458 | && monitor | 4485 | && monitor |
| 4459 | .workspaces | 4486 | .workspaces |
| 4460 | .first() | 4487 | .first() |
src/layout/monitor.rsmodified+40 -4
| @@ -3,7 +3,7 @@ use std::iter::zip; | |||
| 3 | use std::rc::Rc; | 3 | use std::rc::Rc; |
| 4 | use std::time::Duration; | 4 | use std::time::Duration; |
| 5 | 5 | ||
| 6 | -use niri_config::CornerRadius; | 6 | +use niri_config::{CornerRadius, LayoutPart}; |
| 7 | use smithay::backend::renderer::element::utils::{ | 7 | use smithay::backend::renderer::element::utils::{ |
| 8 | CropRenderElement, Relocate, RelocateRenderElement, RescaleRenderElement, | 8 | CropRenderElement, Relocate, RelocateRenderElement, RescaleRenderElement, |
| 9 | }; | 9 | }; |
| @@ -81,8 +81,12 @@ pub struct Monitor<W: LayoutElement> { | |||
| 81 | overview_progress: Option<OverviewProgress>, | 81 | overview_progress: Option<OverviewProgress>, |
| 82 | /// Clock for driving animations. | 82 | /// Clock for driving animations. |
| 83 | pub(super) clock: Clock, | 83 | pub(super) clock: Clock, |
| 84 | + /// Configurable properties of the layout as received from the parent layout. | ||
| 85 | + pub(super) base_options: Rc<Options>, | ||
| 84 | /// Configurable properties of the layout. | 86 | /// Configurable properties of the layout. |
| 85 | pub(super) options: Rc<Options>, | 87 | pub(super) options: Rc<Options>, |
| 88 | + /// Layout config overrides for this monitor. | ||
| 89 | + layout_config: Option<niri_config::LayoutPart>, | ||
| 86 | } | 90 | } |
| 87 | 91 | ||
| 88 | #[derive(Debug)] | 92 | #[derive(Debug)] |
| @@ -280,8 +284,12 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 280 | mut workspaces: Vec<Workspace<W>>, | 284 | mut workspaces: Vec<Workspace<W>>, |
| 281 | ws_id_to_activate: Option<WorkspaceId>, | 285 | ws_id_to_activate: Option<WorkspaceId>, |
| 282 | clock: Clock, | 286 | clock: Clock, |
| 283 | - options: Rc<Options>, | 287 | + base_options: Rc<Options>, |
| 288 | + layout_config: Option<LayoutPart>, | ||
| 284 | ) -> Self { | 289 | ) -> Self { |
| 290 | + let options = | ||
| 291 | + Rc::new(Options::clone(&base_options).with_merged_layout(layout_config.as_ref())); | ||
| 292 | + | ||
| 285 | let scale = output.current_scale(); | 293 | let scale = output.current_scale(); |
| 286 | let view_size = output_size(&output); | 294 | let view_size = output_size(&output); |
| 287 | let working_area = compute_working_area(&output); | 295 | let working_area = compute_working_area(&output); |
| @@ -293,6 +301,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 293 | assert!(ws.has_windows_or_name()); | 301 | assert!(ws.has_windows_or_name()); |
| 294 | 302 | ||
| 295 | ws.set_output(Some(output.clone())); | 303 | ws.set_output(Some(output.clone())); |
| 304 | + ws.update_config(options.clone()); | ||
| 296 | 305 | ||
| 297 | if ws_id_to_activate.is_some_and(|id| ws.id() == id) { | 306 | if ws_id_to_activate.is_some_and(|id| ws.id() == id) { |
| 298 | active_workspace_idx = idx; | 307 | active_workspace_idx = idx; |
| @@ -324,7 +333,9 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 324 | overview_progress: None, | 333 | overview_progress: None, |
| 325 | workspace_switch: None, | 334 | workspace_switch: None, |
| 326 | clock, | 335 | clock, |
| 336 | + base_options, | ||
| 327 | options, | 337 | options, |
| 338 | + layout_config, | ||
| 328 | } | 339 | } |
| 329 | } | 340 | } |
| 330 | 341 | ||
| @@ -666,6 +677,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 666 | 677 | ||
| 667 | pub fn insert_workspace(&mut self, mut ws: Workspace<W>, mut idx: usize, activate: bool) { | 678 | pub fn insert_workspace(&mut self, mut ws: Workspace<W>, mut idx: usize, activate: bool) { |
| 668 | ws.set_output(Some(self.output.clone())); | 679 | ws.set_output(Some(self.output.clone())); |
| 680 | + ws.update_config(self.options.clone()); | ||
| 669 | 681 | ||
| 670 | // Don't insert past the last empty workspace. | 682 | // Don't insert past the last empty workspace. |
| 671 | if idx == self.workspaces.len() { | 683 | if idx == self.workspaces.len() { |
| @@ -699,6 +711,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 699 | 711 | ||
| 700 | for ws in &mut workspaces { | 712 | for ws in &mut workspaces { |
| 701 | ws.set_output(Some(self.output.clone())); | 713 | ws.set_output(Some(self.output.clone())); |
| 714 | + ws.update_config(self.options.clone()); | ||
| 702 | } | 715 | } |
| 703 | 716 | ||
| 704 | let empty_was_focused = self.active_workspace_idx == self.workspaces.len() - 1; | 717 | let empty_was_focused = self.active_workspace_idx == self.workspaces.len() - 1; |
| @@ -1151,7 +1164,10 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1151 | } | 1164 | } |
| 1152 | } | 1165 | } |
| 1153 | 1166 | ||
| 1154 | - pub fn update_config(&mut self, options: Rc<Options>) { | 1167 | + pub fn update_config(&mut self, base_options: Rc<Options>) { |
| 1168 | + let options = | ||
| 1169 | + Rc::new(Options::clone(&base_options).with_merged_layout(self.layout_config.as_ref())); | ||
| 1170 | + | ||
| 1155 | if self.options.layout.empty_workspace_above_first | 1171 | if self.options.layout.empty_workspace_above_first |
| 1156 | != options.layout.empty_workspace_above_first | 1172 | != options.layout.empty_workspace_above_first |
| 1157 | && self.workspaces.len() > 1 | 1173 | && self.workspaces.len() > 1 |
| @@ -1171,9 +1187,21 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1171 | self.insert_hint_element | 1187 | self.insert_hint_element |
| 1172 | .update_config(options.layout.insert_hint); | 1188 | .update_config(options.layout.insert_hint); |
| 1173 | 1189 | ||
| 1190 | + self.base_options = base_options; | ||
| 1174 | self.options = options; | 1191 | self.options = options; |
| 1175 | } | 1192 | } |
| 1176 | 1193 | ||
| 1194 | + pub fn update_layout_config(&mut self, layout_config: Option<niri_config::LayoutPart>) -> bool { | ||
| 1195 | + if self.layout_config == layout_config { | ||
| 1196 | + return false; | ||
| 1197 | + } | ||
| 1198 | + | ||
| 1199 | + self.layout_config = layout_config; | ||
| 1200 | + self.update_config(self.base_options.clone()); | ||
| 1201 | + | ||
| 1202 | + true | ||
| 1203 | + } | ||
| 1204 | + | ||
| 1177 | pub fn update_shaders(&mut self) { | 1205 | pub fn update_shaders(&mut self) { |
| 1178 | for ws in &mut self.workspaces { | 1206 | for ws in &mut self.workspaces { |
| 1179 | ws.update_shaders(); | 1207 | ws.update_shaders(); |
| @@ -2017,10 +2045,18 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 2017 | self.working_area | 2045 | self.working_area |
| 2018 | } | 2046 | } |
| 2019 | 2047 | ||
| 2048 | + pub fn layout_config(&self) -> Option<&niri_config::LayoutPart> { | ||
| 2049 | + self.layout_config.as_ref() | ||
| 2050 | + } | ||
| 2051 | + | ||
| 2020 | #[cfg(test)] | 2052 | #[cfg(test)] |
| 2021 | pub(super) fn verify_invariants(&self) { | 2053 | pub(super) fn verify_invariants(&self) { |
| 2022 | use approx::assert_abs_diff_eq; | 2054 | use approx::assert_abs_diff_eq; |
| 2023 | 2055 | ||
| 2056 | + let options = | ||
| 2057 | + Options::clone(&self.base_options).with_merged_layout(self.layout_config.as_ref()); | ||
| 2058 | + assert_eq!(&*self.options, &options); | ||
| 2059 | + | ||
| 2024 | assert!( | 2060 | assert!( |
| 2025 | !self.workspaces.is_empty(), | 2061 | !self.workspaces.is_empty(), |
| 2026 | "monitor must have at least one workspace" | 2062 | "monitor must have at least one workspace" |
| @@ -2107,7 +2143,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 2107 | 2143 | ||
| 2108 | assert_eq!( | 2144 | assert_eq!( |
| 2109 | workspace.base_options, self.options, | 2145 | workspace.base_options, self.options, |
| 2110 | - "workspace options must be synchronized with layout" | 2146 | + "workspace options must be synchronized with monitor" |
| 2111 | ); | 2147 | ); |
| 2112 | } | 2148 | } |
| 2113 | 2149 | ||
src/layout/tests.rsmodified+23 -3
| @@ -406,9 +406,17 @@ enum Op { | |||
| 406 | id: usize, | 406 | id: usize, |
| 407 | #[proptest(strategy = "arbitrary_scale()")] | 407 | #[proptest(strategy = "arbitrary_scale()")] |
| 408 | scale: f64, | 408 | scale: f64, |
| 409 | + #[proptest(strategy = "prop::option::of(arbitrary_layout_part().prop_map(Box::new))")] | ||
| 410 | + layout_config: Option<Box<niri_config::LayoutPart>>, | ||
| 409 | }, | 411 | }, |
| 410 | RemoveOutput(#[proptest(strategy = "1..=5usize")] usize), | 412 | RemoveOutput(#[proptest(strategy = "1..=5usize")] usize), |
| 411 | FocusOutput(#[proptest(strategy = "1..=5usize")] usize), | 413 | FocusOutput(#[proptest(strategy = "1..=5usize")] usize), |
| 414 | + UpdateOutputLayoutConfig { | ||
| 415 | + #[proptest(strategy = "1..=5usize")] | ||
| 416 | + id: usize, | ||
| 417 | + #[proptest(strategy = "prop::option::of(arbitrary_layout_part().prop_map(Box::new))")] | ||
| 418 | + layout_config: Option<Box<niri_config::LayoutPart>>, | ||
| 419 | + }, | ||
| 412 | AddNamedWorkspace { | 420 | AddNamedWorkspace { |
| 413 | #[proptest(strategy = "1..=5usize")] | 421 | #[proptest(strategy = "1..=5usize")] |
| 414 | ws_name: usize, | 422 | ws_name: usize, |
| @@ -771,9 +779,13 @@ impl Op { | |||
| 771 | model: None, | 779 | model: None, |
| 772 | serial: None, | 780 | serial: None, |
| 773 | }); | 781 | }); |
| 774 | - layout.add_output(output.clone()); | 782 | + layout.add_output(output.clone(), None); |
| 775 | } | 783 | } |
| 776 | - Op::AddScaledOutput { id, scale } => { | 784 | + Op::AddScaledOutput { |
| 785 | + id, | ||
| 786 | + scale, | ||
| 787 | + layout_config, | ||
| 788 | + } => { | ||
| 777 | let name = format!("output{id}"); | 789 | let name = format!("output{id}"); |
| 778 | if layout.outputs().any(|o| o.name() == name) { | 790 | if layout.outputs().any(|o| o.name() == name) { |
| 779 | return; | 791 | return; |
| @@ -804,7 +816,7 @@ impl Op { | |||
| 804 | model: None, | 816 | model: None, |
| 805 | serial: None, | 817 | serial: None, |
| 806 | }); | 818 | }); |
| 807 | - layout.add_output(output.clone()); | 819 | + layout.add_output(output.clone(), layout_config.map(|x| *x)); |
| 808 | } | 820 | } |
| 809 | Op::RemoveOutput(id) => { | 821 | Op::RemoveOutput(id) => { |
| 810 | let name = format!("output{id}"); | 822 | let name = format!("output{id}"); |
| @@ -822,6 +834,14 @@ impl Op { | |||
| 822 | 834 | ||
| 823 | layout.focus_output(&output); | 835 | layout.focus_output(&output); |
| 824 | } | 836 | } |
| 837 | + Op::UpdateOutputLayoutConfig { id, layout_config } => { | ||
| 838 | + let name = format!("output{id}"); | ||
| 839 | + let Some(mon) = layout.monitors_mut().find(|m| m.output_name() == &name) else { | ||
| 840 | + return; | ||
| 841 | + }; | ||
| 842 | + | ||
| 843 | + mon.update_layout_config(layout_config.map(|x| *x)); | ||
| 844 | + } | ||
| 825 | Op::AddNamedWorkspace { | 845 | Op::AddNamedWorkspace { |
| 826 | ws_name, | 846 | ws_name, |
| 827 | output_name, | 847 | output_name, |
src/niri.rsmodified+29 -1
| @@ -1667,6 +1667,26 @@ impl State { | |||
| 1667 | recolored_outputs.push(output.clone()); | 1667 | recolored_outputs.push(output.clone()); |
| 1668 | } | 1668 | } |
| 1669 | } | 1669 | } |
| 1670 | + | ||
| 1671 | + for mon in self.niri.layout.monitors_mut() { | ||
| 1672 | + if mon.output() != output { | ||
| 1673 | + continue; | ||
| 1674 | + } | ||
| 1675 | + | ||
| 1676 | + let mut layout_config = config.and_then(|c| c.layout.clone()); | ||
| 1677 | + // Support the deprecated non-layout background-color key. | ||
| 1678 | + if let Some(layout) = &mut layout_config { | ||
| 1679 | + if layout.background_color.is_none() { | ||
| 1680 | + layout.background_color = config.and_then(|c| c.background_color); | ||
| 1681 | + } | ||
| 1682 | + } | ||
| 1683 | + | ||
| 1684 | + if mon.update_layout_config(layout_config) { | ||
| 1685 | + // Also redraw these; if anything, the background color could've changed. | ||
| 1686 | + recolored_outputs.push(output.clone()); | ||
| 1687 | + } | ||
| 1688 | + break; | ||
| 1689 | + } | ||
| 1670 | } | 1690 | } |
| 1671 | 1691 | ||
| 1672 | for output in resized_outputs { | 1692 | for output in resized_outputs { |
| @@ -2903,6 +2923,14 @@ impl Niri { | |||
| 2903 | if name.connector == "winit" { | 2923 | if name.connector == "winit" { |
| 2904 | transform = Transform::Flipped180; | 2924 | transform = Transform::Flipped180; |
| 2905 | } | 2925 | } |
| 2926 | + | ||
| 2927 | + let mut layout_config = c.and_then(|c| c.layout.clone()); | ||
| 2928 | + // Support the deprecated non-layout background-color key. | ||
| 2929 | + if let Some(layout) = &mut layout_config { | ||
| 2930 | + if layout.background_color.is_none() { | ||
| 2931 | + layout.background_color = c.and_then(|c| c.background_color); | ||
| 2932 | + } | ||
| 2933 | + } | ||
| 2906 | drop(config); | 2934 | drop(config); |
| 2907 | 2935 | ||
| 2908 | // Set scale and transform before adding to the layout since that will read the output size. | 2936 | // Set scale and transform before adding to the layout since that will read the output size. |
| @@ -2913,7 +2941,7 @@ impl Niri { | |||
| 2913 | None, | 2941 | None, |
| 2914 | ); | 2942 | ); |
| 2915 | 2943 | ||
| 2916 | - self.layout.add_output(output.clone()); | 2944 | + self.layout.add_output(output.clone(), layout_config); |
| 2917 | 2945 | ||
| 2918 | let lock_render_state = if self.is_locked() { | 2946 | let lock_render_state = if self.is_locked() { |
| 2919 | // We haven't rendered anything yet so it's as good as locked. | 2947 | // We haven't rendered anything yet so it's as good as locked. |