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,
tree::{
Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, StackedNode,
ToplevelData, ToplevelNode, WorkspaceNode,
ToplevelData, ToplevelNode, ToplevelNodeBase, WorkspaceNode,
},
utils::{clonecell::CloneCell, copyhashmap::CopyHashMap, linkedlist::LinkedNode},
wire::WlSurfaceId,
@ -357,9 +357,7 @@ impl Node for Xwindow {
}
}
impl ToplevelNode for Xwindow {
tl_node_impl!();
impl ToplevelNodeBase for Xwindow {
fn tl_data(&self) -> &ToplevelData {
&self.toplevel_data
}
@ -410,17 +408,19 @@ impl ToplevelNode for Xwindow {
.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.toplevel_data.set_visible(self, visible);
}
fn tl_destroy(&self) {
self.toplevel_data.destroy_node(self);
fn tl_destroy_impl(&self) {
self.display_link.borrow_mut().take();
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>> {
Some(self.x.surface.clone())
}

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
use {
crate::{
it::{test_error::TestResult, testrun::TestRun},
tree::ToplevelNode,
tree::ToplevelNodeBase,
},
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 {
() => {
fn stacked_as_node(&self) -> &dyn Node {

View file

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

View file

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

View file

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

View file

@ -11,7 +11,7 @@ use {
text::{self, TextTexture},
tree::{
Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, ToplevelData,
ToplevelNode,
ToplevelNode, ToplevelNodeBase,
},
utils::{errorfmt::ErrorFmt, smallmap::SmallMap},
},
@ -145,17 +145,11 @@ impl Node for PlaceholderNode {
}
}
impl ToplevelNode for PlaceholderNode {
tl_node_impl!();
impl ToplevelNodeBase for PlaceholderNode {
fn tl_data(&self) -> &ToplevelData {
&self.toplevel
}
fn tl_default_focus_child(&self) -> Option<Rc<dyn Node>> {
None
}
fn tl_change_extents_impl(self: Rc<Self>, rect: &Rect) {
self.toplevel.pos.set(*rect);
if let Some(p) = self.toplevel.parent.get() {
@ -171,12 +165,15 @@ impl ToplevelNode for PlaceholderNode {
});
}
fn tl_set_visible(&self, visible: bool) {
self.toplevel.set_visible(self, visible);
fn tl_set_visible_impl(&self, _visible: bool) {
// nothing
}
fn tl_destroy(&self) {
self.toplevel.destroy_node(self);
fn tl_destroy_impl(&self) {
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);
pub trait ToplevelNode: Node {
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);
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;
fn tl_default_focus_child(&self) -> Option<Rc<dyn Node>> {
None
impl<T: ToplevelNodeBase> ToplevelNode for T {
fn tl_as_node(&self) -> &dyn Node {
self
}
fn tl_accepts_keyboard_focus(&self) -> bool {
true
fn tl_into_node(self: Rc<Self>) -> Rc<dyn Node> {
self
}
fn tl_set_active(&self, active: bool) {
let _ = active;
}
fn tl_on_activate(&self) {
// nothing
fn tl_into_dyn(self: Rc<Self>) -> Rc<dyn ToplevelNode> {
self
}
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) {
let data = self.tl_data();
if fullscreen {
@ -92,7 +91,7 @@ pub trait ToplevelNode: Node {
let data = self.tl_data();
let title = data.title.borrow_mut();
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() {
*data.placeholder.tl_data().title.borrow_mut() = title.clone();
@ -139,10 +138,6 @@ pub trait ToplevelNode: Node {
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) {
let data = self.tl_data();
if data.is_floating.get() {
@ -152,19 +147,56 @@ pub trait ToplevelNode: Node {
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
}
fn tl_set_visible(&self, visible: bool);
fn tl_destroy(&self);
fn tl_last_active_child(self: Rc<Self>) -> Rc<dyn ToplevelNode> {
self.tl_into_dyn()
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_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>> {
None
}