From 4429b4cac6f7394bae4995e57f559087970ff18d Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 20 Feb 2022 16:07:02 +0100 Subject: [PATCH] autocommit 2022-02-20 16:07:02 CET --- src/tree/container.rs | 45 ++++++++++++++++++++++++++++++------------- src/tree/mod.rs | 14 ++++++++++---- src/tree/workspace.rs | 16 +++++++-------- 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/tree/container.rs b/src/tree/container.rs index 1fc81b84..a28555e8 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -22,6 +22,7 @@ use crate::client::{Client, ClientId}; use crate::ifs::wl_surface::WlSurface; use crate::xkbcommon::ModifierState; + #[allow(dead_code)] #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum ContainerSplit { @@ -181,12 +182,18 @@ impl ContainerNode { self.num_children.get() } + pub fn prepend_child(self: &Rc, new: Rc) { + if let Some(child) = self.children.first() { + self.add_child_before_(&child, new); + return; + } + } + pub fn append_child(self: &Rc, new: Rc) { if let Some(child) = self.children.last() { self.add_child_after_(&child, new); return; } - log::error!("Tried to add a child to a container but container is empty"); } pub fn add_child_after(self: &Rc, prev: &dyn Node, new: Rc) { @@ -482,7 +489,6 @@ impl ContainerNode { title.push_str("]"); self.parent.get().child_title_changed(&**self, &title); self.schedule_render_titles(); - log::info!("num children: {}", self.num_children.get()); } fn schedule_render_titles(self: &Rc) { @@ -683,31 +689,34 @@ impl Node for ContainerNode { // CASE 1: This is the only child of the container. Replace the container by the child. if self.num_children.get() == 1 { let parent = self.parent.get(); - let can_replace = parent.is_container() || child.clone().into_container().is_some(); - if can_replace { - self.parent.get().replace_child(&*self, child.clone()); + if parent.accepts_child(&*child) { + parent.replace_child(&*self, child.clone()); } return; } let (split, prev) = direction_to_split(direction); // CASE 2: We're moving the child within the container. if split == self.split.get() { - let mut cn = self.child_nodes.borrow_mut(); - let mut child = match cn.entry(child.id()) { - Entry::Occupied(o) => o, - Entry::Vacant(_) => return, + let mut cc = match self.child_nodes.borrow_mut().get(&child.id()) { + Some(l) => l.to_ref(), + None => return, }; let neighbor = match prev { - true => child.get().prev(), - false => child.get().next(), + true => cc.prev(), + false => cc.next(), }; if let Some(neighbor) = neighbor { - let cc = child.get().deref().deref().clone(); + if neighbor.node.accepts_child(&*child) { + self.remove_child(&*child); + neighbor.node.clone().insert_child(child, direction); + return; + } + let cc = cc.deref().clone(); let link = match prev { true => neighbor.prepend(cc), false => neighbor.append(cc), }; - child.insert(link); + self.child_nodes.borrow_mut().insert(child.id(), link); self.schedule_layout(); return; } @@ -900,6 +909,7 @@ impl Node for ContainerNode { } } self.sum_factors.set(sum); + self.update_title(); self.schedule_layout(); self.cancel_seat_ops(); } @@ -960,6 +970,15 @@ impl Node for ContainerNode { true } + fn insert_child(self: Rc, node: Rc, direction: Direction) { + let (split, right) = direction_to_split(direction); + if split != self.split.get() || right { + self.append_child(node); + } else { + self.prepend_child(node); + } + } + fn change_extents(self: Rc, rect: &Rect) { self.abs_x1.set(rect.x1()); self.abs_y1.set(rect.y1()); diff --git a/src/tree/mod.rs b/src/tree/mod.rs index c81aef0a..34f7af80 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -244,9 +244,15 @@ pub trait Node { } fn accepts_child(&self, node: &dyn Node) -> bool { + let _ = node; false } + fn insert_child(self: Rc, node: Rc, direction: Direction) { + let _ = node; + let _ = direction; + } + fn is_float(&self) -> bool { false } @@ -537,10 +543,6 @@ impl Node for FloatNode { } } - fn accepts_child(&self, _node: &dyn Node) -> bool { - true - } - fn absolute_position(&self) -> Rect { self.position.get() } @@ -582,6 +584,10 @@ impl Node for FloatNode { Some(self) } + fn accepts_child(&self, _node: &dyn Node) -> bool { + true + } + fn is_float(&self) -> bool { true } diff --git a/src/tree/workspace.rs b/src/tree/workspace.rs index 614070ec..fe9e4f55 100644 --- a/src/tree/workspace.rs +++ b/src/tree/workspace.rs @@ -1,20 +1,20 @@ use crate::cursor::KnownCursor; -use crate::ifs::wl_seat::{Dnd, NodeSeatState, WlSeatGlobal}; +use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal}; use crate::rect::Rect; use crate::render::Renderer; use crate::tree::container::ContainerNode; use crate::tree::walker::NodeVisitor; -use crate::tree::{ContainerSplit, FindTreeResult, FloatNode, FoundNode, Node, NodeId, OutputNode}; +use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, OutputNode}; use crate::utils::clonecell::CloneCell; use crate::utils::linkedlist::LinkedList; use std::fmt::Debug; use std::rc::Rc; -use i4config::Direction; -use crate::backend::{KeyState, ScrollAxis}; -use crate::client::{Client, ClientId}; -use crate::fixed::Fixed; -use crate::ifs::wl_surface::WlSurface; -use crate::xkbcommon::ModifierState; + + + + + + tree_id!(WorkspaceNodeId);