1
0
Fork 0
forked from wry/wry

autocommit 2022-02-20 15:48:24 CET

This commit is contained in:
Julian Orth 2022-02-20 15:48:24 +01:00
parent 26fab1e3e2
commit a2f078cb66
6 changed files with 72 additions and 50 deletions

View file

@ -175,13 +175,13 @@ impl XdgSurface {
} }
pub fn move_focus(&self, seat: &Rc<WlSeatGlobal>, direction: Direction) { pub fn move_focus(&self, seat: &Rc<WlSeatGlobal>, direction: Direction) {
if let Some(ext)= self.ext.get() { if let Some(ext) = self.ext.get() {
ext.move_focus(seat, direction); ext.move_focus(seat, direction);
} }
} }
pub fn move_self(&self, direction: Direction) { pub fn move_self(&self, direction: Direction) {
if let Some(ext)= self.ext.get() { if let Some(ext) = self.ext.get() {
ext.move_self(direction); ext.move_self(direction);
} }
} }

View file

@ -26,7 +26,7 @@ use crate::ifs::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Global;
use crate::render::RenderError; use crate::render::RenderError;
use crate::sighand::SighandError; use crate::sighand::SighandError;
use crate::state::State; use crate::state::State;
use crate::tree::{container_layout, DisplayNode, NodeIds, render_titles}; use crate::tree::{container_layout, render_titles, DisplayNode, NodeIds};
use crate::utils::clonecell::CloneCell; use crate::utils::clonecell::CloneCell;
use crate::utils::errorfmt::ErrorFmt; use crate::utils::errorfmt::ErrorFmt;
use crate::utils::numcell::NumCell; use crate::utils::numcell::NumCell;

View file

@ -16,7 +16,7 @@ use crate::render::Texture;
use crate::tree::{ use crate::tree::{
ContainerFocus, ContainerNode, ContainerSplit, FloatNode, OutputNode, WorkspaceNode, ContainerFocus, ContainerNode, ContainerSplit, FloatNode, OutputNode, WorkspaceNode,
}; };
use crate::{State}; use crate::State;
use std::ops::Deref; use std::ops::Deref;
use std::rc::Rc; use std::rc::Rc;
use std::slice; use std::slice;
@ -129,11 +129,7 @@ impl Renderer<'_> {
width += 1; width += 1;
} }
if let Some(title) = child.title_texture.get() { if let Some(title) = child.title_texture.get() {
titles.push(( titles.push((pos, 0, title));
pos,
0,
title,
));
} }
if focus != ContainerFocus::None { if focus != ContainerFocus::None {
let rect = Rect::new_sized(pos, y, width, title_height).unwrap(); let rect = Rect::new_sized(pos, y, width, title_height).unwrap();
@ -163,11 +159,7 @@ impl Renderer<'_> {
for (i, child) in container.children.iter().enumerate() { for (i, child) in container.children.iter().enumerate() {
let body = child.body.get(); let body = child.body.get();
if let Some(title) = child.title_texture.get() { if let Some(title) = child.title_texture.get() {
titles.push(( titles.push((body.x1(), body.y1() - title_height - 1, title));
body.x1(),
body.y1() - title_height - 1,
title,
));
} }
if child.active.get() { if child.active.get() {
active_rects.push( active_rects.push(

View file

@ -1,3 +1,4 @@
use crate::backend::{KeyState, ScrollAxis};
use crate::cursor::KnownCursor; use crate::cursor::KnownCursor;
use crate::fixed::Fixed; use crate::fixed::Fixed;
use crate::ifs::wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT, Dnd}; use crate::ifs::wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT, Dnd};
@ -5,7 +6,7 @@ use crate::rect::Rect;
use crate::render::{Renderer, Texture}; use crate::render::{Renderer, Texture};
use crate::theme::Color; use crate::theme::Color;
use crate::tree::walker::NodeVisitor; use crate::tree::walker::NodeVisitor;
use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode}; use crate::tree::{FindTreeResult, FloatNode, FoundNode, Node, NodeId, WorkspaceNode};
use crate::utils::clonecell::CloneCell; use crate::utils::clonecell::CloneCell;
use crate::utils::linkedlist::{LinkedList, LinkedNode, NodeRef}; use crate::utils::linkedlist::{LinkedList, LinkedNode, NodeRef};
use crate::{text, ErrorFmt, NumCell, State}; use crate::{text, ErrorFmt, NumCell, State};
@ -17,7 +18,9 @@ use std::fmt::{Debug, Formatter};
use std::mem; use std::mem;
use std::ops::{Deref, DerefMut, Sub}; use std::ops::{Deref, DerefMut, Sub};
use std::rc::Rc; use std::rc::Rc;
use crate::backend::KeyState; use crate::client::{Client, ClientId};
use crate::ifs::wl_surface::WlSurface;
use crate::xkbcommon::ModifierState;
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
@ -195,7 +198,8 @@ impl ContainerNode {
} }
fn add_child_x<F>(self: &Rc<Self>, prev: &dyn Node, new: Rc<dyn Node>, f: F) fn add_child_x<F>(self: &Rc<Self>, prev: &dyn Node, new: Rc<dyn Node>, f: F)
where F: FnOnce(&NodeRef<ContainerChild>, Rc<dyn Node>), where
F: FnOnce(&NodeRef<ContainerChild>, Rc<dyn Node>),
{ {
let node = self let node = self
.child_nodes .child_nodes
@ -220,7 +224,8 @@ impl ContainerNode {
} }
fn add_child<F>(self: &Rc<Self>, f: F, new: Rc<dyn Node>) fn add_child<F>(self: &Rc<Self>, f: F, new: Rc<dyn Node>)
where F: FnOnce(ContainerChild) -> LinkedNode<ContainerChild>, where
F: FnOnce(ContainerChild) -> LinkedNode<ContainerChild>,
{ {
{ {
let mut links = self.child_nodes.borrow_mut(); let mut links = self.child_nodes.borrow_mut();
@ -356,19 +361,17 @@ impl ContainerNode {
let nc = self.num_children.get(); let nc = self.num_children.get();
match self.split.get() { match self.split.get() {
ContainerSplit::Horizontal => { ContainerSplit::Horizontal => {
let new_content_size = self let new_content_size = self.width.get().sub((nc - 1) as i32 * border_width).max(0);
.width
.get()
.sub((nc - 1) as i32 * border_width)
.max(0);
self.content_width.set(new_content_size); self.content_width.set(new_content_size);
self.content_height self.content_height
.set(self.height.get().sub(title_height + 1).max(0)); .set(self.height.get().sub(title_height + 1).max(0));
} }
ContainerSplit::Vertical => { ContainerSplit::Vertical => {
let new_content_size = self.height.get().sub( let new_content_size = self
title_height + 1 + (nc - 1) as i32 * (border_width + title_height + 1), .height
).max(0); .get()
.sub(title_height + 1 + (nc - 1) as i32 * (border_width + title_height + 1))
.max(0);
self.content_height.set(new_content_size); self.content_height.set(new_content_size);
self.content_width.set(self.width.get()); self.content_width.set(self.width.get());
} }
@ -503,14 +506,13 @@ impl ContainerNode {
Some(c) => c, Some(c) => c,
_ => continue, _ => continue,
}; };
let texture = let texture = match text::render(&ctx, body.width(), th, &font, &title, Color::GREY) {
match text::render(&ctx, body.width(), th, &font, &title, Color::GREY) { Ok(t) => t,
Ok(t) => t, Err(e) => {
Err(e) => { log::error!("Could not render title {}: {}", title, ErrorFmt(e));
log::error!("Could not render title {}: {}", title, ErrorFmt(e)); continue;
continue; }
} };
};
c.title_texture.set(Some(texture)); c.title_texture.set(Some(texture));
} }
self.render_titles_scheduled.set(false); self.render_titles_scheduled.set(false);
@ -614,7 +616,9 @@ impl Node for ContainerNode {
self.do_focus(seat, direction); self.do_focus(seat, direction);
return; return;
} }
self.parent.get().move_focus_from_child(seat, &*self, direction); self.parent
.get()
.move_focus_from_child(seat, &*self, direction);
} }
fn move_self(self: Rc<Self>, direction: Direction) { fn move_self(self: Rc<Self>, direction: Direction) {
@ -675,15 +679,13 @@ impl Node for ContainerNode {
sibling.node.clone().do_focus(seat, direction); sibling.node.clone().do_focus(seat, direction);
} }
// //
fn move_child( fn move_child(self: Rc<Self>, child: Rc<dyn Node>, direction: Direction) {
self: Rc<Self>,
child: Rc<dyn Node>,
direction: Direction,
) {
// CASE 1: This is the only child of the container. Replace the container by the child. // CASE 1: This is the only child of the container. Replace the container by the child.
if self.num_children.get() == 1 { if self.num_children.get() == 1 {
if let Some(parent) = self.parent.get().into_container() { let parent = self.parent.get();
parent.replace_child(&*self, child.clone()); let can_replace = parent.is_container() || child.clone().into_container().is_some();
if can_replace {
self.parent.get().replace_child(&*self, child.clone());
} }
return; return;
} }
@ -950,6 +952,14 @@ impl Node for ContainerNode {
Some(self) Some(self)
} }
fn is_container(&self) -> bool {
true
}
fn accepts_child(&self, _node: &dyn Node) -> bool {
true
}
fn change_extents(self: Rc<Self>, rect: &Rect) { fn change_extents(self: Rc<Self>, rect: &Rect) {
self.abs_x1.set(rect.x1()); self.abs_x1.set(rect.x1());
self.abs_y1.set(rect.y1()); self.abs_y1.set(rect.y1());
@ -981,7 +991,9 @@ impl Node for ContainerNode {
fn set_parent(self: Rc<Self>, parent: Rc<dyn Node>) { fn set_parent(self: Rc<Self>, parent: Rc<dyn Node>) {
self.parent.set(parent.clone()); self.parent.set(parent.clone());
parent.child_size_changed(&*self, self.width.get(), self.height.get()); parent.child_size_changed(&*self, self.width.get(), self.height.get());
parent.clone().child_title_changed(&*self, self.title.borrow_mut().deref()); parent
.clone()
.child_title_changed(&*self, self.title.borrow_mut().deref());
} }
} }

View file

@ -125,11 +125,7 @@ pub trait Node {
let _ = child; let _ = child;
} }
fn move_child( fn move_child(self: Rc<Self>, child: Rc<dyn Node>, direction: Direction) {
self: Rc<Self>,
child: Rc<dyn Node>,
direction: Direction,
) {
let _ = direction; let _ = direction;
let _ = child; let _ = child;
} }
@ -243,6 +239,14 @@ pub trait Node {
None None
} }
fn is_container(&self) -> bool {
false
}
fn accepts_child(&self, node: &dyn Node) -> bool {
false
}
fn is_float(&self) -> bool { fn is_float(&self) -> bool {
false false
} }
@ -533,6 +537,10 @@ impl Node for FloatNode {
} }
} }
fn accepts_child(&self, _node: &dyn Node) -> bool {
true
}
fn absolute_position(&self) -> Rect { fn absolute_position(&self) -> Rect {
self.position.get() self.position.get()
} }

View file

@ -1,14 +1,20 @@
use crate::cursor::KnownCursor; use crate::cursor::KnownCursor;
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal}; use crate::ifs::wl_seat::{Dnd, NodeSeatState, WlSeatGlobal};
use crate::rect::Rect; use crate::rect::Rect;
use crate::render::Renderer; use crate::render::Renderer;
use crate::tree::container::ContainerNode; use crate::tree::container::ContainerNode;
use crate::tree::walker::NodeVisitor; use crate::tree::walker::NodeVisitor;
use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, OutputNode}; use crate::tree::{ContainerSplit, FindTreeResult, FloatNode, FoundNode, Node, NodeId, OutputNode};
use crate::utils::clonecell::CloneCell; use crate::utils::clonecell::CloneCell;
use crate::utils::linkedlist::LinkedList; use crate::utils::linkedlist::LinkedList;
use std::fmt::Debug; use std::fmt::Debug;
use std::rc::Rc; use std::rc::Rc;
use i4config::Direction;
use crate::backend::{KeyState, ScrollAxis};
use crate::client::{Client, ClientId};
use crate::fixed::Fixed;
use crate::ifs::wl_surface::WlSurface;
use crate::xkbcommon::ModifierState;
tree_id!(WorkspaceNodeId); tree_id!(WorkspaceNodeId);
@ -48,6 +54,10 @@ impl Node for WorkspaceNode {
self.seat_state.destroy_node(self); self.seat_state.destroy_node(self);
} }
fn accepts_child(&self, node: &dyn Node) -> bool {
node.is_container()
}
fn visit(self: Rc<Self>, visitor: &mut dyn NodeVisitor) { fn visit(self: Rc<Self>, visitor: &mut dyn NodeVisitor) {
visitor.visit_workspace(&self); visitor.visit_workspace(&self);
} }