shell/tiling: Make gaps configurable

This commit is contained in:
Victoria Brekenfeld 2023-03-09 18:27:29 +01:00
parent 4bf2c8df79
commit b53e5cae6e
4 changed files with 53 additions and 17 deletions

View file

@ -39,6 +39,8 @@ pub struct StaticConfig {
pub tiling_enabled: bool, pub tiling_enabled: bool,
#[serde(default = "default_active_hint")] #[serde(default = "default_active_hint")]
pub active_hint: u8, pub active_hint: u8,
#[serde(default = "default_gaps")]
pub gaps: (u8, u8),
} }
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
@ -83,6 +85,10 @@ fn default_active_hint() -> u8 {
4 4
} }
fn default_gaps() -> (u8, u8) {
(0, 4)
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub struct OutputConfig { pub struct OutputConfig {
pub mode: ((i32, i32), Option<u32>), pub mode: ((i32, i32), Option<u32>),
@ -228,6 +234,7 @@ impl Config {
workspace_amount: WorkspaceAmount::Dynamic, workspace_amount: WorkspaceAmount::Dynamic,
tiling_enabled: false, tiling_enabled: false,
active_hint: default_active_hint(), active_hint: default_active_hint(),
gaps: default_gaps(),
} }
} }

View file

@ -248,9 +248,9 @@ impl Data {
} }
impl TilingLayout { impl TilingLayout {
pub fn new() -> TilingLayout { pub fn new(gaps: (u8, u8)) -> TilingLayout {
TilingLayout { TilingLayout {
gaps: (0, 4), gaps: (gaps.0 as i32, gaps.1 as i32),
trees: HashMap::new(), trees: HashMap::new(),
} }
} }

View file

@ -69,6 +69,8 @@ pub struct Shell {
pub toplevel_management_state: ToplevelManagementState, pub toplevel_management_state: ToplevelManagementState,
pub xdg_shell_state: XdgShellState, pub xdg_shell_state: XdgShellState,
pub workspace_state: WorkspaceState<State>, pub workspace_state: WorkspaceState<State>,
gaps: (u8, u8),
} }
#[derive(Debug)] #[derive(Debug)]
@ -78,6 +80,7 @@ pub struct WorkspaceSet {
group: WorkspaceGroupHandle, group: WorkspaceGroupHandle,
idx: usize, idx: usize,
tiling_enabled: bool, tiling_enabled: bool,
gaps: (u8, u8),
pub(crate) workspaces: Vec<Workspace>, pub(crate) workspaces: Vec<Workspace>,
} }
@ -92,6 +95,7 @@ fn create_workspace(
group_handle: &WorkspaceGroupHandle, group_handle: &WorkspaceGroupHandle,
active: bool, active: bool,
tiling: bool, tiling: bool,
gaps: (u8, u8),
) -> Workspace { ) -> Workspace {
let workspace_handle = state.create_workspace(&group_handle).unwrap(); let workspace_handle = state.create_workspace(&group_handle).unwrap();
if active { if active {
@ -101,7 +105,7 @@ fn create_workspace(
&workspace_handle, &workspace_handle,
[WorkspaceCapabilities::Activate].into_iter(), [WorkspaceCapabilities::Activate].into_iter(),
); );
Workspace::new(workspace_handle, tiling) Workspace::new(workspace_handle, tiling, gaps)
} }
impl WorkspaceSet { impl WorkspaceSet {
@ -110,12 +114,13 @@ impl WorkspaceSet {
amount: WorkspaceAmount, amount: WorkspaceAmount,
idx: usize, idx: usize,
tiling_enabled: bool, tiling_enabled: bool,
gaps: (u8, u8),
) -> WorkspaceSet { ) -> WorkspaceSet {
let group_handle = state.create_workspace_group(); let group_handle = state.create_workspace_group();
let workspaces = match amount { let workspaces = match amount {
WorkspaceAmount::Dynamic => { 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); workspace_set_idx(state, 1, idx, &workspace.handle);
state.set_workspace_capabilities( state.set_workspace_capabilities(
&workspace.handle, &workspace.handle,
@ -125,7 +130,8 @@ impl WorkspaceSet {
} }
WorkspaceAmount::Static(len) => (0..len) WorkspaceAmount::Static(len) => (0..len)
.map(|i| { .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); workspace_set_idx(state, i + 1, idx, &workspace.handle);
state.set_workspace_capabilities( state.set_workspace_capabilities(
&workspace.handle, &workspace.handle,
@ -142,6 +148,7 @@ impl WorkspaceSet {
group: group_handle, group: group_handle,
idx, idx,
tiling_enabled, tiling_enabled,
gaps,
workspaces, workspaces,
} }
} }
@ -179,8 +186,13 @@ impl WorkspaceSet {
// add empty at the end, if necessary // add empty at the end, if necessary
if self.workspaces.last().unwrap().windows().next().is_some() { if self.workspaces.last().unwrap().windows().next().is_some() {
let mut workspace = let mut workspace = create_workspace(
create_workspace(&mut state, &self.group, false, self.tiling_enabled); &mut state,
&self.group,
false,
self.tiling_enabled,
self.gaps,
);
workspace_set_idx( workspace_set_idx(
&mut state, &mut state,
self.workspaces.len() as u8 + 1, self.workspaces.len() as u8 + 1,
@ -263,8 +275,13 @@ impl WorkspaceSet {
// add empty ones // add empty ones
let outputs = outputs.collect::<Vec<_>>(); let outputs = outputs.collect::<Vec<_>>();
while amount > self.workspaces.len() { while amount > self.workspaces.len() {
let mut workspace = let mut workspace = create_workspace(
create_workspace(&mut state, &self.group, false, self.tiling_enabled); &mut state,
&self.group,
false,
self.tiling_enabled,
self.gaps,
);
workspace_set_idx( workspace_set_idx(
&mut state, &mut state,
self.workspaces.len() as u8 + 1, self.workspaces.len() as u8 + 1,
@ -312,10 +329,11 @@ impl WorkspaceMode {
amount: WorkspaceAmount, amount: WorkspaceAmount,
state: &mut WorkspaceUpdateGuard<'_, State>, state: &mut WorkspaceUpdateGuard<'_, State>,
tiling_enabled: bool, tiling_enabled: bool,
gaps: (u8, u8),
) -> WorkspaceMode { ) -> WorkspaceMode {
match config { match config {
crate::config::WorkspaceMode::Global => { 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 => { crate::config::WorkspaceMode::OutputBound => {
WorkspaceMode::OutputBound(HashMap::new(), amount) WorkspaceMode::OutputBound(HashMap::new(), amount)
@ -459,6 +477,7 @@ impl Shell {
config.static_conf.workspace_amount, config.static_conf.workspace_amount,
&mut workspace_state.update(), &mut workspace_state.update(),
tiling_enabled, tiling_enabled,
config.static_conf.gaps,
); );
Shell { Shell {
@ -476,6 +495,8 @@ impl Shell {
toplevel_management_state, toplevel_management_state,
xdg_shell_state, xdg_shell_state,
workspace_state, workspace_state,
gaps: config.static_conf.gaps,
} }
} }
@ -491,8 +512,13 @@ impl Shell {
WorkspaceMode::OutputBound(sets, amount) => { WorkspaceMode::OutputBound(sets, amount) => {
// TODO: Restore previously assigned workspaces, if possible! // TODO: Restore previously assigned workspaces, if possible!
if !sets.contains_key(output) { if !sets.contains_key(output) {
let set = let set = WorkspaceSet::new(
WorkspaceSet::new(&mut state, *amount, sets.len(), self.tiling_enabled); &mut state,
*amount,
sets.len(),
self.tiling_enabled,
self.gaps,
);
state.add_group_output(&set.group, &output); state.add_group_output(&set.group, &output);
sets.insert(output.clone(), set); sets.insert(output.clone(), set);
} }
@ -630,6 +656,7 @@ impl Shell {
WorkspaceAmount::Static(0), WorkspaceAmount::Static(0),
0, 0,
self.tiling_enabled, self.tiling_enabled,
self.gaps,
); );
for output in &self.outputs { for output in &self.outputs {
state.add_group_output(&new_set.group, output); 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); 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() { for output in self.outputs.iter() {
new_workspace.map_output(output, output.current_location()); new_workspace.map_output(output, output.current_location());
} }
@ -741,6 +769,7 @@ impl Shell {
WorkspaceAmount::Static(0), WorkspaceAmount::Static(0),
i, i,
self.tiling_enabled, self.tiling_enabled,
self.gaps,
); );
state.add_group_output(&set.group, output); state.add_group_output(&set.group, output);
sets.insert(output.clone(), set); sets.insert(output.clone(), set);
@ -758,7 +787,7 @@ impl Shell {
let mut old_tiling_layer = workspace.tiling_layer.clone(); let mut old_tiling_layer = workspace.tiling_layer.clone();
let mut new_floating_layer = FloatingLayout::new(); 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 element in workspace.mapped() {
for (toplevel, _) in element.windows() { for (toplevel, _) in element.windows() {
@ -806,7 +835,7 @@ impl Shell {
.filter(|(key, _)| *key == output) .filter(|(key, _)| *key == output)
.map(|(o, w)| (o.clone(), w.clone())) .map(|(o, w)| (o.clone(), w.clone()))
.collect(), .collect(),
..Workspace::new(new_workspace_handle, true) ..Workspace::new(new_workspace_handle, true, self.gaps)
}; };
for toplevel in new_workspace.windows() { for toplevel in new_workspace.windows() {
self.toplevel_info_state self.toplevel_info_state

View file

@ -63,9 +63,9 @@ pub enum ManagedState {
} }
impl Workspace { impl Workspace {
pub fn new(handle: WorkspaceHandle, tiling_enabled: bool) -> Workspace { pub fn new(handle: WorkspaceHandle, tiling_enabled: bool, gaps: (u8, u8)) -> Workspace {
Workspace { Workspace {
tiling_layer: TilingLayout::new(), tiling_layer: TilingLayout::new(gaps),
floating_layer: FloatingLayout::new(), floating_layer: FloatingLayout::new(),
tiling_enabled, tiling_enabled,
fullscreen: HashMap::new(), fullscreen: HashMap::new(),