tiling: Allow flatten groups to be restore on unminimize
This commit is contained in:
parent
4e09fc0398
commit
30ca382d11
1 changed files with 68 additions and 15 deletions
|
|
@ -323,7 +323,8 @@ enum FocusedNodeData {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MinimizedTilingState {
|
pub struct MinimizedTilingState {
|
||||||
pub parent: id_tree::NodeId,
|
pub parent: Option<id_tree::NodeId>,
|
||||||
|
pub sibling: Option<id_tree::NodeId>,
|
||||||
pub orientation: Orientation,
|
pub orientation: Orientation,
|
||||||
pub idx: usize,
|
pub idx: usize,
|
||||||
pub sizes: Vec<i32>,
|
pub sizes: Vec<i32>,
|
||||||
|
|
@ -411,18 +412,21 @@ impl TilingLayout {
|
||||||
|
|
||||||
if let Some(MinimizedTilingState {
|
if let Some(MinimizedTilingState {
|
||||||
parent,
|
parent,
|
||||||
|
sibling,
|
||||||
orientation,
|
orientation,
|
||||||
idx,
|
idx,
|
||||||
mut sizes,
|
mut sizes,
|
||||||
}) = tiling_state
|
}) = tiling_state
|
||||||
{
|
{
|
||||||
if let Ok(node) = tree.get_mut(&parent) {
|
if let Some(node) = parent.as_ref().and_then(|parent| tree.get_mut(parent).ok()) {
|
||||||
if let Data::Group {
|
if let Data::Group {
|
||||||
orientation: current_orientation,
|
orientation: current_orientation,
|
||||||
sizes: current_sizes,
|
sizes: current_sizes,
|
||||||
..
|
..
|
||||||
} = node.data_mut()
|
} = node.data_mut()
|
||||||
{
|
{
|
||||||
|
let parent_id = parent.unwrap();
|
||||||
|
|
||||||
if *current_orientation == orientation && sizes.len() == current_sizes.len() + 1
|
if *current_orientation == orientation && sizes.len() == current_sizes.len() + 1
|
||||||
{
|
{
|
||||||
let previous_length: i32 = sizes.iter().copied().sum();
|
let previous_length: i32 = sizes.iter().copied().sum();
|
||||||
|
|
@ -451,7 +455,7 @@ impl TilingLayout {
|
||||||
minimize_rect: Some(from),
|
minimize_rect: Some(from),
|
||||||
});
|
});
|
||||||
let new_id = tree
|
let new_id = tree
|
||||||
.insert(new_node, InsertBehavior::UnderNode(&parent))
|
.insert(new_node, InsertBehavior::UnderNode(&parent_id))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
tree.make_nth_sibling(&new_id, idx).unwrap();
|
tree.make_nth_sibling(&new_id, idx).unwrap();
|
||||||
*window.tiling_node_id.lock().unwrap() = Some(new_id);
|
*window.tiling_node_id.lock().unwrap() = Some(new_id);
|
||||||
|
|
@ -461,6 +465,43 @@ impl TilingLayout {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sibling
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|sibling| tree.get(&sibling).is_ok())
|
||||||
|
{
|
||||||
|
let sibling_id = sibling.unwrap();
|
||||||
|
let new_node = Node::new(Data::Mapped {
|
||||||
|
mapped: window.clone(),
|
||||||
|
last_geometry: Rectangle::from_loc_and_size((0, 0), (100, 100)),
|
||||||
|
minimize_rect: Some(from),
|
||||||
|
});
|
||||||
|
|
||||||
|
let new_id = tree.insert(new_node, InsertBehavior::AsRoot).unwrap();
|
||||||
|
let group_id =
|
||||||
|
TilingLayout::new_group(&mut tree, &sibling_id, &new_id, orientation).unwrap();
|
||||||
|
tree.make_nth_sibling(&new_id, idx).unwrap();
|
||||||
|
if let Data::Group {
|
||||||
|
sizes: default_sizes,
|
||||||
|
last_geometry,
|
||||||
|
..
|
||||||
|
} = tree.get_mut(&group_id).unwrap().data_mut()
|
||||||
|
{
|
||||||
|
match orientation {
|
||||||
|
Orientation::Horizontal => {
|
||||||
|
last_geometry.size.h = sizes.iter().copied().sum()
|
||||||
|
}
|
||||||
|
Orientation::Vertical => last_geometry.size.w = sizes.iter().copied().sum(),
|
||||||
|
};
|
||||||
|
*default_sizes = sizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
*window.tiling_node_id.lock().unwrap() = Some(new_id);
|
||||||
|
|
||||||
|
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
|
||||||
|
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// else add as new_window
|
// else add as new_window
|
||||||
|
|
@ -1272,12 +1313,24 @@ impl TilingLayout {
|
||||||
orientation, sizes, ..
|
orientation, sizes, ..
|
||||||
} = parent.data()
|
} = parent.data()
|
||||||
{
|
{
|
||||||
Some(MinimizedTilingState {
|
if sizes.len() == 2 {
|
||||||
parent: parent_id.clone(),
|
// this group will be flattened
|
||||||
orientation: *orientation,
|
Some(MinimizedTilingState {
|
||||||
idx,
|
parent: None,
|
||||||
sizes: sizes.clone(),
|
sibling: parent.children().iter().cloned().find(|id| id != &node_id),
|
||||||
})
|
orientation: *orientation,
|
||||||
|
idx,
|
||||||
|
sizes: sizes.clone(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Some(MinimizedTilingState {
|
||||||
|
parent: Some(parent_id.clone()),
|
||||||
|
sibling: None,
|
||||||
|
orientation: *orientation,
|
||||||
|
idx,
|
||||||
|
sizes: sizes.clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
@ -4674,7 +4727,7 @@ where
|
||||||
elem_geometry,
|
elem_geometry,
|
||||||
ConstrainScaleBehavior::Stretch,
|
ConstrainScaleBehavior::Stretch,
|
||||||
ConstrainAlign::CENTER,
|
ConstrainAlign::CENTER,
|
||||||
output_scale,
|
output_scale,
|
||||||
)
|
)
|
||||||
.next()
|
.next()
|
||||||
.map(CosmicMappedRenderElement::TiledStack),
|
.map(CosmicMappedRenderElement::TiledStack),
|
||||||
|
|
@ -4686,11 +4739,11 @@ where
|
||||||
elem_geometry,
|
elem_geometry,
|
||||||
ConstrainScaleBehavior::Stretch,
|
ConstrainScaleBehavior::Stretch,
|
||||||
ConstrainAlign::CENTER,
|
ConstrainAlign::CENTER,
|
||||||
output_scale,
|
output_scale,
|
||||||
)
|
)
|
||||||
.next()
|
.next()
|
||||||
.map(CosmicMappedRenderElement::TiledWindow),
|
.map(CosmicMappedRenderElement::TiledWindow),
|
||||||
x => Some(x),
|
x => Some(x),
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
if minimize_geo.is_some() && indicator_thickness > 0 {
|
if minimize_geo.is_some() && indicator_thickness > 0 {
|
||||||
|
|
@ -5164,7 +5217,7 @@ where
|
||||||
elem_geometry,
|
elem_geometry,
|
||||||
ConstrainScaleBehavior::Stretch,
|
ConstrainScaleBehavior::Stretch,
|
||||||
ConstrainAlign::CENTER,
|
ConstrainAlign::CENTER,
|
||||||
output_scale,
|
output_scale,
|
||||||
)
|
)
|
||||||
.next()
|
.next()
|
||||||
.map(CosmicMappedRenderElement::TiledStack),
|
.map(CosmicMappedRenderElement::TiledStack),
|
||||||
|
|
@ -5176,7 +5229,7 @@ where
|
||||||
elem_geometry,
|
elem_geometry,
|
||||||
ConstrainScaleBehavior::Stretch,
|
ConstrainScaleBehavior::Stretch,
|
||||||
ConstrainAlign::CENTER,
|
ConstrainAlign::CENTER,
|
||||||
output_scale,
|
output_scale,
|
||||||
)
|
)
|
||||||
.next()
|
.next()
|
||||||
.map(CosmicMappedRenderElement::TiledWindow),
|
.map(CosmicMappedRenderElement::TiledWindow),
|
||||||
|
|
@ -5188,7 +5241,7 @@ where
|
||||||
elem_geometry,
|
elem_geometry,
|
||||||
ConstrainScaleBehavior::Stretch,
|
ConstrainScaleBehavior::Stretch,
|
||||||
ConstrainAlign::CENTER,
|
ConstrainAlign::CENTER,
|
||||||
output_scale,
|
output_scale,
|
||||||
)
|
)
|
||||||
.next()
|
.next()
|
||||||
.map(CosmicMappedRenderElement::TiledOverlay),
|
.map(CosmicMappedRenderElement::TiledOverlay),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue