1
0
Fork 0
forked from wry/wry

autocommit 2022-04-07 17:31:31 CEST

This commit is contained in:
Julian Orth 2022-04-07 17:31:31 +02:00
parent 1d33088dba
commit be32036824
200 changed files with 3267 additions and 2479 deletions

View file

@ -1,27 +1,36 @@
use crate::backend::KeyState;
use crate::cursor::KnownCursor;
use crate::fixed::Fixed;
use crate::ifs::wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT};
use crate::rect::Rect;
use crate::render::{Renderer, Texture};
use crate::theme::Color;
use crate::tree::walker::NodeVisitor;
use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode};
use crate::utils::clonecell::CloneCell;
use crate::utils::linkedlist::{LinkedList, LinkedNode, NodeRef};
use ahash::AHashMap;
use jay_config::{Axis, Direction};
use std::cell::{Cell, RefCell};
use {
crate::{
backend::KeyState,
cursor::KnownCursor,
fixed::Fixed,
ifs::wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT},
rect::Rect,
render::{Renderer, Texture},
theme::Color,
tree::{walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode},
utils::{
clonecell::CloneCell,
linkedlist::{LinkedList, LinkedNode, NodeRef},
},
},
ahash::AHashMap,
jay_config::{Axis, Direction},
std::cell::{Cell, RefCell},
};
use crate::state::State;
use crate::text;
use crate::utils::errorfmt::ErrorFmt;
use crate::utils::numcell::NumCell;
use crate::utils::rc_eq::rc_eq;
use std::fmt::{Debug, Formatter};
use std::mem;
use std::ops::{Deref, DerefMut, Sub};
use std::rc::Rc;
use {
crate::{
state::State,
text,
utils::{errorfmt::ErrorFmt, numcell::NumCell, rc_eq::rc_eq},
},
std::{
fmt::{Debug, Formatter},
mem,
ops::{Deref, DerefMut, Sub},
rc::Rc,
},
};
#[allow(dead_code)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]

140
src/tree/display.rs Normal file
View file

@ -0,0 +1,140 @@
use {
crate::{
backend::ConnectorId,
cursor::KnownCursor,
ifs::{
wl_seat::{NodeSeatState, WlSeatGlobal},
wl_surface::xwindow::Xwindow,
zwlr_layer_shell_v1::{OVERLAY, TOP},
},
tree::{walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId, OutputNode},
utils::{copyhashmap::CopyHashMap, linkedlist::LinkedList},
},
std::{ops::Deref, rc::Rc},
};
pub struct DisplayNode {
pub id: NodeId,
pub outputs: CopyHashMap<ConnectorId, Rc<OutputNode>>,
pub stacked: LinkedList<Rc<dyn Node>>,
pub xstacked: LinkedList<Rc<Xwindow>>,
pub seat_state: NodeSeatState,
}
impl DisplayNode {
pub fn new(id: NodeId) -> Self {
Self {
id,
outputs: Default::default(),
stacked: Default::default(),
xstacked: Default::default(),
seat_state: Default::default(),
}
}
}
impl Node for DisplayNode {
fn id(&self) -> NodeId {
self.id
}
fn seat_state(&self) -> &NodeSeatState {
&self.seat_state
}
fn destroy_node(&self, _detach: bool) {
let mut outputs = self.outputs.lock();
for output in outputs.values() {
output.destroy_node(false);
}
outputs.clear();
for stacked in self.stacked.iter() {
stacked.destroy_node(false);
}
self.seat_state.destroy_node(self);
}
fn visit(self: Rc<Self>, visitor: &mut dyn NodeVisitor) {
visitor.visit_display(&self);
}
fn visit_children(&self, visitor: &mut dyn NodeVisitor) {
let outputs = self.outputs.lock();
for (_, output) in outputs.deref() {
visitor.visit_output(output);
}
for stacked in self.stacked.iter() {
stacked.deref().clone().visit(visitor);
}
}
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
let outputs = self.outputs.lock();
for output in outputs.values() {
let pos = output.global.pos.get();
if pos.contains(x, y) {
let (x, y) = pos.translate(x, y);
tree.push(FoundNode {
node: output.clone(),
x,
y,
});
let len = tree.len();
for layer in [OVERLAY, TOP] {
for surface in output.layers[layer as usize].rev_iter() {
let pos = surface.absolute_position();
if pos.contains(x, y) {
let (x, y) = pos.translate(x, y);
if surface.find_tree_at(x, y, tree) == FindTreeResult::AcceptsInput {
return FindTreeResult::AcceptsInput;
}
tree.truncate(len);
}
}
}
tree.pop();
break;
}
}
for stacked in self.stacked.rev_iter() {
let ext = stacked.absolute_position();
if stacked.absolute_position_constrains_input() && !ext.contains(x, y) {
// TODO: make constrain always true
continue;
}
let (x, y) = ext.translate(x, y);
let idx = tree.len();
tree.push(FoundNode {
node: stacked.deref().clone(),
x,
y,
});
match stacked.find_tree_at(x, y, tree) {
FindTreeResult::AcceptsInput => {
return FindTreeResult::AcceptsInput;
}
FindTreeResult::Other => {
tree.drain(idx..);
}
}
}
for output in outputs.values() {
let pos = output.global.pos.get();
if pos.contains(x, y) {
let (x, y) = pos.translate(x, y);
tree.push(FoundNode {
node: output.clone(),
x,
y,
});
output.find_tree_at(x, y, tree);
break;
}
}
FindTreeResult::AcceptsInput
}
fn pointer_focus(&self, seat: &Rc<WlSeatGlobal>) {
seat.set_known_cursor(KnownCursor::Default);
}
}

View file

@ -1,23 +1,26 @@
use crate::backend::KeyState;
use crate::cursor::KnownCursor;
use crate::fixed::Fixed;
use crate::ifs::wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT};
use crate::rect::Rect;
use crate::render::{Renderer, Texture};
use crate::state::State;
use crate::text;
use crate::theme::Color;
use crate::tree::walker::NodeVisitor;
use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode};
use crate::utils::clonecell::CloneCell;
use crate::utils::errorfmt::ErrorFmt;
use crate::utils::linkedlist::LinkedNode;
use ahash::AHashMap;
use std::cell::{Cell, RefCell};
use std::fmt::{Debug, Formatter};
use std::mem;
use std::ops::Deref;
use std::rc::Rc;
use {
crate::{
backend::KeyState,
cursor::KnownCursor,
fixed::Fixed,
ifs::wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT},
rect::Rect,
render::{Renderer, Texture},
state::State,
text,
theme::Color,
tree::{walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode},
utils::{clonecell::CloneCell, errorfmt::ErrorFmt, linkedlist::LinkedNode},
},
ahash::AHashMap,
std::{
cell::{Cell, RefCell},
fmt::{Debug, Formatter},
mem,
ops::Deref,
rc::Rc,
},
};
tree_id!(FloatNodeId);
pub struct FloatNode {

View file

@ -1,23 +1,28 @@
use crate::backend::Mode;
use crate::cursor::KnownCursor;
use crate::fixed::Fixed;
use crate::ifs::wl_output::WlOutputGlobal;
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
use crate::ifs::wl_surface::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
use crate::rect::Rect;
use crate::render::{Renderer, Texture};
use crate::state::State;
use crate::text;
use crate::theme::Color;
use crate::tree::walker::NodeVisitor;
use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode};
use crate::utils::clonecell::CloneCell;
use crate::utils::errorfmt::ErrorFmt;
use crate::utils::linkedlist::LinkedList;
use std::cell::RefCell;
use std::fmt::{Debug, Formatter};
use std::ops::{Deref, Sub};
use std::rc::Rc;
use {
crate::{
backend::Mode,
cursor::KnownCursor,
fixed::Fixed,
ifs::{
wl_output::WlOutputGlobal,
wl_seat::{NodeSeatState, WlSeatGlobal},
wl_surface::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
},
rect::Rect,
render::{Renderer, Texture},
state::State,
text,
theme::Color,
tree::{walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode},
utils::{clonecell::CloneCell, errorfmt::ErrorFmt, linkedlist::LinkedList},
},
std::{
cell::RefCell,
fmt::{Debug, Formatter},
ops::{Deref, Sub},
rc::Rc,
},
};
tree_id!(OutputNodeId);
pub struct OutputNode {
@ -78,9 +83,9 @@ impl OutputNode {
}
}
pub fn ensure_workspace(self: &Rc<Self>) {
if !self.workspaces.is_empty() {
return;
pub fn ensure_workspace(self: &Rc<Self>) -> Rc<WorkspaceNode> {
if let Some(ws) = self.workspace.get() {
return ws;
}
let name = 'name: {
for i in 1.. {
@ -107,6 +112,7 @@ impl OutputNode {
.set(Some(self.workspaces.add_last(workspace.clone())));
self.show_workspace(&workspace);
self.update_render_data();
workspace
}
pub fn show_workspace(&self, ws: &Rc<WorkspaceNode>) {
@ -238,10 +244,6 @@ impl Node for OutputNode {
unimplemented!();
}
fn leave(&self, seat: &WlSeatGlobal) {
seat.leave_output();
}
fn pointer_enter(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, _x: Fixed, _y: Fixed) {
seat.enter_output(&self)
}

View file

@ -1,11 +1,13 @@
use crate::ifs::wl_seat::SeatId;
use crate::ifs::wl_surface::WlSurface;
use crate::tree::Node;
use crate::utils::linkedlist::LinkedNode;
use crate::utils::numcell::NumCell;
use crate::utils::smallmap::SmallMap;
use std::rc::Rc;
use {
crate::{
ifs::{wl_seat::SeatId, wl_surface::WlSurface},
tree::Node,
utils::{linkedlist::LinkedNode, numcell::NumCell, smallmap::SmallMap},
},
std::rc::Rc,
};
tree_id!(ToplevelNodeId);
pub trait ToplevelNode {
fn data(&self) -> &ToplevelData;
fn parent(&self) -> Option<Rc<dyn Node>>;

View file

@ -1,10 +1,15 @@
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup;
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel;
use crate::ifs::wl_surface::xwindow::Xwindow;
use crate::ifs::wl_surface::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
use crate::ifs::wl_surface::WlSurface;
use crate::tree::{ContainerNode, DisplayNode, FloatNode, Node, OutputNode, WorkspaceNode};
use std::rc::Rc;
use {
crate::{
ifs::wl_surface::{
xdg_surface::{xdg_popup::XdgPopup, xdg_toplevel::XdgToplevel},
xwindow::Xwindow,
zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
WlSurface,
},
tree::{ContainerNode, DisplayNode, FloatNode, Node, OutputNode, WorkspaceNode},
},
std::rc::Rc,
};
pub trait NodeVisitorBase: Sized {
fn visit_surface(&mut self, node: &Rc<WlSurface>) {

View file

@ -1,15 +1,20 @@
use crate::cursor::KnownCursor;
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
use crate::rect::Rect;
use crate::render::Renderer;
use crate::tree::container::ContainerNode;
use crate::tree::walker::NodeVisitor;
use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, OutputNode};
use crate::utils::clonecell::CloneCell;
use crate::utils::linkedlist::{LinkedList, LinkedNode};
use std::cell::Cell;
use std::fmt::Debug;
use std::rc::Rc;
use {
crate::{
cursor::KnownCursor,
ifs::wl_seat::{NodeSeatState, WlSeatGlobal},
rect::Rect,
render::Renderer,
tree::{
container::ContainerNode, walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId,
OutputNode,
},
utils::{
clonecell::CloneCell,
linkedlist::{LinkedList, LinkedNode},
},
},
std::{cell::Cell, fmt::Debug, rc::Rc},
};
tree_id!(WorkspaceNodeId);