1
0
Fork 0
forked from wry/wry

tree: clean up object attachment

This commit is contained in:
Julian Orth 2024-02-21 19:38:31 +01:00
parent ed129c1c3d
commit fe804b8276
8 changed files with 140 additions and 115 deletions

View file

@ -172,7 +172,6 @@ impl ContainerNode {
child: Rc<dyn ToplevelNode>,
split: ContainerSplit,
) -> Rc<Self> {
child.clone().tl_set_workspace(workspace);
let children = LinkedList::new();
let child_node = children.add_last(ContainerChild {
node: child.clone(),
@ -217,7 +216,7 @@ impl ContainerNode {
attention_requests: Default::default(),
});
child.tl_set_parent(slf.clone());
slf.apply_child_flags(&child_node_ref);
slf.pull_child_properties(&child_node_ref);
slf
}
@ -301,9 +300,8 @@ impl ContainerNode {
links.insert(new.node_id(), link);
r
};
self.apply_child_flags(&new_ref);
new.clone().tl_set_workspace(&self.workspace.get());
new.tl_set_parent(self.clone());
self.pull_child_properties(&new_ref);
new.tl_set_visible(self.toplevel_data.visible.get());
let num_children = self.num_children.fetch_add(1) + 1;
self.update_content_size();
@ -605,7 +603,7 @@ impl ContainerNode {
}
}
fn update_title(self: &Rc<Self>) {
fn update_title(&self) {
let mut title = self.toplevel_data.title.borrow_mut();
title.clear();
let split = match (self.mono_child.get().is_some(), self.split.get()) {
@ -951,16 +949,70 @@ impl ContainerNode {
}
}
fn apply_child_flags(&self, child: &ContainerChild) {
let data = child.node.tl_data();
let attention_requested = data.wants_attention.get();
child.attention_requested.set(attention_requested);
if attention_requested {
self.mod_attention_requests(true);
fn update_child_title(self: &Rc<Self>, child: &ContainerChild, title: &str) {
{
let mut ct = child.title.borrow_mut();
if ct.deref() == title {
return;
}
ct.clear();
ct.push_str(title);
}
self.update_title();
// log::info!("node_child_title_changed");
self.schedule_compute_render_data();
}
fn update_child_active(
self: &Rc<Self>,
node: &NodeRef<ContainerChild>,
active: bool,
depth: u32,
) {
if depth == 1 {
node.active.set(active);
}
if active {
node.focus_history
.set(Some(self.focus_history.add_last(node.clone())));
}
// log::info!("node_child_active_changed");
self.schedule_compute_render_data();
if let Some(parent) = self.toplevel_data.parent.get() {
parent.node_child_active_changed(self.deref(), active, depth + 1);
}
}
fn discard_child_flags(&self, child: &ContainerChild) {
fn update_child_size(&self, node: &NodeRef<ContainerChild>, width: i32, height: i32) {
let rect = Rect::new(0, 0, width, height).unwrap();
node.content.set(rect);
node.position_content();
if let Some(mono) = self.mono_child.get() {
if mono.node.node_id() == node.node.node_id() {
let body = self.mono_body.get();
self.mono_content.set(rect.at_point(body.x1(), body.y1()));
}
}
}
fn pull_child_properties(self: &Rc<Self>, child: &NodeRef<ContainerChild>) {
let data = child.node.tl_data();
{
let attention_requested = data.wants_attention.get();
child.attention_requested.set(attention_requested);
if attention_requested {
self.mod_attention_requests(true);
}
}
self.update_child_title(child, &data.title.borrow());
self.update_child_active(child, data.active(), 1);
{
let pos = data.pos.get();
self.update_child_size(child, pos.width(), pos.height());
}
}
fn discard_child_properties(&self, child: &ContainerChild) {
if child.attention_requested.get() {
self.mod_attention_requests(false);
}
@ -1042,21 +1094,9 @@ impl Node for ContainerNode {
}
fn node_child_title_changed(self: Rc<Self>, child: &dyn Node, title: &str) {
let child = match self.child_nodes.borrow().get(&child.node_id()) {
Some(cn) => cn.to_ref(),
_ => return,
};
{
let mut ct = child.title.borrow_mut();
if ct.deref() == title {
return;
}
ct.clear();
ct.push_str(title);
if let Some(child) = self.child_nodes.borrow().get(&child.node_id()) {
self.update_child_title(child, title);
}
self.update_title();
// log::info!("node_child_title_changed");
self.schedule_compute_render_data();
}
fn node_do_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
@ -1115,34 +1155,13 @@ impl Node for ContainerNode {
fn node_child_size_changed(&self, child: &dyn Node, width: i32, height: i32) {
let cn = self.child_nodes.borrow();
if let Some(node) = cn.get(&child.node_id()) {
let rect = Rect::new(0, 0, width, height).unwrap();
node.content.set(rect);
node.position_content();
if let Some(mono) = self.mono_child.get() {
if mono.node.node_id() == node.node.node_id() {
let body = self.mono_body.get();
self.mono_content.set(rect.at_point(body.x1(), body.y1()));
}
}
self.update_child_size(node, width, height);
}
}
fn node_child_active_changed(self: Rc<Self>, child: &dyn Node, active: bool, depth: u32) {
let node = match self.child_nodes.borrow().get(&child.node_id()) {
Some(l) => l.to_ref(),
None => return,
};
if depth == 1 {
node.active.set(active);
}
if active {
node.focus_history
.set(Some(self.focus_history.add_last(node.clone())));
}
// log::info!("node_child_active_changed");
self.schedule_compute_render_data();
if let Some(parent) = self.toplevel_data.parent.get() {
parent.node_child_active_changed(self.deref(), active, depth + 1);
if let Some(l) = self.child_nodes.borrow().get(&child.node_id()) {
self.update_child_active(l, active, depth);
}
}
@ -1314,7 +1333,7 @@ impl ContainingNode for ContainerNode {
None => (false, false),
Some(mc) => (true, mc.node.node_id() == old.node_id()),
};
self.discard_child_flags(&node);
self.discard_child_properties(&node);
let link = node.append(ContainerChild {
node: new.clone(),
active: Cell::new(false),
@ -1327,11 +1346,10 @@ impl ContainingNode for ContainerNode {
focus_history: Cell::new(None),
attention_requested: Cell::new(false),
});
self.apply_child_flags(&link);
if let Some(fh) = node.focus_history.take() {
link.focus_history.set(Some(fh.append(link.to_ref())));
}
new.tl_set_visible(node.node.node_visible());
let visible = node.node.node_visible();
drop(node);
let mut body = None;
if was_mc {
@ -1340,9 +1358,11 @@ impl ContainingNode for ContainerNode {
} else if !have_mc {
body = Some(link.body.get());
};
let link_ref = link.to_ref();
self.child_nodes.borrow_mut().insert(new.node_id(), link);
new.tl_set_parent(self.clone());
new.clone().tl_set_workspace(&self.workspace.get());
self.pull_child_properties(&link_ref);
new.tl_set_visible(visible);
if let Some(body) = body {
let body = body.move_(self.abs_x1.get(), self.abs_y1.get());
new.clone().tl_change_extents(&body);
@ -1355,7 +1375,7 @@ impl ContainingNode for ContainerNode {
None => return,
};
node.focus_history.set(None);
self.discard_child_flags(&node);
self.discard_child_properties(&node);
if let Some(mono) = self.mono_child.get() {
if mono.node.node_id() == child.node_id() {
let mut new = self.focus_history.last().map(|n| n.deref().clone());
@ -1419,6 +1439,10 @@ impl ContainingNode for ContainerNode {
self.mod_attention_requests(set);
self.schedule_compute_render_data();
}
fn cnode_workspace(self: Rc<Self>) -> Rc<WorkspaceNode> {
self.workspace.get()
}
}
impl ToplevelNodeBase for ContainerNode {
@ -1434,7 +1458,7 @@ impl ToplevelNodeBase for ContainerNode {
.map(|tl| tl.tl_into_node())
}
fn tl_set_workspace_ext(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
fn tl_set_workspace_ext(&self, ws: &Rc<WorkspaceNode>) {
for child in self.children.iter() {
child.node.clone().tl_set_workspace(ws);
}