From a2f078cb6658a13bdf8ec7e03160a29ccdf8c78d Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 20 Feb 2022 15:48:24 +0100 Subject: [PATCH] autocommit 2022-02-20 15:48:24 CET --- src/ifs/wl_surface/xdg_surface.rs | 4 +- src/main.rs | 2 +- src/render/renderer/renderer.rs | 14 ++----- src/tree/container.rs | 70 ++++++++++++++++++------------- src/tree/mod.rs | 18 +++++--- src/tree/workspace.rs | 14 ++++++- 6 files changed, 72 insertions(+), 50 deletions(-) diff --git a/src/ifs/wl_surface/xdg_surface.rs b/src/ifs/wl_surface/xdg_surface.rs index c213d50e..9ef7ef94 100644 --- a/src/ifs/wl_surface/xdg_surface.rs +++ b/src/ifs/wl_surface/xdg_surface.rs @@ -175,13 +175,13 @@ impl XdgSurface { } pub fn move_focus(&self, seat: &Rc, direction: Direction) { - if let Some(ext)= self.ext.get() { + if let Some(ext) = self.ext.get() { ext.move_focus(seat, 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); } } diff --git a/src/main.rs b/src/main.rs index 0f6e21c8..a8b5ac6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ use crate::ifs::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Global; use crate::render::RenderError; use crate::sighand::SighandError; 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::errorfmt::ErrorFmt; use crate::utils::numcell::NumCell; diff --git a/src/render/renderer/renderer.rs b/src/render/renderer/renderer.rs index de088f77..561d0fbe 100644 --- a/src/render/renderer/renderer.rs +++ b/src/render/renderer/renderer.rs @@ -16,7 +16,7 @@ use crate::render::Texture; use crate::tree::{ ContainerFocus, ContainerNode, ContainerSplit, FloatNode, OutputNode, WorkspaceNode, }; -use crate::{State}; +use crate::State; use std::ops::Deref; use std::rc::Rc; use std::slice; @@ -129,11 +129,7 @@ impl Renderer<'_> { width += 1; } if let Some(title) = child.title_texture.get() { - titles.push(( - pos, - 0, - title, - )); + titles.push((pos, 0, title)); } if focus != ContainerFocus::None { 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() { let body = child.body.get(); if let Some(title) = child.title_texture.get() { - titles.push(( - body.x1(), - body.y1() - title_height - 1, - title, - )); + titles.push((body.x1(), body.y1() - title_height - 1, title)); } if child.active.get() { active_rects.push( diff --git a/src/tree/container.rs b/src/tree/container.rs index c4d89565..1fc81b84 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -1,3 +1,4 @@ +use crate::backend::{KeyState, ScrollAxis}; use crate::cursor::KnownCursor; use crate::fixed::Fixed; 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::theme::Color; 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::linkedlist::{LinkedList, LinkedNode, NodeRef}; use crate::{text, ErrorFmt, NumCell, State}; @@ -17,7 +18,9 @@ use std::fmt::{Debug, Formatter}; use std::mem; use std::ops::{Deref, DerefMut, Sub}; 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)] #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -195,7 +198,8 @@ impl ContainerNode { } fn add_child_x(self: &Rc, prev: &dyn Node, new: Rc, f: F) - where F: FnOnce(&NodeRef, Rc), + where + F: FnOnce(&NodeRef, Rc), { let node = self .child_nodes @@ -220,7 +224,8 @@ impl ContainerNode { } fn add_child(self: &Rc, f: F, new: Rc) - where F: FnOnce(ContainerChild) -> LinkedNode, + where + F: FnOnce(ContainerChild) -> LinkedNode, { { let mut links = self.child_nodes.borrow_mut(); @@ -356,19 +361,17 @@ impl ContainerNode { let nc = self.num_children.get(); match self.split.get() { ContainerSplit::Horizontal => { - let new_content_size = self - .width - .get() - .sub((nc - 1) as i32 * border_width) - .max(0); + let new_content_size = self.width.get().sub((nc - 1) as i32 * border_width).max(0); self.content_width.set(new_content_size); self.content_height .set(self.height.get().sub(title_height + 1).max(0)); } ContainerSplit::Vertical => { - let new_content_size = self.height.get().sub( - title_height + 1 + (nc - 1) as i32 * (border_width + title_height + 1), - ).max(0); + let new_content_size = self + .height + .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_width.set(self.width.get()); } @@ -503,14 +506,13 @@ impl ContainerNode { Some(c) => c, _ => continue, }; - let texture = - match text::render(&ctx, body.width(), th, &font, &title, Color::GREY) { - Ok(t) => t, - Err(e) => { - log::error!("Could not render title {}: {}", title, ErrorFmt(e)); - continue; - } - }; + let texture = match text::render(&ctx, body.width(), th, &font, &title, Color::GREY) { + Ok(t) => t, + Err(e) => { + log::error!("Could not render title {}: {}", title, ErrorFmt(e)); + continue; + } + }; c.title_texture.set(Some(texture)); } self.render_titles_scheduled.set(false); @@ -614,7 +616,9 @@ impl Node for ContainerNode { self.do_focus(seat, direction); 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, direction: Direction) { @@ -675,15 +679,13 @@ impl Node for ContainerNode { sibling.node.clone().do_focus(seat, direction); } // - fn move_child( - self: Rc, - child: Rc, - direction: Direction, - ) { + fn move_child(self: Rc, child: Rc, direction: Direction) { // CASE 1: This is the only child of the container. Replace the container by the child. if self.num_children.get() == 1 { - if let Some(parent) = self.parent.get().into_container() { - parent.replace_child(&*self, child.clone()); + let parent = self.parent.get(); + let can_replace = parent.is_container() || child.clone().into_container().is_some(); + if can_replace { + self.parent.get().replace_child(&*self, child.clone()); } return; } @@ -950,6 +952,14 @@ impl Node for ContainerNode { Some(self) } + fn is_container(&self) -> bool { + true + } + + fn accepts_child(&self, _node: &dyn Node) -> bool { + true + } + fn change_extents(self: Rc, rect: &Rect) { self.abs_x1.set(rect.x1()); self.abs_y1.set(rect.y1()); @@ -981,7 +991,9 @@ impl Node for ContainerNode { fn set_parent(self: Rc, parent: Rc) { self.parent.set(parent.clone()); 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()); } } diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 57aa3793..c81aef0a 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -125,11 +125,7 @@ pub trait Node { let _ = child; } - fn move_child( - self: Rc, - child: Rc, - direction: Direction, - ) { + fn move_child(self: Rc, child: Rc, direction: Direction) { let _ = direction; let _ = child; } @@ -243,6 +239,14 @@ pub trait Node { None } + fn is_container(&self) -> bool { + false + } + + fn accepts_child(&self, node: &dyn Node) -> bool { + false + } + fn is_float(&self) -> bool { false } @@ -533,6 +537,10 @@ impl Node for FloatNode { } } + fn accepts_child(&self, _node: &dyn Node) -> bool { + true + } + fn absolute_position(&self) -> Rect { self.position.get() } diff --git a/src/tree/workspace.rs b/src/tree/workspace.rs index bca48d7f..614070ec 100644 --- a/src/tree/workspace.rs +++ b/src/tree/workspace.rs @@ -1,14 +1,20 @@ 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::render::Renderer; use crate::tree::container::ContainerNode; 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::linkedlist::LinkedList; use std::fmt::Debug; 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); @@ -48,6 +54,10 @@ impl Node for WorkspaceNode { self.seat_state.destroy_node(self); } + fn accepts_child(&self, node: &dyn Node) -> bool { + node.is_container() + } + fn visit(self: Rc, visitor: &mut dyn NodeVisitor) { visitor.visit_workspace(&self); }