1
0
Fork 0
forked from wry/wry

autocommit 2022-02-17 19:49:59 CET

This commit is contained in:
Julian Orth 2022-02-17 19:49:59 +01:00
parent 195a92d98b
commit bb0468feea
7 changed files with 70 additions and 17 deletions

View file

@ -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;

View file

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

View file

@ -118,6 +118,9 @@ impl XdgToplevel {
}
pub fn set_active(self: &Rc<Self>, 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 {

View file

@ -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();

View file

@ -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<i4config::theme::Color> for Color {
pub struct Theme {
pub background_color: Cell<Color>,
pub title_color: Cell<Color>,
pub active_title_color: Cell<Color>,
pub underline_color: Cell<Color>,
pub border_color: Cell<Color>,
pub title_height: Cell<i32>,
@ -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),

View file

@ -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<dyn Node>,
pub active: Cell<bool>,
pub body: Cell<Rect>,
pub content: Cell<Rect>,
factor: Cell<f64>,
@ -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());

View file

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