Add per-workspace layout config
Browse files at this commitd5f4e79e4c35d4f5a7a4a64e85e72fb1545ef2dbParent: d015c7e5 changed files +233 -29
- niri-config/src/lib.rs +4 -1
- niri-config/src/workspace.rs +35 -1
- src/layout/mod.rs +63 -19
- src/layout/tests.rs +89 -0
- src/layout/workspace.rs +42 -8
niri-config/src/lib.rsmodified+4 -1
| @@ -38,7 +38,7 @@ pub use crate::output::{Output, OutputName, Outputs, Position, Vrr}; | ||
| 38 | 38 | pub use crate::utils::FloatOrInt; |
| 39 | 39 | use crate::utils::MergeWith as _; |
| 40 | 40 | pub use crate::window_rule::{FloatingPosition, RelativeTo, WindowRule}; |
| 41 | -pub use crate::workspace::Workspace; | |
| 41 | +pub use crate::workspace::{Workspace, WorkspaceLayoutPart}; | |
| 42 | 42 | |
| 43 | 43 | #[derive(knuffel::Decode, Debug, PartialEq)] |
| 44 | 44 | pub struct Config { |
| @@ -1795,18 +1795,21 @@ mod tests { | ||
| 1795 | 1795 | open_on_output: Some( |
| 1796 | 1796 | "eDP-1", |
| 1797 | 1797 | ), |
| 1798 | + layout: None, | |
| 1798 | 1799 | }, |
| 1799 | 1800 | Workspace { |
| 1800 | 1801 | name: WorkspaceName( |
| 1801 | 1802 | "workspace-2", |
| 1802 | 1803 | ), |
| 1803 | 1804 | open_on_output: None, |
| 1805 | + layout: None, | |
| 1804 | 1806 | }, |
| 1805 | 1807 | Workspace { |
| 1806 | 1808 | name: WorkspaceName( |
| 1807 | 1809 | "workspace-3", |
| 1808 | 1810 | ), |
| 1809 | 1811 | open_on_output: None, |
| 1812 | + layout: None, | |
| 1810 | 1813 | }, |
| 1811 | 1814 | ], |
| 1812 | 1815 | } |
niri-config/src/workspace.rsmodified+35 -1
| @@ -1,16 +1,50 @@ | ||
| 1 | 1 | use knuffel::errors::DecodeError; |
| 2 | 2 | |
| 3 | -#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)] | |
| 3 | +use crate::LayoutPart; | |
| 4 | + | |
| 5 | +#[derive(knuffel::Decode, Debug, Clone, PartialEq)] | |
| 4 | 6 | pub struct Workspace { |
| 5 | 7 | #[knuffel(argument)] |
| 6 | 8 | pub name: WorkspaceName, |
| 7 | 9 | #[knuffel(child, unwrap(argument))] |
| 8 | 10 | pub open_on_output: Option<String>, |
| 11 | + #[knuffel(child)] | |
| 12 | + pub layout: Option<WorkspaceLayoutPart>, | |
| 9 | 13 | } |
| 10 | 14 | |
| 11 | 15 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 12 | 16 | pub struct WorkspaceName(pub String); |
| 13 | 17 | |
| 18 | +#[derive(Debug, Clone, PartialEq)] | |
| 19 | +pub struct WorkspaceLayoutPart(pub LayoutPart); | |
| 20 | + | |
| 21 | +impl<S: knuffel::traits::ErrorSpan> knuffel::Decode<S> for WorkspaceLayoutPart { | |
| 22 | + fn decode_node( | |
| 23 | + node: &knuffel::ast::SpannedNode<S>, | |
| 24 | + ctx: &mut knuffel::decode::Context<S>, | |
| 25 | + ) -> Result<Self, DecodeError<S>> { | |
| 26 | + for child in node.children() { | |
| 27 | + let name = &**child.node_name; | |
| 28 | + | |
| 29 | + // Check for disallowed properties. | |
| 30 | + // | |
| 31 | + // - empty-workspace-above-first is a monitor-level concept. | |
| 32 | + // - insert-hint customization could make sense for workspaces, however currently it is | |
| 33 | + // also handled at the monitor level (since insert hints in-between workspaces are a | |
| 34 | + // monitor-level concept), so for now this config option would do nothing. | |
| 35 | + if matches!(name, "empty-workspace-above-first" | "insert-hint") { | |
| 36 | + ctx.emit_error(DecodeError::unexpected( | |
| 37 | + child, | |
| 38 | + "node", | |
| 39 | + format!("node `{name}` is not allowed inside `workspace.layout`"), | |
| 40 | + )); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + | |
| 44 | + LayoutPart::decode_node(node, ctx).map(Self) | |
| 45 | + } | |
| 46 | +} | |
| 47 | + | |
| 14 | 48 | impl<S: knuffel::traits::ErrorSpan> knuffel::DecodeScalar<S> for WorkspaceName { |
| 15 | 49 | fn type_check( |
| 16 | 50 | type_name: &Option<knuffel::span::Spanned<knuffel::ast::TypeName, S>>, |
src/layout/mod.rsmodified+63 -19
| @@ -380,6 +380,12 @@ struct InteractiveMoveData<W: LayoutElement> { | ||
| 380 | 380 | /// |
| 381 | 381 | /// This helps the pointer remain inside the window as it resizes. |
| 382 | 382 | pub(self) pointer_ratio_within_window: (f64, f64), |
| 383 | + /// Config overrides for the workspace where the window is currently located. | |
| 384 | + /// | |
| 385 | + /// To avoid sudden window changes when starting an interactive move, it will remember the | |
| 386 | + /// config overrides for the workspace where the move originated from. As soon as the window | |
| 387 | + /// moves over some different workspace though, this override will reset. | |
| 388 | + pub(self) workspace_config: Option<(WorkspaceId, niri_config::LayoutPart)>, | |
| 383 | 389 | } |
| 384 | 390 | |
| 385 | 391 | #[derive(Debug)] |
| @@ -576,6 +582,13 @@ impl Options { | ||
| 576 | 582 | } |
| 577 | 583 | } |
| 578 | 584 | |
| 585 | + fn with_merged_layout(mut self, part: Option<&niri_config::LayoutPart>) -> Self { | |
| 586 | + if let Some(part) = part { | |
| 587 | + self.layout.merge_with(part); | |
| 588 | + } | |
| 589 | + self | |
| 590 | + } | |
| 591 | + | |
| 579 | 592 | fn adjusted_for_scale(mut self, scale: f64) -> Self { |
| 580 | 593 | let round = |logical: f64| round_logical_in_physical_max1(scale, logical); |
| 581 | 594 | |
| @@ -2296,7 +2309,9 @@ impl<W: LayoutElement> Layout<W> { | ||
| 2296 | 2309 | move_.tile.verify_invariants(); |
| 2297 | 2310 | |
| 2298 | 2311 | let scale = move_.output.current_scale().fractional_scale(); |
| 2299 | - let options = Options::clone(&self.options).adjusted_for_scale(scale); | |
| 2312 | + let options = Options::clone(&self.options) | |
| 2313 | + .with_merged_layout(move_.workspace_config.as_ref().map(|(_, c)| c)) | |
| 2314 | + .adjusted_for_scale(scale); | |
| 2300 | 2315 | assert_eq!( |
| 2301 | 2316 | &*move_.tile.options, &options, |
| 2302 | 2317 | "interactive moved tile options must be \ |
| @@ -2830,6 +2845,14 @@ impl<W: LayoutElement> Layout<W> { | ||
| 2830 | 2845 | } |
| 2831 | 2846 | |
| 2832 | 2847 | pub fn update_config(&mut self, config: &Config) { |
| 2848 | + // Update workspace-specific config for all named workspaces. | |
| 2849 | + for ws in self.workspaces_mut() { | |
| 2850 | + let Some(name) = ws.name() else { continue }; | |
| 2851 | + if let Some(config) = config.workspaces.iter().find(|w| &w.name.0 == name) { | |
| 2852 | + ws.update_layout_config(config.layout.clone().map(|x| x.0)); | |
| 2853 | + } | |
| 2854 | + } | |
| 2855 | + | |
| 2833 | 2856 | self.update_options(Options::from_config(config)); |
| 2834 | 2857 | } |
| 2835 | 2858 | |
| @@ -2839,11 +2862,10 @@ impl<W: LayoutElement> Layout<W> { | ||
| 2839 | 2862 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 2840 | 2863 | let view_size = output_size(&move_.output); |
| 2841 | 2864 | let scale = move_.output.current_scale().fractional_scale(); |
| 2842 | - move_.tile.update_config( | |
| 2843 | - view_size, | |
| 2844 | - scale, | |
| 2845 | - Rc::new(Options::clone(&options).adjusted_for_scale(scale)), | |
| 2846 | - ); | |
| 2865 | + let options = Options::clone(&options) | |
| 2866 | + .with_merged_layout(move_.workspace_config.as_ref().map(|(_, c)| c)) | |
| 2867 | + .adjusted_for_scale(scale); | |
| 2868 | + move_.tile.update_config(view_size, scale, Rc::new(options)); | |
| 2847 | 2869 | } |
| 2848 | 2870 | |
| 2849 | 2871 | match &mut self.monitor_set { |
| @@ -3737,15 +3759,17 @@ impl<W: LayoutElement> Layout<W> { | ||
| 3737 | 3759 | } |
| 3738 | 3760 | .band(sq_dist / INTERACTIVE_MOVE_START_THRESHOLD); |
| 3739 | 3761 | |
| 3740 | - let (is_floating, tile) = self | |
| 3762 | + let (is_floating, tile, workspace_config) = self | |
| 3741 | 3763 | .workspaces_mut() |
| 3742 | 3764 | .find(|ws| ws.has_window(&window_id)) |
| 3743 | 3765 | .map(|ws| { |
| 3766 | + let workspace_config = ws.layout_config().cloned().map(|c| (ws.id(), c)); | |
| 3744 | 3767 | ( |
| 3745 | 3768 | ws.is_floating(&window_id), |
| 3746 | 3769 | ws.tiles_mut() |
| 3747 | 3770 | .find(|tile| *tile.window().id() == window_id) |
| 3748 | 3771 | .unwrap(), |
| 3772 | + workspace_config, | |
| 3749 | 3773 | ) |
| 3750 | 3774 | }) |
| 3751 | 3775 | .unwrap(); |
| @@ -3807,11 +3831,10 @@ impl<W: LayoutElement> Layout<W> { | ||
| 3807 | 3831 | |
| 3808 | 3832 | let view_size = output_size(&output); |
| 3809 | 3833 | let scale = output.current_scale().fractional_scale(); |
| 3810 | - tile.update_config( | |
| 3811 | - view_size, | |
| 3812 | - scale, | |
| 3813 | - Rc::new(Options::clone(&self.options).adjusted_for_scale(scale)), | |
| 3814 | - ); | |
| 3834 | + let options = Options::clone(&self.options) | |
| 3835 | + .with_merged_layout(workspace_config.as_ref().map(|(_, c)| c)) | |
| 3836 | + .adjusted_for_scale(scale); | |
| 3837 | + tile.update_config(view_size, scale, Rc::new(options)); | |
| 3815 | 3838 | |
| 3816 | 3839 | // Unfullscreen. |
| 3817 | 3840 | let floating_size = tile.floating_window_size; |
| @@ -3864,6 +3887,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 3864 | 3887 | is_full_width, |
| 3865 | 3888 | is_floating, |
| 3866 | 3889 | pointer_ratio_within_window, |
| 3890 | + workspace_config, | |
| 3867 | 3891 | }; |
| 3868 | 3892 | |
| 3869 | 3893 | if let Some((tile_pos, zoom)) = tile_pos { |
| @@ -3880,6 +3904,23 @@ impl<W: LayoutElement> Layout<W> { | ||
| 3880 | 3904 | return false; |
| 3881 | 3905 | } |
| 3882 | 3906 | |
| 3907 | + let mut ws_id = None; | |
| 3908 | + if let Some(mon) = self.monitor_for_output(&output) { | |
| 3909 | + let (insert_ws, _) = mon.insert_position(move_.pointer_pos_within_output); | |
| 3910 | + if let InsertWorkspace::Existing(id) = insert_ws { | |
| 3911 | + ws_id = Some(id); | |
| 3912 | + } | |
| 3913 | + } | |
| 3914 | + | |
| 3915 | + // If moved over a different workspace, reset the config override. | |
| 3916 | + let mut update_config = false; | |
| 3917 | + if let Some((id, _)) = &move_.workspace_config { | |
| 3918 | + if Some(*id) != ws_id { | |
| 3919 | + move_.workspace_config = None; | |
| 3920 | + update_config = true; | |
| 3921 | + } | |
| 3922 | + } | |
| 3923 | + | |
| 3883 | 3924 | if output != move_.output { |
| 3884 | 3925 | move_.tile.window().output_leave(&move_.output); |
| 3885 | 3926 | move_.tile.window().output_enter(&output); |
| @@ -3887,15 +3928,18 @@ impl<W: LayoutElement> Layout<W> { | ||
| 3887 | 3928 | output.current_scale(), |
| 3888 | 3929 | output.current_transform(), |
| 3889 | 3930 | ); |
| 3890 | - let view_size = output_size(&output); | |
| 3891 | - let scale = output.current_scale().fractional_scale(); | |
| 3892 | - move_.tile.update_config( | |
| 3893 | - view_size, | |
| 3894 | - scale, | |
| 3895 | - Rc::new(Options::clone(&self.options).adjusted_for_scale(scale)), | |
| 3896 | - ); | |
| 3897 | 3931 | move_.output = output.clone(); |
| 3898 | 3932 | self.focus_output(&output); |
| 3933 | + update_config = true; | |
| 3934 | + } | |
| 3935 | + | |
| 3936 | + if update_config { | |
| 3937 | + let view_size = output_size(&output); | |
| 3938 | + let scale = output.current_scale().fractional_scale(); | |
| 3939 | + let options = Options::clone(&self.options) | |
| 3940 | + .with_merged_layout(move_.workspace_config.as_ref().map(|(_, c)| c)) | |
| 3941 | + .adjusted_for_scale(scale); | |
| 3942 | + move_.tile.update_config(view_size, scale, Rc::new(options)); | |
| 3899 | 3943 | } |
| 3900 | 3944 | |
| 3901 | 3945 | move_.pointer_pos_within_output = pointer_pos_within_output; |
src/layout/tests.rsmodified+89 -0
| @@ -414,11 +414,19 @@ enum Op { | ||
| 414 | 414 | ws_name: usize, |
| 415 | 415 | #[proptest(strategy = "prop::option::of(1..=5usize)")] |
| 416 | 416 | output_name: Option<usize>, |
| 417 | + #[proptest(strategy = "prop::option::of(arbitrary_layout_part().prop_map(Box::new))")] | |
| 418 | + layout_config: Option<Box<niri_config::LayoutPart>>, | |
| 417 | 419 | }, |
| 418 | 420 | UnnameWorkspace { |
| 419 | 421 | #[proptest(strategy = "1..=5usize")] |
| 420 | 422 | ws_name: usize, |
| 421 | 423 | }, |
| 424 | + UpdateWorkspaceLayoutConfig { | |
| 425 | + #[proptest(strategy = "1..=5usize")] | |
| 426 | + ws_name: usize, | |
| 427 | + #[proptest(strategy = "prop::option::of(arbitrary_layout_part().prop_map(Box::new))")] | |
| 428 | + layout_config: Option<Box<niri_config::LayoutPart>>, | |
| 429 | + }, | |
| 422 | 430 | AddWindow { |
| 423 | 431 | params: TestWindowParams, |
| 424 | 432 | }, |
| @@ -817,15 +825,31 @@ impl Op { | ||
| 817 | 825 | Op::AddNamedWorkspace { |
| 818 | 826 | ws_name, |
| 819 | 827 | output_name, |
| 828 | + layout_config, | |
| 820 | 829 | } => { |
| 821 | 830 | layout.ensure_named_workspace(&WorkspaceConfig { |
| 822 | 831 | name: WorkspaceName(format!("ws{ws_name}")), |
| 823 | 832 | open_on_output: output_name.map(|name| format!("output{name}")), |
| 833 | + layout: layout_config.map(|x| niri_config::WorkspaceLayoutPart(*x)), | |
| 824 | 834 | }); |
| 825 | 835 | } |
| 826 | 836 | Op::UnnameWorkspace { ws_name } => { |
| 827 | 837 | layout.unname_workspace(&format!("ws{ws_name}")); |
| 828 | 838 | } |
| 839 | + Op::UpdateWorkspaceLayoutConfig { | |
| 840 | + ws_name, | |
| 841 | + layout_config, | |
| 842 | + } => { | |
| 843 | + let ws_name = format!("ws{ws_name}"); | |
| 844 | + let Some(ws) = layout | |
| 845 | + .workspaces_mut() | |
| 846 | + .find(|ws| ws.name() == Some(&ws_name)) | |
| 847 | + else { | |
| 848 | + return; | |
| 849 | + }; | |
| 850 | + | |
| 851 | + ws.update_layout_config(layout_config.map(|x| *x)); | |
| 852 | + } | |
| 829 | 853 | Op::SetWorkspaceName { |
| 830 | 854 | new_ws_name, |
| 831 | 855 | ws_name, |
| @@ -1607,6 +1631,7 @@ fn operations_dont_panic() { | ||
| 1607 | 1631 | Op::AddNamedWorkspace { |
| 1608 | 1632 | ws_name: 1, |
| 1609 | 1633 | output_name: Some(1), |
| 1634 | + layout_config: None, | |
| 1610 | 1635 | }, |
| 1611 | 1636 | Op::UnnameWorkspace { ws_name: 1 }, |
| 1612 | 1637 | Op::AddWindow { |
| @@ -1754,6 +1779,7 @@ fn operations_from_starting_state_dont_panic() { | ||
| 1754 | 1779 | Op::AddNamedWorkspace { |
| 1755 | 1780 | ws_name: 1, |
| 1756 | 1781 | output_name: Some(1), |
| 1782 | + layout_config: None, | |
| 1757 | 1783 | }, |
| 1758 | 1784 | Op::UnnameWorkspace { ws_name: 1 }, |
| 1759 | 1785 | Op::AddWindow { |
| @@ -2289,10 +2315,12 @@ fn removing_all_outputs_preserves_empty_named_workspaces() { | ||
| 2289 | 2315 | Op::AddNamedWorkspace { |
| 2290 | 2316 | ws_name: 1, |
| 2291 | 2317 | output_name: None, |
| 2318 | + layout_config: None, | |
| 2292 | 2319 | }, |
| 2293 | 2320 | Op::AddNamedWorkspace { |
| 2294 | 2321 | ws_name: 2, |
| 2295 | 2322 | output_name: None, |
| 2323 | + layout_config: None, | |
| 2296 | 2324 | }, |
| 2297 | 2325 | Op::RemoveOutput(1), |
| 2298 | 2326 | ]; |
| @@ -2655,6 +2683,7 @@ fn named_workspace_to_output() { | ||
| 2655 | 2683 | Op::AddNamedWorkspace { |
| 2656 | 2684 | ws_name: 1, |
| 2657 | 2685 | output_name: None, |
| 2686 | + layout_config: None, | |
| 2658 | 2687 | }, |
| 2659 | 2688 | Op::AddOutput(1), |
| 2660 | 2689 | Op::MoveWorkspaceToOutput(1), |
| @@ -2670,6 +2699,7 @@ fn named_workspace_to_output_ewaf() { | ||
| 2670 | 2699 | Op::AddNamedWorkspace { |
| 2671 | 2700 | ws_name: 1, |
| 2672 | 2701 | output_name: Some(2), |
| 2702 | + layout_config: None, | |
| 2673 | 2703 | }, |
| 2674 | 2704 | Op::AddOutput(1), |
| 2675 | 2705 | Op::AddOutput(2), |
| @@ -2897,6 +2927,65 @@ fn interactive_move_toggle_floating_ends_dnd_gesture() { | ||
| 2897 | 2927 | check_ops(ops); |
| 2898 | 2928 | } |
| 2899 | 2929 | |
| 2930 | +#[test] | |
| 2931 | +fn interactive_move_from_workspace_with_layout_config() { | |
| 2932 | + let ops = [ | |
| 2933 | + Op::AddNamedWorkspace { | |
| 2934 | + ws_name: 1, | |
| 2935 | + output_name: Some(2), | |
| 2936 | + layout_config: Some(Box::new(niri_config::LayoutPart { | |
| 2937 | + border: Some(niri_config::BorderRule { | |
| 2938 | + on: true, | |
| 2939 | + ..Default::default() | |
| 2940 | + }), | |
| 2941 | + ..Default::default() | |
| 2942 | + })), | |
| 2943 | + }, | |
| 2944 | + Op::AddOutput(1), | |
| 2945 | + Op::AddWindow { | |
| 2946 | + params: TestWindowParams::new(2), | |
| 2947 | + }, | |
| 2948 | + Op::InteractiveMoveBegin { | |
| 2949 | + window: 2, | |
| 2950 | + output_idx: 1, | |
| 2951 | + px: 0.0, | |
| 2952 | + py: 0.0, | |
| 2953 | + }, | |
| 2954 | + Op::InteractiveMoveUpdate { | |
| 2955 | + window: 2, | |
| 2956 | + dx: 0.0, | |
| 2957 | + dy: 3586.692842955048, | |
| 2958 | + output_idx: 1, | |
| 2959 | + px: 0.0, | |
| 2960 | + py: 0.0, | |
| 2961 | + }, | |
| 2962 | + // Now remove and add the output. It will have the same workspace. | |
| 2963 | + Op::RemoveOutput(1), | |
| 2964 | + Op::AddOutput(1), | |
| 2965 | + Op::InteractiveMoveUpdate { | |
| 2966 | + window: 2, | |
| 2967 | + dx: 0.0, | |
| 2968 | + dy: 0.0, | |
| 2969 | + output_idx: 1, | |
| 2970 | + px: 0.0, | |
| 2971 | + py: 0.0, | |
| 2972 | + }, | |
| 2973 | + // Now move onto a different workspace. | |
| 2974 | + Op::FocusWorkspaceDown, | |
| 2975 | + Op::CompleteAnimations, | |
| 2976 | + Op::InteractiveMoveUpdate { | |
| 2977 | + window: 2, | |
| 2978 | + dx: 0.0, | |
| 2979 | + dy: 0.0, | |
| 2980 | + output_idx: 1, | |
| 2981 | + px: 0.0, | |
| 2982 | + py: 0.0, | |
| 2983 | + }, | |
| 2984 | + ]; | |
| 2985 | + | |
| 2986 | + check_ops(ops); | |
| 2987 | +} | |
| 2988 | + | |
| 2900 | 2989 | #[test] |
| 2901 | 2990 | fn set_width_fixed_negative() { |
| 2902 | 2991 | let ops = [ |
src/layout/workspace.rsmodified+42 -8
| @@ -99,6 +99,9 @@ pub struct Workspace<W: LayoutElement> { | ||
| 99 | 99 | /// Optional name of this workspace. |
| 100 | 100 | pub(super) name: Option<String>, |
| 101 | 101 | |
| 102 | + /// Layout config overrides for this workspace. | |
| 103 | + layout_config: Option<niri_config::LayoutPart>, | |
| 104 | + | |
| 102 | 105 | /// Unique ID of this workspace. |
| 103 | 106 | id: WorkspaceId, |
| 104 | 107 | } |
| @@ -202,7 +205,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 202 | 205 | |
| 203 | 206 | pub fn new_with_config( |
| 204 | 207 | output: Output, |
| 205 | - config: Option<WorkspaceConfig>, | |
| 208 | + mut config: Option<WorkspaceConfig>, | |
| 206 | 209 | clock: Clock, |
| 207 | 210 | base_options: Rc<Options>, |
| 208 | 211 | ) -> Self { |
| @@ -212,9 +215,14 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 212 | 215 | .map(OutputId) |
| 213 | 216 | .unwrap_or(OutputId::new(&output)); |
| 214 | 217 | |
| 218 | + let layout_config = config.as_mut().and_then(|c| c.layout.take().map(|x| x.0)); | |
| 219 | + | |
| 215 | 220 | let scale = output.current_scale(); |
| 216 | - let options = | |
| 217 | - Rc::new(Options::clone(&base_options).adjusted_for_scale(scale.fractional_scale())); | |
| 221 | + let options = Rc::new( | |
| 222 | + Options::clone(&base_options) | |
| 223 | + .with_merged_layout(layout_config.as_ref()) | |
| 224 | + .adjusted_for_scale(scale.fractional_scale()), | |
| 225 | + ); | |
| 218 | 226 | |
| 219 | 227 | let view_size = output_size(&output); |
| 220 | 228 | let working_area = compute_working_area(&output); |
| @@ -253,12 +261,13 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 253 | 261 | base_options, |
| 254 | 262 | options, |
| 255 | 263 | name: config.map(|c| c.name.0), |
| 264 | + layout_config, | |
| 256 | 265 | id: WorkspaceId::next(), |
| 257 | 266 | } |
| 258 | 267 | } |
| 259 | 268 | |
| 260 | 269 | pub fn new_with_config_no_outputs( |
| 261 | - config: Option<WorkspaceConfig>, | |
| 270 | + mut config: Option<WorkspaceConfig>, | |
| 262 | 271 | clock: Clock, |
| 263 | 272 | base_options: Rc<Options>, |
| 264 | 273 | ) -> Self { |
| @@ -269,9 +278,14 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 269 | 278 | .unwrap_or_default(), |
| 270 | 279 | ); |
| 271 | 280 | |
| 281 | + let layout_config = config.as_mut().and_then(|c| c.layout.take().map(|x| x.0)); | |
| 282 | + | |
| 272 | 283 | let scale = smithay::output::Scale::Integer(1); |
| 273 | - let options = | |
| 274 | - Rc::new(Options::clone(&base_options).adjusted_for_scale(scale.fractional_scale())); | |
| 284 | + let options = Rc::new( | |
| 285 | + Options::clone(&base_options) | |
| 286 | + .with_merged_layout(layout_config.as_ref()) | |
| 287 | + .adjusted_for_scale(scale.fractional_scale()), | |
| 288 | + ); | |
| 275 | 289 | |
| 276 | 290 | let view_size = Size::from((1280., 720.)); |
| 277 | 291 | let working_area = Rectangle::from_size(Size::from((1280., 720.))); |
| @@ -310,6 +324,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 310 | 324 | base_options, |
| 311 | 325 | options, |
| 312 | 326 | name: config.map(|c| c.name.0), |
| 327 | + layout_config, | |
| 313 | 328 | id: WorkspaceId::next(), |
| 314 | 329 | } |
| 315 | 330 | } |
| @@ -370,7 +385,11 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 370 | 385 | |
| 371 | 386 | pub fn update_config(&mut self, base_options: Rc<Options>) { |
| 372 | 387 | let scale = self.scale.fractional_scale(); |
| 373 | - let options = Rc::new(Options::clone(&base_options).adjusted_for_scale(scale)); | |
| 388 | + let options = Rc::new( | |
| 389 | + Options::clone(&base_options) | |
| 390 | + .with_merged_layout(self.layout_config.as_ref()) | |
| 391 | + .adjusted_for_scale(scale), | |
| 392 | + ); | |
| 374 | 393 | |
| 375 | 394 | self.scrolling.update_config( |
| 376 | 395 | self.view_size, |
| @@ -394,6 +413,15 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 394 | 413 | self.options = options; |
| 395 | 414 | } |
| 396 | 415 | |
| 416 | + pub fn update_layout_config(&mut self, layout_config: Option<niri_config::LayoutPart>) { | |
| 417 | + if self.layout_config == layout_config { | |
| 418 | + return; | |
| 419 | + } | |
| 420 | + | |
| 421 | + self.layout_config = layout_config; | |
| 422 | + self.update_config(self.base_options.clone()); | |
| 423 | + } | |
| 424 | + | |
| 397 | 425 | pub fn update_shaders(&mut self) { |
| 398 | 426 | self.scrolling.update_shaders(); |
| 399 | 427 | self.floating.update_shaders(); |
| @@ -1770,6 +1798,10 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1770 | 1798 | self.working_area |
| 1771 | 1799 | } |
| 1772 | 1800 | |
| 1801 | + pub fn layout_config(&self) -> Option<&niri_config::LayoutPart> { | |
| 1802 | + self.layout_config.as_ref() | |
| 1803 | + } | |
| 1804 | + | |
| 1773 | 1805 | #[cfg(test)] |
| 1774 | 1806 | pub fn scrolling(&self) -> &ScrollingSpace<W> { |
| 1775 | 1807 | &self.scrolling |
| @@ -1788,7 +1820,9 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1788 | 1820 | assert!(scale > 0.); |
| 1789 | 1821 | assert!(scale.is_finite()); |
| 1790 | 1822 | |
| 1791 | - let options = Options::clone(&self.base_options).adjusted_for_scale(scale); | |
| 1823 | + let options = Options::clone(&self.base_options) | |
| 1824 | + .with_merged_layout(self.layout_config.as_ref()) | |
| 1825 | + .adjusted_for_scale(scale); | |
| 1792 | 1826 | assert_eq!( |
| 1793 | 1827 | &*self.options, &options, |
| 1794 | 1828 | "options must be base options adjusted for scale" |