1
0
Fork 0
forked from wry/wry

autocommit 2022-04-13 12:58:04 CEST

This commit is contained in:
Julian Orth 2022-04-13 12:58:04 +02:00
parent 8924936079
commit 661a28e5b0
23 changed files with 165 additions and 143 deletions

View file

@ -4,6 +4,7 @@ use {
cursor::KnownCursor,
fixed::Fixed,
ifs::wl_seat::{
collect_kb_foci, collect_kb_foci2,
wl_pointer::{PendingScroll, VERTICAL_SCROLL},
NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT, PX_PER_SCROLL,
},
@ -13,8 +14,7 @@ use {
text,
theme::Color,
tree::{
generic_node_visitor, walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId,
SizedNode, WorkspaceNode,
walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId, SizedNode, WorkspaceNode,
},
utils::{
clonecell::CloneCell,
@ -25,6 +25,7 @@ use {
},
},
ahash::AHashMap,
isnt::std_1::vec::IsntVecExt,
jay_config::{Axis, Direction},
smallvec::SmallVec,
std::{
@ -81,6 +82,7 @@ pub struct ContainerTitle {
pub struct ContainerRenderData {
pub title_rects: Vec<Rect>,
pub active_title_rects: Vec<Rect>,
pub last_active_rect: Option<Rect>,
pub border_rects: Vec<Rect>,
pub underline_rects: Vec<Rect>,
pub titles: Vec<ContainerTitle>,
@ -336,6 +338,9 @@ impl ContainerNode {
}
fn perform_layout(self: &Rc<Self>) {
if self.num_children.get() == 0 {
return;
}
self.layout_scheduled.set(false);
if let Some(child) = self.mono_child.get() {
self.perform_mono_layout(&child);
@ -582,25 +587,20 @@ impl ContainerNode {
fn update_title(self: &Rc<Self>) {
let mut title = self.title.borrow_mut();
title.clear();
if let Some(mc) = self.mono_child.get() {
title.push_str("M[");
title.push_str(mc.title.borrow_mut().deref());
title.push_str("]");
} else {
let split = match self.split.get() {
ContainerSplit::Horizontal => "H",
ContainerSplit::Vertical => "V",
};
title.push_str(split);
title.push_str("[");
for (i, c) in self.children.iter().enumerate() {
if i > 0 {
title.push_str(", ");
}
title.push_str(c.title.borrow_mut().deref());
let split = match (self.mono_child.get().is_some(), self.split.get()) {
(true, _) => "T",
(_, ContainerSplit::Horizontal) => "H",
(_, ContainerSplit::Vertical) => "V",
};
title.push_str(split);
title.push_str("[");
for (i, c) in self.children.iter().enumerate() {
if i > 0 {
title.push_str(", ");
}
title.push_str("]");
title.push_str(c.title.borrow_mut().deref());
}
title.push_str("]");
self.parent.get().node_child_title_changed(&**self, &title);
}
@ -626,6 +626,7 @@ impl ContainerNode {
rd.active_title_rects.clear();
rd.border_rects.clear();
rd.underline_rects.clear();
let last_active = self.focus_history.last().map(|v| v.node.node_id());
let mono = self.mono_child.get().is_some();
let split = self.split.get();
for (i, child) in self.children.iter().enumerate() {
@ -645,6 +646,9 @@ impl ContainerNode {
} else {
rd.title_rects.push(rect);
}
if last_active == Some(child.node.node_id()) {
rd.last_active_rect = Some(rect);
}
if !mono {
let rect = Rect::new_sized(rect.x1(), rect.y2(), rect.width(), 1).unwrap();
rd.underline_rects.push(rect);
@ -672,6 +676,9 @@ impl ContainerNode {
rd.underline_rects
.push(Rect::new_sized(0, th, cwidth, 1).unwrap());
}
if rd.active_title_rects.is_not_empty() {
rd.last_active_rect.take();
}
}
fn activate_child(self: &Rc<Self>, child: &NodeRef<ContainerChild>) {
@ -679,13 +686,7 @@ impl ContainerNode {
if mc.node.node_id() == child.node.node_id() {
return;
}
let mut seats = SmallVec::<[_; 3]>::new();
mc.node
.node_visit_children(&mut generic_node_visitor(|node| {
node.node_seat_state().for_each_kb_focus(|s| {
seats.push(s);
});
}));
let seats = collect_kb_foci(mc.node.clone());
mc.node.node_set_visible(false);
for seat in seats {
child
@ -765,6 +766,13 @@ impl SizedNode for ContainerNode {
self.visible.get()
}
fn last_active_child(self: &Rc<Self>) -> Rc<dyn Node> {
if let Some(last) = self.focus_history.last() {
return last.node.clone().node_last_active_child();
}
self.clone()
}
fn set_visible(&self, visible: bool) {
self.visible.set(visible);
for child in self.children.iter() {
@ -833,13 +841,7 @@ impl SizedNode for ContainerNode {
let mut seats = SmallVec::<[_; 3]>::new();
for other in self.children.iter() {
if other.node.node_id() != child_id {
other
.node
.node_visit_children(&mut generic_node_visitor(|node| {
node.node_seat_state().for_each_kb_focus(|s| {
seats.push(s);
});
}));
collect_kb_foci2(other.node.clone(), &mut seats);
other.node.node_set_visible(false);
}
}
@ -906,7 +908,7 @@ impl SizedNode for ContainerNode {
}
self.parent
.get()
.node_move_focus_from_child(seat, &**self, direction);
.node_move_focus_from_child(seat, self.deref(), direction);
}
fn move_self(self: &Rc<Self>, direction: Direction) {
@ -1035,7 +1037,7 @@ impl SizedNode for ContainerNode {
fn active_changed(&self, active: bool) {
self.active.set(active);
self.parent.get().node_child_active_changed(self, active);
self.parent.get().node_child_active_changed(self, active, 1);
}
fn button(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) {
@ -1282,15 +1284,22 @@ impl SizedNode for ContainerNode {
}
}
fn child_active_changed(self: &Rc<Self>, child: &dyn Node, active: bool) {
fn child_active_changed(self: &Rc<Self>, child: &dyn Node, active: bool, depth: u32) {
let node = match self.child_nodes.borrow_mut().get(&child.node_id()) {
Some(l) => l.to_ref(),
None => return,
};
node.active.set(active);
node.focus_history
.set(Some(self.focus_history.add_last(node.clone())));
if depth == 1 {
node.active.set(active);
}
if active {
node.focus_history
.set(Some(self.focus_history.add_last(node.clone())));
}
self.schedule_compute_render_data();
self.parent
.get()
.node_child_active_changed(self.deref(), active, depth + 1);
}
fn pointer_enter(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) {
@ -1381,7 +1390,7 @@ impl SizedNode for ContainerNode {
self.parent.set(parent.clone());
parent
.clone()
.node_child_active_changed(self.deref(), self.active.get());
.node_child_active_changed(self.deref(), self.active.get(), 1);
parent.node_child_size_changed(self.deref(), self.width.get(), self.height.get());
parent
.clone()

View file

@ -461,7 +461,7 @@ impl SizedNode for FloatNode {
self.workspace_link.set(None);
}
fn child_active_changed(self: &Rc<Self>, _child: &dyn Node, active: bool) {
fn child_active_changed(self: &Rc<Self>, _child: &dyn Node, active: bool, _depth: u32) {
self.active.set(active);
}

View file

@ -4,7 +4,7 @@ use {
cursor::KnownCursor,
ifs::{
wl_output::WlOutputGlobal,
wl_seat::{NodeSeatState, WlSeatGlobal},
wl_seat::{collect_kb_foci2, NodeSeatState, WlSeatGlobal},
wl_surface::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
zwlr_layer_shell_v1::{BACKGROUND, BOTTOM},
},
@ -18,6 +18,8 @@ use {
},
utils::{clonecell::CloneCell, errorfmt::ErrorFmt, linkedlist::LinkedList},
},
jay_config::Direction,
smallvec::SmallVec,
std::{
cell::{Cell, RefCell},
fmt::{Debug, Formatter},
@ -45,11 +47,14 @@ impl OutputNode {
let mut rd = self.render_data.borrow_mut();
rd.titles.clear();
rd.inactive_workspaces.clear();
rd.active_workspace = None;
rd.status = None;
let mut pos = 0;
let font = self.state.theme.font.borrow_mut();
let th = self.state.theme.title_height.get();
let active_id = self.workspace.get().map(|w| w.id);
let width = self.global.pos.get().width();
rd.underline = Rect::new_sized(0, th, width, 1).unwrap();
for ws in self.workspaces.iter() {
let mut title_width = th;
'create_texture: {
@ -80,7 +85,7 @@ impl OutputNode {
}
let rect = Rect::new_sized(pos, 0, title_width, th).unwrap();
if Some(ws.id) == active_id {
rd.active_workspace = rect;
rd.active_workspace = Some(rect);
} else {
rd.inactive_workspaces.push(rect);
}
@ -102,7 +107,7 @@ impl OutputNode {
break 'set_status;
}
};
let pos = self.global.pos.get().width() - title.width() - 1;
let pos = width - title.width() - 1;
rd.status = Some(OutputTitle {
x: pos,
y: 0,
@ -144,15 +149,22 @@ impl OutputNode {
workspace
}
pub fn show_workspace(&self, ws: &Rc<WorkspaceNode>) {
pub fn show_workspace(&self, ws: &Rc<WorkspaceNode>) -> bool {
let mut seats = SmallVec::new();
if let Some(old) = self.workspace.set(Some(ws.clone())) {
if old.id == ws.id {
return;
return false;
}
collect_kb_foci2(old.clone(), &mut seats);
old.node_set_visible(false);
}
ws.node_set_visible(true);
ws.clone().node_change_extents(&self.workspace_rect());
ws.change_extents(&self.workspace_rect());
let node = ws.last_active_child();
for seat in seats {
node.clone().node_do_focus(&seat, Direction::Unspecified);
}
true
}
fn workspace_rect(&self) -> Rect {
@ -160,9 +172,9 @@ impl OutputNode {
let th = self.state.theme.title_height.get();
Rect::new_sized(
rect.x1(),
rect.y1() + th,
rect.y1() + th + 1,
rect.width(),
rect.height().sub(th).max(0),
rect.height().sub(th + 1).max(0),
)
.unwrap()
}
@ -237,7 +249,8 @@ pub struct OutputTitle {
#[derive(Default)]
pub struct OutputRenderData {
pub active_workspace: Rect,
pub active_workspace: Option<Rect>,
pub underline: Rect,
pub inactive_workspaces: Vec<Rect>,
pub titles: Vec<OutputTitle>,
pub status: Option<OutputTitle>,
@ -260,7 +273,7 @@ impl SizedNode for OutputNode {
fn destroy_node(&self, detach: bool) {
if detach {
self.state.root.clone().node_remove_child(self);
self.state.root.remove_child(self);
}
self.workspace.set(None);
let workspaces: Vec<_> = self.workspaces.iter().map(|e| e.deref().clone()).collect();
@ -289,14 +302,21 @@ impl SizedNode for OutputNode {
true
}
fn last_active_child(self: &Rc<Self>) -> Rc<dyn Node> {
if let Some(ws) = self.workspace.get() {
return ws.last_active_child();
}
self.clone()
}
fn absolute_position(&self) -> Rect {
self.global.pos.get()
}
fn find_tree_at(&self, x: i32, mut y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
let th = self.state.theme.title_height.get();
if y > th {
y -= th;
let bar_height = self.state.theme.title_height.get() + 1;
if y > bar_height {
y -= bar_height;
let len = tree.len();
if let Some(ws) = self.workspace.get() {
tree.push(FoundNode {

View file

@ -33,9 +33,9 @@ pub struct WorkspaceNode {
impl WorkspaceNode {
pub fn set_container(self: &Rc<Self>, container: &Rc<ContainerNode>) {
let pos = self.position.get();
container.clone().node_change_extents(&pos);
container.clone().node_set_workspace(self);
container.node_set_visible(self.visible.get());
container.change_extents(&pos);
container.set_workspace(self);
container.set_visible(self.visible.get());
self.container.set(Some(container.clone()));
}
}
@ -74,6 +74,13 @@ impl SizedNode for WorkspaceNode {
self.visible.get()
}
fn last_active_child(self: &Rc<Self>) -> Rc<dyn Node> {
if let Some(c) = self.container.get() {
return c.last_active_child();
}
self.clone()
}
fn set_visible(&self, visible: bool) {
self.visible.set(visible);
if let Some(container) = self.container.get() {