1
0
Fork 0
forked from wry/wry

seat: add framework to select toplevels

This commit is contained in:
Julian Orth 2024-04-18 13:43:44 +02:00
parent e4e090d3a2
commit 17a0dfed5e
31 changed files with 603 additions and 131 deletions

View file

@ -13,8 +13,8 @@ use {
state::State,
text::{self, TextTexture},
tree::{
walker::NodeVisitor, ContainingNode, Direction, FindTreeResult, FoundNode, Node,
NodeId, ToplevelData, ToplevelNode, ToplevelNodeBase, WorkspaceNode,
walker::NodeVisitor, ContainingNode, Direction, FindTreeResult, FindTreeUsecase,
FoundNode, Node, NodeId, ToplevelData, ToplevelNode, ToplevelNodeBase, WorkspaceNode,
},
utils::{
clonecell::CloneCell,
@ -1131,7 +1131,13 @@ impl Node for ContainerNode {
self.toplevel_data.update_self_active(self, active);
}
fn node_find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
fn node_find_tree_at(
&self,
x: i32,
y: i32,
tree: &mut Vec<FoundNode>,
usecase: FindTreeUsecase,
) -> FindTreeResult {
let mut recurse = |content: Rect, child: NodeRef<ContainerChild>| {
if content.contains(x, y) {
let (x, y) = content.translate(x, y);
@ -1140,7 +1146,7 @@ impl Node for ContainerNode {
x,
y,
});
child.node.node_find_tree_at(x, y, tree);
child.node.node_find_tree_at(x, y, tree, usecase);
}
};
if let Some(child) = self.mono_child.get() {
@ -1329,6 +1335,10 @@ impl Node for ContainerNode {
fn node_is_container(&self) -> bool {
true
}
fn node_into_toplevel(self: Rc<Self>) -> Option<Rc<dyn ToplevelNode>> {
Some(self)
}
}
impl ContainingNode for ContainerNode {
@ -1549,6 +1559,10 @@ impl ToplevelNodeBase for ContainerNode {
}
}
}
fn tl_admits_children(&self) -> bool {
true
}
}
fn direction_to_split(dir: Direction) -> (ContainerSplit, bool) {

View file

@ -7,7 +7,8 @@ use {
renderer::Renderer,
state::State,
tree::{
walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId, OutputNode, StackedNode,
walker::NodeVisitor, FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId,
OutputNode, StackedNode,
},
utils::{copyhashmap::CopyHashMap, linkedlist::LinkedList},
},
@ -109,7 +110,13 @@ impl Node for DisplayNode {
self.extents.get()
}
fn node_find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
fn node_find_tree_at(
&self,
x: i32,
y: i32,
tree: &mut Vec<FoundNode>,
usecase: FindTreeUsecase,
) -> FindTreeResult {
let outputs = self.outputs.lock();
for output in outputs.values() {
let pos = output.global.pos.get();
@ -120,7 +127,7 @@ impl Node for DisplayNode {
x,
y,
});
output.node_find_tree_at(x, y, tree);
output.node_find_tree_at(x, y, tree, usecase);
break;
}
}

View file

@ -10,8 +10,8 @@ use {
state::State,
text::{self, TextTexture},
tree::{
walker::NodeVisitor, ContainingNode, Direction, FindTreeResult, FoundNode, Node,
NodeId, StackedNode, ToplevelNode, WorkspaceNode,
walker::NodeVisitor, ContainingNode, Direction, FindTreeResult, FindTreeUsecase,
FoundNode, Node, NodeId, StackedNode, ToplevelNode, WorkspaceNode,
},
utils::{
clonecell::CloneCell, copyhashmap::CopyHashMap, double_click_state::DoubleClickState,
@ -437,7 +437,13 @@ impl Node for FloatNode {
self.update_child_title(title);
}
fn node_find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
fn node_find_tree_at(
&self,
x: i32,
y: i32,
tree: &mut Vec<FoundNode>,
usecase: FindTreeUsecase,
) -> FindTreeResult {
let theme = &self.state.theme;
let th = theme.sizes.title_height.get();
let bw = theme.sizes.border_width.get();
@ -459,7 +465,7 @@ impl Node for FloatNode {
x,
y,
});
child.node_find_tree_at(x, y, tree)
child.node_find_tree_at(x, y, tree, usecase)
}
fn node_child_active_changed(self: Rc<Self>, _child: &dyn Node, active: bool, _depth: u32) {

View file

@ -26,7 +26,8 @@ use {
state::State,
text::{self, TextTexture},
tree::{
walker::NodeVisitor, Direction, FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode,
walker::NodeVisitor, Direction, FindTreeResult, FindTreeUsecase, FoundNode, Node,
NodeId, WorkspaceNode,
},
utils::{
clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt,
@ -470,14 +471,20 @@ impl OutputNode {
y: i32,
layers: &[u32],
tree: &mut Vec<FoundNode>,
usecase: FindTreeUsecase,
) -> FindTreeResult {
if usecase == FindTreeUsecase::SelectToplevel {
return FindTreeResult::Other;
}
let len = tree.len();
for layer in layers.iter().copied() {
for surface in self.layers[layer as usize].rev_iter() {
let pos = surface.output_position();
if pos.contains(x, y) {
let (x, y) = pos.translate(x, y);
if surface.node_find_tree_at(x, y, tree) == FindTreeResult::AcceptsInput {
if surface.node_find_tree_at(x, y, tree, usecase)
== FindTreeResult::AcceptsInput
{
return FindTreeResult::AcceptsInput;
}
tree.truncate(len);
@ -627,20 +634,28 @@ impl Node for OutputNode {
}
}
fn node_find_tree_at(&self, x: i32, mut y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
fn node_find_tree_at(
&self,
x: i32,
mut y: i32,
tree: &mut Vec<FoundNode>,
usecase: FindTreeUsecase,
) -> FindTreeResult {
if self.state.lock.locked.get() {
if let Some(ls) = self.lock_surface.get() {
tree.push(FoundNode {
node: ls.clone(),
x,
y,
});
return ls.node_find_tree_at(x, y, tree);
if usecase != FindTreeUsecase::SelectToplevel {
if let Some(ls) = self.lock_surface.get() {
tree.push(FoundNode {
node: ls.clone(),
x,
y,
});
return ls.node_find_tree_at(x, y, tree, usecase);
}
}
return FindTreeResult::AcceptsInput;
}
{
let res = self.find_layer_surface_at(x, y, &[OVERLAY, TOP], tree);
let res = self.find_layer_surface_at(x, y, &[OVERLAY, TOP], tree, usecase);
if res.accepts_input() {
return res;
}
@ -665,7 +680,7 @@ impl Node for OutputNode {
x,
y,
});
match stacked.node_find_tree_at(x, y, tree) {
match stacked.node_find_tree_at(x, y, tree, usecase) {
FindTreeResult::AcceptsInput => {
return FindTreeResult::AcceptsInput;
}
@ -685,7 +700,7 @@ impl Node for OutputNode {
x,
y,
});
fs.tl_as_node().node_find_tree_at(x, y, tree)
fs.tl_as_node().node_find_tree_at(x, y, tree, usecase)
} else {
let bar_height = self.state.theme.sizes.title_height.get() + 1;
if y >= bar_height {
@ -697,10 +712,10 @@ impl Node for OutputNode {
x,
y,
});
ws.node_find_tree_at(x, y, tree);
ws.node_find_tree_at(x, y, tree, usecase);
}
if tree.len() == len {
self.find_layer_surface_at(x, y, &[BOTTOM, BACKGROUND], tree);
self.find_layer_surface_at(x, y, &[BOTTOM, BACKGROUND], tree, usecase);
}
}
FindTreeResult::AcceptsInput

View file

@ -10,8 +10,8 @@ use {
state::State,
text::{self, TextTexture},
tree::{
Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, ToplevelData,
ToplevelNode, ToplevelNodeBase,
Direction, FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId, NodeVisitor,
ToplevelData, ToplevelNode, ToplevelNodeBase,
},
utils::{errorfmt::ErrorFmt, smallmap::SmallMap},
},
@ -116,12 +116,18 @@ impl Node for PlaceholderNode {
self.toplevel.update_self_active(self, active);
}
fn node_find_tree_at(&self, _x: i32, _y: i32, _tree: &mut Vec<FoundNode>) -> FindTreeResult {
fn node_find_tree_at(
&self,
_x: i32,
_y: i32,
_tree: &mut Vec<FoundNode>,
_usecase: FindTreeUsecase,
) -> FindTreeResult {
FindTreeResult::AcceptsInput
}
fn node_render(&self, renderer: &mut Renderer, x: i32, y: i32, _bounds: Option<&Rect>) {
renderer.render_placeholder(self, x, y);
fn node_render(&self, renderer: &mut Renderer, x: i32, y: i32, bounds: Option<&Rect>) {
renderer.render_placeholder(self, x, y, bounds);
}
fn node_client(&self) -> Option<Rc<Client>> {
@ -140,6 +146,10 @@ impl Node for PlaceholderNode {
fn node_is_placeholder(&self) -> bool {
true
}
fn node_into_toplevel(self: Rc<Self>) -> Option<Rc<dyn ToplevelNode>> {
Some(self)
}
}
impl ToplevelNodeBase for PlaceholderNode {
@ -173,4 +183,8 @@ impl ToplevelNodeBase for PlaceholderNode {
fn tl_last_active_child(self: Rc<Self>) -> Rc<dyn ToplevelNode> {
self
}
fn tl_admits_children(&self) -> bool {
false
}
}

View file

@ -13,6 +13,7 @@ use {
utils::{
clonecell::CloneCell,
copyhashmap::CopyHashMap,
numcell::NumCell,
smallmap::SmallMap,
threshold_counter::ThresholdCounter,
toplevel_identifier::{toplevel_identifier, ToplevelIdentifier},
@ -173,6 +174,8 @@ pub trait ToplevelNodeBase: Node {
fn tl_restack_popups(&self) {
// nothing
}
fn tl_admits_children(&self) -> bool;
}
pub struct FullscreenedData {
@ -203,6 +206,7 @@ pub struct ToplevelData {
pub identifier: Cell<ToplevelIdentifier>,
pub handles:
CopyHashMap<(ClientId, ExtForeignToplevelHandleV1Id), Rc<ExtForeignToplevelHandleV1>>,
pub render_highlight: NumCell<u32>,
}
impl ToplevelData {
@ -229,6 +233,7 @@ impl ToplevelData {
app_id: Default::default(),
identifier: Cell::new(toplevel_identifier()),
handles: Default::default(),
render_highlight: Default::default(),
}
}

View file

@ -13,8 +13,8 @@ use {
text::TextTexture,
tree::{
container::ContainerNode, walker::NodeVisitor, ContainingNode, Direction,
FindTreeResult, FoundNode, Node, NodeId, NodeVisitorBase, OutputNode, StackedNode,
ToplevelNode,
FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId, NodeVisitorBase, OutputNode,
StackedNode, ToplevelNode,
},
utils::{
clonecell::CloneCell,
@ -224,14 +224,20 @@ impl Node for WorkspaceNode {
}
}
fn node_find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
fn node_find_tree_at(
&self,
x: i32,
y: i32,
tree: &mut Vec<FoundNode>,
usecase: FindTreeUsecase,
) -> FindTreeResult {
if let Some(n) = self.container.get() {
tree.push(FoundNode {
node: n.clone(),
x,
y,
});
n.node_find_tree_at(x, y, tree);
n.node_find_tree_at(x, y, tree, usecase);
}
FindTreeResult::AcceptsInput
}