1
0
Fork 0
forked from wry/wry

tree: add Node::node_location

This commit is contained in:
Julian Orth 2025-07-19 11:21:45 +02:00
parent f75051281b
commit 289c201a69
20 changed files with 152 additions and 45 deletions

View file

@ -18,8 +18,8 @@ use {
text::TextTexture,
tree::{
ContainingNode, Direction, FindTreeResult, FindTreeUsecase, FloatNode, FoundNode, Node,
NodeId, OutputNode, TddType, TileDragDestination, ToplevelData, ToplevelNode,
ToplevelNodeBase, ToplevelType, WorkspaceNode, default_tile_drag_bounds,
NodeId, NodeLocation, OutputNode, TddType, TileDragDestination, ToplevelData,
ToplevelNode, ToplevelNodeBase, ToplevelType, WorkspaceNode, default_tile_drag_bounds,
toplevel_set_floating, walker::NodeVisitor,
},
utils::{
@ -129,6 +129,7 @@ pub struct ContainerNode {
focus_history: LinkedList<NodeRef<ContainerChild>>,
child_nodes: RefCell<AHashMap<NodeId, LinkedNode<ContainerChild>>>,
workspace: CloneCell<Rc<WorkspaceNode>>,
location: Cell<NodeLocation>,
cursors: RefCell<AHashMap<CursorType, CursorState>>,
state: Rc<State>,
pub render_data: RefCell<ContainerRenderData>,
@ -235,6 +236,7 @@ impl ContainerNode {
focus_history: Default::default(),
child_nodes: RefCell::new(child_nodes),
workspace: CloneCell::new(workspace.clone()),
location: Cell::new(workspace.location()),
cursors: RefCell::new(Default::default()),
state: state.clone(),
render_data: Default::default(),
@ -1547,6 +1549,10 @@ impl Node for ContainerNode {
self.toplevel_data.output_opt()
}
fn node_location(&self) -> Option<NodeLocation> {
Some(self.location.get())
}
fn node_child_title_changed(self: Rc<Self>, child: &dyn Node, title: &str) {
if let Some(child) = self.child_nodes.borrow().get(&child.node_id()) {
self.update_child_title(child, title);
@ -2085,6 +2091,7 @@ impl ToplevelNodeBase for ContainerNode {
fn tl_set_workspace_ext(&self, ws: &Rc<WorkspaceNode>) {
self.workspace.set(ws.clone());
self.location.set(ws.location());
for child in self.children.iter() {
child.node.clone().tl_set_workspace(ws);
}

View file

@ -8,8 +8,9 @@ use {
renderer::Renderer,
state::State,
tree::{
FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId, OutputNode, StackedNode,
TileDragDestination, WorkspaceDragDestination, WorkspaceNodeId, walker::NodeVisitor,
FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId, NodeLocation, OutputNode,
StackedNode, TileDragDestination, WorkspaceDragDestination, WorkspaceNodeId,
walker::NodeVisitor,
},
utils::{copyhashmap::CopyHashMap, linkedlist::LinkedList},
},
@ -150,6 +151,10 @@ impl Node for DisplayNode {
None
}
fn node_location(&self) -> Option<NodeLocation> {
None
}
fn node_find_tree_at(
&self,
x: i32,

View file

@ -15,8 +15,8 @@ use {
text::TextTexture,
tree::{
ContainingNode, Direction, FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId,
OutputNode, PinnedNode, StackedNode, TileDragDestination, ToplevelNode, WorkspaceNode,
toplevel_set_floating, walker::NodeVisitor,
NodeLocation, OutputNode, PinnedNode, StackedNode, TileDragDestination, ToplevelNode,
WorkspaceNode, toplevel_set_floating, walker::NodeVisitor,
},
utils::{
asyncevent::AsyncEvent, clonecell::CloneCell, double_click_state::DoubleClickState,
@ -45,6 +45,7 @@ pub struct FloatNode {
pub workspace_link: Cell<Option<LinkedNode<Rc<dyn StackedNode>>>>,
pub pinned_link: RefCell<Option<LinkedNode<Rc<dyn PinnedNode>>>>,
pub workspace: CloneCell<Rc<WorkspaceNode>>,
pub location: Cell<NodeLocation>,
pub child: CloneCell<Option<Rc<dyn ToplevelNode>>>,
pub active: Cell<bool>,
pub seat_state: NodeSeatState,
@ -124,6 +125,7 @@ impl FloatNode {
workspace_link: Cell::new(None),
pinned_link: RefCell::new(None),
workspace: CloneCell::new(ws.clone()),
location: Cell::new(ws.location()),
child: CloneCell::new(Some(child.clone())),
active: Cell::new(false),
seat_state: Default::default(),
@ -423,6 +425,7 @@ impl FloatNode {
self.workspace_link
.set(Some(ws.stacked.add_last(self.clone())));
self.workspace.set(ws.clone());
self.location.set(ws.location());
if update_visible {
self.stacked_set_visible(ws.float_visible());
}
@ -702,6 +705,10 @@ impl Node for FloatNode {
Some(self.workspace.get().output.get())
}
fn node_location(&self) -> Option<NodeLocation> {
Some(self.location.get())
}
fn node_child_title_changed(self: Rc<Self>, _child: &dyn Node, title: &str) {
self.update_child_title(title);
}

View file

@ -43,9 +43,9 @@ use {
state::State,
text::TextTexture,
tree::{
Direction, FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId, PinnedNode,
StackedNode, TddType, TileDragDestination, WorkspaceDragDestination, WorkspaceNode,
WorkspaceNodeId, walker::NodeVisitor,
Direction, FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId, NodeLocation,
PinnedNode, StackedNode, TddType, TileDragDestination, WorkspaceDragDestination,
WorkspaceNode, WorkspaceNodeId, walker::NodeVisitor,
},
utils::{
asyncevent::AsyncEvent, bitflags::BitflagsExt, clonecell::CloneCell,
@ -718,6 +718,7 @@ impl OutputNode {
state: self.state.clone(),
is_dummy: false,
output: CloneCell::new(self.clone()),
output_id: Cell::new(self.id),
position: Cell::new(Default::default()),
container: Default::default(),
stacked: Default::default(),
@ -1476,6 +1477,10 @@ impl Node for OutputNode {
self.global.opt.node()
}
fn node_location(&self) -> Option<NodeLocation> {
Some(NodeLocation::Output(self.id))
}
fn node_do_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
if self.state.lock.locked.get() {
if let Some(lock) = self.lock_surface.get() {

View file

@ -11,8 +11,8 @@ use {
text::TextTexture,
tree::{
ContainerSplit, Direction, FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId,
NodeVisitor, OutputNode, TileDragDestination, ToplevelData, ToplevelNode,
ToplevelNodeBase, ToplevelType, default_tile_drag_destination,
NodeLocation, NodeVisitor, OutputNode, TileDragDestination, ToplevelData, ToplevelNode,
ToplevelNodeBase, ToplevelType, WorkspaceNode, default_tile_drag_destination,
},
utils::{
asyncevent::AsyncEvent, errorfmt::ErrorFmt, on_drop_event::OnDropEvent,
@ -35,6 +35,7 @@ pub struct PlaceholderNode {
destroyed: Cell<bool>,
update_textures_scheduled: Cell<bool>,
state: Rc<State>,
location: Cell<Option<NodeLocation>>,
pub textures: RefCell<SmallMapMut<Scale, TextTexture, 2>>,
}
@ -63,6 +64,7 @@ impl PlaceholderNode {
destroyed: Default::default(),
update_textures_scheduled: Cell::new(false),
state: state.clone(),
location: Cell::new(node.node_location()),
textures: Default::default(),
}
}
@ -82,6 +84,7 @@ impl PlaceholderNode {
destroyed: Default::default(),
update_textures_scheduled: Default::default(),
state: state.clone(),
location: Default::default(),
textures: Default::default(),
}
}
@ -174,6 +177,10 @@ impl Node for PlaceholderNode {
self.toplevel.output_opt()
}
fn node_location(&self) -> Option<NodeLocation> {
self.location.get()
}
fn node_do_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, _direction: Direction) {
seat.focus_toplevel(self.clone());
}
@ -223,6 +230,10 @@ impl ToplevelNodeBase for PlaceholderNode {
&self.toplevel
}
fn tl_set_workspace_ext(&self, ws: &Rc<WorkspaceNode>) {
self.location.set(ws.node_location());
}
fn tl_change_extents_impl(self: Rc<Self>, rect: &Rect) {
self.toplevel.pos.set(*rect);
if let Some(p) = self.toplevel.parent.get() {

View file

@ -21,8 +21,8 @@ use {
text::TextTexture,
tree::{
ContainingNode, Direction, FindTreeResult, FindTreeUsecase, FloatNode, FoundNode, Node,
NodeId, NodeVisitorBase, OutputNode, PlaceholderNode, StackedNode, ToplevelNode,
container::ContainerNode, walker::NodeVisitor,
NodeId, NodeLocation, NodeVisitorBase, OutputNode, OutputNodeId, PlaceholderNode,
StackedNode, ToplevelNode, container::ContainerNode, walker::NodeVisitor,
},
utils::{
clonecell::CloneCell,
@ -49,6 +49,7 @@ pub struct WorkspaceNode {
pub state: Rc<State>,
pub is_dummy: bool,
pub output: CloneCell<Rc<OutputNode>>,
pub output_id: Cell<OutputNodeId>,
pub position: Cell<Rect>,
pub container: CloneCell<Option<Rc<ContainerNode>>>,
pub stacked: LinkedList<Rc<dyn StackedNode>>,
@ -104,6 +105,7 @@ impl WorkspaceNode {
}
pub fn set_output(&self, output: &Rc<OutputNode>) {
self.output_id.set(output.id);
let old = self.output.set(output.clone());
for wh in self.ext_workspaces.lock().values() {
wh.handle_new_output(output);
@ -113,12 +115,13 @@ impl WorkspaceNode {
}
self.update_has_captures();
struct OutputSetter<'a> {
ws: &'a WorkspaceNode,
old: &'a Rc<OutputNode>,
new: &'a Rc<OutputNode>,
}
impl NodeVisitorBase for OutputSetter<'_> {
fn visit_surface(&mut self, node: &Rc<WlSurface>) {
node.set_output(self.new);
node.set_output(self.new, self.ws.location());
}
fn visit_container(&mut self, node: &Rc<ContainerNode>) {
@ -147,6 +150,7 @@ impl WorkspaceNode {
}
}
let mut visitor = OutputSetter {
ws: self,
old: &old,
new: output,
};
@ -273,6 +277,10 @@ impl WorkspaceNode {
self.output.get().schedule_update_render_data();
}
}
pub fn location(&self) -> NodeLocation {
NodeLocation::Workspace(self.output_id.get(), self.id)
}
}
impl Node for WorkspaceNode {
@ -309,6 +317,10 @@ impl Node for WorkspaceNode {
Some(self.output.get())
}
fn node_location(&self) -> Option<NodeLocation> {
Some(self.location())
}
fn node_do_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
if let Some(fs) = self.fullscreen.get() {
fs.node_do_focus(seat, direction);