1
0
Fork 0
forked from wry/wry

autocommit 2022-02-02 20:01:25 CET

This commit is contained in:
Julian Orth 2022-02-02 20:01:25 +01:00
parent 65a7a55b82
commit 89b8396932
12 changed files with 279 additions and 57 deletions

View file

@ -294,13 +294,28 @@ impl WlSeatGlobal {
self.handle_new_position(false);
}
fn handle_new_position(self: &Rc<Self>, changed: bool) {
fn handle_new_position(self: &Rc<Self>, pos_changed: bool) {
let (x, y) = self.pos.get();
if changed {
if pos_changed {
if let Some(cursor) = self.cursor.get() {
cursor.set_position(x.round_down(), y.round_down());
}
}
'handle_grab: {
let grab_node = {
let grabber = self.grabber.borrow_mut();
match grabber.as_ref() {
Some(n) => n.node.clone(),
None => break 'handle_grab,
}
};
if pos_changed {
let pos = grab_node.absolute_position();
let (x_int, y_int) = pos.translate(x.round_down(), y.round_down());
grab_node.motion(self, x.apply_fract(x_int), y.apply_fract(y_int));
}
return;
}
let mut found_tree = self.found_tree.borrow_mut();
let mut stack = self.pointer_stack.borrow_mut();
// if self.move_.get() {
@ -332,7 +347,7 @@ impl WlSeatGlobal {
}
}
if (stack.len(), found_tree.len()) == (divergence, divergence) {
if changed {
if pos_changed {
if let Some(node) = found_tree.last() {
node.node
.motion(self, x.apply_fract(node.x), y.apply_fract(node.y));

View file

@ -50,11 +50,25 @@ const TOUCH: u32 = 4;
#[allow(dead_code)]
const MISSING_CAPABILITY: u32 = 0;
#[allow(dead_code)]
const BTN_LEFT: u32 = 0x110;
pub const BTN_LEFT: u32 = 0x110;
pub const SEAT_NAME_SINCE: u32 = 2;
pub struct PointerGrab {
seat: Rc<WlSeatGlobal>,
}
pub struct PointerGrabber {
node: Rc<dyn Node>,
}
impl Drop for PointerGrab {
fn drop(&mut self) {
*self.seat.grabber.borrow_mut() = None;
self.seat.tree_changed();
}
}
pub struct WlSeatGlobal {
name: GlobalName,
state: Rc<State>,
@ -76,6 +90,7 @@ pub struct WlSeatGlobal {
layout_size: u32,
cursor: CloneCell<Option<Rc<dyn Cursor>>>,
serial: NumCell<u32>,
grabber: RefCell<Option<PointerGrabber>>,
}
impl WlSeatGlobal {
@ -118,9 +133,23 @@ impl WlSeatGlobal {
layout_size,
cursor: Default::default(),
serial: Default::default(),
grabber: RefCell::new(None),
}
}
pub fn grab_pointer(self: &Rc<Self>, node: Rc<dyn Node>) -> Option<PointerGrab> {
let mut grabber = self.grabber.borrow_mut();
if grabber.is_some() {
return None;
}
*grabber = Some(PointerGrabber {
node,
});
Some(PointerGrab {
seat: self.clone(),
})
}
pub fn set_known_cursor(&self, cursor: KnownCursor) {
let cursors = match self.state.cursors.get() {
Some(c) => c,