autocommit 2022-04-23 00:55:20 CEST
This commit is contained in:
parent
436f383cd6
commit
e3b3d848c3
32 changed files with 1773 additions and 2451 deletions
|
|
@ -1,93 +1,193 @@
|
|||
use {
|
||||
crate::{
|
||||
ifs::{wl_seat::SeatId, wl_surface::WlSurface},
|
||||
tree::{Node, SizedNode, WorkspaceNode},
|
||||
utils::{numcell::NumCell, smallmap::SmallMap},
|
||||
client::Client,
|
||||
ifs::wl_seat::{collect_kb_foci, NodeSeatState, SeatId},
|
||||
rect::Rect,
|
||||
state::State,
|
||||
tree::{ContainingNode, Node, OutputNode, PlaceholderNode, WorkspaceNode},
|
||||
utils::{clonecell::CloneCell, numcell::NumCell, smallmap::SmallMap},
|
||||
},
|
||||
jay_config::Direction,
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
ops::Deref,
|
||||
rc::Rc,
|
||||
},
|
||||
std::{cell::Cell, rc::Rc},
|
||||
};
|
||||
|
||||
pub trait SizedToplevelNode: SizedNode {
|
||||
fn data(&self) -> &ToplevelData;
|
||||
fn accepts_keyboard_focus(&self) -> bool;
|
||||
fn default_surface(&self) -> Option<Rc<WlSurface>>;
|
||||
fn set_active(&self, active: bool);
|
||||
fn activate(&self);
|
||||
fn set_fullscreen(self: &Rc<Self>, fullscreen: bool);
|
||||
fn fullscreen(&self) -> bool;
|
||||
|
||||
fn as_node(&self) -> &dyn Node {
|
||||
self
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Rc<dyn Node> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
tree_id!(ToplevelNodeId);
|
||||
pub trait ToplevelNode {
|
||||
fn data(&self) -> &ToplevelData;
|
||||
fn as_node(&self) -> &dyn Node;
|
||||
fn into_node(self: Rc<Self>) -> Rc<dyn Node>;
|
||||
fn accepts_keyboard_focus(&self) -> bool;
|
||||
fn default_surface(&self) -> Option<Rc<WlSurface>>;
|
||||
fn set_active(&self, active: bool);
|
||||
fn activate(&self);
|
||||
fn set_fullscreen(self: Rc<Self>, fullscreen: bool);
|
||||
fn fullscreen(&self) -> bool;
|
||||
}
|
||||
|
||||
impl<T: SizedToplevelNode> ToplevelNode for T {
|
||||
fn data(&self) -> &ToplevelData {
|
||||
<Self as SizedToplevelNode>::data(self)
|
||||
pub trait ToplevelNode: Node {
|
||||
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_data(&self) -> &ToplevelData;
|
||||
fn tl_default_focus_child(&self) -> Option<Rc<dyn Node>>;
|
||||
|
||||
fn tl_accepts_keyboard_focus(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn as_node(&self) -> &dyn Node {
|
||||
<Self as SizedToplevelNode>::as_node(self)
|
||||
fn tl_set_active(&self, active: bool) {
|
||||
let _ = active;
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Rc<dyn Node> {
|
||||
<Self as SizedToplevelNode>::into_node(self)
|
||||
fn tl_on_activate(&self) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
fn accepts_keyboard_focus(&self) -> bool {
|
||||
<Self as SizedToplevelNode>::accepts_keyboard_focus(self)
|
||||
fn tl_surface_active_changed(&self, active: bool) {
|
||||
if active {
|
||||
if self.tl_data().active_children.fetch_add(1) == 0 {
|
||||
self.tl_set_active(true);
|
||||
}
|
||||
} else {
|
||||
if self.tl_data().active_children.fetch_sub(1) == 1 {
|
||||
self.tl_set_active(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_surface(&self) -> Option<Rc<WlSurface>> {
|
||||
<Self as SizedToplevelNode>::default_surface(self)
|
||||
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 set_active(&self, active: bool) {
|
||||
<Self as SizedToplevelNode>::set_active(self, active)
|
||||
fn tl_set_fullscreen(self: Rc<Self>, fullscreen: bool) {
|
||||
let data = self.tl_data();
|
||||
if fullscreen {
|
||||
if let Some(ws) = data.workspace.get() {
|
||||
data.set_fullscreen2(
|
||||
&data.state,
|
||||
self.clone().tl_into_dyn(),
|
||||
&ws,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
data.unset_fullscreen(&data.state, self.clone().tl_into_dyn());
|
||||
}
|
||||
}
|
||||
|
||||
fn activate(&self) {
|
||||
<Self as SizedToplevelNode>::activate(self)
|
||||
fn tl_title(&self) -> String {
|
||||
self.tl_data().title.borrow_mut().clone()
|
||||
}
|
||||
|
||||
fn set_fullscreen(self: Rc<Self>, fullscreen: bool) {
|
||||
<Self as SizedToplevelNode>::set_fullscreen(&self, fullscreen)
|
||||
fn tl_title_changed(&self) {
|
||||
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);
|
||||
}
|
||||
if let Some(data) = data.fullscrceen_data.borrow_mut().deref() {
|
||||
*data.placeholder.tl_data().title.borrow_mut() = title.clone();
|
||||
data.placeholder.tl_title_changed();
|
||||
}
|
||||
}
|
||||
|
||||
fn fullscreen(&self) -> bool {
|
||||
<Self as SizedToplevelNode>::fullscreen(self)
|
||||
fn tl_set_parent(&self, parent: Rc<dyn ContainingNode>) {
|
||||
let data = self.tl_data();
|
||||
data.parent.set(Some(parent.clone()));
|
||||
data.is_floating.set(parent.node_is_float());
|
||||
self.tl_notify_parent();
|
||||
self.tl_after_parent_set(parent);
|
||||
}
|
||||
|
||||
fn tl_after_parent_set(&self, parent: Rc<dyn ContainingNode>) {
|
||||
let _ = parent;
|
||||
}
|
||||
|
||||
fn tl_notify_parent(&self) {
|
||||
let data = self.tl_data();
|
||||
let parent = match data.parent.get() {
|
||||
Some(p) => p,
|
||||
_ => return,
|
||||
};
|
||||
let node = self.tl_as_node();
|
||||
let pos = data.pos.get();
|
||||
let depth = if data.active.get() {
|
||||
1
|
||||
} else if data.active_children.get() > 0 {
|
||||
2
|
||||
} else {
|
||||
0
|
||||
};
|
||||
if depth > 0 {
|
||||
parent.clone().node_child_active_changed(node, true, depth);
|
||||
}
|
||||
parent.node_child_size_changed(node, pos.width(), pos.height());
|
||||
parent
|
||||
.clone()
|
||||
.node_child_title_changed(node, data.title.borrow_mut().deref());
|
||||
}
|
||||
|
||||
fn tl_set_workspace(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
let data = self.tl_data();
|
||||
data.workspace.set(Some(ws.clone()));
|
||||
}
|
||||
|
||||
fn tl_change_extents(self: Rc<Self>, rect: &Rect) {
|
||||
let _ = rect;
|
||||
}
|
||||
|
||||
fn tl_close(self: Rc<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()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FullscreenedData {
|
||||
pub placeholder: Rc<PlaceholderNode>,
|
||||
pub workspace: Rc<WorkspaceNode>,
|
||||
}
|
||||
|
||||
pub struct ToplevelData {
|
||||
pub active_surfaces: NumCell<u32>,
|
||||
pub focus_surface: SmallMap<SeatId, Rc<WlSurface>, 1>,
|
||||
pub active: Cell<bool>,
|
||||
pub client: Option<Rc<Client>>,
|
||||
pub state: Rc<State>,
|
||||
pub active_children: NumCell<u32>,
|
||||
pub focus_node: SmallMap<SeatId, Rc<dyn Node>, 1>,
|
||||
pub visible: Cell<bool>,
|
||||
pub is_floating: Cell<bool>,
|
||||
pub float_width: Cell<i32>,
|
||||
pub float_height: Cell<i32>,
|
||||
pub is_fullscreen: Cell<bool>,
|
||||
pub fullscrceen_data: RefCell<Option<FullscreenedData>>,
|
||||
pub workspace: CloneCell<Option<Rc<WorkspaceNode>>>,
|
||||
pub title: RefCell<String>,
|
||||
pub parent: CloneCell<Option<Rc<dyn ContainingNode>>>,
|
||||
pub pos: Cell<Rect>,
|
||||
pub seat_state: NodeSeatState,
|
||||
}
|
||||
|
||||
impl ToplevelData {
|
||||
pub fn clear(&self) {
|
||||
self.focus_surface.clear();
|
||||
pub fn new(state: &Rc<State>, title: String, client: Option<Rc<Client>>) -> Self {
|
||||
Self {
|
||||
active: Cell::new(false),
|
||||
client,
|
||||
state: state.clone(),
|
||||
active_children: Default::default(),
|
||||
focus_node: Default::default(),
|
||||
visible: Cell::new(false),
|
||||
is_floating: Default::default(),
|
||||
float_width: Default::default(),
|
||||
float_height: Default::default(),
|
||||
is_fullscreen: Default::default(),
|
||||
fullscrceen_data: Default::default(),
|
||||
workspace: Default::default(),
|
||||
title: RefCell::new(title),
|
||||
parent: Default::default(),
|
||||
pos: Default::default(),
|
||||
seat_state: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn float_size(&self, ws: &WorkspaceNode) -> (i32, i32) {
|
||||
|
|
@ -102,29 +202,127 @@ impl ToplevelData {
|
|||
}
|
||||
(width, height)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> dyn ToplevelNode + 'a {
|
||||
pub fn surface_active_changed(&self, active: bool) {
|
||||
if active {
|
||||
if self.data().active_surfaces.fetch_add(1) == 0 {
|
||||
self.set_active(true);
|
||||
}
|
||||
} else {
|
||||
if self.data().active_surfaces.fetch_sub(1) == 1 {
|
||||
self.set_active(false);
|
||||
pub fn destroy_node(&self, node: &dyn Node) {
|
||||
if let Some(fd) = self.fullscrceen_data.borrow_mut().take() {
|
||||
fd.placeholder.tl_destroy();
|
||||
}
|
||||
if let Some(parent) = self.parent.take() {
|
||||
parent.cnode_remove_child(node);
|
||||
}
|
||||
self.workspace.take();
|
||||
self.seat_state.destroy_node(node);
|
||||
self.focus_node.clear();
|
||||
}
|
||||
|
||||
pub fn set_fullscreen(
|
||||
&self,
|
||||
state: &Rc<State>,
|
||||
node: Rc<dyn ToplevelNode>,
|
||||
output: &Rc<OutputNode>,
|
||||
) {
|
||||
self.set_fullscreen2(state, node, &output.ensure_workspace());
|
||||
}
|
||||
|
||||
pub fn set_fullscreen2(
|
||||
&self,
|
||||
state: &Rc<State>,
|
||||
node: Rc<dyn ToplevelNode>,
|
||||
ws: &Rc<WorkspaceNode>,
|
||||
) {
|
||||
if ws.fullscreen.get().is_some() {
|
||||
log::info!("Cannot fullscreen a node on a workspace that already has a fullscreen node attached");
|
||||
return;
|
||||
}
|
||||
if node.node_is_placeholder() {
|
||||
log::info!("Cannot fullscreen a placeholder node");
|
||||
return;
|
||||
}
|
||||
let mut data = self.fullscrceen_data.borrow_mut();
|
||||
if data.is_some() {
|
||||
log::info!("Cannot fullscreen a node that is already fullscreen");
|
||||
return;
|
||||
}
|
||||
let parent = match node.tl_data().parent.get() {
|
||||
None => {
|
||||
log::warn!("Cannot fullscreen a node without a parent");
|
||||
return;
|
||||
}
|
||||
Some(p) => p,
|
||||
};
|
||||
let placeholder = Rc::new(PlaceholderNode::new_for(state, node.clone()));
|
||||
parent.cnode_replace_child(node.tl_as_node(), placeholder.clone());
|
||||
let mut kb_foci = Default::default();
|
||||
if let Some(container) = ws.container.get() {
|
||||
kb_foci = collect_kb_foci(container.clone());
|
||||
container.tl_set_visible(false);
|
||||
}
|
||||
*data = Some(FullscreenedData {
|
||||
placeholder,
|
||||
workspace: ws.clone(),
|
||||
});
|
||||
self.is_fullscreen.set(true);
|
||||
ws.fullscreen.set(Some(node.clone()));
|
||||
node.tl_set_parent(ws.clone());
|
||||
node.clone().tl_set_workspace(&ws);
|
||||
node.clone()
|
||||
.tl_change_extents(&ws.output.get().global.pos.get());
|
||||
for seat in kb_foci {
|
||||
node.clone()
|
||||
.tl_into_node()
|
||||
.node_do_focus(&seat, Direction::Unspecified);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn focus_surface(&self, seat: SeatId) -> Option<Rc<WlSurface>> {
|
||||
self.data()
|
||||
.focus_surface
|
||||
.get(&seat)
|
||||
.or_else(|| self.default_surface())
|
||||
pub fn unset_fullscreen(&self, state: &Rc<State>, node: Rc<dyn ToplevelNode>) {
|
||||
if !self.is_fullscreen.get() {
|
||||
log::warn!("Cannot unset fullscreen on a node that is not fullscreen");
|
||||
return;
|
||||
}
|
||||
let fd = match self.fullscrceen_data.borrow_mut().take() {
|
||||
Some(fd) => fd,
|
||||
_ => {
|
||||
log::error!("is_fullscreen = true but data is None");
|
||||
return;
|
||||
}
|
||||
};
|
||||
self.is_fullscreen.set(false);
|
||||
match fd.workspace.fullscreen.get() {
|
||||
None => {
|
||||
log::error!("Node is supposed to be fullscreened on a workspace but workspace has not fullscreen node.");
|
||||
return;
|
||||
}
|
||||
Some(f) if f.tl_as_node().node_id() != node.tl_as_node().node_id() => {
|
||||
log::error!("Node is supposed to be fullscreened on a workspace but the workspace has a different node attached.");
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
fd.workspace.fullscreen.take();
|
||||
if let Some(container) = fd.workspace.container.get() {
|
||||
container.tl_set_visible(node.tl_as_node().node_visible());
|
||||
}
|
||||
if fd.placeholder.is_destroyed() {
|
||||
state.map_tiled(node);
|
||||
return;
|
||||
}
|
||||
let parent = fd.placeholder.tl_data().parent.get().unwrap();
|
||||
parent.cnode_replace_child(fd.placeholder.deref(), node.clone());
|
||||
if node.tl_as_node().node_visible() {
|
||||
let kb_foci = collect_kb_foci(fd.placeholder.clone());
|
||||
for seat in kb_foci {
|
||||
node.clone()
|
||||
.tl_into_node()
|
||||
.node_do_focus(&seat, Direction::Unspecified);
|
||||
}
|
||||
}
|
||||
fd.placeholder
|
||||
.node_seat_state()
|
||||
.destroy_node(fd.placeholder.deref());
|
||||
}
|
||||
|
||||
pub fn parent(&self) -> Option<Rc<dyn Node>> {
|
||||
self.as_node().node_parent()
|
||||
pub fn set_visible(&self, node: &dyn Node, visible: bool) {
|
||||
self.visible.set(visible);
|
||||
self.seat_state.set_visible(node, visible)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue