autocommit 2022-04-20 14:58:34 CEST
This commit is contained in:
parent
c1773c0fee
commit
fa1ec0b36c
22 changed files with 583 additions and 185 deletions
183
src/tree/placeholder.rs
Normal file
183
src/tree/placeholder.rs
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
use std::cell::{Cell, RefCell};
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use jay_config::Direction;
|
||||
use crate::client::{Client};
|
||||
use crate::cursor::KnownCursor;
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
|
||||
use crate::ifs::wl_surface::WlSurface;
|
||||
use crate::rect::Rect;
|
||||
use crate::state::State;
|
||||
use crate::tree::{FindTreeResult, FoundNode, FullscreenNode, Node, NodeId, NodeVisitor, SizedNode, ToplevelData, ToplevelNode, WorkspaceNode};
|
||||
use crate::utils::clonecell::CloneCell;
|
||||
|
||||
tree_id!(DetachedNodeId);
|
||||
pub struct PlaceholderNode {
|
||||
id: DetachedNodeId,
|
||||
state: Rc<State>,
|
||||
seat_state: NodeSeatState,
|
||||
parent: CloneCell<Option<Rc<dyn Node>>>,
|
||||
workspace: CloneCell<Option<Rc<WorkspaceNode>>>,
|
||||
title: RefCell<String>,
|
||||
visible: Cell<bool>,
|
||||
pos: Cell<Rect>,
|
||||
client: Option<Rc<Client>>,
|
||||
toplevel: ToplevelData,
|
||||
active: Cell<bool>,
|
||||
destroyed: Cell<bool>,
|
||||
}
|
||||
|
||||
impl PlaceholderNode {
|
||||
pub fn new_for(state: &Rc<State>, node: Rc<dyn FullscreenNode>) -> Self {
|
||||
Self {
|
||||
id: state.node_ids.next(),
|
||||
state: state.clone(),
|
||||
seat_state: Default::default(),
|
||||
parent: Default::default(),
|
||||
workspace: Default::default(),
|
||||
title: RefCell::new(node.title()),
|
||||
visible: Default::default(),
|
||||
pos: Default::default(),
|
||||
client: node.as_node().node_client(),
|
||||
toplevel: Default::default(),
|
||||
active: Default::default(),
|
||||
destroyed: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_title(&self, title: &str) {
|
||||
*self.title.borrow_mut() = title.to_string();
|
||||
if let Some(parent) = self.parent.get() {
|
||||
parent.node_child_title_changed(self, title);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_destroyed(&self) -> bool {
|
||||
self.destroyed.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl SizedNode for PlaceholderNode {
|
||||
fn id(&self) -> NodeId {
|
||||
self.id.into()
|
||||
}
|
||||
|
||||
fn seat_state(&self) -> &NodeSeatState {
|
||||
&self.seat_state
|
||||
}
|
||||
|
||||
fn destroy_node(&self, detach: bool) {
|
||||
if detach {
|
||||
if let Some(parent) = self.parent.get() {
|
||||
parent.node_remove_child(self);
|
||||
}
|
||||
}
|
||||
self.parent.take();
|
||||
self.workspace.take();
|
||||
self.seat_state.destroy_node(self);
|
||||
self.destroyed.set(true);
|
||||
}
|
||||
|
||||
fn visit(self: &Rc<Self>, visitor: &mut dyn NodeVisitor) {
|
||||
visitor.visit_placeholder(self);
|
||||
}
|
||||
|
||||
fn visit_children(&self, _visitor: &mut dyn NodeVisitor) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
fn visible(&self) -> bool {
|
||||
self.visible.get()
|
||||
}
|
||||
|
||||
fn parent(&self) -> Option<Rc<dyn Node>> {
|
||||
self.parent.get()
|
||||
}
|
||||
|
||||
fn set_visible(&self, visible: bool) {
|
||||
self.visible.set(visible);
|
||||
}
|
||||
|
||||
fn get_workspace(&self) -> Option<Rc<WorkspaceNode>> {
|
||||
self.workspace.get()
|
||||
}
|
||||
|
||||
fn do_focus(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>, _direction: Direction) {
|
||||
seat.focus_toplevel(self.clone());
|
||||
}
|
||||
|
||||
fn close(self: &Rc<Self>) {
|
||||
let slf = self.clone();
|
||||
self.state.run_toplevel.schedule(move || {
|
||||
slf.destroy_node(true);
|
||||
});
|
||||
}
|
||||
|
||||
fn absolute_position(&self) -> Rect {
|
||||
self.pos.get()
|
||||
}
|
||||
|
||||
fn active_changed(&self, active: bool) {
|
||||
self.active.set(active);
|
||||
if let Some(parent) = self.parent.get() {
|
||||
parent.node_child_active_changed(self, active, 1);
|
||||
}
|
||||
}
|
||||
|
||||
fn find_tree_at(&self, _x: i32, _y: i32, _tree: &mut Vec<FoundNode>) -> FindTreeResult {
|
||||
FindTreeResult::AcceptsInput
|
||||
}
|
||||
|
||||
fn pointer_enter(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>, _x: Fixed, _y: Fixed) {
|
||||
seat.set_known_cursor(KnownCursor::Default);
|
||||
seat.enter_toplevel(self.clone());
|
||||
}
|
||||
|
||||
fn change_extents(self: &Rc<Self>, rect: &Rect) {
|
||||
self.pos.set(*rect);
|
||||
}
|
||||
|
||||
fn set_workspace(self: &Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
self.workspace.set(Some(ws.clone()));
|
||||
}
|
||||
|
||||
fn set_parent(self: &Rc<Self>, parent: Rc<dyn Node>) {
|
||||
self.parent.set(Some(parent.clone()));
|
||||
parent.node_child_title_changed(self.deref(), self.title.borrow_mut().deref());
|
||||
}
|
||||
|
||||
fn client(&self) -> Option<Rc<Client>> {
|
||||
self.client.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToplevelNode for PlaceholderNode {
|
||||
fn data(&self) -> &ToplevelData {
|
||||
&self.toplevel
|
||||
}
|
||||
|
||||
fn as_node(&self) -> &dyn Node {
|
||||
self
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Rc<dyn Node> {
|
||||
self
|
||||
}
|
||||
|
||||
fn accepts_keyboard_focus(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_surface(&self) -> Option<Rc<WlSurface>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn set_active(&self, _active: bool) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
fn activate(&self) {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue