From 65a7a55b826493c76fc2fee65d84106bddff625c Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 2 Feb 2022 01:20:49 +0100 Subject: [PATCH] autocommit 2022-02-02 01:20:49 CET --- src/cursor.rs | 6 ++- src/ifs/wl_seat/handling.rs | 23 +++++++--- src/ifs/wl_seat/mod.rs | 3 +- src/ifs/wl_surface/mod.rs | 2 +- src/main.rs | 3 +- src/render/renderer/renderer.rs | 4 +- src/tree/container.rs | 75 +++++++++++++++++++++++++++++++-- src/tree/mod.rs | 6 ++- 8 files changed, 105 insertions(+), 17 deletions(-) diff --git a/src/cursor.rs b/src/cursor.rs index 3d289a58..d73527c6 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -51,6 +51,8 @@ pub struct ServerCursors { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum KnownCursor { Default, + ResizeLeftRight, + ResizeTopBottom, } impl ServerCursors { @@ -61,8 +63,8 @@ impl ServerCursors { ServerCursorTemplate::load(name, None, 16, &paths, ctx) }; Ok(Self { - // default: load("left_ptr")?, - default: load("left_ptr_watch")?, + default: load("left_ptr")?, + // default: load("left_ptr_watch")?, resize_right: load("right_side")?, resize_left: load("left_side")?, resize_top: load("top_side")?, diff --git a/src/ifs/wl_seat/handling.rs b/src/ifs/wl_seat/handling.rs index 9566b2ed..8f13c085 100644 --- a/src/ifs/wl_seat/handling.rs +++ b/src/ifs/wl_seat/handling.rs @@ -339,16 +339,27 @@ impl WlSeatGlobal { } } } else { + if let Some(last) = stack.last() { + last.pointer_untarget(self); + } for old in stack.drain(divergence..).rev() { old.leave(self); old.seat_state().leave(self); } - for new in found_tree.drain(divergence..) { - new.node.seat_state().enter(self); - new.node - .clone() - .enter(self, x.apply_fract(new.x), y.apply_fract(new.y)); - stack.push(new.node); + if found_tree.len() == divergence { + if let Some(node) = found_tree.last() { + node.node + .clone() + .motion(self, x.apply_fract(node.x), y.apply_fract(node.y)); + } + } else { + for new in found_tree.drain(divergence..) { + new.node.seat_state().enter(self); + new.node + .clone() + .enter(self, x.apply_fract(new.x), y.apply_fract(new.y)); + stack.push(new.node); + } } if let Some(node) = stack.last() { node.pointer_target(self); diff --git a/src/ifs/wl_seat/mod.rs b/src/ifs/wl_seat/mod.rs index 9ef7b52f..1e37c1da 100644 --- a/src/ifs/wl_seat/mod.rs +++ b/src/ifs/wl_seat/mod.rs @@ -131,6 +131,8 @@ impl WlSeatGlobal { }; let tpl = match cursor { KnownCursor::Default => &cursors.default, + KnownCursor::ResizeLeftRight => &cursors.resize_left_right, + KnownCursor::ResizeTopBottom => &cursors.resize_top_bottom, }; self.set_cursor(Some(tpl.instantiate())); } @@ -145,7 +147,6 @@ impl WlSeatGlobal { old.handle_unset(); } if let Some(cursor) = cursor.as_ref() { - log::info!("setting new cursor"); let (x, y) = self.pos.get(); cursor.set_position(x.round_down(), y.round_down()); } diff --git a/src/ifs/wl_surface/mod.rs b/src/ifs/wl_surface/mod.rs index 8e330fab..299689c0 100644 --- a/src/ifs/wl_surface/mod.rs +++ b/src/ifs/wl_surface/mod.rs @@ -632,7 +632,7 @@ impl Node for WlSurface { seat.enter_surface(&self, x, y) } - fn motion(&self, seat: &WlSeatGlobal, x: Fixed, y: Fixed) { + fn motion(&self, seat: &Rc, x: Fixed, y: Fixed) { seat.motion_surface(self, x, y) } diff --git a/src/main.rs b/src/main.rs index 06f496e7..f6cd7dbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,8 @@ mod xkbcommon; fn main() { env_logger::builder() .filter_level(LevelFilter::Info) - .filter_level(LevelFilter::Trace) + .filter_level(LevelFilter::Debug) + // .filter_level(LevelFilter::Trace) .init(); if let Err(e) = main_() { log::error!("A fatal error occurred: {}", ErrorFmt(e)); diff --git a/src/render/renderer/renderer.rs b/src/render/renderer/renderer.rs index 2adabed8..d1d97484 100644 --- a/src/render/renderer/renderer.rs +++ b/src/render/renderer/renderer.rs @@ -147,10 +147,10 @@ impl Renderer<'_> { .unwrap() } else { Rect::new_sized( - x + body.x1(), + x, y + body.y2(), container.width.get(), - CONTAINER_BORDER, + CONTAINER_BORDER + CONTAINER_TITLE_HEIGHT, ) .unwrap() }; diff --git a/src/tree/container.rs b/src/tree/container.rs index 472120b4..6a79956f 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -7,8 +7,11 @@ use crate::utils::linkedlist::{LinkedList, LinkedNode, NodeRef}; use crate::{NumCell, State}; use ahash::AHashMap; use std::cell::{Cell, RefCell}; +use std::mem; use std::rc::Rc; +use crate::backend::SeatId; use crate::cursor::KnownCursor; +use crate::fixed::Fixed; #[allow(dead_code)] #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -48,6 +51,7 @@ pub struct ContainerNode { child_nodes: RefCell>>, seat_state: NodeSeatState, workspace: CloneCell>, + seats: RefCell>, } pub struct ContainerChild { @@ -58,6 +62,13 @@ pub struct ContainerChild { pub focus: Cell, } +struct SeatState { + cursor: KnownCursor, + target: bool, + x: i32, + y: i32, +} + impl ContainerChild { fn position_content(&self) { let mut content = self.content.get(); @@ -98,7 +109,7 @@ impl ContainerNode { Self { id: state.node_ids.next(), parent: CloneCell::new(parent), - split: Cell::new(ContainerSplit::Horizontal), + split: Cell::new(ContainerSplit::Vertical), mono_child: CloneCell::new(None), mono_body: Cell::new(Default::default()), mono_content: Cell::new(Default::default()), @@ -113,6 +124,7 @@ impl ContainerNode { child_nodes: RefCell::new(child_nodes), seat_state: Default::default(), workspace: CloneCell::new(workspace.clone()), + seats: RefCell::new(Default::default()), } } @@ -197,7 +209,7 @@ impl ContainerNode { ContainerSplit::Horizontal => { (pos, CONTAINER_TITLE_HEIGHT, body_size, other_content_size) } - _ => (0, pos, other_content_size, body_size), + _ => (0, pos + CONTAINER_TITLE_HEIGHT, other_content_size, body_size), }; let body = Rect::new_sized(x1, y1, width, height).unwrap(); child.body.set(body); @@ -270,6 +282,44 @@ impl ContainerNode { } } } + + fn pointer_move(&self, seat: &Rc, x: i32, y: i32) { + let mut seats = self.seats.borrow_mut(); + let seat_state = seats.entry(seat.id()).or_insert_with(|| SeatState { + cursor: KnownCursor::Default, + target: false, + x, + y, + }); + seat_state.x = x; + seat_state.y = y; + let new_cursor = if self.mono_child.get().is_some() { + KnownCursor::Default + } else if self.split.get() == ContainerSplit::Horizontal { + if y < CONTAINER_TITLE_HEIGHT { + KnownCursor::Default + } else { + KnownCursor::ResizeLeftRight + } + } else { + let mut cursor = KnownCursor::Default; + for child in self.children.iter() { + let body = child.body.get(); + if body.y1() > y { + if body.y1() - y > CONTAINER_TITLE_HEIGHT { + cursor = KnownCursor::ResizeTopBottom + } + break; + } + } + cursor + }; + if new_cursor != mem::replace(&mut seat_state.cursor, new_cursor) { + if seat_state.target { + seat.set_known_cursor(new_cursor); + } + } + } } impl Node for ContainerNode { @@ -355,8 +405,27 @@ impl Node for ContainerNode { } } + fn pointer_untarget(&self, seat: &Rc) { + let mut seats = self.seats.borrow_mut(); + if let Some(seat_state) = seats.get_mut(&seat.id()) { + seat_state.target = false; + } + } + fn pointer_target(&self, seat: &Rc) { - seat.set_known_cursor(KnownCursor::Default); + let mut seats = self.seats.borrow_mut(); + if let Some(seat_state) = seats.get_mut(&seat.id()) { + seat_state.target = true; + seat.set_known_cursor(seat_state.cursor); + } + } + + fn motion(&self, seat: &Rc, x: Fixed, y: Fixed) { + self.pointer_move(seat, x.round_down(), y.round_down()); + } + + fn enter(self: Rc, seat: &Rc, x: Fixed, y: Fixed) { + self.pointer_move(seat, x.round_down(), y.round_down()); } fn render(&self, renderer: &mut Renderer, x: i32, y: i32) { diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 83268375..d37b2b1a 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -127,11 +127,15 @@ pub trait Node { let _ = y; } + fn pointer_untarget(&self, seat: &Rc) { + let _ = seat; + } + fn pointer_target(&self, seat: &Rc) { let _ = seat; } - fn motion(&self, seat: &WlSeatGlobal, x: Fixed, y: Fixed) { + fn motion(&self, seat: &Rc, x: Fixed, y: Fixed) { let _ = seat; let _ = x; let _ = y;