diff --git a/src/shell/layout/mod.rs b/src/shell/layout/mod.rs index 17feb37c..b4573719 100644 --- a/src/shell/layout/mod.rs +++ b/src/shell/layout/mod.rs @@ -51,9 +51,9 @@ pub trait Layout { } } -pub fn new_default_layout() -> Box { +pub fn new_default_layout(idx: u8) -> Box { Box::new(combined::Combined::new( - tiling::TilingLayout::new(), + tiling::TilingLayout::new(idx), floating::FloatingLayout, |app_id, title| { slog_scope::debug!( diff --git a/src/shell/layout/tiling.rs b/src/shell/layout/tiling.rs index 9ea3e1af..aaee5ed1 100644 --- a/src/shell/layout/tiling.rs +++ b/src/shell/layout/tiling.rs @@ -8,10 +8,11 @@ use smithay::{ utils::Rectangle, wayland::{output::Output, seat::Seat}, }; -use std::cell::RefCell; +use std::{cell::RefCell, collections::HashMap}; #[derive(Debug)] pub struct TilingLayout { + idx: u8, gaps: (i32, i32), } @@ -41,18 +42,14 @@ pub struct WindowInfo { } pub struct OutputInfo { - tree: Tree, -} - -impl std::fmt::Debug for OutputInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.tree.write_formatted(f) - } + trees: HashMap>, } impl Default for OutputInfo { fn default() -> OutputInfo { - OutputInfo { tree: Tree::new() } + OutputInfo { + trees: HashMap::new(), + } } } @@ -66,8 +63,8 @@ impl Data { } impl TilingLayout { - pub fn new() -> TilingLayout { - TilingLayout { gaps: (0, 4) } + pub fn new(idx: u8) -> TilingLayout { + TilingLayout { idx, gaps: (0, 4) } } } @@ -84,8 +81,12 @@ impl Layout for TilingLayout { output .user_data() .insert_if_missing(|| RefCell::new(OutputInfo::default())); - let output_info = output.user_data().get::>().unwrap(); - let tree = &mut output_info.borrow_mut().tree; + let mut output_info = output + .user_data() + .get::>() + .unwrap() + .borrow_mut(); + let tree = &mut output_info.trees.entry(self.idx).or_insert_with(Tree::new); let new_window = Node::new(Data::Window(window.clone())); @@ -144,7 +145,7 @@ impl Layout for TilingLayout { fn refresh(&mut self, space: &mut Space) { while let Some(dead_windows) = - Some(update_space_positions(space, self.gaps)).filter(|v| !v.is_empty()) + Some(update_space_positions(self.idx, space, self.gaps)).filter(|v| !v.is_empty()) { for window in dead_windows { self.unmap_window(&window); @@ -157,8 +158,12 @@ impl TilingLayout { fn unmap_window(&mut self, window: &Window) { if let Some(info) = window.user_data().get::>() { let output = &info.borrow().output; - let output_info = output.user_data().get::>().unwrap(); - let tree = &mut output_info.borrow_mut().tree; + let mut output_info = output + .user_data() + .get::>() + .unwrap() + .borrow_mut(); + let tree = &mut output_info.trees.entry(self.idx).or_insert_with(Tree::new); let node_id = info.borrow().node.clone(); let parent_id = tree @@ -259,7 +264,7 @@ fn new_fork( tree.insert(new, InsertBehavior::UnderNode(&fork_id)) } -fn update_space_positions(space: &mut Space, gaps: (i32, i32)) -> Vec { +fn update_space_positions(idx: u8, space: &mut Space, gaps: (i32, i32)) -> Vec { let mut dead_windows = Vec::new(); let (outer, inner) = gaps; for output in space.outputs().cloned().collect::>().into_iter() { @@ -268,8 +273,7 @@ fn update_space_positions(space: &mut Space, gaps: (i32, i32)) -> Vec { .get::>() .map(|x| x.borrow_mut()) { - slog_scope::trace!("Tree:\n{:?}", info); - let tree = &mut info.tree; + let tree = &mut info.trees.entry(idx).or_insert_with(Tree::new); if let Some(root) = tree.root_node_id() { let mut stack = Vec::new(); diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 6cab5985..d3efd4af 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -68,8 +68,8 @@ impl Shell { outputs: Vec::new(), spaces: unsafe { let mut spaces = [UNINIT_SPACE; MAX_WORKSPACES]; - for space in &mut spaces { - *space = MaybeUninit::new(Workspace::new()); + for (idx, space) in spaces.iter_mut().enumerate() { + *space = MaybeUninit::new(Workspace::new(idx as u8)); } std::mem::transmute(spaces) }, diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index dfc4b395..f7417811 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -40,10 +40,10 @@ pub struct Workspace { } impl Workspace { - pub fn new() -> Workspace { + pub fn new(idx: u8) -> Workspace { Workspace { space: Space::new(None), - layout: layout::new_default_layout(), + layout: layout::new_default_layout(idx), focus_stack: FocusStack::new(), pending_windows: Vec::new(), }