diff --git a/default-config/src/lib.rs b/default-config/src/lib.rs index 6738f0c3..f50006ec 100644 --- a/default-config/src/lib.rs +++ b/default-config/src/lib.rs @@ -1,13 +1,16 @@ use i4config::embedded::grab_keyboard; use i4config::keyboard::mods::{Modifiers, ALT, CTRL, SHIFT}; -use i4config::keyboard::syms::{SYM_Super_L, SYM_b, SYM_comma, SYM_h, SYM_j, SYM_k, SYM_l, SYM_period, SYM_r, SYM_t, SYM_y, SYM_d, SYM_v}; +use i4config::keyboard::syms::{ + SYM_Super_L, SYM_b, SYM_comma, SYM_d, SYM_h, SYM_j, SYM_k, SYM_l, SYM_period, SYM_r, SYM_t, + SYM_v, SYM_y, +}; use i4config::theme::{get_title_height, set_title_color, set_title_height, Color}; +use i4config::Axis::{Horizontal, Vertical}; use i4config::Direction::{Down, Left, Right, Up}; use i4config::{ config, create_seat, input_devices, on_new_input_device, Command, InputDevice, Seat, }; use rand::Rng; -use i4config::Axis::{Horizontal, Vertical}; const MOD: Modifiers = ALT; diff --git a/src/ifs/wl_seat/pointer_owner.rs b/src/ifs/wl_seat/pointer_owner.rs index 3ad0ee10..32869c58 100644 --- a/src/ifs/wl_seat/pointer_owner.rs +++ b/src/ifs/wl_seat/pointer_owner.rs @@ -147,7 +147,8 @@ impl PointerOwner for DefaultPointerOwner { } if (stack.len(), found_tree.len()) == (divergence, divergence) { if let Some(node) = found_tree.last() { - node.node.clone() + node.node + .clone() .motion(seat, x.apply_fract(node.x), y.apply_fract(node.y)); } } else { @@ -242,7 +243,8 @@ impl PointerOwner for GrabPointerOwner { let (x, y) = seat.pos.get(); let pos = self.node.absolute_position(); let (x_int, y_int) = pos.translate(x.round_down(), y.round_down()); - self.node.clone() + self.node + .clone() .motion(seat, x.apply_fract(x_int), y.apply_fract(y_int)); } diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs index b798359c..f2902657 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs @@ -118,6 +118,9 @@ impl XdgToplevel { } pub fn set_active(self: &Rc, active: bool) { + if let Some(parent) = self.parent_node.get() { + parent.child_active_changed(&**self, active); + } let changed = { let mut states = self.states.borrow_mut(); match active { diff --git a/src/render/renderer/renderer.rs b/src/render/renderer/renderer.rs index a3b34860..0436127b 100644 --- a/src/render/renderer/renderer.rs +++ b/src/render/renderer/renderer.rs @@ -65,6 +65,9 @@ impl Renderer<'_> { } fn fill_boxes(&self, boxes: &[Rect], r: f32, g: f32, b: f32, a: f32) { + if boxes.is_empty() { + return; + } let mut pos = Vec::with_capacity(boxes.len() * 12); for bx in boxes { let x1 = self.x_to_f(bx.x1()); @@ -146,10 +149,22 @@ impl Renderer<'_> { let mut title_rects = Vec::with_capacity(num_title_rects); let mut underline_rects = Vec::with_capacity(num_title_rects); let mut border_rects = Vec::with_capacity(num_children - 1); + let mut active_rects = Vec::new(); title_rects.push(title_rect); underline_rects.push(underline_rect); for (i, child) in container.children.iter().enumerate() { let body = child.body.get(); + if child.active.get() { + active_rects.push( + Rect::new_sized( + x + body.x1(), + y + body.y1() - title_height - 1, + body.width(), + title_height, + ) + .unwrap(), + ); + } if i + 1 < num_children { let border_rect = if split == ContainerSplit::Horizontal { Rect::new_sized( @@ -187,6 +202,8 @@ impl Renderer<'_> { { let c = self.state.theme.title_color.get(); self.fill_boxes(&title_rects, c.r, c.g, c.b, c.a); + let c = self.state.theme.active_title_color.get(); + self.fill_boxes(&active_rects, c.r, c.g, c.b, c.a); let c = self.state.theme.underline_color.get(); self.fill_boxes(&underline_rects, c.r, c.g, c.b, c.a); let c = self.state.theme.border_color.get(); diff --git a/src/theme.rs b/src/theme.rs index 3194f01f..655e0d2a 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -1,5 +1,5 @@ -use std::cell::Cell; use crate::NumCell; +use std::cell::Cell; #[derive(Copy, Clone, Debug)] pub struct Color { @@ -38,6 +38,7 @@ impl From for Color { pub struct Theme { pub background_color: Cell, pub title_color: Cell, + pub active_title_color: Cell, pub underline_color: Cell, pub border_color: Cell, pub title_height: Cell, @@ -50,6 +51,7 @@ impl Default for Theme { Self { background_color: Cell::new(Color::from_rgba(0, 0, 0, 255)), title_color: Cell::new(Color::from_rgba(0x46, 0x04, 0x17, 255)), + active_title_color: Cell::new(Color::from_rgba(0x17, 0x04, 0x46, 255)), underline_color: Cell::new(Color::from_rgba(0x66, 0x24, 0x37, 255)), border_color: Cell::new(Color::from_rgba(0x36, 0x00, 0x07, 255)), title_height: Cell::new(17), diff --git a/src/tree/container.rs b/src/tree/container.rs index d58dab22..fb0ef12d 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -1,10 +1,10 @@ -use crate::backend::{KeyState}; +use crate::backend::KeyState; use crate::cursor::KnownCursor; use crate::fixed::Fixed; use crate::ifs::wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT}; use crate::rect::Rect; use crate::render::Renderer; -use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode}; +use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode}; use crate::utils::clonecell::CloneCell; use crate::utils::linkedlist::{LinkedList, LinkedNode, NodeRef}; use crate::{NumCell, State}; @@ -84,6 +84,7 @@ impl Debug for ContainerNode { pub struct ContainerChild { pub node: Rc, + pub active: Cell, pub body: Cell, pub content: Cell, factor: Cell, @@ -130,6 +131,7 @@ impl ContainerNode { child.id(), children.add_last(ContainerChild { node: child, + active: Cell::new(false), body: Cell::new(Default::default()), content: Cell::new(Default::default()), factor: Cell::new(1.0), @@ -200,6 +202,7 @@ impl ContainerNode { new.id(), prev.append(ContainerChild { node: new.clone(), + active: Cell::new(false), body: Default::default(), content: Default::default(), factor: Cell::new(0.0), @@ -362,7 +365,9 @@ impl ContainerNode { let (prev_factor, child_factor) = match self.split.get() { ContainerSplit::Horizontal => { let cw = self.content_width.get(); - x = x.max(prev_body.x1() + dist_left).min(child_body.x2() - dist_right); + x = x + .max(prev_body.x1() + dist_left) + .min(child_body.x2() - dist_right); let prev_factor = (x - prev_body.x1() - dist_left) as f64 / cw as f64; let child_factor = (child_body.x2() - x - dist_right) as f64 / cw as f64; @@ -370,16 +375,19 @@ impl ContainerNode { } ContainerSplit::Vertical => { let ch = self.content_height.get(); - y = y.max(prev_body.y1() + dist_left).min(child_body.y2() - dist_right); + y = y + .max(prev_body.y1() + dist_left) + .min(child_body.y2() - dist_right); let prev_factor = (y - prev_body.y1() - dist_left) as f64 / ch as f64; let child_factor = (child_body.y2() - y - dist_right) as f64 / ch as f64; (prev_factor, child_factor) } }; - let sum_factors = self.sum_factors.get() - prev.factor.get() - op.child.factor.get() - + prev_factor - + child_factor; + let sum_factors = + self.sum_factors.get() - prev.factor.get() - op.child.factor.get() + + prev_factor + + child_factor; prev.factor.set(prev_factor); op.child.factor.set(child_factor); self.apply_factors(sum_factors); @@ -484,9 +492,8 @@ impl Node for ContainerNode { child: &dyn Node, direction: Direction, ) { - let children = self.child_nodes.borrow_mut(); - let child = match children.get(&child.id()) { - Some(c) => c, + let child = match self.child_nodes.borrow_mut().get(&child.id()) { + Some(c) => c.to_ref(), _ => return, }; let in_line = match self.split.get() { @@ -633,8 +640,9 @@ impl Node for ContainerNode { Some(c) => c, None => return, }; - let link= node.append(ContainerChild { + let link = node.append(ContainerChild { node: new.clone(), + active: Cell::new(false), body: Cell::new(node.body.get()), content: Cell::new(node.content.get()), factor: Cell::new(node.factor.get()), @@ -709,6 +717,18 @@ impl Node for ContainerNode { self.pointer_move(seat, x.round_down(), y.round_down()); } + fn child_active_changed(&self, child: &dyn Node, active: bool) { + log::info!("cac = {}", active); + let node = match self.child_nodes.borrow_mut().get(&child.id()) { + Some(l) => l.to_ref(), + None => { + log::info!("return"); + return + }, + }; + node.active.set(active); + } + fn render(&self, renderer: &mut Renderer, x: i32, y: i32) { renderer.render_container(self, x, y); } @@ -727,7 +747,9 @@ impl Node for ContainerNode { self.update_content_size(); self.do_apply_factors(); self.cancel_seat_ops(); - self.parent.get().child_size_changed(&*self, rect.width(), rect.height()); + self.parent + .get() + .child_size_changed(&*self, rect.width(), rect.height()); } else { for child in self.children.iter() { let body = child.body.get().move_(self.abs_x1.get(), self.abs_y1.get()); diff --git a/src/tree/mod.rs b/src/tree/mod.rs index d6a45b8e..e3a9b3d7 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -179,6 +179,10 @@ pub trait Node { let _ = (child, width, height); } + fn child_active_changed(&self, child: &dyn Node, active: bool) { + let _ = (child, active); + } + fn leave(&self, seat: &WlSeatGlobal) { let _ = seat; }