Refactor layout for configurability, add preset-column-widths option
Browse files at this commit6fcdb4192275a8112fd45a91eb3e4b70c5ac684fParent: 3ac160710 changed files +424 -238
- resources/default-config.kdl +13 -0
- src/config.rs +22 -1
- src/handlers/compositor.rs +7 -7
- src/handlers/layer_shell.rs +3 -3
- src/handlers/mod.rs +1 -1
- src/handlers/xdg_shell.rs +12 -13
- src/input.rs +36 -38
- src/layout.rs +304 -152
- src/main.rs +1 -1
- src/niri.rs +25 -22
resources/default-config.kdlmodified+13 -0
| @@ -93,6 +93,19 @@ cursor { | |||
| 93 | // If the client will specifically ask for CSD, the request will be honored. | 93 | // If the client will specifically ask for CSD, the request will be honored. |
| 94 | // prefer-no-csd | 94 | // prefer-no-csd |
| 95 | 95 | ||
| 96 | +// You can customize the widths that "switch-preset-column-width" (Mod+R) toggles between. | ||
| 97 | +preset-column-widths { | ||
| 98 | + // Proportion sets the width as a fraction of the output width, taking gaps into account. | ||
| 99 | + // For example, you can perfectly fit four windows sized "proportion 0.25" on an output. | ||
| 100 | + // The default preset widths are 1/3, 1/2 and 2/3 of the output. | ||
| 101 | + proportion 0.333 | ||
| 102 | + proportion 0.5 | ||
| 103 | + proportion 0.667 | ||
| 104 | + | ||
| 105 | + // Fixed sets the width in logical pixels exactly. | ||
| 106 | + // fixed 1920 | ||
| 107 | +} | ||
| 108 | + | ||
| 96 | binds { | 109 | binds { |
| 97 | // Keys consist of modifiers separated by + signs, followed by an XKB key name | 110 | // Keys consist of modifiers separated by + signs, followed by an XKB key name |
| 98 | // in the end. To find an XKB name for a particular key, you may use a program | 111 | // in the end. To find an XKB name for a particular key, you may use a program |
src/config.rsmodified+22 -1
| @@ -22,6 +22,8 @@ pub struct Config { | |||
| 22 | pub prefer_no_csd: bool, | 22 | pub prefer_no_csd: bool, |
| 23 | #[knuffel(child, default)] | 23 | #[knuffel(child, default)] |
| 24 | pub cursor: Cursor, | 24 | pub cursor: Cursor, |
| 25 | + #[knuffel(child, unwrap(children), default)] | ||
| 26 | + pub preset_column_widths: Vec<PresetWidth>, | ||
| 25 | #[knuffel(child, default)] | 27 | #[knuffel(child, default)] |
| 26 | pub binds: Binds, | 28 | pub binds: Binds, |
| 27 | #[knuffel(child, default)] | 29 | #[knuffel(child, default)] |
| @@ -125,7 +127,7 @@ pub struct SpawnAtStartup { | |||
| 125 | pub command: Vec<String>, | 127 | pub command: Vec<String>, |
| 126 | } | 128 | } |
| 127 | 129 | ||
| 128 | -#[derive(knuffel::Decode, Debug, Clone, PartialEq)] | 130 | +#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] |
| 129 | pub struct FocusRing { | 131 | pub struct FocusRing { |
| 130 | #[knuffel(child)] | 132 | #[knuffel(child)] |
| 131 | pub off: bool, | 133 | pub off: bool, |
| @@ -189,6 +191,12 @@ impl Default for Cursor { | |||
| 189 | } | 191 | } |
| 190 | } | 192 | } |
| 191 | 193 | ||
| 194 | +#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | ||
| 195 | +pub enum PresetWidth { | ||
| 196 | + Proportion(#[knuffel(argument)] f64), | ||
| 197 | + Fixed(#[knuffel(argument)] i32), | ||
| 198 | +} | ||
| 199 | + | ||
| 192 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 200 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 193 | pub struct Binds(#[knuffel(children)] pub Vec<Bind>); | 201 | pub struct Binds(#[knuffel(children)] pub Vec<Bind>); |
| 194 | 202 | ||
| @@ -513,6 +521,13 @@ mod tests { | |||
| 513 | xcursor-size 16 | 521 | xcursor-size 16 |
| 514 | } | 522 | } |
| 515 | 523 | ||
| 524 | + preset-column-widths { | ||
| 525 | + proportion 0.25 | ||
| 526 | + proportion 0.5 | ||
| 527 | + fixed 960 | ||
| 528 | + fixed 1280 | ||
| 529 | + } | ||
| 530 | + | ||
| 516 | binds { | 531 | binds { |
| 517 | Mod+T { spawn "alacritty"; } | 532 | Mod+T { spawn "alacritty"; } |
| 518 | Mod+Q { close-window; } | 533 | Mod+Q { close-window; } |
| @@ -580,6 +595,12 @@ mod tests { | |||
| 580 | xcursor_theme: String::from("breeze_cursors"), | 595 | xcursor_theme: String::from("breeze_cursors"), |
| 581 | xcursor_size: 16, | 596 | xcursor_size: 16, |
| 582 | }, | 597 | }, |
| 598 | + preset_column_widths: vec![ | ||
| 599 | + PresetWidth::Proportion(0.25), | ||
| 600 | + PresetWidth::Proportion(0.5), | ||
| 601 | + PresetWidth::Fixed(960), | ||
| 602 | + PresetWidth::Fixed(1280), | ||
| 603 | + ], | ||
| 583 | binds: Binds(vec![ | 604 | binds: Binds(vec![ |
| 584 | Bind { | 605 | Bind { |
| 585 | key: Key { | 606 | key: Key { |
src/handlers/compositor.rsmodified+7 -7
| @@ -87,7 +87,7 @@ impl CompositorHandler for State { | |||
| 87 | let window = entry.remove(); | 87 | let window = entry.remove(); |
| 88 | window.on_commit(); | 88 | window.on_commit(); |
| 89 | 89 | ||
| 90 | - if let Some(output) = self.niri.monitor_set.add_window(window, true).cloned() { | 90 | + if let Some(output) = self.niri.layout.add_window(window, true).cloned() { |
| 91 | self.niri.queue_redraw(output); | 91 | self.niri.queue_redraw(output); |
| 92 | } | 92 | } |
| 93 | return; | 93 | return; |
| @@ -100,7 +100,7 @@ impl CompositorHandler for State { | |||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | // This is a commit of a previously-mapped root or a non-toplevel root. | 102 | // This is a commit of a previously-mapped root or a non-toplevel root. |
| 103 | - if let Some((window, output)) = self.niri.monitor_set.find_window_and_output(surface) { | 103 | + if let Some((window, output)) = self.niri.layout.find_window_and_output(surface) { |
| 104 | // This is a commit of a previously-mapped toplevel. | 104 | // This is a commit of a previously-mapped toplevel. |
| 105 | window.on_commit(); | 105 | window.on_commit(); |
| 106 | 106 | ||
| @@ -110,14 +110,14 @@ impl CompositorHandler for State { | |||
| 110 | 110 | ||
| 111 | if !is_mapped { | 111 | if !is_mapped { |
| 112 | // The toplevel got unmapped. | 112 | // The toplevel got unmapped. |
| 113 | - self.niri.monitor_set.remove_window(&window); | 113 | + self.niri.layout.remove_window(&window); |
| 114 | self.niri.unmapped_windows.insert(surface.clone(), window); | 114 | self.niri.unmapped_windows.insert(surface.clone(), window); |
| 115 | self.niri.queue_redraw(output); | 115 | self.niri.queue_redraw(output); |
| 116 | return; | 116 | return; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | // The toplevel remains mapped. | 119 | // The toplevel remains mapped. |
| 120 | - self.niri.monitor_set.update_window(&window); | 120 | + self.niri.layout.update_window(&window); |
| 121 | 121 | ||
| 122 | self.niri.queue_redraw(output); | 122 | self.niri.queue_redraw(output); |
| 123 | return; | 123 | return; |
| @@ -127,10 +127,10 @@ impl CompositorHandler for State { | |||
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | // This is a commit of a non-root or a non-toplevel root. | 129 | // This is a commit of a non-root or a non-toplevel root. |
| 130 | - let root_window_output = self.niri.monitor_set.find_window_and_output(&root_surface); | 130 | + let root_window_output = self.niri.layout.find_window_and_output(&root_surface); |
| 131 | if let Some((window, output)) = root_window_output { | 131 | if let Some((window, output)) = root_window_output { |
| 132 | window.on_commit(); | 132 | window.on_commit(); |
| 133 | - self.niri.monitor_set.update_window(&window); | 133 | + self.niri.layout.update_window(&window); |
| 134 | self.niri.queue_redraw(output); | 134 | self.niri.queue_redraw(output); |
| 135 | return; | 135 | return; |
| 136 | } | 136 | } |
| @@ -139,7 +139,7 @@ impl CompositorHandler for State { | |||
| 139 | self.popups_handle_commit(surface); | 139 | self.popups_handle_commit(surface); |
| 140 | if let Some(popup) = self.niri.popups.find_popup(surface) { | 140 | if let Some(popup) = self.niri.popups.find_popup(surface) { |
| 141 | if let Ok(root) = find_popup_root_surface(&popup) { | 141 | if let Ok(root) = find_popup_root_surface(&popup) { |
| 142 | - let root_window_output = self.niri.monitor_set.find_window_and_output(&root); | 142 | + let root_window_output = self.niri.layout.find_window_and_output(&root); |
| 143 | if let Some((_window, output)) = root_window_output { | 143 | if let Some((_window, output)) = root_window_output { |
| 144 | self.niri.queue_redraw(output); | 144 | self.niri.queue_redraw(output); |
| 145 | } | 145 | } |
src/handlers/layer_shell.rsmodified+3 -3
| @@ -26,7 +26,7 @@ impl WlrLayerShellHandler for State { | |||
| 26 | let output = wl_output | 26 | let output = wl_output |
| 27 | .as_ref() | 27 | .as_ref() |
| 28 | .and_then(Output::from_resource) | 28 | .and_then(Output::from_resource) |
| 29 | - .or_else(|| self.niri.monitor_set.active_output().cloned()) | 29 | + .or_else(|| self.niri.layout.active_output().cloned()) |
| 30 | .unwrap(); | 30 | .unwrap(); |
| 31 | let mut map = layer_map_for_output(&output); | 31 | let mut map = layer_map_for_output(&output); |
| 32 | map.map_layer(&LayerSurface::new(surface, namespace)) | 32 | map.map_layer(&LayerSurface::new(surface, namespace)) |
| @@ -35,7 +35,7 @@ impl WlrLayerShellHandler for State { | |||
| 35 | 35 | ||
| 36 | fn layer_destroyed(&mut self, surface: WlrLayerSurface) { | 36 | fn layer_destroyed(&mut self, surface: WlrLayerSurface) { |
| 37 | let output = if let Some((output, mut map, layer)) = | 37 | let output = if let Some((output, mut map, layer)) = |
| 38 | - self.niri.monitor_set.outputs().find_map(|o| { | 38 | + self.niri.layout.outputs().find_map(|o| { |
| 39 | let map = layer_map_for_output(o); | 39 | let map = layer_map_for_output(o); |
| 40 | let layer = map | 40 | let layer = map |
| 41 | .layers() | 41 | .layers() |
| @@ -59,7 +59,7 @@ impl State { | |||
| 59 | pub fn layer_shell_handle_commit(&mut self, surface: &WlSurface) { | 59 | pub fn layer_shell_handle_commit(&mut self, surface: &WlSurface) { |
| 60 | let Some(output) = self | 60 | let Some(output) = self |
| 61 | .niri | 61 | .niri |
| 62 | - .monitor_set | 62 | + .layout |
| 63 | .outputs() | 63 | .outputs() |
| 64 | .find(|o| { | 64 | .find(|o| { |
| 65 | let map = layer_map_for_output(o); | 65 | let map = layer_map_for_output(o); |
src/handlers/mod.rsmodified+1 -1
| @@ -65,7 +65,7 @@ impl InputMethodHandler for State { | |||
| 65 | } | 65 | } |
| 66 | fn parent_geometry(&self, parent: &WlSurface) -> Rectangle<i32, Logical> { | 66 | fn parent_geometry(&self, parent: &WlSurface) -> Rectangle<i32, Logical> { |
| 67 | self.niri | 67 | self.niri |
| 68 | - .monitor_set | 68 | + .layout |
| 69 | .find_window_and_output(parent) | 69 | .find_window_and_output(parent) |
| 70 | .map(|(window, _)| window.geometry()) | 70 | .map(|(window, _)| window.geometry()) |
| 71 | .unwrap_or_default() | 71 | .unwrap_or_default() |
src/handlers/xdg_shell.rsmodified+12 -13
| @@ -1,4 +1,4 @@ | |||
| 1 | -use smithay::desktop::{find_popup_root_surface, layer_map_for_output, PopupKind, Window}; | 1 | +use smithay::desktop::{find_popup_root_surface, PopupKind, Window}; |
| 2 | use smithay::output::Output; | 2 | use smithay::output::Output; |
| 3 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; | 3 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; |
| 4 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self, ResizeEdge}; | 4 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self, ResizeEdge}; |
| @@ -15,7 +15,6 @@ use smithay::wayland::shell::xdg::{ | |||
| 15 | }; | 15 | }; |
| 16 | use smithay::{delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_shell}; | 16 | use smithay::{delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_shell}; |
| 17 | 17 | ||
| 18 | -use crate::layout::configure_new_window; | ||
| 19 | use crate::niri::State; | 18 | use crate::niri::State; |
| 20 | 19 | ||
| 21 | impl XdgShellHandler for State { | 20 | impl XdgShellHandler for State { |
| @@ -28,9 +27,9 @@ impl XdgShellHandler for State { | |||
| 28 | let window = Window::new(surface); | 27 | let window = Window::new(surface); |
| 29 | 28 | ||
| 30 | // Tell the surface the preferred size and bounds for its likely output. | 29 | // Tell the surface the preferred size and bounds for its likely output. |
| 31 | - let output = self.niri.monitor_set.active_output().unwrap(); | 30 | + if let Some(ws) = self.niri.layout.active_workspace() { |
| 32 | - let working_area = layer_map_for_output(output).non_exclusive_zone(); | 31 | + ws.configure_new_window(&window); |
| 33 | - configure_new_window(working_area, &window); | 32 | + } |
| 34 | 33 | ||
| 35 | // At the moment of creation, xdg toplevels must have no buffer. | 34 | // At the moment of creation, xdg toplevels must have no buffer. |
| 36 | let existing = self.niri.unmapped_windows.insert(wl_surface, window); | 35 | let existing = self.niri.unmapped_windows.insert(wl_surface, window); |
| @@ -106,18 +105,18 @@ impl XdgShellHandler for State { | |||
| 106 | // independently from its buffer size | 105 | // independently from its buffer size |
| 107 | if let Some((window, current_output)) = self | 106 | if let Some((window, current_output)) = self |
| 108 | .niri | 107 | .niri |
| 109 | - .monitor_set | 108 | + .layout |
| 110 | .find_window_and_output(surface.wl_surface()) | 109 | .find_window_and_output(surface.wl_surface()) |
| 111 | { | 110 | { |
| 112 | if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { | 111 | if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { |
| 113 | if requested_output != current_output { | 112 | if requested_output != current_output { |
| 114 | self.niri | 113 | self.niri |
| 115 | - .monitor_set | 114 | + .layout |
| 116 | .move_window_to_output(window.clone(), &requested_output); | 115 | .move_window_to_output(window.clone(), &requested_output); |
| 117 | } | 116 | } |
| 118 | } | 117 | } |
| 119 | 118 | ||
| 120 | - self.niri.monitor_set.set_fullscreen(&window, true); | 119 | + self.niri.layout.set_fullscreen(&window, true); |
| 121 | } | 120 | } |
| 122 | } | 121 | } |
| 123 | 122 | ||
| @@ -129,10 +128,10 @@ impl XdgShellHandler for State { | |||
| 129 | fn unfullscreen_request(&mut self, surface: ToplevelSurface) { | 128 | fn unfullscreen_request(&mut self, surface: ToplevelSurface) { |
| 130 | if let Some((window, _)) = self | 129 | if let Some((window, _)) = self |
| 131 | .niri | 130 | .niri |
| 132 | - .monitor_set | 131 | + .layout |
| 133 | .find_window_and_output(surface.wl_surface()) | 132 | .find_window_and_output(surface.wl_surface()) |
| 134 | { | 133 | { |
| 135 | - self.niri.monitor_set.set_fullscreen(&window, false); | 134 | + self.niri.layout.set_fullscreen(&window, false); |
| 136 | } | 135 | } |
| 137 | } | 136 | } |
| 138 | 137 | ||
| @@ -149,16 +148,16 @@ impl XdgShellHandler for State { | |||
| 149 | 148 | ||
| 150 | let (window, output) = self | 149 | let (window, output) = self |
| 151 | .niri | 150 | .niri |
| 152 | - .monitor_set | 151 | + .layout |
| 153 | .find_window_and_output(surface.wl_surface()) | 152 | .find_window_and_output(surface.wl_surface()) |
| 154 | .unwrap(); | 153 | .unwrap(); |
| 155 | - self.niri.monitor_set.remove_window(&window); | 154 | + self.niri.layout.remove_window(&window); |
| 156 | self.niri.queue_redraw(output); | 155 | self.niri.queue_redraw(output); |
| 157 | } | 156 | } |
| 158 | 157 | ||
| 159 | fn popup_destroyed(&mut self, surface: PopupSurface) { | 158 | fn popup_destroyed(&mut self, surface: PopupSurface) { |
| 160 | if let Ok(root) = find_popup_root_surface(&surface.into()) { | 159 | if let Ok(root) = find_popup_root_surface(&surface.into()) { |
| 161 | - let root_window_output = self.niri.monitor_set.find_window_and_output(&root); | 160 | + let root_window_output = self.niri.layout.find_window_and_output(&root); |
| 162 | if let Some((_window, output)) = root_window_output { | 161 | if let Some((_window, output)) = root_window_output { |
| 163 | self.niri.queue_redraw(output); | 162 | self.niri.queue_redraw(output); |
| 164 | } | 163 | } |
src/input.rsmodified+36 -38
| @@ -101,9 +101,7 @@ impl State { | |||
| 101 | // doesn't always trigger due to damage, etc. So run it here right before it might prove | 101 | // doesn't always trigger due to damage, etc. So run it here right before it might prove |
| 102 | // important. Besides, animations affect the input, so it's best to have up-to-date values | 102 | // important. Besides, animations affect the input, so it's best to have up-to-date values |
| 103 | // here. | 103 | // here. |
| 104 | - self.niri | 104 | + self.niri.layout.advance_animations(get_monotonic_time()); |
| 105 | - .monitor_set | ||
| 106 | - .advance_animations(get_monotonic_time()); | ||
| 107 | 105 | ||
| 108 | let comp_mod = self.backend.mod_key(); | 106 | let comp_mod = self.backend.mod_key(); |
| 109 | 107 | ||
| @@ -150,7 +148,7 @@ impl State { | |||
| 150 | } | 148 | } |
| 151 | } | 149 | } |
| 152 | Action::Screenshot => { | 150 | Action::Screenshot => { |
| 153 | - let active = self.niri.monitor_set.active_output().cloned(); | 151 | + let active = self.niri.layout.active_output().cloned(); |
| 154 | if let Some(active) = active { | 152 | if let Some(active) = active { |
| 155 | if let Some(renderer) = self.backend.renderer() { | 153 | if let Some(renderer) = self.backend.renderer() { |
| 156 | if let Err(err) = self.niri.screenshot(renderer, &active) { | 154 | if let Err(err) = self.niri.screenshot(renderer, &active) { |
| @@ -160,144 +158,144 @@ impl State { | |||
| 160 | } | 158 | } |
| 161 | } | 159 | } |
| 162 | Action::CloseWindow => { | 160 | Action::CloseWindow => { |
| 163 | - if let Some(window) = self.niri.monitor_set.focus() { | 161 | + if let Some(window) = self.niri.layout.focus() { |
| 164 | window.toplevel().send_close(); | 162 | window.toplevel().send_close(); |
| 165 | } | 163 | } |
| 166 | } | 164 | } |
| 167 | Action::FullscreenWindow => { | 165 | Action::FullscreenWindow => { |
| 168 | - let focus = self.niri.monitor_set.focus().cloned(); | 166 | + let focus = self.niri.layout.focus().cloned(); |
| 169 | if let Some(window) = focus { | 167 | if let Some(window) = focus { |
| 170 | - self.niri.monitor_set.toggle_fullscreen(&window); | 168 | + self.niri.layout.toggle_fullscreen(&window); |
| 171 | } | 169 | } |
| 172 | } | 170 | } |
| 173 | Action::MoveColumnLeft => { | 171 | Action::MoveColumnLeft => { |
| 174 | - self.niri.monitor_set.move_left(); | 172 | + self.niri.layout.move_left(); |
| 175 | // FIXME: granular | 173 | // FIXME: granular |
| 176 | self.niri.queue_redraw_all(); | 174 | self.niri.queue_redraw_all(); |
| 177 | } | 175 | } |
| 178 | Action::MoveColumnRight => { | 176 | Action::MoveColumnRight => { |
| 179 | - self.niri.monitor_set.move_right(); | 177 | + self.niri.layout.move_right(); |
| 180 | // FIXME: granular | 178 | // FIXME: granular |
| 181 | self.niri.queue_redraw_all(); | 179 | self.niri.queue_redraw_all(); |
| 182 | } | 180 | } |
| 183 | Action::MoveWindowDown => { | 181 | Action::MoveWindowDown => { |
| 184 | - self.niri.monitor_set.move_down(); | 182 | + self.niri.layout.move_down(); |
| 185 | // FIXME: granular | 183 | // FIXME: granular |
| 186 | self.niri.queue_redraw_all(); | 184 | self.niri.queue_redraw_all(); |
| 187 | } | 185 | } |
| 188 | Action::MoveWindowUp => { | 186 | Action::MoveWindowUp => { |
| 189 | - self.niri.monitor_set.move_up(); | 187 | + self.niri.layout.move_up(); |
| 190 | // FIXME: granular | 188 | // FIXME: granular |
| 191 | self.niri.queue_redraw_all(); | 189 | self.niri.queue_redraw_all(); |
| 192 | } | 190 | } |
| 193 | Action::FocusColumnLeft => { | 191 | Action::FocusColumnLeft => { |
| 194 | - self.niri.monitor_set.focus_left(); | 192 | + self.niri.layout.focus_left(); |
| 195 | } | 193 | } |
| 196 | Action::FocusColumnRight => { | 194 | Action::FocusColumnRight => { |
| 197 | - self.niri.monitor_set.focus_right(); | 195 | + self.niri.layout.focus_right(); |
| 198 | } | 196 | } |
| 199 | Action::FocusWindowDown => { | 197 | Action::FocusWindowDown => { |
| 200 | - self.niri.monitor_set.focus_down(); | 198 | + self.niri.layout.focus_down(); |
| 201 | } | 199 | } |
| 202 | Action::FocusWindowUp => { | 200 | Action::FocusWindowUp => { |
| 203 | - self.niri.monitor_set.focus_up(); | 201 | + self.niri.layout.focus_up(); |
| 204 | } | 202 | } |
| 205 | Action::MoveWindowToWorkspaceDown => { | 203 | Action::MoveWindowToWorkspaceDown => { |
| 206 | - self.niri.monitor_set.move_to_workspace_down(); | 204 | + self.niri.layout.move_to_workspace_down(); |
| 207 | // FIXME: granular | 205 | // FIXME: granular |
| 208 | self.niri.queue_redraw_all(); | 206 | self.niri.queue_redraw_all(); |
| 209 | } | 207 | } |
| 210 | Action::MoveWindowToWorkspaceUp => { | 208 | Action::MoveWindowToWorkspaceUp => { |
| 211 | - self.niri.monitor_set.move_to_workspace_up(); | 209 | + self.niri.layout.move_to_workspace_up(); |
| 212 | // FIXME: granular | 210 | // FIXME: granular |
| 213 | self.niri.queue_redraw_all(); | 211 | self.niri.queue_redraw_all(); |
| 214 | } | 212 | } |
| 215 | Action::MoveWindowToWorkspace(idx) => { | 213 | Action::MoveWindowToWorkspace(idx) => { |
| 216 | - self.niri.monitor_set.move_to_workspace(idx); | 214 | + self.niri.layout.move_to_workspace(idx); |
| 217 | // FIXME: granular | 215 | // FIXME: granular |
| 218 | self.niri.queue_redraw_all(); | 216 | self.niri.queue_redraw_all(); |
| 219 | } | 217 | } |
| 220 | Action::FocusWorkspaceDown => { | 218 | Action::FocusWorkspaceDown => { |
| 221 | - self.niri.monitor_set.switch_workspace_down(); | 219 | + self.niri.layout.switch_workspace_down(); |
| 222 | // FIXME: granular | 220 | // FIXME: granular |
| 223 | self.niri.queue_redraw_all(); | 221 | self.niri.queue_redraw_all(); |
| 224 | } | 222 | } |
| 225 | Action::FocusWorkspaceUp => { | 223 | Action::FocusWorkspaceUp => { |
| 226 | - self.niri.monitor_set.switch_workspace_up(); | 224 | + self.niri.layout.switch_workspace_up(); |
| 227 | // FIXME: granular | 225 | // FIXME: granular |
| 228 | self.niri.queue_redraw_all(); | 226 | self.niri.queue_redraw_all(); |
| 229 | } | 227 | } |
| 230 | Action::FocusWorkspace(idx) => { | 228 | Action::FocusWorkspace(idx) => { |
| 231 | - self.niri.monitor_set.switch_workspace(idx); | 229 | + self.niri.layout.switch_workspace(idx); |
| 232 | // FIXME: granular | 230 | // FIXME: granular |
| 233 | self.niri.queue_redraw_all(); | 231 | self.niri.queue_redraw_all(); |
| 234 | } | 232 | } |
| 235 | Action::ConsumeWindowIntoColumn => { | 233 | Action::ConsumeWindowIntoColumn => { |
| 236 | - self.niri.monitor_set.consume_into_column(); | 234 | + self.niri.layout.consume_into_column(); |
| 237 | // FIXME: granular | 235 | // FIXME: granular |
| 238 | self.niri.queue_redraw_all(); | 236 | self.niri.queue_redraw_all(); |
| 239 | } | 237 | } |
| 240 | Action::ExpelWindowFromColumn => { | 238 | Action::ExpelWindowFromColumn => { |
| 241 | - self.niri.monitor_set.expel_from_column(); | 239 | + self.niri.layout.expel_from_column(); |
| 242 | // FIXME: granular | 240 | // FIXME: granular |
| 243 | self.niri.queue_redraw_all(); | 241 | self.niri.queue_redraw_all(); |
| 244 | } | 242 | } |
| 245 | Action::SwitchPresetColumnWidth => { | 243 | Action::SwitchPresetColumnWidth => { |
| 246 | - self.niri.monitor_set.toggle_width(); | 244 | + self.niri.layout.toggle_width(); |
| 247 | } | 245 | } |
| 248 | Action::MaximizeColumn => { | 246 | Action::MaximizeColumn => { |
| 249 | - self.niri.monitor_set.toggle_full_width(); | 247 | + self.niri.layout.toggle_full_width(); |
| 250 | } | 248 | } |
| 251 | Action::FocusMonitorLeft => { | 249 | Action::FocusMonitorLeft => { |
| 252 | if let Some(output) = self.niri.output_left() { | 250 | if let Some(output) = self.niri.output_left() { |
| 253 | - self.niri.monitor_set.focus_output(&output); | 251 | + self.niri.layout.focus_output(&output); |
| 254 | self.move_cursor_to_output(&output); | 252 | self.move_cursor_to_output(&output); |
| 255 | } | 253 | } |
| 256 | } | 254 | } |
| 257 | Action::FocusMonitorRight => { | 255 | Action::FocusMonitorRight => { |
| 258 | if let Some(output) = self.niri.output_right() { | 256 | if let Some(output) = self.niri.output_right() { |
| 259 | - self.niri.monitor_set.focus_output(&output); | 257 | + self.niri.layout.focus_output(&output); |
| 260 | self.move_cursor_to_output(&output); | 258 | self.move_cursor_to_output(&output); |
| 261 | } | 259 | } |
| 262 | } | 260 | } |
| 263 | Action::FocusMonitorDown => { | 261 | Action::FocusMonitorDown => { |
| 264 | if let Some(output) = self.niri.output_down() { | 262 | if let Some(output) = self.niri.output_down() { |
| 265 | - self.niri.monitor_set.focus_output(&output); | 263 | + self.niri.layout.focus_output(&output); |
| 266 | self.move_cursor_to_output(&output); | 264 | self.move_cursor_to_output(&output); |
| 267 | } | 265 | } |
| 268 | } | 266 | } |
| 269 | Action::FocusMonitorUp => { | 267 | Action::FocusMonitorUp => { |
| 270 | if let Some(output) = self.niri.output_up() { | 268 | if let Some(output) = self.niri.output_up() { |
| 271 | - self.niri.monitor_set.focus_output(&output); | 269 | + self.niri.layout.focus_output(&output); |
| 272 | self.move_cursor_to_output(&output); | 270 | self.move_cursor_to_output(&output); |
| 273 | } | 271 | } |
| 274 | } | 272 | } |
| 275 | Action::MoveWindowToMonitorLeft => { | 273 | Action::MoveWindowToMonitorLeft => { |
| 276 | if let Some(output) = self.niri.output_left() { | 274 | if let Some(output) = self.niri.output_left() { |
| 277 | - self.niri.monitor_set.move_to_output(&output); | 275 | + self.niri.layout.move_to_output(&output); |
| 278 | self.move_cursor_to_output(&output); | 276 | self.move_cursor_to_output(&output); |
| 279 | } | 277 | } |
| 280 | } | 278 | } |
| 281 | Action::MoveWindowToMonitorRight => { | 279 | Action::MoveWindowToMonitorRight => { |
| 282 | if let Some(output) = self.niri.output_right() { | 280 | if let Some(output) = self.niri.output_right() { |
| 283 | - self.niri.monitor_set.move_to_output(&output); | 281 | + self.niri.layout.move_to_output(&output); |
| 284 | self.move_cursor_to_output(&output); | 282 | self.move_cursor_to_output(&output); |
| 285 | } | 283 | } |
| 286 | } | 284 | } |
| 287 | Action::MoveWindowToMonitorDown => { | 285 | Action::MoveWindowToMonitorDown => { |
| 288 | if let Some(output) = self.niri.output_down() { | 286 | if let Some(output) = self.niri.output_down() { |
| 289 | - self.niri.monitor_set.move_to_output(&output); | 287 | + self.niri.layout.move_to_output(&output); |
| 290 | self.move_cursor_to_output(&output); | 288 | self.move_cursor_to_output(&output); |
| 291 | } | 289 | } |
| 292 | } | 290 | } |
| 293 | Action::MoveWindowToMonitorUp => { | 291 | Action::MoveWindowToMonitorUp => { |
| 294 | if let Some(output) = self.niri.output_up() { | 292 | if let Some(output) = self.niri.output_up() { |
| 295 | - self.niri.monitor_set.move_to_output(&output); | 293 | + self.niri.layout.move_to_output(&output); |
| 296 | self.move_cursor_to_output(&output); | 294 | self.move_cursor_to_output(&output); |
| 297 | } | 295 | } |
| 298 | } | 296 | } |
| 299 | Action::SetColumnWidth(change) => { | 297 | Action::SetColumnWidth(change) => { |
| 300 | - self.niri.monitor_set.set_column_width(change); | 298 | + self.niri.layout.set_column_width(change); |
| 301 | } | 299 | } |
| 302 | } | 300 | } |
| 303 | } | 301 | } |
| @@ -415,9 +413,9 @@ impl State { | |||
| 415 | if ButtonState::Pressed == button_state && !pointer.is_grabbed() { | 413 | if ButtonState::Pressed == button_state && !pointer.is_grabbed() { |
| 416 | if let Some(window) = self.niri.window_under_cursor() { | 414 | if let Some(window) = self.niri.window_under_cursor() { |
| 417 | let window = window.clone(); | 415 | let window = window.clone(); |
| 418 | - self.niri.monitor_set.activate_window(&window); | 416 | + self.niri.layout.activate_window(&window); |
| 419 | } else if let Some(output) = self.niri.output_under_cursor() { | 417 | } else if let Some(output) = self.niri.output_under_cursor() { |
| 420 | - self.niri.monitor_set.activate_output(&output); | 418 | + self.niri.layout.activate_output(&output); |
| 421 | } | 419 | } |
| 422 | }; | 420 | }; |
| 423 | 421 | ||
| @@ -546,9 +544,9 @@ impl State { | |||
| 546 | if !pointer.is_grabbed() { | 544 | if !pointer.is_grabbed() { |
| 547 | if let Some(window) = self.niri.window_under_cursor() { | 545 | if let Some(window) = self.niri.window_under_cursor() { |
| 548 | let window = window.clone(); | 546 | let window = window.clone(); |
| 549 | - self.niri.monitor_set.activate_window(&window); | 547 | + self.niri.layout.activate_window(&window); |
| 550 | } else if let Some(output) = self.niri.output_under_cursor() { | 548 | } else if let Some(output) = self.niri.output_under_cursor() { |
| 551 | - self.niri.monitor_set.activate_output(&output); | 549 | + self.niri.layout.activate_output(&output); |
| 552 | } | 550 | } |
| 553 | }; | 551 | }; |
| 554 | } | 552 | } |
src/layout.rsmodified+304 -152
| @@ -31,6 +31,7 @@ | |||
| 31 | 31 | ||
| 32 | use std::cmp::{max, min}; | 32 | use std::cmp::{max, min}; |
| 33 | use std::mem; | 33 | use std::mem; |
| 34 | +use std::rc::Rc; | ||
| 34 | use std::time::Duration; | 35 | use std::time::Duration; |
| 35 | 36 | ||
| 36 | use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; | 37 | use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; |
| @@ -52,14 +53,9 @@ use smithay::wayland::compositor::with_states; | |||
| 52 | use smithay::wayland::shell::xdg::SurfaceCachedState; | 53 | use smithay::wayland::shell::xdg::SurfaceCachedState; |
| 53 | 54 | ||
| 54 | use crate::animation::Animation; | 55 | use crate::animation::Animation; |
| 55 | -use crate::config::{Color, Config, SizeChange}; | 56 | +use crate::config::{self, Color, Config, PresetWidth, SizeChange}; |
| 56 | 57 | ||
| 57 | const PADDING: i32 = 16; | 58 | const PADDING: i32 = 16; |
| 58 | -const WIDTH_PROPORTIONS: [ColumnWidth; 3] = [ | ||
| 59 | - ColumnWidth::Proportion(1. / 3.), | ||
| 60 | - ColumnWidth::Proportion(0.5), | ||
| 61 | - ColumnWidth::Proportion(2. / 3.), | ||
| 62 | -]; | ||
| 63 | 59 | ||
| 64 | #[derive(Debug, Clone, PartialEq, Eq)] | 60 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 65 | pub struct OutputId(String); | 61 | pub struct OutputId(String); |
| @@ -82,7 +78,15 @@ pub trait LayoutElement: SpaceElement + PartialEq + Clone { | |||
| 82 | } | 78 | } |
| 83 | 79 | ||
| 84 | #[derive(Debug)] | 80 | #[derive(Debug)] |
| 85 | -pub enum MonitorSet<W: LayoutElement> { | 81 | +pub struct Layout<W: LayoutElement> { |
| 82 | + /// Monitors and workspaes in the layout. | ||
| 83 | + monitor_set: MonitorSet<W>, | ||
| 84 | + /// Configurable properties of the layout. | ||
| 85 | + options: Rc<Options>, | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +#[derive(Debug)] | ||
| 89 | +enum MonitorSet<W: LayoutElement> { | ||
| 86 | /// At least one output is connected. | 90 | /// At least one output is connected. |
| 87 | Normal { | 91 | Normal { |
| 88 | /// Connected monitors. | 92 | /// Connected monitors. |
| @@ -93,7 +97,10 @@ pub enum MonitorSet<W: LayoutElement> { | |||
| 93 | active_monitor_idx: usize, | 97 | active_monitor_idx: usize, |
| 94 | }, | 98 | }, |
| 95 | /// No outputs are connected, and these are the workspaces. | 99 | /// No outputs are connected, and these are the workspaces. |
| 96 | - NoOutputs(Vec<Workspace<W>>), | 100 | + NoOutputs { |
| 101 | + /// The workspaces. | ||
| 102 | + workspaces: Vec<Workspace<W>>, | ||
| 103 | + }, | ||
| 97 | } | 104 | } |
| 98 | 105 | ||
| 99 | #[derive(Debug)] | 106 | #[derive(Debug)] |
| @@ -106,6 +113,8 @@ pub struct Monitor<W: LayoutElement> { | |||
| 106 | active_workspace_idx: usize, | 113 | active_workspace_idx: usize, |
| 107 | /// Animation for workspace switching. | 114 | /// Animation for workspace switching. |
| 108 | workspace_idx_anim: Option<Animation>, | 115 | workspace_idx_anim: Option<Animation>, |
| 116 | + /// Configurable properties of the layout. | ||
| 117 | + options: Rc<Options>, | ||
| 109 | } | 118 | } |
| 110 | 119 | ||
| 111 | #[derive(Debug)] | 120 | #[derive(Debug)] |
| @@ -155,6 +164,9 @@ pub struct Workspace<W: LayoutElement> { | |||
| 155 | /// contrast to tabs in Firefox, for example), we can track this as a bool, rather than an | 164 | /// contrast to tabs in Firefox, for example), we can track this as a bool, rather than an |
| 156 | /// index of the previous column to activate. | 165 | /// index of the previous column to activate. |
| 157 | activate_prev_column_on_removal: bool, | 166 | activate_prev_column_on_removal: bool, |
| 167 | + | ||
| 168 | + /// Configurable properties of the layout. | ||
| 169 | + options: Rc<Options>, | ||
| 158 | } | 170 | } |
| 159 | 171 | ||
| 160 | #[derive(Debug)] | 172 | #[derive(Debug)] |
| @@ -166,8 +178,49 @@ struct FocusRing { | |||
| 166 | inactive_color: Color, | 178 | inactive_color: Color, |
| 167 | } | 179 | } |
| 168 | 180 | ||
| 181 | +#[derive(Debug, PartialEq)] | ||
| 182 | +struct Options { | ||
| 183 | + focus_ring: config::FocusRing, | ||
| 184 | + /// Column widths that `toggle_width()` switches between. | ||
| 185 | + preset_widths: Vec<ColumnWidth>, | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +impl Default for Options { | ||
| 189 | + fn default() -> Self { | ||
| 190 | + Self { | ||
| 191 | + focus_ring: Default::default(), | ||
| 192 | + preset_widths: vec![ | ||
| 193 | + ColumnWidth::Proportion(1. / 3.), | ||
| 194 | + ColumnWidth::Proportion(0.5), | ||
| 195 | + ColumnWidth::Proportion(2. / 3.), | ||
| 196 | + ], | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | +} | ||
| 200 | + | ||
| 201 | +impl Options { | ||
| 202 | + fn from_config(config: &Config) -> Self { | ||
| 203 | + let preset_column_widths = &config.preset_column_widths; | ||
| 204 | + | ||
| 205 | + let preset_widths = if preset_column_widths.is_empty() { | ||
| 206 | + Options::default().preset_widths | ||
| 207 | + } else { | ||
| 208 | + preset_column_widths | ||
| 209 | + .iter() | ||
| 210 | + .copied() | ||
| 211 | + .map(ColumnWidth::from) | ||
| 212 | + .collect() | ||
| 213 | + }; | ||
| 214 | + | ||
| 215 | + Self { | ||
| 216 | + focus_ring: config.focus_ring, | ||
| 217 | + preset_widths, | ||
| 218 | + } | ||
| 219 | + } | ||
| 220 | +} | ||
| 221 | + | ||
| 169 | /// Width of a column. | 222 | /// Width of a column. |
| 170 | -#[derive(Debug, Clone, Copy)] | 223 | +#[derive(Debug, Clone, Copy, PartialEq)] |
| 171 | enum ColumnWidth { | 224 | enum ColumnWidth { |
| 172 | /// Proportion of the current view width. | 225 | /// Proportion of the current view width. |
| 173 | Proportion(f64), | 226 | Proportion(f64), |
| @@ -175,11 +228,20 @@ enum ColumnWidth { | |||
| 175 | /// | 228 | /// |
| 176 | /// This is separate from Proportion in order to be able to reliably cycle between preset | 229 | /// This is separate from Proportion in order to be able to reliably cycle between preset |
| 177 | /// proportions. | 230 | /// proportions. |
| 178 | - PresetProportion(usize), | 231 | + Preset(usize), |
| 179 | /// Fixed width in logical pixels. | 232 | /// Fixed width in logical pixels. |
| 180 | Fixed(i32), | 233 | Fixed(i32), |
| 181 | } | 234 | } |
| 182 | 235 | ||
| 236 | +impl From<PresetWidth> for ColumnWidth { | ||
| 237 | + fn from(value: PresetWidth) -> Self { | ||
| 238 | + match value { | ||
| 239 | + PresetWidth::Proportion(p) => Self::Proportion(p.clamp(0., 10000.)), | ||
| 240 | + PresetWidth::Fixed(f) => Self::Fixed(f.clamp(1, 100000)), | ||
| 241 | + } | ||
| 242 | + } | ||
| 243 | +} | ||
| 244 | + | ||
| 183 | #[derive(Debug)] | 245 | #[derive(Debug)] |
| 184 | struct Column<W: LayoutElement> { | 246 | struct Column<W: LayoutElement> { |
| 185 | /// Windows in this column. | 247 | /// Windows in this column. |
| @@ -201,6 +263,9 @@ struct Column<W: LayoutElement> { | |||
| 201 | 263 | ||
| 202 | /// Latest known working area for this column's workspace. | 264 | /// Latest known working area for this column's workspace. |
| 203 | working_area: Rectangle<i32, Logical>, | 265 | working_area: Rectangle<i32, Logical>, |
| 266 | + | ||
| 267 | + /// Configurable properties of the layout. | ||
| 268 | + options: Rc<Options>, | ||
| 204 | } | 269 | } |
| 205 | 270 | ||
| 206 | impl OutputId { | 271 | impl OutputId { |
| @@ -277,23 +342,23 @@ impl FocusRing { | |||
| 277 | } | 342 | } |
| 278 | } | 343 | } |
| 279 | 344 | ||
| 280 | -impl Default for FocusRing { | 345 | +impl FocusRing { |
| 281 | - fn default() -> Self { | 346 | + fn new(config: config::FocusRing) -> Self { |
| 282 | Self { | 347 | Self { |
| 283 | buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.]), | 348 | buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.]), |
| 284 | - is_off: true, | 349 | + is_off: config.off, |
| 285 | - width: 0, | 350 | + width: config.width.into(), |
| 286 | - active_color: Color::default(), | 351 | + active_color: config.active_color, |
| 287 | - inactive_color: Color::default(), | 352 | + inactive_color: config.inactive_color, |
| 288 | } | 353 | } |
| 289 | } | 354 | } |
| 290 | } | 355 | } |
| 291 | 356 | ||
| 292 | impl ColumnWidth { | 357 | impl ColumnWidth { |
| 293 | - fn resolve(self, view_width: i32) -> i32 { | 358 | + fn resolve(self, options: &Options, view_width: i32) -> i32 { |
| 294 | match self { | 359 | match self { |
| 295 | ColumnWidth::Proportion(proportion) => (view_width as f64 * proportion).floor() as i32, | 360 | ColumnWidth::Proportion(proportion) => (view_width as f64 * proportion).floor() as i32, |
| 296 | - ColumnWidth::PresetProportion(idx) => WIDTH_PROPORTIONS[idx].resolve(view_width), | 361 | + ColumnWidth::Preset(idx) => options.preset_widths[idx].resolve(options, view_width), |
| 297 | // FIXME: remove this PADDING from here after redesigning how padding works. | 362 | // FIXME: remove this PADDING from here after redesigning how padding works. |
| 298 | ColumnWidth::Fixed(width) => width + PADDING, | 363 | ColumnWidth::Fixed(width) => width + PADDING, |
| 299 | } | 364 | } |
| @@ -306,15 +371,18 @@ impl Default for ColumnWidth { | |||
| 306 | } | 371 | } |
| 307 | } | 372 | } |
| 308 | 373 | ||
| 309 | -impl<W: LayoutElement> MonitorSet<W> { | 374 | +impl<W: LayoutElement> Layout<W> { |
| 310 | - pub fn new() -> Self { | 375 | + pub fn new(config: &Config) -> Self { |
| 311 | - Self::NoOutputs(vec![]) | 376 | + Self { |
| 377 | + monitor_set: MonitorSet::NoOutputs { workspaces: vec![] }, | ||
| 378 | + options: Rc::new(Options::from_config(config)), | ||
| 379 | + } | ||
| 312 | } | 380 | } |
| 313 | 381 | ||
| 314 | pub fn add_output(&mut self, output: Output) { | 382 | pub fn add_output(&mut self, output: Output) { |
| 315 | let id = OutputId::new(&output); | 383 | let id = OutputId::new(&output); |
| 316 | 384 | ||
| 317 | - *self = match mem::take(self) { | 385 | + self.monitor_set = match mem::take(&mut self.monitor_set) { |
| 318 | MonitorSet::Normal { | 386 | MonitorSet::Normal { |
| 319 | mut monitors, | 387 | mut monitors, |
| 320 | primary_idx, | 388 | primary_idx, |
| @@ -337,29 +405,30 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 337 | workspaces.reverse(); | 405 | workspaces.reverse(); |
| 338 | if workspaces.iter().all(|ws| ws.has_windows()) { | 406 | if workspaces.iter().all(|ws| ws.has_windows()) { |
| 339 | // Make sure there's always an empty workspace. | 407 | // Make sure there's always an empty workspace. |
| 340 | - workspaces.push(Workspace::new(output.clone())); | 408 | + workspaces.push(Workspace::new(output.clone(), self.options.clone())); |
| 341 | } | 409 | } |
| 342 | 410 | ||
| 343 | for ws in &mut workspaces { | 411 | for ws in &mut workspaces { |
| 344 | ws.set_output(Some(output.clone())); | 412 | ws.set_output(Some(output.clone())); |
| 345 | } | 413 | } |
| 346 | 414 | ||
| 347 | - monitors.push(Monitor::new(output, workspaces)); | 415 | + monitors.push(Monitor::new(output, workspaces, self.options.clone())); |
| 348 | MonitorSet::Normal { | 416 | MonitorSet::Normal { |
| 349 | monitors, | 417 | monitors, |
| 350 | primary_idx, | 418 | primary_idx, |
| 351 | active_monitor_idx, | 419 | active_monitor_idx, |
| 352 | } | 420 | } |
| 353 | } | 421 | } |
| 354 | - MonitorSet::NoOutputs(mut workspaces) => { | 422 | + MonitorSet::NoOutputs { mut workspaces } => { |
| 355 | // We know there are no empty workspaces there, so add one. | 423 | // We know there are no empty workspaces there, so add one. |
| 356 | - workspaces.push(Workspace::new(output.clone())); | 424 | + workspaces.push(Workspace::new(output.clone(), self.options.clone())); |
| 357 | 425 | ||
| 358 | for workspace in &mut workspaces { | 426 | for workspace in &mut workspaces { |
| 359 | workspace.set_output(Some(output.clone())); | 427 | workspace.set_output(Some(output.clone())); |
| 360 | } | 428 | } |
| 361 | 429 | ||
| 362 | - let monitor = Monitor::new(output, workspaces); | 430 | + let monitor = Monitor::new(output, workspaces, self.options.clone()); |
| 431 | + | ||
| 363 | MonitorSet::Normal { | 432 | MonitorSet::Normal { |
| 364 | monitors: vec![monitor], | 433 | monitors: vec![monitor], |
| 365 | primary_idx: 0, | 434 | primary_idx: 0, |
| @@ -370,7 +439,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 370 | } | 439 | } |
| 371 | 440 | ||
| 372 | pub fn remove_output(&mut self, output: &Output) { | 441 | pub fn remove_output(&mut self, output: &Output) { |
| 373 | - *self = match mem::take(self) { | 442 | + self.monitor_set = match mem::take(&mut self.monitor_set) { |
| 374 | MonitorSet::Normal { | 443 | MonitorSet::Normal { |
| 375 | mut monitors, | 444 | mut monitors, |
| 376 | mut primary_idx, | 445 | mut primary_idx, |
| @@ -392,7 +461,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 392 | 461 | ||
| 393 | if monitors.is_empty() { | 462 | if monitors.is_empty() { |
| 394 | // Removed the last monitor. | 463 | // Removed the last monitor. |
| 395 | - MonitorSet::NoOutputs(workspaces) | 464 | + MonitorSet::NoOutputs { workspaces } |
| 396 | } else { | 465 | } else { |
| 397 | if primary_idx >= idx { | 466 | if primary_idx >= idx { |
| 398 | // Update primary_idx to either still point at the same monitor, or at some | 467 | // Update primary_idx to either still point at the same monitor, or at some |
| @@ -422,7 +491,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 422 | } | 491 | } |
| 423 | } | 492 | } |
| 424 | } | 493 | } |
| 425 | - MonitorSet::NoOutputs(_) => { | 494 | + MonitorSet::NoOutputs { .. } => { |
| 426 | panic!("tried to remove output when there were already none") | 495 | panic!("tried to remove output when there were already none") |
| 427 | } | 496 | } |
| 428 | } | 497 | } |
| @@ -439,7 +508,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 439 | monitors, | 508 | monitors, |
| 440 | active_monitor_idx, | 509 | active_monitor_idx, |
| 441 | .. | 510 | .. |
| 442 | - } = self | 511 | + } = &mut self.monitor_set |
| 443 | else { | 512 | else { |
| 444 | panic!() | 513 | panic!() |
| 445 | }; | 514 | }; |
| @@ -455,7 +524,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 455 | /// | 524 | /// |
| 456 | /// Returns an output that the window was added to, if there were any outputs. | 525 | /// Returns an output that the window was added to, if there were any outputs. |
| 457 | pub fn add_window(&mut self, window: W, activate: bool) -> Option<&Output> { | 526 | pub fn add_window(&mut self, window: W, activate: bool) -> Option<&Output> { |
| 458 | - match self { | 527 | + match &mut self.monitor_set { |
| 459 | MonitorSet::Normal { | 528 | MonitorSet::Normal { |
| 460 | monitors, | 529 | monitors, |
| 461 | active_monitor_idx, | 530 | active_monitor_idx, |
| @@ -465,11 +534,11 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 465 | mon.add_window(mon.active_workspace_idx, window, activate); | 534 | mon.add_window(mon.active_workspace_idx, window, activate); |
| 466 | Some(&mon.output) | 535 | Some(&mon.output) |
| 467 | } | 536 | } |
| 468 | - MonitorSet::NoOutputs(workspaces) => { | 537 | + MonitorSet::NoOutputs { workspaces } => { |
| 469 | let ws = if let Some(ws) = workspaces.get_mut(0) { | 538 | let ws = if let Some(ws) = workspaces.get_mut(0) { |
| 470 | ws | 539 | ws |
| 471 | } else { | 540 | } else { |
| 472 | - workspaces.push(Workspace::new_no_outputs()); | 541 | + workspaces.push(Workspace::new_no_outputs(self.options.clone())); |
| 473 | &mut workspaces[0] | 542 | &mut workspaces[0] |
| 474 | }; | 543 | }; |
| 475 | ws.add_window(window, activate); | 544 | ws.add_window(window, activate); |
| @@ -479,7 +548,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 479 | } | 548 | } |
| 480 | 549 | ||
| 481 | pub fn remove_window(&mut self, window: &W) { | 550 | pub fn remove_window(&mut self, window: &W) { |
| 482 | - match self { | 551 | + match &mut self.monitor_set { |
| 483 | MonitorSet::Normal { monitors, .. } => { | 552 | MonitorSet::Normal { monitors, .. } => { |
| 484 | for mon in monitors { | 553 | for mon in monitors { |
| 485 | for (idx, ws) in mon.workspaces.iter_mut().enumerate() { | 554 | for (idx, ws) in mon.workspaces.iter_mut().enumerate() { |
| @@ -503,7 +572,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 503 | } | 572 | } |
| 504 | } | 573 | } |
| 505 | } | 574 | } |
| 506 | - MonitorSet::NoOutputs(workspaces) => { | 575 | + MonitorSet::NoOutputs { workspaces, .. } => { |
| 507 | for (idx, ws) in workspaces.iter_mut().enumerate() { | 576 | for (idx, ws) in workspaces.iter_mut().enumerate() { |
| 508 | if ws.has_window(window) { | 577 | if ws.has_window(window) { |
| 509 | ws.remove_window(window); | 578 | ws.remove_window(window); |
| @@ -521,7 +590,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 521 | } | 590 | } |
| 522 | 591 | ||
| 523 | pub fn update_window(&mut self, window: &W) { | 592 | pub fn update_window(&mut self, window: &W) { |
| 524 | - match self { | 593 | + match &mut self.monitor_set { |
| 525 | MonitorSet::Normal { monitors, .. } => { | 594 | MonitorSet::Normal { monitors, .. } => { |
| 526 | for mon in monitors { | 595 | for mon in monitors { |
| 527 | for ws in &mut mon.workspaces { | 596 | for ws in &mut mon.workspaces { |
| @@ -532,7 +601,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 532 | } | 601 | } |
| 533 | } | 602 | } |
| 534 | } | 603 | } |
| 535 | - MonitorSet::NoOutputs(workspaces) => { | 604 | + MonitorSet::NoOutputs { workspaces, .. } => { |
| 536 | for ws in workspaces { | 605 | for ws in workspaces { |
| 537 | if ws.has_window(window) { | 606 | if ws.has_window(window) { |
| 538 | ws.update_window(window); | 607 | ws.update_window(window); |
| @@ -544,7 +613,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 544 | } | 613 | } |
| 545 | 614 | ||
| 546 | pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(W, Output)> { | 615 | pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(W, Output)> { |
| 547 | - if let MonitorSet::Normal { monitors, .. } = self { | 616 | + if let MonitorSet::Normal { monitors, .. } = &self.monitor_set { |
| 548 | for mon in monitors { | 617 | for mon in monitors { |
| 549 | for ws in &mon.workspaces { | 618 | for ws in &mon.workspaces { |
| 550 | if let Some(window) = ws.find_wl_surface(wl_surface) { | 619 | if let Some(window) = ws.find_wl_surface(wl_surface) { |
| @@ -558,7 +627,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 558 | } | 627 | } |
| 559 | 628 | ||
| 560 | pub fn update_output_size(&mut self, output: &Output) { | 629 | pub fn update_output_size(&mut self, output: &Output) { |
| 561 | - let MonitorSet::Normal { monitors, .. } = self else { | 630 | + let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else { |
| 562 | panic!() | 631 | panic!() |
| 563 | }; | 632 | }; |
| 564 | 633 | ||
| @@ -581,7 +650,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 581 | monitors, | 650 | monitors, |
| 582 | active_monitor_idx, | 651 | active_monitor_idx, |
| 583 | .. | 652 | .. |
| 584 | - } = self | 653 | + } = &mut self.monitor_set |
| 585 | else { | 654 | else { |
| 586 | todo!() | 655 | todo!() |
| 587 | }; | 656 | }; |
| @@ -604,7 +673,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 604 | monitors, | 673 | monitors, |
| 605 | active_monitor_idx, | 674 | active_monitor_idx, |
| 606 | .. | 675 | .. |
| 607 | - } = self | 676 | + } = &mut self.monitor_set |
| 608 | else { | 677 | else { |
| 609 | return; | 678 | return; |
| 610 | }; | 679 | }; |
| @@ -621,7 +690,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 621 | monitors, | 690 | monitors, |
| 622 | active_monitor_idx, | 691 | active_monitor_idx, |
| 623 | .. | 692 | .. |
| 624 | - } = self | 693 | + } = &self.monitor_set |
| 625 | else { | 694 | else { |
| 626 | return None; | 695 | return None; |
| 627 | }; | 696 | }; |
| @@ -629,8 +698,22 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 629 | Some(&monitors[*active_monitor_idx].output) | 698 | Some(&monitors[*active_monitor_idx].output) |
| 630 | } | 699 | } |
| 631 | 700 | ||
| 701 | + pub fn active_workspace(&self) -> Option<&Workspace<W>> { | ||
| 702 | + let MonitorSet::Normal { | ||
| 703 | + monitors, | ||
| 704 | + active_monitor_idx, | ||
| 705 | + .. | ||
| 706 | + } = &self.monitor_set | ||
| 707 | + else { | ||
| 708 | + return None; | ||
| 709 | + }; | ||
| 710 | + | ||
| 711 | + let mon = &monitors[*active_monitor_idx]; | ||
| 712 | + Some(&mon.workspaces[mon.active_workspace_idx]) | ||
| 713 | + } | ||
| 714 | + | ||
| 632 | pub fn workspace_for_output(&self, output: &Output) -> Option<&Workspace<W>> { | 715 | pub fn workspace_for_output(&self, output: &Output) -> Option<&Workspace<W>> { |
| 633 | - let MonitorSet::Normal { monitors, .. } = self else { | 716 | + let MonitorSet::Normal { monitors, .. } = &self.monitor_set else { |
| 634 | return None; | 717 | return None; |
| 635 | }; | 718 | }; |
| 636 | 719 | ||
| @@ -644,7 +727,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 644 | } | 727 | } |
| 645 | 728 | ||
| 646 | pub fn windows_for_output(&self, output: &Output) -> impl Iterator<Item = &W> + '_ { | 729 | pub fn windows_for_output(&self, output: &Output) -> impl Iterator<Item = &W> + '_ { |
| 647 | - let MonitorSet::Normal { monitors, .. } = self else { | 730 | + let MonitorSet::Normal { monitors, .. } = &self.monitor_set else { |
| 648 | panic!() | 731 | panic!() |
| 649 | }; | 732 | }; |
| 650 | 733 | ||
| @@ -657,7 +740,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 657 | monitors, | 740 | monitors, |
| 658 | active_monitor_idx, | 741 | active_monitor_idx, |
| 659 | .. | 742 | .. |
| 660 | - } = self | 743 | + } = &mut self.monitor_set |
| 661 | else { | 744 | else { |
| 662 | return None; | 745 | return None; |
| 663 | }; | 746 | }; |
| @@ -666,7 +749,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 666 | } | 749 | } |
| 667 | 750 | ||
| 668 | pub fn monitor_for_output(&self, output: &Output) -> Option<&Monitor<W>> { | 751 | pub fn monitor_for_output(&self, output: &Output) -> Option<&Monitor<W>> { |
| 669 | - let MonitorSet::Normal { monitors, .. } = self else { | 752 | + let MonitorSet::Normal { monitors, .. } = &self.monitor_set else { |
| 670 | return None; | 753 | return None; |
| 671 | }; | 754 | }; |
| 672 | 755 | ||
| @@ -674,7 +757,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 674 | } | 757 | } |
| 675 | 758 | ||
| 676 | pub fn outputs(&self) -> impl Iterator<Item = &Output> + '_ { | 759 | pub fn outputs(&self) -> impl Iterator<Item = &Output> + '_ { |
| 677 | - let monitors = if let MonitorSet::Normal { monitors, .. } = self { | 760 | + let monitors = if let MonitorSet::Normal { monitors, .. } = &self.monitor_set { |
| 678 | &monitors[..] | 761 | &monitors[..] |
| 679 | } else { | 762 | } else { |
| 680 | &[][..] | 763 | &[][..] |
| @@ -800,7 +883,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 800 | monitors, | 883 | monitors, |
| 801 | active_monitor_idx, | 884 | active_monitor_idx, |
| 802 | .. | 885 | .. |
| 803 | - } = self | 886 | + } = &self.monitor_set |
| 804 | else { | 887 | else { |
| 805 | return None; | 888 | return None; |
| 806 | }; | 889 | }; |
| @@ -819,19 +902,24 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 819 | 902 | ||
| 820 | #[cfg(test)] | 903 | #[cfg(test)] |
| 821 | fn verify_invariants(&self) { | 904 | fn verify_invariants(&self) { |
| 822 | - let (monitors, &primary_idx, &active_monitor_idx) = match &self { | 905 | + let (monitors, &primary_idx, &active_monitor_idx) = match &self.monitor_set { |
| 823 | MonitorSet::Normal { | 906 | MonitorSet::Normal { |
| 824 | monitors, | 907 | monitors, |
| 825 | primary_idx, | 908 | primary_idx, |
| 826 | active_monitor_idx, | 909 | active_monitor_idx, |
| 827 | } => (monitors, primary_idx, active_monitor_idx), | 910 | } => (monitors, primary_idx, active_monitor_idx), |
| 828 | - MonitorSet::NoOutputs(workspaces) => { | 911 | + MonitorSet::NoOutputs { workspaces } => { |
| 829 | for workspace in workspaces { | 912 | for workspace in workspaces { |
| 830 | assert!( | 913 | assert!( |
| 831 | workspace.has_windows(), | 914 | workspace.has_windows(), |
| 832 | "with no outputs there cannot be empty workspaces" | 915 | "with no outputs there cannot be empty workspaces" |
| 833 | ); | 916 | ); |
| 834 | 917 | ||
| 918 | + assert_eq!( | ||
| 919 | + workspace.options, self.options, | ||
| 920 | + "workspace options must be synchronized with layout" | ||
| 921 | + ); | ||
| 922 | + | ||
| 835 | workspace.verify_invariants(); | 923 | workspace.verify_invariants(); |
| 836 | } | 924 | } |
| 837 | 925 | ||
| @@ -849,6 +937,11 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 849 | ); | 937 | ); |
| 850 | assert!(monitor.active_workspace_idx < monitor.workspaces.len()); | 938 | assert!(monitor.active_workspace_idx < monitor.workspaces.len()); |
| 851 | 939 | ||
| 940 | + assert_eq!( | ||
| 941 | + monitor.options, self.options, | ||
| 942 | + "monitor options must be synchronized with layout" | ||
| 943 | + ); | ||
| 944 | + | ||
| 852 | let monitor_id = OutputId::new(&monitor.output); | 945 | let monitor_id = OutputId::new(&monitor.output); |
| 853 | 946 | ||
| 854 | if idx == primary_idx { | 947 | if idx == primary_idx { |
| @@ -866,13 +959,18 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 866 | // exists. | 959 | // exists. |
| 867 | 960 | ||
| 868 | for workspace in &monitor.workspaces { | 961 | for workspace in &monitor.workspaces { |
| 962 | + assert_eq!( | ||
| 963 | + workspace.options, self.options, | ||
| 964 | + "workspace options must be synchronized with layout" | ||
| 965 | + ); | ||
| 966 | + | ||
| 869 | workspace.verify_invariants(); | 967 | workspace.verify_invariants(); |
| 870 | } | 968 | } |
| 871 | } | 969 | } |
| 872 | } | 970 | } |
| 873 | 971 | ||
| 874 | pub fn advance_animations(&mut self, current_time: Duration) { | 972 | pub fn advance_animations(&mut self, current_time: Duration) { |
| 875 | - match self { | 973 | + match &mut self.monitor_set { |
| 876 | MonitorSet::Normal { | 974 | MonitorSet::Normal { |
| 877 | monitors, | 975 | monitors, |
| 878 | active_monitor_idx, | 976 | active_monitor_idx, |
| @@ -882,7 +980,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 882 | mon.advance_animations(current_time, idx == *active_monitor_idx); | 980 | mon.advance_animations(current_time, idx == *active_monitor_idx); |
| 883 | } | 981 | } |
| 884 | } | 982 | } |
| 885 | - MonitorSet::NoOutputs(workspaces) => { | 983 | + MonitorSet::NoOutputs { workspaces, .. } => { |
| 886 | for ws in workspaces { | 984 | for ws in workspaces { |
| 887 | ws.advance_animations(current_time, false); | 985 | ws.advance_animations(current_time, false); |
| 888 | } | 986 | } |
| @@ -891,18 +989,22 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 891 | } | 989 | } |
| 892 | 990 | ||
| 893 | pub fn update_config(&mut self, config: &Config) { | 991 | pub fn update_config(&mut self, config: &Config) { |
| 894 | - match self { | 992 | + let options = Rc::new(Options::from_config(config)); |
| 993 | + | ||
| 994 | + match &mut self.monitor_set { | ||
| 895 | MonitorSet::Normal { monitors, .. } => { | 995 | MonitorSet::Normal { monitors, .. } => { |
| 896 | for mon in monitors { | 996 | for mon in monitors { |
| 897 | - mon.update_config(config); | 997 | + mon.update_config(options.clone()); |
| 898 | } | 998 | } |
| 899 | } | 999 | } |
| 900 | - MonitorSet::NoOutputs(workspaces) => { | 1000 | + MonitorSet::NoOutputs { workspaces } => { |
| 901 | for ws in workspaces { | 1001 | for ws in workspaces { |
| 902 | - ws.update_config(config); | 1002 | + ws.update_config(options.clone()); |
| 903 | } | 1003 | } |
| 904 | } | 1004 | } |
| 905 | } | 1005 | } |
| 1006 | + | ||
| 1007 | + self.options = options; | ||
| 906 | } | 1008 | } |
| 907 | 1009 | ||
| 908 | pub fn toggle_width(&mut self) { | 1010 | pub fn toggle_width(&mut self) { |
| @@ -931,7 +1033,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 931 | monitors, | 1033 | monitors, |
| 932 | active_monitor_idx, | 1034 | active_monitor_idx, |
| 933 | .. | 1035 | .. |
| 934 | - } = self | 1036 | + } = &mut self.monitor_set |
| 935 | { | 1037 | { |
| 936 | for (idx, mon) in monitors.iter().enumerate() { | 1038 | for (idx, mon) in monitors.iter().enumerate() { |
| 937 | if &mon.output == output { | 1039 | if &mon.output == output { |
| @@ -947,7 +1049,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 947 | monitors, | 1049 | monitors, |
| 948 | active_monitor_idx, | 1050 | active_monitor_idx, |
| 949 | .. | 1051 | .. |
| 950 | - } = self | 1052 | + } = &mut self.monitor_set |
| 951 | { | 1053 | { |
| 952 | let new_idx = monitors | 1054 | let new_idx = monitors |
| 953 | .iter() | 1055 | .iter() |
| @@ -971,7 +1073,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 971 | pub fn move_window_to_output(&mut self, window: W, output: &Output) { | 1073 | pub fn move_window_to_output(&mut self, window: W, output: &Output) { |
| 972 | self.remove_window(&window); | 1074 | self.remove_window(&window); |
| 973 | 1075 | ||
| 974 | - if let MonitorSet::Normal { monitors, .. } = self { | 1076 | + if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { |
| 975 | let new_idx = monitors | 1077 | let new_idx = monitors |
| 976 | .iter() | 1078 | .iter() |
| 977 | .position(|mon| &mon.output == output) | 1079 | .position(|mon| &mon.output == output) |
| @@ -984,7 +1086,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 984 | } | 1086 | } |
| 985 | 1087 | ||
| 986 | pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) { | 1088 | pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) { |
| 987 | - match self { | 1089 | + match &mut self.monitor_set { |
| 988 | MonitorSet::Normal { monitors, .. } => { | 1090 | MonitorSet::Normal { monitors, .. } => { |
| 989 | for mon in monitors { | 1091 | for mon in monitors { |
| 990 | for ws in &mut mon.workspaces { | 1092 | for ws in &mut mon.workspaces { |
| @@ -995,7 +1097,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 995 | } | 1097 | } |
| 996 | } | 1098 | } |
| 997 | } | 1099 | } |
| 998 | - MonitorSet::NoOutputs(workspaces) => { | 1100 | + MonitorSet::NoOutputs { workspaces, .. } => { |
| 999 | for ws in workspaces { | 1101 | for ws in workspaces { |
| 1000 | if ws.has_window(window) { | 1102 | if ws.has_window(window) { |
| 1001 | ws.set_fullscreen(window, is_fullscreen); | 1103 | ws.set_fullscreen(window, is_fullscreen); |
| @@ -1007,7 +1109,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 1007 | } | 1109 | } |
| 1008 | 1110 | ||
| 1009 | pub fn toggle_fullscreen(&mut self, window: &W) { | 1111 | pub fn toggle_fullscreen(&mut self, window: &W) { |
| 1010 | - match self { | 1112 | + match &mut self.monitor_set { |
| 1011 | MonitorSet::Normal { monitors, .. } => { | 1113 | MonitorSet::Normal { monitors, .. } => { |
| 1012 | for mon in monitors { | 1114 | for mon in monitors { |
| 1013 | for ws in &mut mon.workspaces { | 1115 | for ws in &mut mon.workspaces { |
| @@ -1018,7 +1120,7 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 1018 | } | 1120 | } |
| 1019 | } | 1121 | } |
| 1020 | } | 1122 | } |
| 1021 | - MonitorSet::NoOutputs(workspaces) => { | 1123 | + MonitorSet::NoOutputs { workspaces, .. } => { |
| 1022 | for ws in workspaces { | 1124 | for ws in workspaces { |
| 1023 | if ws.has_window(window) { | 1125 | if ws.has_window(window) { |
| 1024 | ws.toggle_fullscreen(window); | 1126 | ws.toggle_fullscreen(window); |
| @@ -1030,11 +1132,11 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 1030 | } | 1132 | } |
| 1031 | } | 1133 | } |
| 1032 | 1134 | ||
| 1033 | -impl MonitorSet<Window> { | 1135 | +impl Layout<Window> { |
| 1034 | pub fn refresh(&self) { | 1136 | pub fn refresh(&self) { |
| 1035 | let _span = tracy_client::span!("MonitorSet::refresh"); | 1137 | let _span = tracy_client::span!("MonitorSet::refresh"); |
| 1036 | 1138 | ||
| 1037 | - match self { | 1139 | + match &self.monitor_set { |
| 1038 | MonitorSet::Normal { monitors, .. } => { | 1140 | MonitorSet::Normal { monitors, .. } => { |
| 1039 | for mon in monitors { | 1141 | for mon in monitors { |
| 1040 | for ws in &mon.workspaces { | 1142 | for ws in &mon.workspaces { |
| @@ -1042,7 +1144,7 @@ impl MonitorSet<Window> { | |||
| 1042 | } | 1144 | } |
| 1043 | } | 1145 | } |
| 1044 | } | 1146 | } |
| 1045 | - MonitorSet::NoOutputs(workspaces) => { | 1147 | + MonitorSet::NoOutputs { workspaces, .. } => { |
| 1046 | for ws in workspaces { | 1148 | for ws in workspaces { |
| 1047 | ws.refresh(); | 1149 | ws.refresh(); |
| 1048 | } | 1150 | } |
| @@ -1053,17 +1155,18 @@ impl MonitorSet<Window> { | |||
| 1053 | 1155 | ||
| 1054 | impl<W: LayoutElement> Default for MonitorSet<W> { | 1156 | impl<W: LayoutElement> Default for MonitorSet<W> { |
| 1055 | fn default() -> Self { | 1157 | fn default() -> Self { |
| 1056 | - Self::new() | 1158 | + Self::NoOutputs { workspaces: vec![] } |
| 1057 | } | 1159 | } |
| 1058 | } | 1160 | } |
| 1059 | 1161 | ||
| 1060 | impl<W: LayoutElement> Monitor<W> { | 1162 | impl<W: LayoutElement> Monitor<W> { |
| 1061 | - fn new(output: Output, workspaces: Vec<Workspace<W>>) -> Self { | 1163 | + fn new(output: Output, workspaces: Vec<Workspace<W>>, options: Rc<Options>) -> Self { |
| 1062 | Self { | 1164 | Self { |
| 1063 | output, | 1165 | output, |
| 1064 | workspaces, | 1166 | workspaces, |
| 1065 | active_workspace_idx: 0, | 1167 | active_workspace_idx: 0, |
| 1066 | workspace_idx_anim: None, | 1168 | workspace_idx_anim: None, |
| 1169 | + options, | ||
| 1067 | } | 1170 | } |
| 1068 | } | 1171 | } |
| 1069 | 1172 | ||
| @@ -1101,7 +1204,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1101 | 1204 | ||
| 1102 | if workspace_idx == self.workspaces.len() - 1 { | 1205 | if workspace_idx == self.workspaces.len() - 1 { |
| 1103 | // Insert a new empty workspace. | 1206 | // Insert a new empty workspace. |
| 1104 | - let ws = Workspace::new(self.output.clone()); | 1207 | + let ws = Workspace::new(self.output.clone(), self.options.clone()); |
| 1105 | self.workspaces.push(ws); | 1208 | self.workspaces.push(ws); |
| 1106 | } | 1209 | } |
| 1107 | 1210 | ||
| @@ -1279,10 +1382,12 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1279 | || self.workspaces.iter().any(|ws| ws.are_animations_ongoing()) | 1382 | || self.workspaces.iter().any(|ws| ws.are_animations_ongoing()) |
| 1280 | } | 1383 | } |
| 1281 | 1384 | ||
| 1282 | - pub fn update_config(&mut self, config: &Config) { | 1385 | + fn update_config(&mut self, options: Rc<Options>) { |
| 1283 | for ws in &mut self.workspaces { | 1386 | for ws in &mut self.workspaces { |
| 1284 | - ws.update_config(config); | 1387 | + ws.update_config(options.clone()); |
| 1285 | } | 1388 | } |
| 1389 | + | ||
| 1390 | + self.options = options; | ||
| 1286 | } | 1391 | } |
| 1287 | 1392 | ||
| 1288 | fn toggle_width(&mut self) { | 1393 | fn toggle_width(&mut self) { |
| @@ -1366,7 +1471,7 @@ impl Monitor<Window> { | |||
| 1366 | } | 1471 | } |
| 1367 | 1472 | ||
| 1368 | impl<W: LayoutElement> Workspace<W> { | 1473 | impl<W: LayoutElement> Workspace<W> { |
| 1369 | - fn new(output: Output) -> Self { | 1474 | + fn new(output: Output, options: Rc<Options>) -> Self { |
| 1370 | let working_area = layer_map_for_output(&output).non_exclusive_zone(); | 1475 | let working_area = layer_map_for_output(&output).non_exclusive_zone(); |
| 1371 | Self { | 1476 | Self { |
| 1372 | original_output: OutputId::new(&output), | 1477 | original_output: OutputId::new(&output), |
| @@ -1375,14 +1480,15 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1375 | output: Some(output), | 1480 | output: Some(output), |
| 1376 | columns: vec![], | 1481 | columns: vec![], |
| 1377 | active_column_idx: 0, | 1482 | active_column_idx: 0, |
| 1378 | - focus_ring: FocusRing::default(), | 1483 | + focus_ring: FocusRing::new(options.focus_ring), |
| 1379 | view_offset: 0, | 1484 | view_offset: 0, |
| 1380 | view_offset_anim: None, | 1485 | view_offset_anim: None, |
| 1381 | activate_prev_column_on_removal: false, | 1486 | activate_prev_column_on_removal: false, |
| 1487 | + options, | ||
| 1382 | } | 1488 | } |
| 1383 | } | 1489 | } |
| 1384 | 1490 | ||
| 1385 | - fn new_no_outputs() -> Self { | 1491 | + fn new_no_outputs(options: Rc<Options>) -> Self { |
| 1386 | Self { | 1492 | Self { |
| 1387 | output: None, | 1493 | output: None, |
| 1388 | original_output: OutputId(String::new()), | 1494 | original_output: OutputId(String::new()), |
| @@ -1390,10 +1496,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1390 | working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)), | 1496 | working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)), |
| 1391 | columns: vec![], | 1497 | columns: vec![], |
| 1392 | active_column_idx: 0, | 1498 | active_column_idx: 0, |
| 1393 | - focus_ring: FocusRing::default(), | 1499 | + focus_ring: FocusRing::new(options.focus_ring), |
| 1394 | view_offset: 0, | 1500 | view_offset: 0, |
| 1395 | view_offset_anim: None, | 1501 | view_offset_anim: None, |
| 1396 | activate_prev_column_on_removal: false, | 1502 | activate_prev_column_on_removal: false, |
| 1503 | + options, | ||
| 1397 | } | 1504 | } |
| 1398 | } | 1505 | } |
| 1399 | 1506 | ||
| @@ -1423,13 +1530,19 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1423 | self.view_offset_anim.is_some() | 1530 | self.view_offset_anim.is_some() |
| 1424 | } | 1531 | } |
| 1425 | 1532 | ||
| 1426 | - pub fn update_config(&mut self, config: &Config) { | 1533 | + fn update_config(&mut self, options: Rc<Options>) { |
| 1427 | - let c = &config.focus_ring; | 1534 | + let c = &options.focus_ring; |
| 1428 | self.focus_ring.is_off = c.off; | 1535 | self.focus_ring.is_off = c.off; |
| 1429 | self.focus_ring.width = c.width.into(); | 1536 | self.focus_ring.width = c.width.into(); |
| 1430 | self.focus_ring.active_color = c.active_color; | 1537 | self.focus_ring.active_color = c.active_color; |
| 1431 | self.focus_ring.inactive_color = c.inactive_color; | 1538 | self.focus_ring.inactive_color = c.inactive_color; |
| 1432 | // The focus ring buffer will be updated in a subsequent update_animations call. | 1539 | // The focus ring buffer will be updated in a subsequent update_animations call. |
| 1540 | + | ||
| 1541 | + for column in &mut self.columns { | ||
| 1542 | + column.update_config(options.clone()); | ||
| 1543 | + } | ||
| 1544 | + | ||
| 1545 | + self.options = options; | ||
| 1433 | } | 1546 | } |
| 1434 | 1547 | ||
| 1435 | fn windows(&self) -> impl Iterator<Item = &W> + '_ { | 1548 | fn windows(&self) -> impl Iterator<Item = &W> + '_ { |
| @@ -1482,6 +1595,24 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1482 | } | 1595 | } |
| 1483 | } | 1596 | } |
| 1484 | 1597 | ||
| 1598 | + pub fn configure_new_window(&self, window: &Window) { | ||
| 1599 | + let width = ColumnWidth::default() | ||
| 1600 | + .resolve(&self.options, self.working_area.size.w - PADDING) | ||
| 1601 | + - PADDING; | ||
| 1602 | + let height = self.working_area.size.h - PADDING * 2; | ||
| 1603 | + let size = Size::from((max(width, 1), max(height, 1))); | ||
| 1604 | + | ||
| 1605 | + let bounds = Size::from(( | ||
| 1606 | + self.working_area.size.w - PADDING * 2, | ||
| 1607 | + self.working_area.size.h - PADDING * 2, | ||
| 1608 | + )); | ||
| 1609 | + | ||
| 1610 | + window.toplevel().with_pending_state(|state| { | ||
| 1611 | + state.size = Some(size); | ||
| 1612 | + state.bounds = Some(bounds); | ||
| 1613 | + }); | ||
| 1614 | + } | ||
| 1615 | + | ||
| 1485 | fn activate_column(&mut self, idx: usize) { | 1616 | fn activate_column(&mut self, idx: usize) { |
| 1486 | if self.active_column_idx == idx { | 1617 | if self.active_column_idx == idx { |
| 1487 | return; | 1618 | return; |
| @@ -1549,7 +1680,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1549 | self.active_column_idx + 1 | 1680 | self.active_column_idx + 1 |
| 1550 | }; | 1681 | }; |
| 1551 | 1682 | ||
| 1552 | - let column = Column::new(window, self.view_size, self.working_area); | 1683 | + let column = Column::new( |
| 1684 | + window, | ||
| 1685 | + self.view_size, | ||
| 1686 | + self.working_area, | ||
| 1687 | + self.options.clone(), | ||
| 1688 | + ); | ||
| 1553 | self.columns.insert(idx, column); | 1689 | self.columns.insert(idx, column); |
| 1554 | 1690 | ||
| 1555 | if activate { | 1691 | if activate { |
| @@ -1923,7 +2059,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1923 | col_idx += 1; | 2059 | col_idx += 1; |
| 1924 | self.columns.insert( | 2060 | self.columns.insert( |
| 1925 | col_idx, | 2061 | col_idx, |
| 1926 | - Column::new(window, self.view_size, self.working_area), | 2062 | + Column::new( |
| 2063 | + window, | ||
| 2064 | + self.view_size, | ||
| 2065 | + self.working_area, | ||
| 2066 | + self.options.clone(), | ||
| 2067 | + ), | ||
| 1927 | ); | 2068 | ); |
| 1928 | if self.active_column_idx >= col_idx || target_window_was_focused { | 2069 | if self.active_column_idx >= col_idx || target_window_was_focused { |
| 1929 | self.active_column_idx += 1; | 2070 | self.active_column_idx += 1; |
| @@ -2046,6 +2187,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2046 | window: W, | 2187 | window: W, |
| 2047 | view_size: Size<i32, Logical>, | 2188 | view_size: Size<i32, Logical>, |
| 2048 | working_area: Rectangle<i32, Logical>, | 2189 | working_area: Rectangle<i32, Logical>, |
| 2190 | + options: Rc<Options>, | ||
| 2049 | ) -> Self { | 2191 | ) -> Self { |
| 2050 | let mut rv = Self { | 2192 | let mut rv = Self { |
| 2051 | windows: vec![], | 2193 | windows: vec![], |
| @@ -2054,6 +2196,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2054 | is_fullscreen: false, | 2196 | is_fullscreen: false, |
| 2055 | view_size, | 2197 | view_size, |
| 2056 | working_area, | 2198 | working_area, |
| 2199 | + options, | ||
| 2057 | }; | 2200 | }; |
| 2058 | 2201 | ||
| 2059 | rv.add_window(window); | 2202 | rv.add_window(window); |
| @@ -2072,6 +2215,17 @@ impl<W: LayoutElement> Column<W> { | |||
| 2072 | self.update_window_sizes(); | 2215 | self.update_window_sizes(); |
| 2073 | } | 2216 | } |
| 2074 | 2217 | ||
| 2218 | + fn update_config(&mut self, options: Rc<Options>) { | ||
| 2219 | + // If preset widths changed, make our width non-preset. | ||
| 2220 | + if self.options.preset_widths != options.preset_widths { | ||
| 2221 | + if let ColumnWidth::Preset(idx) = self.width { | ||
| 2222 | + self.width = self.options.preset_widths[idx]; | ||
| 2223 | + } | ||
| 2224 | + } | ||
| 2225 | + | ||
| 2226 | + self.options = options; | ||
| 2227 | + } | ||
| 2228 | + | ||
| 2075 | fn window_count(&self) -> usize { | 2229 | fn window_count(&self) -> usize { |
| 2076 | self.windows.len() | 2230 | self.windows.len() |
| 2077 | } | 2231 | } |
| @@ -2130,7 +2284,10 @@ impl<W: LayoutElement> Column<W> { | |||
| 2130 | .unwrap_or(i32::MAX); | 2284 | .unwrap_or(i32::MAX); |
| 2131 | let max_width = max(max_width, min_width); | 2285 | let max_width = max(max_width, min_width); |
| 2132 | 2286 | ||
| 2133 | - let width = self.width.resolve(self.working_area.size.w - PADDING) - PADDING; | 2287 | + let width = self |
| 2288 | + .width | ||
| 2289 | + .resolve(&self.options, self.working_area.size.w - PADDING) | ||
| 2290 | + - PADDING; | ||
| 2134 | let height = (self.working_area.size.h - PADDING) / self.window_count() as i32 - PADDING; | 2291 | let height = (self.working_area.size.h - PADDING) / self.window_count() as i32 - PADDING; |
| 2135 | let size = Size::from((max(min(width, max_width), min_width), max(height, 1))); | 2292 | let size = Size::from((max(min(width, max_width), min_width), max(height, 1))); |
| 2136 | 2293 | ||
| @@ -2192,18 +2349,20 @@ impl<W: LayoutElement> Column<W> { | |||
| 2192 | 2349 | ||
| 2193 | fn toggle_width(&mut self) { | 2350 | fn toggle_width(&mut self) { |
| 2194 | let idx = match self.width { | 2351 | let idx = match self.width { |
| 2195 | - ColumnWidth::PresetProportion(idx) => (idx + 1) % WIDTH_PROPORTIONS.len(), | 2352 | + ColumnWidth::Preset(idx) => (idx + 1) % self.options.preset_widths.len(), |
| 2196 | _ => { | 2353 | _ => { |
| 2197 | let current = self.size().w; | 2354 | let current = self.size().w; |
| 2198 | - WIDTH_PROPORTIONS | 2355 | + self.options |
| 2199 | - .into_iter() | 2356 | + .preset_widths |
| 2357 | + .iter() | ||
| 2200 | .position(|prop| { | 2358 | .position(|prop| { |
| 2201 | - prop.resolve(self.working_area.size.w - PADDING) - PADDING > current | 2359 | + prop.resolve(&self.options, self.working_area.size.w - PADDING) - PADDING |
| 2360 | + > current | ||
| 2202 | }) | 2361 | }) |
| 2203 | .unwrap_or(0) | 2362 | .unwrap_or(0) |
| 2204 | } | 2363 | } |
| 2205 | }; | 2364 | }; |
| 2206 | - let width = ColumnWidth::PresetProportion(idx); | 2365 | + let width = ColumnWidth::Preset(idx); |
| 2207 | self.set_width(width); | 2366 | self.set_width(width); |
| 2208 | } | 2367 | } |
| 2209 | 2368 | ||
| @@ -2219,10 +2378,13 @@ impl<W: LayoutElement> Column<W> { | |||
| 2219 | } | 2378 | } |
| 2220 | 2379 | ||
| 2221 | fn set_column_width(&mut self, change: SizeChange) { | 2380 | fn set_column_width(&mut self, change: SizeChange) { |
| 2222 | - let current_px = self.width.resolve(self.working_area.size.w - PADDING) - PADDING; | 2381 | + let current_px = self |
| 2382 | + .width | ||
| 2383 | + .resolve(&self.options, self.working_area.size.w - PADDING) | ||
| 2384 | + - PADDING; | ||
| 2223 | 2385 | ||
| 2224 | let current = match self.width { | 2386 | let current = match self.width { |
| 2225 | - ColumnWidth::PresetProportion(idx) => WIDTH_PROPORTIONS[idx], | 2387 | + ColumnWidth::Preset(idx) => self.options.preset_widths[idx], |
| 2226 | current => current, | 2388 | current => current, |
| 2227 | }; | 2389 | }; |
| 2228 | 2390 | ||
| @@ -2249,7 +2411,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2249 | let proportion = (current + delta / 100.).clamp(0., MAX_F); | 2411 | let proportion = (current + delta / 100.).clamp(0., MAX_F); |
| 2250 | ColumnWidth::Proportion(proportion) | 2412 | ColumnWidth::Proportion(proportion) |
| 2251 | } | 2413 | } |
| 2252 | - (ColumnWidth::PresetProportion(_), _) => unreachable!(), | 2414 | + (ColumnWidth::Preset(_), _) => unreachable!(), |
| 2253 | }; | 2415 | }; |
| 2254 | 2416 | ||
| 2255 | self.set_width(width); | 2417 | self.set_width(width); |
| @@ -2286,22 +2448,6 @@ pub fn output_size(output: &Output) -> Size<i32, Logical> { | |||
| 2286 | .to_logical(output_scale) | 2448 | .to_logical(output_scale) |
| 2287 | } | 2449 | } |
| 2288 | 2450 | ||
| 2289 | -pub fn configure_new_window(working_area: Rectangle<i32, Logical>, window: &Window) { | ||
| 2290 | - let width = ColumnWidth::default().resolve(working_area.size.w - PADDING) - PADDING; | ||
| 2291 | - let height = working_area.size.h - PADDING * 2; | ||
| 2292 | - let size = Size::from((max(width, 1), max(height, 1))); | ||
| 2293 | - | ||
| 2294 | - let bounds = Size::from(( | ||
| 2295 | - working_area.size.w - PADDING * 2, | ||
| 2296 | - working_area.size.h - PADDING * 2, | ||
| 2297 | - )); | ||
| 2298 | - | ||
| 2299 | - window.toplevel().with_pending_state(|state| { | ||
| 2300 | - state.size = Some(size); | ||
| 2301 | - state.bounds = Some(bounds); | ||
| 2302 | - }); | ||
| 2303 | -} | ||
| 2304 | - | ||
| 2305 | fn compute_new_view_offset(cur_x: i32, view_width: i32, new_x: i32, new_col_width: i32) -> i32 { | 2451 | fn compute_new_view_offset(cur_x: i32, view_width: i32, new_x: i32, new_col_width: i32) -> i32 { |
| 2306 | // If the column is wider than the view, always left-align it. | 2452 | // If the column is wider than the view, always left-align it. |
| 2307 | if new_col_width + PADDING * 2 >= view_width { | 2453 | if new_col_width + PADDING * 2 >= view_width { |
| @@ -2335,6 +2481,15 @@ mod tests { | |||
| 2335 | 2481 | ||
| 2336 | use super::*; | 2482 | use super::*; |
| 2337 | 2483 | ||
| 2484 | + impl<W: LayoutElement> Default for Layout<W> { | ||
| 2485 | + fn default() -> Self { | ||
| 2486 | + Self { | ||
| 2487 | + monitor_set: MonitorSet::NoOutputs { workspaces: vec![] }, | ||
| 2488 | + options: Rc::new(Options::default()), | ||
| 2489 | + } | ||
| 2490 | + } | ||
| 2491 | + } | ||
| 2492 | + | ||
| 2338 | #[derive(Debug)] | 2493 | #[derive(Debug)] |
| 2339 | struct TestWindowInner { | 2494 | struct TestWindowInner { |
| 2340 | id: usize, | 2495 | id: usize, |
| @@ -2480,11 +2635,11 @@ mod tests { | |||
| 2480 | } | 2635 | } |
| 2481 | 2636 | ||
| 2482 | impl Op { | 2637 | impl Op { |
| 2483 | - fn apply(self, monitor_set: &mut MonitorSet<TestWindow>) { | 2638 | + fn apply(self, layout: &mut Layout<TestWindow>) { |
| 2484 | match self { | 2639 | match self { |
| 2485 | Op::AddOutput(id) => { | 2640 | Op::AddOutput(id) => { |
| 2486 | let name = format!("output{id}"); | 2641 | let name = format!("output{id}"); |
| 2487 | - if monitor_set.outputs().any(|o| o.name() == name) { | 2642 | + if layout.outputs().any(|o| o.name() == name) { |
| 2488 | return; | 2643 | return; |
| 2489 | } | 2644 | } |
| 2490 | 2645 | ||
| @@ -2506,69 +2661,66 @@ mod tests { | |||
| 2506 | None, | 2661 | None, |
| 2507 | None, | 2662 | None, |
| 2508 | ); | 2663 | ); |
| 2509 | - monitor_set.add_output(output.clone()); | 2664 | + layout.add_output(output.clone()); |
| 2510 | } | 2665 | } |
| 2511 | Op::RemoveOutput(id) => { | 2666 | Op::RemoveOutput(id) => { |
| 2512 | let name = format!("output{id}"); | 2667 | let name = format!("output{id}"); |
| 2513 | - let Some(output) = monitor_set.outputs().find(|o| o.name() == name).cloned() | 2668 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { |
| 2514 | - else { | ||
| 2515 | return; | 2669 | return; |
| 2516 | }; | 2670 | }; |
| 2517 | 2671 | ||
| 2518 | - monitor_set.remove_output(&output); | 2672 | + layout.remove_output(&output); |
| 2519 | } | 2673 | } |
| 2520 | Op::FocusOutput(id) => { | 2674 | Op::FocusOutput(id) => { |
| 2521 | let name = format!("output{id}"); | 2675 | let name = format!("output{id}"); |
| 2522 | - let Some(output) = monitor_set.outputs().find(|o| o.name() == name).cloned() | 2676 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { |
| 2523 | - else { | ||
| 2524 | return; | 2677 | return; |
| 2525 | }; | 2678 | }; |
| 2526 | 2679 | ||
| 2527 | - monitor_set.focus_output(&output); | 2680 | + layout.focus_output(&output); |
| 2528 | } | 2681 | } |
| 2529 | Op::AddWindow { id, bbox, activate } => { | 2682 | Op::AddWindow { id, bbox, activate } => { |
| 2530 | let win = TestWindow::new(id, bbox); | 2683 | let win = TestWindow::new(id, bbox); |
| 2531 | - monitor_set.add_window(win, activate); | 2684 | + layout.add_window(win, activate); |
| 2532 | } | 2685 | } |
| 2533 | Op::CloseWindow(id) => { | 2686 | Op::CloseWindow(id) => { |
| 2534 | let dummy = TestWindow::new(id, Rectangle::default()); | 2687 | let dummy = TestWindow::new(id, Rectangle::default()); |
| 2535 | - monitor_set.remove_window(&dummy); | 2688 | + layout.remove_window(&dummy); |
| 2536 | } | 2689 | } |
| 2537 | Op::FullscreenWindow(id) => { | 2690 | Op::FullscreenWindow(id) => { |
| 2538 | let dummy = TestWindow::new(id, Rectangle::default()); | 2691 | let dummy = TestWindow::new(id, Rectangle::default()); |
| 2539 | - monitor_set.toggle_fullscreen(&dummy); | 2692 | + layout.toggle_fullscreen(&dummy); |
| 2540 | } | 2693 | } |
| 2541 | - Op::FocusColumnLeft => monitor_set.focus_left(), | 2694 | + Op::FocusColumnLeft => layout.focus_left(), |
| 2542 | - Op::FocusColumnRight => monitor_set.focus_right(), | 2695 | + Op::FocusColumnRight => layout.focus_right(), |
| 2543 | - Op::FocusWindowDown => monitor_set.focus_down(), | 2696 | + Op::FocusWindowDown => layout.focus_down(), |
| 2544 | - Op::FocusWindowUp => monitor_set.focus_up(), | 2697 | + Op::FocusWindowUp => layout.focus_up(), |
| 2545 | - Op::MoveColumnLeft => monitor_set.move_left(), | 2698 | + Op::MoveColumnLeft => layout.move_left(), |
| 2546 | - Op::MoveColumnRight => monitor_set.move_right(), | 2699 | + Op::MoveColumnRight => layout.move_right(), |
| 2547 | - Op::MoveWindowDown => monitor_set.move_down(), | 2700 | + Op::MoveWindowDown => layout.move_down(), |
| 2548 | - Op::MoveWindowUp => monitor_set.move_up(), | 2701 | + Op::MoveWindowUp => layout.move_up(), |
| 2549 | - Op::ConsumeWindowIntoColumn => monitor_set.consume_into_column(), | 2702 | + Op::ConsumeWindowIntoColumn => layout.consume_into_column(), |
| 2550 | - Op::ExpelWindowFromColumn => monitor_set.expel_from_column(), | 2703 | + Op::ExpelWindowFromColumn => layout.expel_from_column(), |
| 2551 | - Op::FocusWorkspaceDown => monitor_set.switch_workspace_down(), | 2704 | + Op::FocusWorkspaceDown => layout.switch_workspace_down(), |
| 2552 | - Op::FocusWorkspaceUp => monitor_set.switch_workspace_up(), | 2705 | + Op::FocusWorkspaceUp => layout.switch_workspace_up(), |
| 2553 | - Op::FocusWorkspace(idx) => monitor_set.switch_workspace(idx), | 2706 | + Op::FocusWorkspace(idx) => layout.switch_workspace(idx), |
| 2554 | - Op::MoveWindowToWorkspaceDown => monitor_set.move_to_workspace_down(), | 2707 | + Op::MoveWindowToWorkspaceDown => layout.move_to_workspace_down(), |
| 2555 | - Op::MoveWindowToWorkspaceUp => monitor_set.move_to_workspace_up(), | 2708 | + Op::MoveWindowToWorkspaceUp => layout.move_to_workspace_up(), |
| 2556 | - Op::MoveWindowToWorkspace(idx) => monitor_set.move_to_workspace(idx), | 2709 | + Op::MoveWindowToWorkspace(idx) => layout.move_to_workspace(idx), |
| 2557 | Op::MoveWindowToOutput(id) => { | 2710 | Op::MoveWindowToOutput(id) => { |
| 2558 | let name = format!("output{id}"); | 2711 | let name = format!("output{id}"); |
| 2559 | - let Some(output) = monitor_set.outputs().find(|o| o.name() == name).cloned() | 2712 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { |
| 2560 | - else { | ||
| 2561 | return; | 2713 | return; |
| 2562 | }; | 2714 | }; |
| 2563 | 2715 | ||
| 2564 | - monitor_set.move_to_output(&output); | 2716 | + layout.move_to_output(&output); |
| 2565 | } | 2717 | } |
| 2566 | - Op::SwitchPresetColumnWidth => monitor_set.toggle_width(), | 2718 | + Op::SwitchPresetColumnWidth => layout.toggle_width(), |
| 2567 | - Op::MaximizeColumn => monitor_set.toggle_full_width(), | 2719 | + Op::MaximizeColumn => layout.toggle_full_width(), |
| 2568 | - Op::SetColumnWidth(change) => monitor_set.set_column_width(change), | 2720 | + Op::SetColumnWidth(change) => layout.set_column_width(change), |
| 2569 | Op::Communicate(id) => { | 2721 | Op::Communicate(id) => { |
| 2570 | let mut window = None; | 2722 | let mut window = None; |
| 2571 | - match monitor_set { | 2723 | + match &mut layout.monitor_set { |
| 2572 | MonitorSet::Normal { monitors, .. } => { | 2724 | MonitorSet::Normal { monitors, .. } => { |
| 2573 | 'outer: for mon in monitors { | 2725 | 'outer: for mon in monitors { |
| 2574 | for ws in &mut mon.workspaces { | 2726 | for ws in &mut mon.workspaces { |
| @@ -2583,7 +2735,7 @@ mod tests { | |||
| 2583 | } | 2735 | } |
| 2584 | } | 2736 | } |
| 2585 | } | 2737 | } |
| 2586 | - MonitorSet::NoOutputs(workspaces) => { | 2738 | + MonitorSet::NoOutputs { workspaces, .. } => { |
| 2587 | 'outer: for ws in workspaces { | 2739 | 'outer: for ws in workspaces { |
| 2588 | for win in ws.windows() { | 2740 | for win in ws.windows() { |
| 2589 | if win.0.id == id { | 2741 | if win.0.id == id { |
| @@ -2598,7 +2750,7 @@ mod tests { | |||
| 2598 | } | 2750 | } |
| 2599 | 2751 | ||
| 2600 | if let Some(win) = window { | 2752 | if let Some(win) = window { |
| 2601 | - monitor_set.update_window(&win); | 2753 | + layout.update_window(&win); |
| 2602 | } | 2754 | } |
| 2603 | } | 2755 | } |
| 2604 | } | 2756 | } |
| @@ -2607,10 +2759,10 @@ mod tests { | |||
| 2607 | 2759 | ||
| 2608 | #[track_caller] | 2760 | #[track_caller] |
| 2609 | fn check_ops(ops: &[Op]) { | 2761 | fn check_ops(ops: &[Op]) { |
| 2610 | - let mut monitor_set = MonitorSet::default(); | 2762 | + let mut layout = Layout::default(); |
| 2611 | for op in ops { | 2763 | for op in ops { |
| 2612 | - op.apply(&mut monitor_set); | 2764 | + op.apply(&mut layout); |
| 2613 | - monitor_set.verify_invariants(); | 2765 | + layout.verify_invariants(); |
| 2614 | } | 2766 | } |
| 2615 | } | 2767 | } |
| 2616 | 2768 | ||
| @@ -2667,13 +2819,13 @@ mod tests { | |||
| 2667 | for first in every_op { | 2819 | for first in every_op { |
| 2668 | eprintln!("{first:?}, {second:?}, {third:?}"); | 2820 | eprintln!("{first:?}, {second:?}, {third:?}"); |
| 2669 | 2821 | ||
| 2670 | - let mut monitor_set = MonitorSet::default(); | 2822 | + let mut layout = Layout::default(); |
| 2671 | - first.apply(&mut monitor_set); | 2823 | + first.apply(&mut layout); |
| 2672 | - monitor_set.verify_invariants(); | 2824 | + layout.verify_invariants(); |
| 2673 | - second.apply(&mut monitor_set); | 2825 | + second.apply(&mut layout); |
| 2674 | - monitor_set.verify_invariants(); | 2826 | + layout.verify_invariants(); |
| 2675 | - third.apply(&mut monitor_set); | 2827 | + third.apply(&mut layout); |
| 2676 | - monitor_set.verify_invariants(); | 2828 | + layout.verify_invariants(); |
| 2677 | } | 2829 | } |
| 2678 | } | 2830 | } |
| 2679 | } | 2831 | } |
src/main.rsmodified+1 -1
| @@ -115,7 +115,7 @@ fn main() { | |||
| 115 | let _span = tracy_client::span!("loop callback"); | 115 | let _span = tracy_client::span!("loop callback"); |
| 116 | 116 | ||
| 117 | // These should be called periodically, before flushing the clients. | 117 | // These should be called periodically, before flushing the clients. |
| 118 | - state.niri.monitor_set.refresh(); | 118 | + state.niri.layout.refresh(); |
| 119 | state.niri.refresh_pointer_outputs(); | 119 | state.niri.refresh_pointer_outputs(); |
| 120 | state.niri.popups.cleanup(); | 120 | state.niri.popups.cleanup(); |
| 121 | state.update_focus(); | 121 | state.update_focus(); |
src/niri.rsmodified+25 -22
| @@ -82,7 +82,7 @@ use crate::dbus::mutter_display_config::DisplayConfig; | |||
| 82 | use crate::dbus::mutter_screen_cast::{self, ScreenCast, ToNiriMsg}; | 82 | use crate::dbus::mutter_screen_cast::{self, ScreenCast, ToNiriMsg}; |
| 83 | use crate::dbus::mutter_service_channel::ServiceChannel; | 83 | use crate::dbus::mutter_service_channel::ServiceChannel; |
| 84 | use crate::frame_clock::FrameClock; | 84 | use crate::frame_clock::FrameClock; |
| 85 | -use crate::layout::{output_size, MonitorRenderElement, MonitorSet}; | 85 | +use crate::layout::{output_size, Layout, MonitorRenderElement}; |
| 86 | use crate::pw_utils::{Cast, PipeWire}; | 86 | use crate::pw_utils::{Cast, PipeWire}; |
| 87 | use crate::utils::{center, get_monotonic_time, make_screenshot_path}; | 87 | use crate::utils::{center, get_monotonic_time, make_screenshot_path}; |
| 88 | 88 | ||
| @@ -95,7 +95,7 @@ pub struct Niri { | |||
| 95 | 95 | ||
| 96 | // Each workspace corresponds to a Space. Each workspace generally has one Output mapped to it, | 96 | // Each workspace corresponds to a Space. Each workspace generally has one Output mapped to it, |
| 97 | // however it may have none (when there are no outputs connected) or mutiple (when mirroring). | 97 | // however it may have none (when there are no outputs connected) or mutiple (when mirroring). |
| 98 | - pub monitor_set: MonitorSet<Window>, | 98 | + pub layout: Layout<Window>, |
| 99 | 99 | ||
| 100 | // This space does not actually contain any windows, but all outputs are mapped into it | 100 | // This space does not actually contain any windows, but all outputs are mapped into it |
| 101 | // according to their global position. | 101 | // according to their global position. |
| @@ -245,7 +245,7 @@ impl State { | |||
| 245 | pub fn update_focus(&mut self) { | 245 | pub fn update_focus(&mut self) { |
| 246 | let focus = self.niri.layer_surface_focus().or_else(|| { | 246 | let focus = self.niri.layer_surface_focus().or_else(|| { |
| 247 | self.niri | 247 | self.niri |
| 248 | - .monitor_set | 248 | + .layout |
| 249 | .focus() | 249 | .focus() |
| 250 | .map(|win| win.toplevel().wl_surface().clone()) | 250 | .map(|win| win.toplevel().wl_surface().clone()) |
| 251 | }); | 251 | }); |
| @@ -268,6 +268,8 @@ impl State { | |||
| 268 | } | 268 | } |
| 269 | }; | 269 | }; |
| 270 | 270 | ||
| 271 | + self.niri.layout.update_config(&config); | ||
| 272 | + | ||
| 271 | let mut old_config = self.niri.config.borrow_mut(); | 273 | let mut old_config = self.niri.config.borrow_mut(); |
| 272 | 274 | ||
| 273 | if config.cursor != old_config.cursor { | 275 | if config.cursor != old_config.cursor { |
| @@ -299,6 +301,8 @@ impl Niri { | |||
| 299 | let display_handle = display.handle(); | 301 | let display_handle = display.handle(); |
| 300 | let config_ = config.borrow(); | 302 | let config_ = config.borrow(); |
| 301 | 303 | ||
| 304 | + let layout = Layout::new(&config_); | ||
| 305 | + | ||
| 302 | let compositor_state = CompositorState::new::<State>(&display_handle); | 306 | let compositor_state = CompositorState::new::<State>(&display_handle); |
| 303 | let xdg_shell_state = XdgShellState::new_with_capabilities::<State>( | 307 | let xdg_shell_state = XdgShellState::new_with_capabilities::<State>( |
| 304 | &display_handle, | 308 | &display_handle, |
| @@ -677,7 +681,7 @@ impl Niri { | |||
| 677 | stop_signal, | 681 | stop_signal, |
| 678 | display_handle, | 682 | display_handle, |
| 679 | 683 | ||
| 680 | - monitor_set: MonitorSet::new(), | 684 | + layout, |
| 681 | global_space: Space::default(), | 685 | global_space: Space::default(), |
| 682 | output_state: HashMap::new(), | 686 | output_state: HashMap::new(), |
| 683 | output_by_name: HashMap::new(), | 687 | output_by_name: HashMap::new(), |
| @@ -780,7 +784,7 @@ impl Niri { | |||
| 780 | position.x, position.y | 784 | position.x, position.y |
| 781 | ); | 785 | ); |
| 782 | self.global_space.map_output(&output, position); | 786 | self.global_space.map_output(&output, position); |
| 783 | - self.monitor_set.add_output(output.clone()); | 787 | + self.layout.add_output(output.clone()); |
| 784 | 788 | ||
| 785 | let state = OutputState { | 789 | let state = OutputState { |
| 786 | global, | 790 | global, |
| @@ -796,7 +800,7 @@ impl Niri { | |||
| 796 | } | 800 | } |
| 797 | 801 | ||
| 798 | pub fn remove_output(&mut self, output: &Output) { | 802 | pub fn remove_output(&mut self, output: &Output) { |
| 799 | - self.monitor_set.remove_output(output); | 803 | + self.layout.remove_output(output); |
| 800 | self.global_space.unmap_output(output); | 804 | self.global_space.unmap_output(output); |
| 801 | // FIXME: reposition outputs so they are adjacent. | 805 | // FIXME: reposition outputs so they are adjacent. |
| 802 | 806 | ||
| @@ -834,7 +838,7 @@ impl Niri { | |||
| 834 | 838 | ||
| 835 | pub fn output_resized(&mut self, output: Output) { | 839 | pub fn output_resized(&mut self, output: Output) { |
| 836 | layer_map_for_output(&output).arrange(); | 840 | layer_map_for_output(&output).arrange(); |
| 837 | - self.monitor_set.update_output_size(&output); | 841 | + self.layout.update_output_size(&output); |
| 838 | self.queue_redraw(output); | 842 | self.queue_redraw(output); |
| 839 | } | 843 | } |
| 840 | 844 | ||
| @@ -854,7 +858,7 @@ impl Niri { | |||
| 854 | pub fn window_under_cursor(&self) -> Option<&Window> { | 858 | pub fn window_under_cursor(&self) -> Option<&Window> { |
| 855 | let pos = self.seat.get_pointer().unwrap().current_location(); | 859 | let pos = self.seat.get_pointer().unwrap().current_location(); |
| 856 | let (output, pos_within_output) = self.output_under(pos)?; | 860 | let (output, pos_within_output) = self.output_under(pos)?; |
| 857 | - let (window, _loc) = self.monitor_set.window_under(output, pos_within_output)?; | 861 | + let (window, _loc) = self.layout.window_under(output, pos_within_output)?; |
| 858 | Some(window) | 862 | Some(window) |
| 859 | } | 863 | } |
| 860 | 864 | ||
| @@ -869,7 +873,7 @@ impl Niri { | |||
| 869 | ) -> Option<(WlSurface, Point<i32, Logical>)> { | 873 | ) -> Option<(WlSurface, Point<i32, Logical>)> { |
| 870 | let (output, pos_within_output) = self.output_under(pos)?; | 874 | let (output, pos_within_output) = self.output_under(pos)?; |
| 871 | let (window, win_pos_within_output) = | 875 | let (window, win_pos_within_output) = |
| 872 | - self.monitor_set.window_under(output, pos_within_output)?; | 876 | + self.layout.window_under(output, pos_within_output)?; |
| 873 | 877 | ||
| 874 | let (surface, surface_pos_within_output) = window | 878 | let (surface, surface_pos_within_output) = window |
| 875 | .surface_under( | 879 | .surface_under( |
| @@ -889,7 +893,7 @@ impl Niri { | |||
| 889 | } | 893 | } |
| 890 | 894 | ||
| 891 | pub fn output_left(&self) -> Option<Output> { | 895 | pub fn output_left(&self) -> Option<Output> { |
| 892 | - let active = self.monitor_set.active_output()?; | 896 | + let active = self.layout.active_output()?; |
| 893 | let active_geo = self.global_space.output_geometry(active).unwrap(); | 897 | let active_geo = self.global_space.output_geometry(active).unwrap(); |
| 894 | let extended_geo = Rectangle::from_loc_and_size( | 898 | let extended_geo = Rectangle::from_loc_and_size( |
| 895 | (i32::MIN / 2, active_geo.loc.y), | 899 | (i32::MIN / 2, active_geo.loc.y), |
| @@ -906,7 +910,7 @@ impl Niri { | |||
| 906 | } | 910 | } |
| 907 | 911 | ||
| 908 | pub fn output_right(&self) -> Option<Output> { | 912 | pub fn output_right(&self) -> Option<Output> { |
| 909 | - let active = self.monitor_set.active_output()?; | 913 | + let active = self.layout.active_output()?; |
| 910 | let active_geo = self.global_space.output_geometry(active).unwrap(); | 914 | let active_geo = self.global_space.output_geometry(active).unwrap(); |
| 911 | let extended_geo = Rectangle::from_loc_and_size( | 915 | let extended_geo = Rectangle::from_loc_and_size( |
| 912 | (i32::MIN / 2, active_geo.loc.y), | 916 | (i32::MIN / 2, active_geo.loc.y), |
| @@ -923,7 +927,7 @@ impl Niri { | |||
| 923 | } | 927 | } |
| 924 | 928 | ||
| 925 | pub fn output_up(&self) -> Option<Output> { | 929 | pub fn output_up(&self) -> Option<Output> { |
| 926 | - let active = self.monitor_set.active_output()?; | 930 | + let active = self.layout.active_output()?; |
| 927 | let active_geo = self.global_space.output_geometry(active).unwrap(); | 931 | let active_geo = self.global_space.output_geometry(active).unwrap(); |
| 928 | let extended_geo = Rectangle::from_loc_and_size( | 932 | let extended_geo = Rectangle::from_loc_and_size( |
| 929 | (active_geo.loc.x, i32::MIN / 2), | 933 | (active_geo.loc.x, i32::MIN / 2), |
| @@ -940,7 +944,7 @@ impl Niri { | |||
| 940 | } | 944 | } |
| 941 | 945 | ||
| 942 | pub fn output_down(&self) -> Option<Output> { | 946 | pub fn output_down(&self) -> Option<Output> { |
| 943 | - let active = self.monitor_set.active_output()?; | 947 | + let active = self.layout.active_output()?; |
| 944 | let active_geo = self.global_space.output_geometry(active).unwrap(); | 948 | let active_geo = self.global_space.output_geometry(active).unwrap(); |
| 945 | let extended_geo = Rectangle::from_loc_and_size( | 949 | let extended_geo = Rectangle::from_loc_and_size( |
| 946 | (active_geo.loc.x, i32::MIN / 2), | 950 | (active_geo.loc.x, i32::MIN / 2), |
| @@ -965,7 +969,7 @@ impl Niri { | |||
| 965 | } | 969 | } |
| 966 | 970 | ||
| 967 | fn layer_surface_focus(&self) -> Option<WlSurface> { | 971 | fn layer_surface_focus(&self) -> Option<WlSurface> { |
| 968 | - let output = self.monitor_set.active_output()?; | 972 | + let output = self.layout.active_output()?; |
| 969 | let layers = layer_map_for_output(output); | 973 | let layers = layer_map_for_output(output); |
| 970 | let surface = layers | 974 | let surface = layers |
| 971 | .layers_on(Layer::Overlay) | 975 | .layers_on(Layer::Overlay) |
| @@ -1177,7 +1181,7 @@ impl Niri { | |||
| 1177 | let output_scale = Scale::from(output.current_scale().fractional_scale()); | 1181 | let output_scale = Scale::from(output.current_scale().fractional_scale()); |
| 1178 | 1182 | ||
| 1179 | // Get monitor elements. | 1183 | // Get monitor elements. |
| 1180 | - let mon = self.monitor_set.monitor_for_output(output).unwrap(); | 1184 | + let mon = self.layout.monitor_for_output(output).unwrap(); |
| 1181 | let monitor_elements = mon.render_elements(renderer); | 1185 | let monitor_elements = mon.render_elements(renderer); |
| 1182 | 1186 | ||
| 1183 | // The pointer goes on the top. | 1187 | // The pointer goes on the top. |
| @@ -1246,10 +1250,9 @@ impl Niri { | |||
| 1246 | let presentation_time = state.frame_clock.next_presentation_time(); | 1250 | let presentation_time = state.frame_clock.next_presentation_time(); |
| 1247 | 1251 | ||
| 1248 | // Update from the config and advance the animations. | 1252 | // Update from the config and advance the animations. |
| 1249 | - self.monitor_set.update_config(&self.config.borrow()); | 1253 | + self.layout.advance_animations(presentation_time); |
| 1250 | - self.monitor_set.advance_animations(presentation_time); | ||
| 1251 | state.unfinished_animations_remain = self | 1254 | state.unfinished_animations_remain = self |
| 1252 | - .monitor_set | 1255 | + .layout |
| 1253 | .monitor_for_output(output) | 1256 | .monitor_for_output(output) |
| 1254 | .unwrap() | 1257 | .unwrap() |
| 1255 | .are_animations_ongoing(); | 1258 | .are_animations_ongoing(); |
| @@ -1341,7 +1344,7 @@ impl Niri { | |||
| 1341 | // The reason to do this at all is that it keeps track of whether the surface is visible or | 1344 | // The reason to do this at all is that it keeps track of whether the surface is visible or |
| 1342 | // not in a unified way with the pointer surfaces, which makes the logic elsewhere simpler. | 1345 | // not in a unified way with the pointer surfaces, which makes the logic elsewhere simpler. |
| 1343 | 1346 | ||
| 1344 | - for win in self.monitor_set.windows_for_output(output) { | 1347 | + for win in self.layout.windows_for_output(output) { |
| 1345 | win.with_surfaces(|surface, states| { | 1348 | win.with_surfaces(|surface, states| { |
| 1346 | update_surface_primary_scanout_output( | 1349 | update_surface_primary_scanout_output( |
| 1347 | surface, | 1350 | surface, |
| @@ -1374,7 +1377,7 @@ impl Niri { | |||
| 1374 | // We can unconditionally send the current output's feedback to regular and layer-shell | 1377 | // We can unconditionally send the current output's feedback to regular and layer-shell |
| 1375 | // surfaces, as they can only be displayed on a single output at a time. Even if a surface | 1378 | // surfaces, as they can only be displayed on a single output at a time. Even if a surface |
| 1376 | // is currently invisible, this is the DMABUF feedback that it should know about. | 1379 | // is currently invisible, this is the DMABUF feedback that it should know about. |
| 1377 | - for win in self.monitor_set.windows_for_output(output) { | 1380 | + for win in self.layout.windows_for_output(output) { |
| 1378 | win.send_dmabuf_feedback(output, |_, _| Some(output.clone()), |_, _| feedback); | 1381 | win.send_dmabuf_feedback(output, |_, _| Some(output.clone()), |_, _| feedback); |
| 1379 | } | 1382 | } |
| 1380 | 1383 | ||
| @@ -1445,7 +1448,7 @@ impl Niri { | |||
| 1445 | 1448 | ||
| 1446 | let frame_callback_time = get_monotonic_time(); | 1449 | let frame_callback_time = get_monotonic_time(); |
| 1447 | 1450 | ||
| 1448 | - for win in self.monitor_set.windows_for_output(output) { | 1451 | + for win in self.layout.windows_for_output(output) { |
| 1449 | win.send_frame(output, frame_callback_time, None, should_send); | 1452 | win.send_frame(output, frame_callback_time, None, should_send); |
| 1450 | } | 1453 | } |
| 1451 | 1454 | ||
| @@ -1491,7 +1494,7 @@ impl Niri { | |||
| 1491 | ); | 1494 | ); |
| 1492 | } | 1495 | } |
| 1493 | 1496 | ||
| 1494 | - for win in self.monitor_set.windows_for_output(output) { | 1497 | + for win in self.layout.windows_for_output(output) { |
| 1495 | win.take_presentation_feedback( | 1498 | win.take_presentation_feedback( |
| 1496 | &mut feedback, | 1499 | &mut feedback, |
| 1497 | surface_primary_scanout_output, | 1500 | surface_primary_scanout_output, |