tiling: fix workspaces
This commit is contained in:
parent
aab52b502c
commit
936356b312
4 changed files with 29 additions and 25 deletions
|
|
@ -51,9 +51,9 @@ pub trait Layout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_default_layout() -> Box<dyn Layout> {
|
pub fn new_default_layout(idx: u8) -> Box<dyn Layout> {
|
||||||
Box::new(combined::Combined::new(
|
Box::new(combined::Combined::new(
|
||||||
tiling::TilingLayout::new(),
|
tiling::TilingLayout::new(idx),
|
||||||
floating::FloatingLayout,
|
floating::FloatingLayout,
|
||||||
|app_id, title| {
|
|app_id, title| {
|
||||||
slog_scope::debug!(
|
slog_scope::debug!(
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,11 @@ use smithay::{
|
||||||
utils::Rectangle,
|
utils::Rectangle,
|
||||||
wayland::{output::Output, seat::Seat},
|
wayland::{output::Output, seat::Seat},
|
||||||
};
|
};
|
||||||
use std::cell::RefCell;
|
use std::{cell::RefCell, collections::HashMap};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TilingLayout {
|
pub struct TilingLayout {
|
||||||
|
idx: u8,
|
||||||
gaps: (i32, i32),
|
gaps: (i32, i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,18 +42,14 @@ pub struct WindowInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct OutputInfo {
|
pub struct OutputInfo {
|
||||||
tree: Tree<Data>,
|
trees: HashMap<u8, Tree<Data>>,
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Debug for OutputInfo {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
self.tree.write_formatted(f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for OutputInfo {
|
impl Default for OutputInfo {
|
||||||
fn default() -> OutputInfo {
|
fn default() -> OutputInfo {
|
||||||
OutputInfo { tree: Tree::new() }
|
OutputInfo {
|
||||||
|
trees: HashMap::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,8 +63,8 @@ impl Data {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TilingLayout {
|
impl TilingLayout {
|
||||||
pub fn new() -> TilingLayout {
|
pub fn new(idx: u8) -> TilingLayout {
|
||||||
TilingLayout { gaps: (0, 4) }
|
TilingLayout { idx, gaps: (0, 4) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,8 +81,12 @@ impl Layout for TilingLayout {
|
||||||
output
|
output
|
||||||
.user_data()
|
.user_data()
|
||||||
.insert_if_missing(|| RefCell::new(OutputInfo::default()));
|
.insert_if_missing(|| RefCell::new(OutputInfo::default()));
|
||||||
let output_info = output.user_data().get::<RefCell<OutputInfo>>().unwrap();
|
let mut output_info = output
|
||||||
let tree = &mut output_info.borrow_mut().tree;
|
.user_data()
|
||||||
|
.get::<RefCell<OutputInfo>>()
|
||||||
|
.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()));
|
let new_window = Node::new(Data::Window(window.clone()));
|
||||||
|
|
||||||
|
|
@ -144,7 +145,7 @@ impl Layout for TilingLayout {
|
||||||
|
|
||||||
fn refresh(&mut self, space: &mut Space) {
|
fn refresh(&mut self, space: &mut Space) {
|
||||||
while let Some(dead_windows) =
|
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 {
|
for window in dead_windows {
|
||||||
self.unmap_window(&window);
|
self.unmap_window(&window);
|
||||||
|
|
@ -157,8 +158,12 @@ impl TilingLayout {
|
||||||
fn unmap_window(&mut self, window: &Window) {
|
fn unmap_window(&mut self, window: &Window) {
|
||||||
if let Some(info) = window.user_data().get::<RefCell<WindowInfo>>() {
|
if let Some(info) = window.user_data().get::<RefCell<WindowInfo>>() {
|
||||||
let output = &info.borrow().output;
|
let output = &info.borrow().output;
|
||||||
let output_info = output.user_data().get::<RefCell<OutputInfo>>().unwrap();
|
let mut output_info = output
|
||||||
let tree = &mut output_info.borrow_mut().tree;
|
.user_data()
|
||||||
|
.get::<RefCell<OutputInfo>>()
|
||||||
|
.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 node_id = info.borrow().node.clone();
|
||||||
let parent_id = tree
|
let parent_id = tree
|
||||||
|
|
@ -259,7 +264,7 @@ fn new_fork(
|
||||||
tree.insert(new, InsertBehavior::UnderNode(&fork_id))
|
tree.insert(new, InsertBehavior::UnderNode(&fork_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_space_positions(space: &mut Space, gaps: (i32, i32)) -> Vec<Window> {
|
fn update_space_positions(idx: u8, space: &mut Space, gaps: (i32, i32)) -> Vec<Window> {
|
||||||
let mut dead_windows = Vec::new();
|
let mut dead_windows = Vec::new();
|
||||||
let (outer, inner) = gaps;
|
let (outer, inner) = gaps;
|
||||||
for output in space.outputs().cloned().collect::<Vec<_>>().into_iter() {
|
for output in space.outputs().cloned().collect::<Vec<_>>().into_iter() {
|
||||||
|
|
@ -268,8 +273,7 @@ fn update_space_positions(space: &mut Space, gaps: (i32, i32)) -> Vec<Window> {
|
||||||
.get::<RefCell<OutputInfo>>()
|
.get::<RefCell<OutputInfo>>()
|
||||||
.map(|x| x.borrow_mut())
|
.map(|x| x.borrow_mut())
|
||||||
{
|
{
|
||||||
slog_scope::trace!("Tree:\n{:?}", info);
|
let tree = &mut info.trees.entry(idx).or_insert_with(Tree::new);
|
||||||
let tree = &mut info.tree;
|
|
||||||
if let Some(root) = tree.root_node_id() {
|
if let Some(root) = tree.root_node_id() {
|
||||||
let mut stack = Vec::new();
|
let mut stack = Vec::new();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,8 @@ impl Shell {
|
||||||
outputs: Vec::new(),
|
outputs: Vec::new(),
|
||||||
spaces: unsafe {
|
spaces: unsafe {
|
||||||
let mut spaces = [UNINIT_SPACE; MAX_WORKSPACES];
|
let mut spaces = [UNINIT_SPACE; MAX_WORKSPACES];
|
||||||
for space in &mut spaces {
|
for (idx, space) in spaces.iter_mut().enumerate() {
|
||||||
*space = MaybeUninit::new(Workspace::new());
|
*space = MaybeUninit::new(Workspace::new(idx as u8));
|
||||||
}
|
}
|
||||||
std::mem::transmute(spaces)
|
std::mem::transmute(spaces)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,10 @@ pub struct Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Workspace {
|
impl Workspace {
|
||||||
pub fn new() -> Workspace {
|
pub fn new(idx: u8) -> Workspace {
|
||||||
Workspace {
|
Workspace {
|
||||||
space: Space::new(None),
|
space: Space::new(None),
|
||||||
layout: layout::new_default_layout(),
|
layout: layout::new_default_layout(idx),
|
||||||
focus_stack: FocusStack::new(),
|
focus_stack: FocusStack::new(),
|
||||||
pending_windows: Vec::new(),
|
pending_windows: Vec::new(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue