1
0
Fork 0
forked from wry/wry

autocommit 2022-04-20 17:28:17 CEST

This commit is contained in:
Julian Orth 2022-04-20 17:28:17 +02:00
parent ab3c2e44f4
commit 1227ede560
9 changed files with 137 additions and 25 deletions

View file

@ -14,7 +14,8 @@ use {
text,
theme::Color,
tree::{
walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId, SizedNode, WorkspaceNode,
walker::NodeVisitor, FindTreeResult, FoundNode, FullscreenData, Node, NodeId,
SizedFullscreenNode, SizedNode, WorkspaceNode,
},
utils::{
clonecell::CloneCell,
@ -117,6 +118,7 @@ pub struct ContainerNode {
pub render_data: RefCell<ContainerRenderData>,
visible: Cell<bool>,
scroll: Cell<f64>,
fullscreen_data: FullscreenData,
}
impl Debug for ContainerNode {
@ -216,6 +218,7 @@ impl ContainerNode {
render_data: Default::default(),
visible: Cell::new(false),
scroll: Cell::new(0.0),
fullscreen_data: Default::default(),
});
child.node_set_parent(slf.clone());
slf
@ -602,6 +605,7 @@ impl ContainerNode {
}
title.push_str("]");
self.parent.get().node_child_title_changed(&**self, &title);
self.fullscreen_data.set_title(&title);
}
pub fn schedule_compute_render_data(self: &Rc<Self>) {
@ -747,6 +751,7 @@ impl SizedNode for ContainerNode {
}
fn destroy_node(&self, detach: bool) {
self.fullscreen_data.destroy_node();
if detach {
self.parent.get().node_remove_child(self);
}
@ -1257,8 +1262,7 @@ impl SizedNode for ContainerNode {
};
let num_children = self.num_children.fetch_sub(1) - 1;
if num_children == 0 {
self.seats.borrow_mut().clear();
self.parent.get().node_remove_child(self.deref());
self.destroy_node(true);
return;
}
self.update_content_size();
@ -1411,12 +1415,35 @@ impl SizedNode for ContainerNode {
.node_child_title_changed(self.deref(), self.title.borrow_mut().deref());
}
fn set_fullscreen(self: &Rc<Self>, _fullscreen: bool) {
// todo
fn fullscreen(&self) -> bool {
self.fullscreen_data.is_fullscreen.get()
}
fn fullscreen(&self) -> bool {
false
fn set_fullscreen(self: &Rc<Self>, fullscreen: bool) {
if fullscreen {
self.fullscreen_data.set_fullscreen(
&self.state,
self.clone(),
&self.workspace.get().output.get().clone(),
);
} else {
self.fullscreen_data
.unset_fullscreen(&self.state, self.clone());
}
}
}
impl SizedFullscreenNode for ContainerNode {
fn on_set_fullscreen(&self, _workspace: &Rc<WorkspaceNode>) {
// nothing
}
fn on_unset_fullscreen(&self) {
// nothing
}
fn title(&self) -> String {
self.title.borrow_mut().clone()
}
}

View file

@ -1,15 +1,16 @@
use {
crate::tree::{Node, PlaceholderNode, SizedNode, WorkspaceNode},
crate::{
ifs::wl_seat::collect_kb_foci,
state::State,
tree::{Node, OutputNode, PlaceholderNode, SizedNode, WorkspaceNode},
},
jay_config::Direction,
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 on_set_fullscreen(&self, workspace: &Rc<WorkspaceNode>);
@ -76,7 +77,12 @@ impl FullscreenData {
}
impl FullscreenData {
pub fn set_fullscreen(&self, state: &Rc<State>, node: Rc<dyn FullscreenNode>, output: &Rc<OutputNode>) {
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");

View file

@ -8,7 +8,10 @@ use {
wl_surface::WlSurface,
},
rect::Rect,
render::{Renderer, Texture},
state::State,
text,
theme::Color,
tree::{
FindTreeResult, FoundNode, FullscreenNode, Node, NodeId, NodeVisitor, SizedNode,
SizedToplevelNode, ToplevelData, WorkspaceNode,
@ -22,6 +25,7 @@ use {
rc::Rc,
},
};
use crate::utils::errorfmt::ErrorFmt;
tree_id!(DetachedNodeId);
pub struct PlaceholderNode {
@ -37,6 +41,7 @@ pub struct PlaceholderNode {
toplevel: ToplevelData,
active: Cell<bool>,
destroyed: Cell<bool>,
texture: CloneCell<Option<Rc<Texture>>>,
}
impl PlaceholderNode {
@ -54,9 +59,14 @@ impl PlaceholderNode {
toplevel: Default::default(),
active: Default::default(),
destroyed: Default::default(),
texture: Default::default(),
}
}
pub fn texture(&self) -> Option<Rc<Texture>> {
self.texture.get()
}
pub fn set_title(&self, title: &str) {
*self.title.borrow_mut() = title.to_string();
if let Some(parent) = self.parent.get() {
@ -67,6 +77,10 @@ impl PlaceholderNode {
pub fn is_destroyed(&self) -> bool {
self.destroyed.get()
}
pub fn position(&self) -> Rect {
self.pos.get()
}
}
impl SizedNode for PlaceholderNode {
@ -146,7 +160,32 @@ impl SizedNode for PlaceholderNode {
}
fn change_extents(self: &Rc<Self>, rect: &Rect) {
log::info!("{:?}", rect);
self.pos.set(*rect);
if let Some(p) = self.parent.get() {
p.node_child_size_changed(self.deref(), rect.width(), rect.height());
}
self.texture.set(None);
if let Some(ctx) = self.state.render_ctx.get() {
if rect.width() != 0 && rect.height() != 0 {
let font = format!("monospace {}", rect.width() / 10);
match text::render_fitting(
&ctx,
rect.height(),
&font,
"Fullscreen",
Color::GREY,
false,
) {
Ok(t) => {
self.texture.set(Some(t));
},
Err(e) => {
log::warn!("Could not render fullscreen texture: {}", ErrorFmt(e));
}
}
}
}
}
fn set_workspace(self: &Rc<Self>, ws: &Rc<WorkspaceNode>) {
@ -161,6 +200,10 @@ impl SizedNode for PlaceholderNode {
fn client(&self) -> Option<Rc<Client>> {
self.client.clone()
}
fn render(&self, renderer: &mut Renderer, x: i32, y: i32) {
renderer.render_placeholder(self, x, y);
}
}
impl SizedToplevelNode for PlaceholderNode {

View file

@ -120,8 +120,20 @@ impl SizedNode for WorkspaceNode {
FindTreeResult::AcceptsInput
}
fn remove_child2(self: &Rc<Self>, _child: &dyn Node, _preserve_focus: bool) {
self.container.set(None);
fn remove_child2(self: &Rc<Self>, child: &dyn Node, _preserve_focus: bool) {
if let Some(container) = self.container.get() {
if container.node_id() == child.node_id() {
self.container.set(None);
return;
}
}
if let Some(fs) = self.fullscreen.get() {
if fs.as_node().node_id() == child.node_id() {
self.fullscreen.set(None);
return;
}
}
log::error!("Trying to remove child that's not a child");
}
fn pointer_focus(&self, seat: &Rc<WlSeatGlobal>) {