1
0
Fork 0
forked from wry/wry

all: use trait upcasting

This commit is contained in:
Julian Orth 2025-04-03 16:47:24 +02:00
parent f0caafc862
commit 09e5f89174
44 changed files with 90 additions and 269 deletions

View file

@ -856,7 +856,7 @@ impl ContainerNode {
return;
}
if !preserve_focus {
let seats = collect_kb_foci(mc.node.clone().tl_into_node());
let seats = collect_kb_foci(mc.node.clone());
mc.node.tl_set_visible(false);
for seat in seats {
child
@ -898,7 +898,7 @@ impl ContainerNode {
let mut seats = SmallVec::<[_; 3]>::new();
for other in self.children.iter() {
if other.node.node_id() != child_id {
collect_kb_foci2(other.node.clone().tl_into_node(), &mut seats);
collect_kb_foci2(other.node.clone(), &mut seats);
other.node.tl_set_visible(false);
}
}
@ -996,9 +996,7 @@ impl ContainerNode {
// CASE 1: This is the only child of the container. Replace the container by the child.
if self.num_children.get() == 1 {
if let Some(parent) = self.toplevel_data.parent.get() {
if !self.toplevel_data.is_fullscreen.get()
&& parent.cnode_accepts_child(child.tl_as_node())
{
if !self.toplevel_data.is_fullscreen.get() && parent.cnode_accepts_child(&*child) {
parent.cnode_replace_child(self.deref(), child.clone());
}
}
@ -1019,13 +1017,13 @@ impl ContainerNode {
};
if let Some(neighbor) = neighbor {
if let Some(cn) = neighbor.node.clone().node_into_container() {
if cn.cnode_accepts_child(child.tl_as_node()) {
if cn.cnode_accepts_child(&*child) {
if let Some(mc) = self.mono_child.get() {
if mc.node.node_id() == child.node_id() {
self.activate_child2(&neighbor, true);
}
}
self.cnode_remove_child2(child.tl_as_node(), true);
self.cnode_remove_child2(&*child, true);
cn.insert_child(child, direction);
return;
}
@ -1053,7 +1051,7 @@ impl ContainerNode {
Some(p) => p,
_ => return,
};
self.cnode_remove_child2(child.tl_as_node(), true);
self.cnode_remove_child2(&*child, true);
match prev {
true => parent.add_child_before(&*neighbor, child.clone()),
false => parent.add_child_after(&*neighbor, child.clone()),
@ -1567,7 +1565,7 @@ impl Node for ContainerNode {
if content.contains(x, y) {
let (x, y) = content.translate(x, y);
tree.push(FoundNode {
node: child.node.clone().tl_into_node(),
node: child.node.clone(),
x,
y,
});

View file

@ -614,7 +614,7 @@ impl Node for FloatNode {
let x = x - bw;
let y = y - bw - th - 1;
tree.push(FoundNode {
node: child.clone().tl_into_node(),
node: child.clone(),
x,
y,
});
@ -833,8 +833,6 @@ impl ContainingNode for FloatNode {
}
impl StackedNode for FloatNode {
stacked_node_impl!();
fn stacked_set_visible(&self, visible: bool) {
if self.visible.replace(visible) != visible {
self.state.damage(self.position.get());

View file

@ -881,7 +881,7 @@ impl OutputNode {
let (x, y) = ext.translate(x_abs, y_abs);
let idx = tree.len();
tree.push(FoundNode {
node: stacked.deref().clone().stacked_into_node(),
node: stacked.deref().clone(),
x,
y,
});
@ -1401,11 +1401,11 @@ impl Node for OutputNode {
}
if let Some(fs) = fullscreen {
tree.push(FoundNode {
node: fs.clone().tl_into_node(),
node: fs.clone(),
x,
y,
});
fs.tl_as_node().node_find_tree_at(x, y, tree, usecase)
fs.node_find_tree_at(x, y, tree, usecase)
} else {
let mut search_layers = true;
let non_exclusive_rect = self.non_exclusive_rect_rel.get();
@ -1419,7 +1419,7 @@ impl Node for OutputNode {
if pos.contains(x, y) {
let (x, y) = pos.translate(x, y);
tree.push(FoundNode {
node: item.deref().clone().into_node(),
node: item.deref().clone(),
x,
y,
});

View file

@ -1,7 +1,6 @@
use {crate::tree::Node, std::rc::Rc};
use crate::tree::Node;
pub trait StackedNode: Node {
fn stacked_into_node(self: Rc<Self>) -> Rc<dyn Node>;
fn stacked_prepare_set_visible(&self) {
// nothing
}

View file

@ -40,9 +40,6 @@ use {
tree_id!(ToplevelNodeId);
pub trait ToplevelNode: ToplevelNodeBase {
fn tl_as_node(&self) -> &dyn Node;
fn tl_into_node(self: Rc<Self>) -> Rc<dyn Node>;
fn tl_into_dyn(self: Rc<Self>) -> Rc<dyn ToplevelNode>;
fn tl_surface_active_changed(&self, active: bool);
fn tl_set_fullscreen(self: Rc<Self>, fullscreen: bool);
fn tl_title_changed(&self);
@ -56,18 +53,6 @@ pub trait ToplevelNode: ToplevelNodeBase {
}
impl<T: ToplevelNodeBase> ToplevelNode for T {
fn tl_as_node(&self) -> &dyn Node {
self
}
fn tl_into_node(self: Rc<Self>) -> Rc<dyn Node> {
self
}
fn tl_into_dyn(self: Rc<Self>) -> Rc<dyn ToplevelNode> {
self
}
fn tl_surface_active_changed(&self, active: bool) {
let data = self.tl_data();
data.update_active(self, || {
@ -79,10 +64,10 @@ impl<T: ToplevelNodeBase> ToplevelNode for T {
let data = self.tl_data();
if fullscreen {
if let Some(ws) = data.workspace.get() {
data.set_fullscreen2(&data.state, self.clone().tl_into_dyn(), &ws);
data.set_fullscreen2(&data.state, self.clone(), &ws);
}
} else {
data.unset_fullscreen(&data.state, self.clone().tl_into_dyn());
data.unset_fullscreen(&data.state, self.clone());
}
}
@ -323,7 +308,7 @@ impl ToplevelData {
if active_old != active_new {
tl.tl_set_active(active_new);
if let Some(parent) = self.parent.get() {
parent.node_child_active_changed(tl.tl_as_node(), active_new, 1);
parent.node_child_active_changed(tl, active_new, 1);
}
}
}
@ -480,14 +465,14 @@ impl ToplevelData {
}
let placeholder =
Rc::new_cyclic(|weak| PlaceholderNode::new_for(state, node.clone(), weak));
parent.cnode_replace_child(node.tl_as_node(), placeholder.clone());
parent.cnode_replace_child(&*node, placeholder.clone());
let mut kb_foci = Default::default();
if ws.visible.get() {
if let Some(container) = ws.container.get() {
kb_foci = collect_kb_foci(container);
}
for stacked in ws.stacked.iter() {
collect_kb_foci2(stacked.deref().clone().stacked_into_node(), &mut kb_foci);
collect_kb_foci2(stacked.deref().clone(), &mut kb_foci);
}
}
*data = Some(FullscreenedData {
@ -501,9 +486,7 @@ impl ToplevelData {
node.clone()
.tl_change_extents(&ws.output.get().global.pos.get());
for seat in kb_foci {
node.clone()
.tl_into_node()
.node_do_focus(&seat, Direction::Unspecified);
node.clone().node_do_focus(&seat, Direction::Unspecified);
}
}
@ -527,7 +510,7 @@ impl ToplevelData {
);
return;
}
Some(f) if f.tl_as_node().node_id() != node.tl_as_node().node_id() => {
Some(f) if f.node_id() != node.node_id() => {
log::error!(
"Node is supposed to be fullscreened on a workspace but the workspace has a different node attached."
);
@ -542,12 +525,10 @@ impl ToplevelData {
}
let parent = fd.placeholder.tl_data().parent.get().unwrap();
parent.cnode_replace_child(fd.placeholder.deref(), node.clone());
if node.tl_as_node().node_visible() {
if node.node_visible() {
let kb_foci = collect_kb_foci(fd.placeholder.clone());
for seat in kb_foci {
node.clone()
.tl_into_node()
.node_do_focus(&seat, Direction::Unspecified);
node.clone().node_do_focus(&seat, Direction::Unspecified);
}
}
fd.placeholder

View file

@ -277,7 +277,7 @@ impl Node for WorkspaceNode {
visitor.visit_container(&c);
}
if let Some(fs) = self.fullscreen.get() {
fs.tl_into_node().node_visit(visitor);
fs.node_visit(visitor);
}
}
@ -291,7 +291,7 @@ impl Node for WorkspaceNode {
fn node_do_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
if let Some(fs) = self.fullscreen.get() {
fs.tl_into_node().node_do_focus(seat, direction);
fs.node_do_focus(seat, direction);
} else if let Some(container) = self.container.get() {
container.node_do_focus(seat, direction);
} else if let Some(float) = self
@ -359,7 +359,7 @@ impl ContainingNode for WorkspaceNode {
fn cnode_replace_child(self: Rc<Self>, old: &dyn Node, new: Rc<dyn ToplevelNode>) {
if let Some(container) = self.container.get() {
if container.node_id() == old.node_id() {
let new = match new.tl_into_node().node_into_container() {
let new = match new.node_into_container() {
Some(c) => c,
_ => {
log::error!("cnode_replace_child called with non-container new");
@ -383,7 +383,7 @@ impl ContainingNode for WorkspaceNode {
}
}
if let Some(fs) = self.fullscreen.get() {
if fs.tl_as_node().node_id() == child.node_id() {
if fs.node_id() == child.node_id() {
self.remove_fullscreen_node();
return;
}