1
0
Fork 0
forked from wry/wry

tree: move common code out of ToplevelNode trait

This commit is contained in:
Julian Orth 2024-02-21 14:03:33 +01:00
parent 8430278264
commit 1d1d542839
12 changed files with 100 additions and 90 deletions

View file

@ -12,7 +12,7 @@ use {
state::State, state::State,
tree::{ tree::{
Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, StackedNode, Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, StackedNode,
ToplevelData, ToplevelNode, WorkspaceNode, ToplevelData, ToplevelNode, ToplevelNodeBase, WorkspaceNode,
}, },
utils::{clonecell::CloneCell, copyhashmap::CopyHashMap, linkedlist::LinkedNode}, utils::{clonecell::CloneCell, copyhashmap::CopyHashMap, linkedlist::LinkedNode},
wire::WlSurfaceId, wire::WlSurfaceId,
@ -357,9 +357,7 @@ impl Node for Xwindow {
} }
} }
impl ToplevelNode for Xwindow { impl ToplevelNodeBase for Xwindow {
tl_node_impl!();
fn tl_data(&self) -> &ToplevelData { fn tl_data(&self) -> &ToplevelData {
&self.toplevel_data &self.toplevel_data
} }
@ -410,17 +408,19 @@ impl ToplevelNode for Xwindow {
.push(XWaylandEvent::Close(self.data.clone())); .push(XWaylandEvent::Close(self.data.clone()));
} }
fn tl_set_visible(&self, visible: bool) { fn tl_set_visible_impl(&self, visible: bool) {
self.x.surface.set_visible(visible); self.x.surface.set_visible(visible);
self.toplevel_data.set_visible(self, visible);
} }
fn tl_destroy(&self) { fn tl_destroy_impl(&self) {
self.toplevel_data.destroy_node(self);
self.display_link.borrow_mut().take(); self.display_link.borrow_mut().take();
self.x.surface.destroy_node(); self.x.surface.destroy_node();
} }
fn tl_last_active_child(self: Rc<Self>) -> Rc<dyn ToplevelNode> {
self
}
fn tl_scanout_surface(&self) -> Option<Rc<WlSurface>> { fn tl_scanout_surface(&self) -> Option<Rc<WlSurface>> {
Some(self.x.surface.clone()) Some(self.x.surface.clone())
} }

View file

@ -20,7 +20,7 @@ use {
state::State, state::State,
tree::{ tree::{
Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, ToplevelData, Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, ToplevelData,
ToplevelNode, ToplevelNodeId, WorkspaceNode, ToplevelNode, ToplevelNodeBase, ToplevelNodeId, WorkspaceNode,
}, },
utils::{ utils::{
buffd::{MsgParser, MsgParserError}, buffd::{MsgParser, MsgParserError},
@ -453,9 +453,7 @@ impl Node for XdgToplevel {
} }
} }
impl ToplevelNode for XdgToplevel { impl ToplevelNodeBase for XdgToplevel {
tl_node_impl!();
fn tl_data(&self) -> &ToplevelData { fn tl_data(&self) -> &ToplevelData {
&self.toplevel_data &self.toplevel_data
} }
@ -499,13 +497,12 @@ impl ToplevelNode for XdgToplevel {
self.send_close(); self.send_close();
} }
fn tl_set_visible(&self, visible: bool) { fn tl_set_visible_impl(&self, visible: bool) {
// log::info!("set_visible {}", visible); // log::info!("set_visible {}", visible);
// if !visible { // if !visible {
// log::info!("\n{:?}", Backtrace::new()); // log::info!("\n{:?}", Backtrace::new());
// } // }
self.xdg.set_visible(visible); self.xdg.set_visible(visible);
self.toplevel_data.set_visible(self, visible);
if self.xdg.base.version >= SUSPENDED_SINCE { if self.xdg.base.version >= SUSPENDED_SINCE {
if visible { if visible {
self.states.borrow_mut().remove(&STATE_SUSPENDED); self.states.borrow_mut().remove(&STATE_SUSPENDED);
@ -516,8 +513,7 @@ impl ToplevelNode for XdgToplevel {
} }
} }
fn tl_destroy(&self) { fn tl_destroy_impl(&self) {
self.toplevel_data.destroy_node(self);
self.xdg.destroy_node(); self.xdg.destroy_node();
} }
@ -544,6 +540,10 @@ impl ToplevelNode for XdgToplevel {
// } // }
// } // }
fn tl_last_active_child(self: Rc<Self>) -> Rc<dyn ToplevelNode> {
self
}
fn tl_scanout_surface(&self) -> Option<Rc<WlSurface>> { fn tl_scanout_surface(&self) -> Option<Rc<WlSurface>> {
Some(self.xdg.surface.clone()) Some(self.xdg.surface.clone())
} }

View file

@ -7,7 +7,7 @@ use {
test_transport::TestTransport, test_transport::TestTransport,
testrun::ParseFull, testrun::ParseFull,
}, },
tree::{ContainerNode, ToplevelNode}, tree::{ContainerNode, ToplevelNodeBase},
utils::buffd::MsgParser, utils::buffd::MsgParser,
wire::{xdg_toplevel::*, XdgToplevelId}, wire::{xdg_toplevel::*, XdgToplevelId},
}, },

View file

@ -1,7 +1,7 @@
use { use {
crate::{ crate::{
it::{test_error::TestError, testrun::TestRun}, it::{test_error::TestError, testrun::TestRun},
tree::ToplevelNode, tree::ToplevelNodeBase,
}, },
std::rc::Rc, std::rc::Rc,
}; };

View file

@ -4,7 +4,7 @@ use {
test_error::{TestErrorExt, TestResult}, test_error::{TestErrorExt, TestResult},
testrun::TestRun, testrun::TestRun,
}, },
tree::ToplevelNode, tree::ToplevelNodeBase,
}, },
jay_config::Axis, jay_config::Axis,
std::rc::Rc, std::rc::Rc,

View file

@ -1,7 +1,7 @@
use { use {
crate::{ crate::{
it::{test_error::TestResult, testrun::TestRun}, it::{test_error::TestResult, testrun::TestRun},
tree::ToplevelNode, tree::ToplevelNodeBase,
}, },
std::rc::Rc, std::rc::Rc,
}; };

View file

@ -476,22 +476,6 @@ macro_rules! fatal {
}} }}
} }
macro_rules! tl_node_impl {
() => {
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
}
};
}
macro_rules! stacked_node_impl { macro_rules! stacked_node_impl {
() => { () => {
fn stacked_as_node(&self) -> &dyn Node { fn stacked_as_node(&self) -> &dyn Node {

View file

@ -15,7 +15,7 @@ use {
state::State, state::State,
theme::Color, theme::Color,
tree::{ tree::{
ContainerNode, DisplayNode, FloatNode, OutputNode, PlaceholderNode, ToplevelNode, ContainerNode, DisplayNode, FloatNode, OutputNode, PlaceholderNode, ToplevelNodeBase,
WorkspaceNode, WorkspaceNode,
}, },
}, },

View file

@ -42,7 +42,8 @@ use {
theme::{Color, Theme}, theme::{Color, Theme},
tree::{ tree::{
ContainerNode, ContainerSplit, Direction, DisplayNode, FloatNode, Node, NodeIds, ContainerNode, ContainerSplit, Direction, DisplayNode, FloatNode, Node, NodeIds,
NodeVisitorBase, OutputNode, PlaceholderNode, ToplevelNode, WorkspaceNode, NodeVisitorBase, OutputNode, PlaceholderNode, ToplevelNode, ToplevelNodeBase,
WorkspaceNode,
}, },
utils::{ utils::{
activation_token::ActivationToken, asyncevent::AsyncEvent, clonecell::CloneCell, activation_token::ActivationToken, asyncevent::AsyncEvent, clonecell::CloneCell,

View file

@ -14,7 +14,7 @@ use {
text::{self, TextTexture}, text::{self, TextTexture},
tree::{ tree::{
walker::NodeVisitor, ContainingNode, Direction, FindTreeResult, FoundNode, Node, walker::NodeVisitor, ContainingNode, Direction, FindTreeResult, FoundNode, Node,
NodeId, ToplevelData, ToplevelNode, WorkspaceNode, NodeId, ToplevelData, ToplevelNode, ToplevelNodeBase, WorkspaceNode,
}, },
utils::{ utils::{
clonecell::CloneCell, clonecell::CloneCell,
@ -1421,9 +1421,7 @@ impl ContainingNode for ContainerNode {
} }
} }
impl ToplevelNode for ContainerNode { impl ToplevelNodeBase for ContainerNode {
tl_node_impl!();
fn tl_data(&self) -> &ToplevelData { fn tl_data(&self) -> &ToplevelData {
&self.toplevel_data &self.toplevel_data
} }
@ -1479,7 +1477,7 @@ impl ToplevelNode for ContainerNode {
} }
} }
fn tl_set_visible(&self, visible: bool) { fn tl_set_visible_impl(&self, visible: bool) {
if let Some(mc) = self.mono_child.get() { if let Some(mc) = self.mono_child.get() {
mc.node.tl_set_visible(visible); mc.node.tl_set_visible(visible);
} else { } else {
@ -1487,11 +1485,9 @@ impl ToplevelNode for ContainerNode {
child.node.tl_set_visible(visible); child.node.tl_set_visible(visible);
} }
} }
self.toplevel_data.set_visible(self, visible);
} }
fn tl_destroy(&self) { fn tl_destroy_impl(&self) {
self.toplevel_data.destroy_node(self);
mem::take(self.seats.borrow_mut().deref_mut()); mem::take(self.seats.borrow_mut().deref_mut());
let mut cn = self.child_nodes.borrow_mut(); let mut cn = self.child_nodes.borrow_mut();
for (_, n) in cn.drain() { for (_, n) in cn.drain() {

View file

@ -11,7 +11,7 @@ use {
text::{self, TextTexture}, text::{self, TextTexture},
tree::{ tree::{
Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, ToplevelData, Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, ToplevelData,
ToplevelNode, ToplevelNode, ToplevelNodeBase,
}, },
utils::{errorfmt::ErrorFmt, smallmap::SmallMap}, utils::{errorfmt::ErrorFmt, smallmap::SmallMap},
}, },
@ -145,17 +145,11 @@ impl Node for PlaceholderNode {
} }
} }
impl ToplevelNode for PlaceholderNode { impl ToplevelNodeBase for PlaceholderNode {
tl_node_impl!();
fn tl_data(&self) -> &ToplevelData { fn tl_data(&self) -> &ToplevelData {
&self.toplevel &self.toplevel
} }
fn tl_default_focus_child(&self) -> Option<Rc<dyn Node>> {
None
}
fn tl_change_extents_impl(self: Rc<Self>, rect: &Rect) { fn tl_change_extents_impl(self: Rc<Self>, rect: &Rect) {
self.toplevel.pos.set(*rect); self.toplevel.pos.set(*rect);
if let Some(p) = self.toplevel.parent.get() { if let Some(p) = self.toplevel.parent.get() {
@ -171,12 +165,15 @@ impl ToplevelNode for PlaceholderNode {
}); });
} }
fn tl_set_visible(&self, visible: bool) { fn tl_set_visible_impl(&self, _visible: bool) {
self.toplevel.set_visible(self, visible); // nothing
} }
fn tl_destroy(&self) { fn tl_destroy_impl(&self) {
self.toplevel.destroy_node(self);
self.destroyed.set(true); self.destroyed.set(true);
} }
fn tl_last_active_child(self: Rc<Self>) -> Rc<dyn ToplevelNode> {
self
}
} }

View file

@ -28,27 +28,33 @@ use {
tree_id!(ToplevelNodeId); tree_id!(ToplevelNodeId);
pub trait ToplevelNode: Node { pub trait ToplevelNode: ToplevelNodeBase {
fn tl_as_node(&self) -> &dyn Node; fn tl_as_node(&self) -> &dyn Node;
fn tl_into_node(self: Rc<Self>) -> Rc<dyn Node>; fn tl_into_node(self: Rc<Self>) -> Rc<dyn Node>;
fn tl_into_dyn(self: Rc<Self>) -> Rc<dyn ToplevelNode>; 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);
fn tl_set_parent(&self, parent: Rc<dyn ContainingNode>);
fn tl_active_changed(&self);
fn tl_extents_changed(&self);
fn tl_set_workspace(self: Rc<Self>, ws: &Rc<WorkspaceNode>);
fn tl_change_extents(self: Rc<Self>, rect: &Rect);
fn tl_set_visible(&self, visible: bool);
fn tl_destroy(&self);
}
fn tl_data(&self) -> &ToplevelData; impl<T: ToplevelNodeBase> ToplevelNode for T {
fn tl_as_node(&self) -> &dyn Node {
fn tl_default_focus_child(&self) -> Option<Rc<dyn Node>> { self
None
} }
fn tl_accepts_keyboard_focus(&self) -> bool { fn tl_into_node(self: Rc<Self>) -> Rc<dyn Node> {
true self
} }
fn tl_set_active(&self, active: bool) { fn tl_into_dyn(self: Rc<Self>) -> Rc<dyn ToplevelNode> {
let _ = active; self
}
fn tl_on_activate(&self) {
// nothing
} }
fn tl_surface_active_changed(&self, active: bool) { fn tl_surface_active_changed(&self, active: bool) {
@ -70,13 +76,6 @@ pub trait ToplevelNode: Node {
} }
} }
fn tl_focus_child(&self, seat: SeatId) -> Option<Rc<dyn Node>> {
self.tl_data()
.focus_node
.get(&seat)
.or_else(|| self.tl_default_focus_child())
}
fn tl_set_fullscreen(self: Rc<Self>, fullscreen: bool) { fn tl_set_fullscreen(self: Rc<Self>, fullscreen: bool) {
let data = self.tl_data(); let data = self.tl_data();
if fullscreen { if fullscreen {
@ -92,7 +91,7 @@ pub trait ToplevelNode: Node {
let data = self.tl_data(); let data = self.tl_data();
let title = data.title.borrow_mut(); let title = data.title.borrow_mut();
if let Some(parent) = data.parent.get() { if let Some(parent) = data.parent.get() {
parent.node_child_title_changed(self.tl_as_node(), &title); parent.node_child_title_changed(self, &title);
} }
if let Some(data) = data.fullscrceen_data.borrow_mut().deref() { if let Some(data) = data.fullscrceen_data.borrow_mut().deref() {
*data.placeholder.tl_data().title.borrow_mut() = title.clone(); *data.placeholder.tl_data().title.borrow_mut() = title.clone();
@ -139,10 +138,6 @@ pub trait ToplevelNode: Node {
self.tl_set_workspace_ext(ws); self.tl_set_workspace_ext(ws);
} }
fn tl_set_workspace_ext(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
let _ = ws;
}
fn tl_change_extents(self: Rc<Self>, rect: &Rect) { fn tl_change_extents(self: Rc<Self>, rect: &Rect) {
let data = self.tl_data(); let data = self.tl_data();
if data.is_floating.get() { if data.is_floating.get() {
@ -152,19 +147,56 @@ pub trait ToplevelNode: Node {
self.tl_change_extents_impl(rect) self.tl_change_extents_impl(rect)
} }
fn tl_change_extents_impl(self: Rc<Self>, rect: &Rect); fn tl_set_visible(&self, visible: bool) {
self.tl_set_visible_impl(visible);
self.tl_data().set_visible(self, visible);
}
fn tl_close(self: Rc<Self>) { fn tl_destroy(&self) {
self.tl_data().destroy_node(self);
self.tl_destroy_impl();
}
}
pub trait ToplevelNodeBase: Node {
fn tl_data(&self) -> &ToplevelData;
fn tl_default_focus_child(&self) -> Option<Rc<dyn Node>> {
None
}
fn tl_accepts_keyboard_focus(&self) -> bool {
true
}
fn tl_set_active(&self, active: bool) {
let _ = active;
}
fn tl_on_activate(&self) {
// nothing // nothing
} }
fn tl_set_visible(&self, visible: bool); fn tl_focus_child(&self, seat: SeatId) -> Option<Rc<dyn Node>> {
fn tl_destroy(&self); self.tl_data()
.focus_node
fn tl_last_active_child(self: Rc<Self>) -> Rc<dyn ToplevelNode> { .get(&seat)
self.tl_into_dyn() .or_else(|| self.tl_default_focus_child())
} }
fn tl_set_workspace_ext(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
let _ = ws;
}
fn tl_change_extents_impl(self: Rc<Self>, rect: &Rect);
fn tl_close(self: Rc<Self>);
fn tl_set_visible_impl(&self, visible: bool);
fn tl_destroy_impl(&self);
fn tl_last_active_child(self: Rc<Self>) -> Rc<dyn ToplevelNode>;
fn tl_scanout_surface(&self) -> Option<Rc<WlSurface>> { fn tl_scanout_surface(&self) -> Option<Rc<WlSurface>> {
None None
} }