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)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum KnownCursor {
|
pub enum KnownCursor {
|
||||||
Default,
|
Default,
|
||||||
|
ResizeLeftRight,
|
||||||
|
ResizeTopBottom,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerCursors {
|
impl ServerCursors {
|
||||||
|
|
@ -61,8 +63,8 @@ impl ServerCursors {
|
||||||
ServerCursorTemplate::load(name, None, 16, &paths, ctx)
|
ServerCursorTemplate::load(name, None, 16, &paths, ctx)
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
// default: load("left_ptr")?,
|
default: load("left_ptr")?,
|
||||||
default: load("left_ptr_watch")?,
|
// default: load("left_ptr_watch")?,
|
||||||
resize_right: load("right_side")?,
|
resize_right: load("right_side")?,
|
||||||
resize_left: load("left_side")?,
|
resize_left: load("left_side")?,
|
||||||
resize_top: load("top_side")?,
|
resize_top: load("top_side")?,
|
||||||
|
|
|
||||||
|
|
@ -339,16 +339,27 @@ impl WlSeatGlobal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if let Some(last) = stack.last() {
|
||||||
|
last.pointer_untarget(self);
|
||||||
|
}
|
||||||
for old in stack.drain(divergence..).rev() {
|
for old in stack.drain(divergence..).rev() {
|
||||||
old.leave(self);
|
old.leave(self);
|
||||||
old.seat_state().leave(self);
|
old.seat_state().leave(self);
|
||||||
}
|
}
|
||||||
for new in found_tree.drain(divergence..) {
|
if found_tree.len() == divergence {
|
||||||
new.node.seat_state().enter(self);
|
if let Some(node) = found_tree.last() {
|
||||||
new.node
|
node.node
|
||||||
.clone()
|
.clone()
|
||||||
.enter(self, x.apply_fract(new.x), y.apply_fract(new.y));
|
.motion(self, x.apply_fract(node.x), y.apply_fract(node.y));
|
||||||
stack.push(new.node);
|
}
|
||||||
|
} 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() {
|
if let Some(node) = stack.last() {
|
||||||
node.pointer_target(self);
|
node.pointer_target(self);
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,8 @@ impl WlSeatGlobal {
|
||||||
};
|
};
|
||||||
let tpl = match cursor {
|
let tpl = match cursor {
|
||||||
KnownCursor::Default => &cursors.default,
|
KnownCursor::Default => &cursors.default,
|
||||||
|
KnownCursor::ResizeLeftRight => &cursors.resize_left_right,
|
||||||
|
KnownCursor::ResizeTopBottom => &cursors.resize_top_bottom,
|
||||||
};
|
};
|
||||||
self.set_cursor(Some(tpl.instantiate()));
|
self.set_cursor(Some(tpl.instantiate()));
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +147,6 @@ impl WlSeatGlobal {
|
||||||
old.handle_unset();
|
old.handle_unset();
|
||||||
}
|
}
|
||||||
if let Some(cursor) = cursor.as_ref() {
|
if let Some(cursor) = cursor.as_ref() {
|
||||||
log::info!("setting new cursor");
|
|
||||||
let (x, y) = self.pos.get();
|
let (x, y) = self.pos.get();
|
||||||
cursor.set_position(x.round_down(), y.round_down());
|
cursor.set_position(x.round_down(), y.round_down());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -632,7 +632,7 @@ impl Node for WlSurface {
|
||||||
seat.enter_surface(&self, x, y)
|
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)
|
seat.motion_surface(self, x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,8 @@ mod xkbcommon;
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::builder()
|
env_logger::builder()
|
||||||
.filter_level(LevelFilter::Info)
|
.filter_level(LevelFilter::Info)
|
||||||
.filter_level(LevelFilter::Trace)
|
.filter_level(LevelFilter::Debug)
|
||||||
|
// .filter_level(LevelFilter::Trace)
|
||||||
.init();
|
.init();
|
||||||
if let Err(e) = main_() {
|
if let Err(e) = main_() {
|
||||||
log::error!("A fatal error occurred: {}", ErrorFmt(e));
|
log::error!("A fatal error occurred: {}", ErrorFmt(e));
|
||||||
|
|
|
||||||
|
|
@ -147,10 +147,10 @@ impl Renderer<'_> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
} else {
|
} else {
|
||||||
Rect::new_sized(
|
Rect::new_sized(
|
||||||
x + body.x1(),
|
x,
|
||||||
y + body.y2(),
|
y + body.y2(),
|
||||||
container.width.get(),
|
container.width.get(),
|
||||||
CONTAINER_BORDER,
|
CONTAINER_BORDER + CONTAINER_TITLE_HEIGHT,
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,11 @@ use crate::utils::linkedlist::{LinkedList, LinkedNode, NodeRef};
|
||||||
use crate::{NumCell, State};
|
use crate::{NumCell, State};
|
||||||
use ahash::AHashMap;
|
use ahash::AHashMap;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use crate::backend::SeatId;
|
||||||
use crate::cursor::KnownCursor;
|
use crate::cursor::KnownCursor;
|
||||||
|
use crate::fixed::Fixed;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
@ -48,6 +51,7 @@ pub struct ContainerNode {
|
||||||
child_nodes: RefCell<AHashMap<NodeId, LinkedNode<ContainerChild>>>,
|
child_nodes: RefCell<AHashMap<NodeId, LinkedNode<ContainerChild>>>,
|
||||||
seat_state: NodeSeatState,
|
seat_state: NodeSeatState,
|
||||||
workspace: CloneCell<Rc<WorkspaceNode>>,
|
workspace: CloneCell<Rc<WorkspaceNode>>,
|
||||||
|
seats: RefCell<AHashMap<SeatId, SeatState>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ContainerChild {
|
pub struct ContainerChild {
|
||||||
|
|
@ -58,6 +62,13 @@ pub struct ContainerChild {
|
||||||
pub focus: Cell<ContainerFocus>,
|
pub focus: Cell<ContainerFocus>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SeatState {
|
||||||
|
cursor: KnownCursor,
|
||||||
|
target: bool,
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
}
|
||||||
|
|
||||||
impl ContainerChild {
|
impl ContainerChild {
|
||||||
fn position_content(&self) {
|
fn position_content(&self) {
|
||||||
let mut content = self.content.get();
|
let mut content = self.content.get();
|
||||||
|
|
@ -98,7 +109,7 @@ impl ContainerNode {
|
||||||
Self {
|
Self {
|
||||||
id: state.node_ids.next(),
|
id: state.node_ids.next(),
|
||||||
parent: CloneCell::new(parent),
|
parent: CloneCell::new(parent),
|
||||||
split: Cell::new(ContainerSplit::Horizontal),
|
split: Cell::new(ContainerSplit::Vertical),
|
||||||
mono_child: CloneCell::new(None),
|
mono_child: CloneCell::new(None),
|
||||||
mono_body: Cell::new(Default::default()),
|
mono_body: Cell::new(Default::default()),
|
||||||
mono_content: Cell::new(Default::default()),
|
mono_content: Cell::new(Default::default()),
|
||||||
|
|
@ -113,6 +124,7 @@ impl ContainerNode {
|
||||||
child_nodes: RefCell::new(child_nodes),
|
child_nodes: RefCell::new(child_nodes),
|
||||||
seat_state: Default::default(),
|
seat_state: Default::default(),
|
||||||
workspace: CloneCell::new(workspace.clone()),
|
workspace: CloneCell::new(workspace.clone()),
|
||||||
|
seats: RefCell::new(Default::default()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,7 +209,7 @@ impl ContainerNode {
|
||||||
ContainerSplit::Horizontal => {
|
ContainerSplit::Horizontal => {
|
||||||
(pos, CONTAINER_TITLE_HEIGHT, body_size, other_content_size)
|
(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();
|
let body = Rect::new_sized(x1, y1, width, height).unwrap();
|
||||||
child.body.set(body);
|
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 {
|
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>) {
|
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) {
|
fn render(&self, renderer: &mut Renderer, x: i32, y: i32) {
|
||||||
|
|
|
||||||
|
|
@ -127,11 +127,15 @@ pub trait Node {
|
||||||
let _ = y;
|
let _ = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pointer_untarget(&self, seat: &Rc<WlSeatGlobal>) {
|
||||||
|
let _ = seat;
|
||||||
|
}
|
||||||
|
|
||||||
fn pointer_target(&self, seat: &Rc<WlSeatGlobal>) {
|
fn pointer_target(&self, seat: &Rc<WlSeatGlobal>) {
|
||||||
let _ = seat;
|
let _ = seat;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn motion(&self, seat: &WlSeatGlobal, x: Fixed, y: Fixed) {
|
fn motion(&self, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) {
|
||||||
let _ = seat;
|
let _ = seat;
|
||||||
let _ = x;
|
let _ = x;
|
||||||
let _ = y;
|
let _ = y;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue