From b53e5cae6ed2333e59d6e893f77187556ef7df75 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Thu, 9 Mar 2023 18:27:29 +0100 Subject: [PATCH] shell/tiling: Make gaps configurable --- src/config/mod.rs | 7 +++++ src/shell/layout/tiling/mod.rs | 4 +-- src/shell/mod.rs | 55 ++++++++++++++++++++++++++-------- src/shell/workspace.rs | 4 +-- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index b5e0af94..9e34d709 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -39,6 +39,8 @@ pub struct StaticConfig { pub tiling_enabled: bool, #[serde(default = "default_active_hint")] pub active_hint: u8, + #[serde(default = "default_gaps")] + pub gaps: (u8, u8), } #[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)] @@ -83,6 +85,10 @@ fn default_active_hint() -> u8 { 4 } +fn default_gaps() -> (u8, u8) { + (0, 4) +} + #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] pub struct OutputConfig { pub mode: ((i32, i32), Option), @@ -228,6 +234,7 @@ impl Config { workspace_amount: WorkspaceAmount::Dynamic, tiling_enabled: false, active_hint: default_active_hint(), + gaps: default_gaps(), } } diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index a94a678e..f157c310 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -248,9 +248,9 @@ impl Data { } impl TilingLayout { - pub fn new() -> TilingLayout { + pub fn new(gaps: (u8, u8)) -> TilingLayout { TilingLayout { - gaps: (0, 4), + gaps: (gaps.0 as i32, gaps.1 as i32), trees: HashMap::new(), } } diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 5eb7e8b8..0ff4b8e6 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -69,6 +69,8 @@ pub struct Shell { pub toplevel_management_state: ToplevelManagementState, pub xdg_shell_state: XdgShellState, pub workspace_state: WorkspaceState, + + gaps: (u8, u8), } #[derive(Debug)] @@ -78,6 +80,7 @@ pub struct WorkspaceSet { group: WorkspaceGroupHandle, idx: usize, tiling_enabled: bool, + gaps: (u8, u8), pub(crate) workspaces: Vec, } @@ -92,6 +95,7 @@ fn create_workspace( group_handle: &WorkspaceGroupHandle, active: bool, tiling: bool, + gaps: (u8, u8), ) -> Workspace { let workspace_handle = state.create_workspace(&group_handle).unwrap(); if active { @@ -101,7 +105,7 @@ fn create_workspace( &workspace_handle, [WorkspaceCapabilities::Activate].into_iter(), ); - Workspace::new(workspace_handle, tiling) + Workspace::new(workspace_handle, tiling, gaps) } impl WorkspaceSet { @@ -110,12 +114,13 @@ impl WorkspaceSet { amount: WorkspaceAmount, idx: usize, tiling_enabled: bool, + gaps: (u8, u8), ) -> WorkspaceSet { let group_handle = state.create_workspace_group(); let workspaces = match amount { WorkspaceAmount::Dynamic => { - let workspace = create_workspace(state, &group_handle, true, tiling_enabled); + let workspace = create_workspace(state, &group_handle, true, tiling_enabled, gaps); workspace_set_idx(state, 1, idx, &workspace.handle); state.set_workspace_capabilities( &workspace.handle, @@ -125,7 +130,8 @@ impl WorkspaceSet { } WorkspaceAmount::Static(len) => (0..len) .map(|i| { - let workspace = create_workspace(state, &group_handle, i == 0, tiling_enabled); + let workspace = + create_workspace(state, &group_handle, i == 0, tiling_enabled, gaps); workspace_set_idx(state, i + 1, idx, &workspace.handle); state.set_workspace_capabilities( &workspace.handle, @@ -142,6 +148,7 @@ impl WorkspaceSet { group: group_handle, idx, tiling_enabled, + gaps, workspaces, } } @@ -179,8 +186,13 @@ impl WorkspaceSet { // add empty at the end, if necessary if self.workspaces.last().unwrap().windows().next().is_some() { - let mut workspace = - create_workspace(&mut state, &self.group, false, self.tiling_enabled); + let mut workspace = create_workspace( + &mut state, + &self.group, + false, + self.tiling_enabled, + self.gaps, + ); workspace_set_idx( &mut state, self.workspaces.len() as u8 + 1, @@ -263,8 +275,13 @@ impl WorkspaceSet { // add empty ones let outputs = outputs.collect::>(); while amount > self.workspaces.len() { - let mut workspace = - create_workspace(&mut state, &self.group, false, self.tiling_enabled); + let mut workspace = create_workspace( + &mut state, + &self.group, + false, + self.tiling_enabled, + self.gaps, + ); workspace_set_idx( &mut state, self.workspaces.len() as u8 + 1, @@ -312,10 +329,11 @@ impl WorkspaceMode { amount: WorkspaceAmount, state: &mut WorkspaceUpdateGuard<'_, State>, tiling_enabled: bool, + gaps: (u8, u8), ) -> WorkspaceMode { match config { crate::config::WorkspaceMode::Global => { - WorkspaceMode::Global(WorkspaceSet::new(state, amount, 0, tiling_enabled)) + WorkspaceMode::Global(WorkspaceSet::new(state, amount, 0, tiling_enabled, gaps)) } crate::config::WorkspaceMode::OutputBound => { WorkspaceMode::OutputBound(HashMap::new(), amount) @@ -459,6 +477,7 @@ impl Shell { config.static_conf.workspace_amount, &mut workspace_state.update(), tiling_enabled, + config.static_conf.gaps, ); Shell { @@ -476,6 +495,8 @@ impl Shell { toplevel_management_state, xdg_shell_state, workspace_state, + + gaps: config.static_conf.gaps, } } @@ -491,8 +512,13 @@ impl Shell { WorkspaceMode::OutputBound(sets, amount) => { // TODO: Restore previously assigned workspaces, if possible! if !sets.contains_key(output) { - let set = - WorkspaceSet::new(&mut state, *amount, sets.len(), self.tiling_enabled); + let set = WorkspaceSet::new( + &mut state, + *amount, + sets.len(), + self.tiling_enabled, + self.gaps, + ); state.add_group_output(&set.group, &output); sets.insert(output.clone(), set); } @@ -630,6 +656,7 @@ impl Shell { WorkspaceAmount::Static(0), 0, self.tiling_enabled, + self.gaps, ); for output in &self.outputs { state.add_group_output(&new_set.group, output); @@ -691,7 +718,8 @@ impl Shell { ); workspace_set_idx(&mut state, i as u8 + 1, 0, &workspace_handle); - let mut new_workspace = Workspace::new(workspace_handle, self.tiling_enabled); + let mut new_workspace = + Workspace::new(workspace_handle, self.tiling_enabled, self.gaps); for output in self.outputs.iter() { new_workspace.map_output(output, output.current_location()); } @@ -741,6 +769,7 @@ impl Shell { WorkspaceAmount::Static(0), i, self.tiling_enabled, + self.gaps, ); state.add_group_output(&set.group, output); sets.insert(output.clone(), set); @@ -758,7 +787,7 @@ impl Shell { let mut old_tiling_layer = workspace.tiling_layer.clone(); let mut new_floating_layer = FloatingLayout::new(); - let mut new_tiling_layer = TilingLayout::new(); + let mut new_tiling_layer = TilingLayout::new(self.gaps); for element in workspace.mapped() { for (toplevel, _) in element.windows() { @@ -806,7 +835,7 @@ impl Shell { .filter(|(key, _)| *key == output) .map(|(o, w)| (o.clone(), w.clone())) .collect(), - ..Workspace::new(new_workspace_handle, true) + ..Workspace::new(new_workspace_handle, true, self.gaps) }; for toplevel in new_workspace.windows() { self.toplevel_info_state diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index 9d14e2ea..1eef4669 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -63,9 +63,9 @@ pub enum ManagedState { } impl Workspace { - pub fn new(handle: WorkspaceHandle, tiling_enabled: bool) -> Workspace { + pub fn new(handle: WorkspaceHandle, tiling_enabled: bool, gaps: (u8, u8)) -> Workspace { Workspace { - tiling_layer: TilingLayout::new(), + tiling_layer: TilingLayout::new(gaps), floating_layer: FloatingLayout::new(), tiling_enabled, fullscreen: HashMap::new(),