1
0
Fork 0
forked from wry/wry

autocommit 2022-04-20 16:11:37 CEST

This commit is contained in:
Julian Orth 2022-04-20 16:11:37 +02:00
parent fa1ec0b36c
commit ab3c2e44f4
19 changed files with 409 additions and 210 deletions

View file

@ -1,10 +1,17 @@
use std::cell::{Cell, RefCell};
use std::ops::Deref;
use std::rc::Rc;
use crate::tree::{PlaceholderNode, Node, WorkspaceNode, SizedNode};
use {
crate::tree::{Node, PlaceholderNode, SizedNode, WorkspaceNode},
std::{
cell::{Cell, RefCell},
ops::Deref,
rc::Rc,
},
};
use jay_config::Direction;
use crate::ifs::wl_seat::collect_kb_foci;
use crate::state::State;
use crate::tree::OutputNode;
pub trait SizedFullscreenNode: SizedNode {
fn data(&self) -> &FullscreenData;
fn on_set_fullscreen(&self, workspace: &Rc<WorkspaceNode>);
fn on_unset_fullscreen(&self);
fn title(&self) -> String;
@ -19,7 +26,6 @@ pub trait SizedFullscreenNode: SizedNode {
}
pub trait FullscreenNode {
fn data(&self) -> &FullscreenData;
fn on_set_fullscreen(&self, workspace: &Rc<WorkspaceNode>);
fn on_unset_fullscreen(&self);
fn as_node(&self) -> &dyn Node;
@ -28,10 +34,6 @@ pub trait FullscreenNode {
}
impl<T: SizedFullscreenNode> FullscreenNode for T {
fn data(&self) -> &FullscreenData {
<Self as SizedFullscreenNode>::data(self)
}
fn on_set_fullscreen(&self, workspace: &Rc<WorkspaceNode>) {
<Self as SizedFullscreenNode>::on_set_fullscreen(self, workspace)
}
@ -72,3 +74,103 @@ impl FullscreenData {
}
}
}
impl FullscreenData {
pub fn set_fullscreen(&self, state: &Rc<State>, node: Rc<dyn FullscreenNode>, output: &Rc<OutputNode>) {
let ws = output.ensure_workspace();
if ws.fullscreen.get().is_some() {
log::info!("Cannot fullscreen a node on a workspace that already has a fullscreen node attached");
return;
}
let mut data = self.data.borrow_mut();
if data.is_some() {
log::info!("Cannot fullscreen a node that is already fullscreen");
return;
}
let parent = match node.as_node().node_parent() {
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.node_replace_child(node.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.set_visible(false);
}
*data = Some(FullscreenedData {
placeholder,
workspace: ws.clone(),
});
self.is_fullscreen.set(true);
ws.fullscreen.set(Some(node.clone()));
node.clone().into_node().node_set_parent(ws.clone());
node.clone().into_node().node_set_workspace(&ws);
node.clone()
.into_node()
.node_change_extents(&output.global.pos.get());
for seat in kb_foci {
node.clone()
.into_node()
.node_do_focus(&seat, Direction::Unspecified);
}
node.on_set_fullscreen(&ws);
}
pub fn unset_fullscreen(&self, state: &Rc<State>, node: Rc<dyn FullscreenNode>) {
if !self.is_fullscreen.get() {
log::warn!("Cannot unset fullscreen on a node that is not fullscreen");
return;
}
let fd = match self.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.as_node().node_id() != node.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.set_visible(true);
}
if fd.placeholder.is_destroyed() {
state.map_tiled(node.into_node());
return;
}
let parent = fd.placeholder.parent().unwrap();
parent.node_replace_child(fd.placeholder.deref(), node.clone().into_node());
if node.as_node().node_visible() {
let kb_foci = collect_kb_foci(fd.placeholder.clone());
for seat in kb_foci {
node.clone()
.into_node()
.node_do_focus(&seat, Direction::Unspecified);
}
}
fd.placeholder
.node_seat_state()
.destroy_node(fd.placeholder.deref());
node.on_unset_fullscreen();
}
pub fn destroy_node(&self) {
if let Some(fd) = self.data.borrow_mut().take() {
fd.placeholder.destroy_node(true);
}
}
}