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

@ -983,7 +983,9 @@ impl SizedNode for ContainerNode {
}
let (split, prev) = direction_to_split(direction);
// CASE 2: We're moving the child within the container.
if split == self.split.get() || (split == ContainerSplit::Horizontal && self.mono_child.get().is_some()) {
if split == self.split.get()
|| (split == ContainerSplit::Horizontal && self.mono_child.get().is_some())
{
let cc = match self.child_nodes.borrow_mut().get(&child.node_id()) {
Some(l) => l.to_ref(),
None => return,
@ -1192,8 +1194,8 @@ impl SizedNode for ContainerNode {
Some(c) => c,
None => {
log::error!("Trying to replace a node that isn't a child of this container");
return
},
return;
}
};
let (have_mc, was_mc) = match self.mono_child.get() {
None => (false, false),
@ -1408,6 +1410,14 @@ impl SizedNode for ContainerNode {
.clone()
.node_child_title_changed(self.deref(), self.title.borrow_mut().deref());
}
fn set_fullscreen(self: &Rc<Self>, _fullscreen: bool) {
// todo
}
fn fullscreen(&self) -> bool {
false
}
}
fn direction_to_split(dir: Direction) -> (ContainerSplit, bool) {

View file

@ -2,9 +2,7 @@ use {
crate::{
backend::ConnectorId,
cursor::KnownCursor,
ifs::{
wl_seat::{NodeSeatState, WlSeatGlobal},
},
ifs::wl_seat::{NodeSeatState, WlSeatGlobal},
rect::Rect,
render::Renderer,
tree::{

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);
}
}
}

View file

@ -6,7 +6,7 @@ use {
wl_output::WlOutputGlobal,
wl_seat::{collect_kb_foci2, NodeSeatState, WlSeatGlobal},
wl_surface::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
zwlr_layer_shell_v1::{BACKGROUND, BOTTOM},
zwlr_layer_shell_v1::{BACKGROUND, BOTTOM, OVERLAY, TOP},
},
rect::Rect,
render::{Renderer, Texture},
@ -27,7 +27,6 @@ use {
rc::Rc,
},
};
use crate::ifs::zwlr_layer_shell_v1::{OVERLAY, TOP};
tree_id!(OutputNodeId);
pub struct OutputNode {
@ -348,7 +347,8 @@ impl SizedNode for OutputNode {
{
for stacked in self.state.root.stacked.rev_iter() {
let ext = stacked.node_absolute_position();
if stacked.node_absolute_position_constrains_input() && !ext.contains(x_abs, y_abs) {
if stacked.node_absolute_position_constrains_input() && !ext.contains(x_abs, y_abs)
{
// TODO: make constrain always true
continue;
}

View file

@ -1,16 +1,27 @@
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;
use {
crate::{
client::Client,
cursor::KnownCursor,
fixed::Fixed,
ifs::{
wl_seat::{NodeSeatState, WlSeatGlobal},
wl_surface::WlSurface,
},
rect::Rect,
state::State,
tree::{
FindTreeResult, FoundNode, FullscreenNode, Node, NodeId, NodeVisitor, SizedNode,
SizedToplevelNode, ToplevelData, WorkspaceNode,
},
utils::clonecell::CloneCell,
},
jay_config::Direction,
std::{
cell::{Cell, RefCell},
ops::Deref,
rc::Rc,
},
};
tree_id!(DetachedNodeId);
pub struct PlaceholderNode {
@ -152,19 +163,11 @@ impl SizedNode for PlaceholderNode {
}
}
impl ToplevelNode for PlaceholderNode {
impl SizedToplevelNode 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
}
@ -180,4 +183,12 @@ impl ToplevelNode for PlaceholderNode {
fn activate(&self) {
// nothing
}
fn set_fullscreen(self: &Rc<Self>, _fullscreen: bool) {
// nothing
}
fn fullscreen(&self) -> bool {
false
}
}

View file

@ -1,12 +1,30 @@
use {
crate::{
ifs::{wl_seat::SeatId, wl_surface::WlSurface},
tree::{Node, WorkspaceNode},
tree::{Node, SizedNode, WorkspaceNode},
utils::{numcell::NumCell, smallmap::SmallMap},
},
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;
@ -16,6 +34,46 @@ pub trait ToplevelNode {
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)
}
fn as_node(&self) -> &dyn Node {
<Self as SizedToplevelNode>::as_node(self)
}
fn into_node(self: Rc<Self>) -> Rc<dyn Node> {
<Self as SizedToplevelNode>::into_node(self)
}
fn accepts_keyboard_focus(&self) -> bool {
<Self as SizedToplevelNode>::accepts_keyboard_focus(self)
}
fn default_surface(&self) -> Option<Rc<WlSurface>> {
<Self as SizedToplevelNode>::default_surface(self)
}
fn set_active(&self, active: bool) {
<Self as SizedToplevelNode>::set_active(self, active)
}
fn activate(&self) {
<Self as SizedToplevelNode>::activate(self)
}
fn set_fullscreen(self: Rc<Self>, fullscreen: bool) {
<Self as SizedToplevelNode>::set_fullscreen(&self, fullscreen)
}
fn fullscreen(&self) -> bool {
<Self as SizedToplevelNode>::fullscreen(self)
}
}
#[derive(Default)]

View file

@ -6,11 +6,12 @@ use {
zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
WlSurface,
},
tree::{ContainerNode, DisplayNode, FloatNode, Node, OutputNode, WorkspaceNode},
tree::{
ContainerNode, DisplayNode, FloatNode, Node, OutputNode, PlaceholderNode, WorkspaceNode,
},
},
std::rc::Rc,
};
use crate::tree::PlaceholderNode;
pub trait NodeVisitorBase: Sized {
fn visit_surface(&mut self, node: &Rc<WlSurface>) {

View file

@ -5,8 +5,8 @@ use {
rect::Rect,
render::Renderer,
tree::{
container::ContainerNode, walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId,
OutputNode, SizedNode,
container::ContainerNode, walker::NodeVisitor, FindTreeResult, FoundNode,
FullscreenNode, Node, NodeId, OutputNode, SizedNode,
},
utils::{
clonecell::CloneCell,
@ -16,7 +16,6 @@ use {
jay_config::Direction,
std::{cell::Cell, fmt::Debug, rc::Rc},
};
use crate::tree::FullscreenNode;
tree_id!(WorkspaceNodeId);