autocommit 2022-02-02 01:20:49 CET
This commit is contained in:
parent
2dbe3ba732
commit
65a7a55b82
8 changed files with 105 additions and 17 deletions
|
|
@ -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")?,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<WlSeatGlobal>, x: Fixed, y: Fixed) {
|
||||
seat.motion_surface(self, x, y)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<AHashMap<NodeId, LinkedNode<ContainerChild>>>,
|
||||
seat_state: NodeSeatState,
|
||||
workspace: CloneCell<Rc<WorkspaceNode>>,
|
||||
seats: RefCell<AHashMap<SeatId, SeatState>>,
|
||||
}
|
||||
|
||||
pub struct ContainerChild {
|
||||
|
|
@ -58,6 +62,13 @@ pub struct ContainerChild {
|
|||
pub focus: Cell<ContainerFocus>,
|
||||
}
|
||||
|
||||
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<WlSeatGlobal>, 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<WlSeatGlobal>) {
|
||||
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<WlSeatGlobal>) {
|
||||
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<WlSeatGlobal>, x: Fixed, y: Fixed) {
|
||||
self.pointer_move(seat, x.round_down(), y.round_down());
|
||||
}
|
||||
|
||||
fn enter(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) {
|
||||
self.pointer_move(seat, x.round_down(), y.round_down());
|
||||
}
|
||||
|
||||
fn render(&self, renderer: &mut Renderer, x: i32, y: i32) {
|
||||
|
|
|
|||
|
|
@ -127,11 +127,15 @@ pub trait Node {
|
|||
let _ = y;
|
||||
}
|
||||
|
||||
fn pointer_untarget(&self, seat: &Rc<WlSeatGlobal>) {
|
||||
let _ = seat;
|
||||
}
|
||||
|
||||
fn pointer_target(&self, seat: &Rc<WlSeatGlobal>) {
|
||||
let _ = seat;
|
||||
}
|
||||
|
||||
fn motion(&self, seat: &WlSeatGlobal, x: Fixed, y: Fixed) {
|
||||
fn motion(&self, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) {
|
||||
let _ = seat;
|
||||
let _ = x;
|
||||
let _ = y;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue