wayland: add times to all input events
This commit is contained in:
parent
568341a3d0
commit
145e4dbc24
16 changed files with 235 additions and 101 deletions
|
|
@ -115,11 +115,11 @@ impl WlDataDevice {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn send_motion(&self, x: Fixed, y: Fixed) {
|
||||
pub fn send_motion(&self, time_usec: u64, x: Fixed, y: Fixed) {
|
||||
if !self.data.is_xwm {
|
||||
self.client.event(Motion {
|
||||
self_id: self.id,
|
||||
time: 0,
|
||||
time: (time_usec / 1000) as _,
|
||||
x,
|
||||
y,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ pub struct WlSeatGlobal {
|
|||
move_: Cell<bool>,
|
||||
move_start_pos: Cell<(Fixed, Fixed)>,
|
||||
extents_start_pos: Cell<(i32, i32)>,
|
||||
pos_time_usec: Cell<u64>,
|
||||
pos: Cell<(Fixed, Fixed)>,
|
||||
pointer_stack: RefCell<Vec<Rc<dyn Node>>>,
|
||||
pointer_stack_modified: Cell<bool>,
|
||||
|
|
@ -163,6 +164,7 @@ impl WlSeatGlobal {
|
|||
move_: Cell::new(false),
|
||||
move_start_pos: Cell::new((Fixed(0), Fixed(0))),
|
||||
extents_start_pos: Cell::new((0, 0)),
|
||||
pos_time_usec: Cell::new(0),
|
||||
pos: Cell::new((Fixed(0), Fixed(0))),
|
||||
pointer_stack: RefCell::new(vec![]),
|
||||
pointer_stack_modified: Cell::new(false),
|
||||
|
|
|
|||
|
|
@ -167,8 +167,17 @@ impl NodeSeatState {
|
|||
impl WlSeatGlobal {
|
||||
pub fn event(self: &Rc<Self>, event: InputEvent) {
|
||||
match event {
|
||||
InputEvent::Key(k, s) => self.key_event(k, s),
|
||||
InputEvent::ConnectorPosition(o, x, y) => self.connector_position_event(o, x, y),
|
||||
InputEvent::Key {
|
||||
time_usec,
|
||||
key,
|
||||
state,
|
||||
} => self.key_event(time_usec, key, state),
|
||||
InputEvent::ConnectorPosition {
|
||||
time_usec,
|
||||
connector,
|
||||
x,
|
||||
y,
|
||||
} => self.connector_position_event(time_usec, connector, x, y),
|
||||
InputEvent::Motion {
|
||||
dx,
|
||||
dy,
|
||||
|
|
@ -176,18 +185,23 @@ impl WlSeatGlobal {
|
|||
dy_unaccelerated,
|
||||
time_usec,
|
||||
} => self.motion_event(time_usec, dx, dy, dx_unaccelerated, dy_unaccelerated),
|
||||
InputEvent::Button(b, s) => self.pointer_owner.button(self, b, s),
|
||||
InputEvent::Button {
|
||||
time_usec,
|
||||
button,
|
||||
state,
|
||||
} => self.pointer_owner.button(self, time_usec, button, state),
|
||||
|
||||
InputEvent::AxisSource(s) => self.pointer_owner.axis_source(s),
|
||||
InputEvent::AxisDiscrete(d, a) => self.pointer_owner.axis_discrete(d, a),
|
||||
InputEvent::Axis(d, a) => self.pointer_owner.axis(d, a),
|
||||
InputEvent::AxisStop(d) => self.pointer_owner.axis_stop(d),
|
||||
InputEvent::Frame => self.pointer_owner.frame(self),
|
||||
InputEvent::AxisSource { source } => self.pointer_owner.axis_source(source),
|
||||
InputEvent::AxisDiscrete { dist, axis } => self.pointer_owner.axis_discrete(dist, axis),
|
||||
InputEvent::Axis { dist, axis } => self.pointer_owner.axis(dist, axis),
|
||||
InputEvent::AxisStop { axis } => self.pointer_owner.axis_stop(axis),
|
||||
InputEvent::AxisFrame { time_usec } => self.pointer_owner.frame(self, time_usec),
|
||||
}
|
||||
}
|
||||
|
||||
fn connector_position_event(
|
||||
self: &Rc<Self>,
|
||||
time_usec: u64,
|
||||
connector: ConnectorId,
|
||||
mut x: Fixed,
|
||||
mut y: Fixed,
|
||||
|
|
@ -200,7 +214,7 @@ impl WlSeatGlobal {
|
|||
let pos = output.node.global.pos.get();
|
||||
x += Fixed::from_int(pos.x1());
|
||||
y += Fixed::from_int(pos.y1());
|
||||
self.set_new_position(x, y);
|
||||
self.set_new_position(time_usec, x, y);
|
||||
}
|
||||
|
||||
fn motion_event(
|
||||
|
|
@ -249,10 +263,10 @@ impl WlSeatGlobal {
|
|||
y = y.apply_fract(y_int);
|
||||
}
|
||||
}
|
||||
self.set_new_position(x, y);
|
||||
self.set_new_position(time_usec, x, y);
|
||||
}
|
||||
|
||||
fn key_event(&self, key: u32, state: KeyState) {
|
||||
fn key_event(&self, time_usec: u64, key: u32, state: KeyState) {
|
||||
let (state, xkb_dir) = {
|
||||
let mut pk = self.pressed_keys.borrow_mut();
|
||||
match state {
|
||||
|
|
@ -290,7 +304,7 @@ impl WlSeatGlobal {
|
|||
}
|
||||
let node = self.keyboard_node.get();
|
||||
if shortcuts.is_empty() {
|
||||
node.node_on_key(self, key, state);
|
||||
node.node_on_key(self, time_usec, key, state);
|
||||
} else if let Some(config) = self.state.config.get() {
|
||||
for shortcut in shortcuts {
|
||||
config.invoke_shortcut(self.id(), &shortcut);
|
||||
|
|
@ -461,7 +475,8 @@ impl WlSeatGlobal {
|
|||
// client.flush();
|
||||
}
|
||||
|
||||
fn set_new_position(self: &Rc<Self>, x: Fixed, y: Fixed) {
|
||||
fn set_new_position(self: &Rc<Self>, time_usec: u64, x: Fixed, y: Fixed) {
|
||||
self.pos_time_usec.set(time_usec);
|
||||
self.pos.set((x, y));
|
||||
if let Some(cursor) = self.cursor.get() {
|
||||
cursor.set_position(x.round_down(), y.round_down());
|
||||
|
|
@ -499,6 +514,7 @@ impl WlSeatGlobal {
|
|||
pub fn button_surface(
|
||||
self: &Rc<Self>,
|
||||
surface: &Rc<WlSurface>,
|
||||
time_usec: u64,
|
||||
button: u32,
|
||||
state: KeyState,
|
||||
serial: u32,
|
||||
|
|
@ -507,7 +523,8 @@ impl WlSeatGlobal {
|
|||
KeyState::Released => (wl_pointer::RELEASED, false),
|
||||
KeyState::Pressed => (wl_pointer::PRESSED, true),
|
||||
};
|
||||
self.surface_pointer_event(0, surface, |p| p.send_button(serial, 0, button, state));
|
||||
let time = (time_usec / 1000) as u32;
|
||||
self.surface_pointer_event(0, surface, |p| p.send_button(serial, time, button, state));
|
||||
self.surface_pointer_frame(surface);
|
||||
if pressed {
|
||||
if let Some(node) = surface.get_focus_node(self.id) {
|
||||
|
|
@ -528,6 +545,7 @@ impl WlSeatGlobal {
|
|||
};
|
||||
self.surface_pointer_event(since, surface, |p| p.send_axis_source(source));
|
||||
}
|
||||
let time = (event.time_usec.get() / 1000) as _;
|
||||
for i in 0..1 {
|
||||
if let Some(delta) = event.discrete[i].get() {
|
||||
self.surface_pointer_event(AXIS_DISCRETE_SINCE_VERSION, surface, |p| {
|
||||
|
|
@ -535,11 +553,11 @@ impl WlSeatGlobal {
|
|||
});
|
||||
}
|
||||
if let Some(delta) = event.axis[i].get() {
|
||||
self.surface_pointer_event(0, surface, |p| p.send_axis(0, i as _, delta));
|
||||
self.surface_pointer_event(0, surface, |p| p.send_axis(time, i as _, delta));
|
||||
}
|
||||
if event.stop[i].get() {
|
||||
self.surface_pointer_event(AXIS_STOP_SINCE_VERSION, surface, |p| {
|
||||
p.send_axis_stop(0, i as _)
|
||||
p.send_axis_stop(time, i as _)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -550,7 +568,8 @@ impl WlSeatGlobal {
|
|||
// Motion callbacks
|
||||
impl WlSeatGlobal {
|
||||
pub fn motion_surface(&self, n: &WlSurface, x: Fixed, y: Fixed) {
|
||||
self.surface_pointer_event(0, n, |p| p.send_motion(0, x, y));
|
||||
let time = (self.pos_time_usec.get() / 1000) as u32;
|
||||
self.surface_pointer_event(0, n, |p| p.send_motion(time, x, y));
|
||||
self.surface_pointer_frame(n);
|
||||
}
|
||||
}
|
||||
|
|
@ -638,9 +657,10 @@ impl WlSeatGlobal {
|
|||
|
||||
// Key callbacks
|
||||
impl WlSeatGlobal {
|
||||
pub fn key_surface(&self, surface: &WlSurface, key: u32, state: u32) {
|
||||
pub fn key_surface(&self, surface: &WlSurface, time_usec: u64, key: u32, state: u32) {
|
||||
let serial = surface.client.next_serial();
|
||||
self.surface_kb_event(0, surface, |k| k.send_key(serial, 0, key, state));
|
||||
let time = (time_usec / 1000) as _;
|
||||
self.surface_kb_event(0, surface, |k| k.send_key(serial, time, key, state));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -708,10 +728,17 @@ impl WlSeatGlobal {
|
|||
// surface.client.flush();
|
||||
}
|
||||
|
||||
pub fn dnd_surface_motion(&self, surface: &WlSurface, dnd: &Dnd, x: Fixed, y: Fixed) {
|
||||
pub fn dnd_surface_motion(
|
||||
&self,
|
||||
surface: &WlSurface,
|
||||
dnd: &Dnd,
|
||||
time_usec: u64,
|
||||
x: Fixed,
|
||||
y: Fixed,
|
||||
) {
|
||||
if dnd.src.is_some() || surface.client.id == dnd.client.id {
|
||||
self.for_each_data_device(0, surface.client.id, |dd| {
|
||||
dd.send_motion(x, y);
|
||||
dd.send_motion(time_usec, x, y);
|
||||
})
|
||||
}
|
||||
// surface.client.flush();
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ impl Default for PointerOwnerHolder {
|
|||
}
|
||||
|
||||
impl PointerOwnerHolder {
|
||||
pub fn button(&self, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) {
|
||||
self.owner.get().button(seat, button, state)
|
||||
pub fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: KeyState) {
|
||||
self.owner.get().button(seat, time_usec, button, state)
|
||||
}
|
||||
|
||||
pub fn axis_source(&self, axis_source: AxisSource) {
|
||||
|
|
@ -51,7 +51,8 @@ impl PointerOwnerHolder {
|
|||
self.pending_scroll.stop[axis as usize].set(true);
|
||||
}
|
||||
|
||||
pub fn frame(&self, seat: &Rc<WlSeatGlobal>) {
|
||||
pub fn frame(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64) {
|
||||
self.pending_scroll.time_usec.set(time_usec);
|
||||
let pending = self.pending_scroll.take();
|
||||
if let Some(node) = self.owner.get().axis_node(seat) {
|
||||
node.node_on_axis_event(seat, &pending);
|
||||
|
|
@ -122,7 +123,7 @@ impl PointerOwnerHolder {
|
|||
}
|
||||
|
||||
trait PointerOwner {
|
||||
fn button(&self, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState);
|
||||
fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: KeyState);
|
||||
fn axis_node(&self, seat: &Rc<WlSeatGlobal>) -> Option<Rc<dyn Node>>;
|
||||
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>);
|
||||
fn start_drag(
|
||||
|
|
@ -158,7 +159,7 @@ struct DndPointerOwner {
|
|||
}
|
||||
|
||||
impl PointerOwner for DefaultPointerOwner {
|
||||
fn button(&self, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) {
|
||||
fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: KeyState) {
|
||||
if state != KeyState::Pressed {
|
||||
return;
|
||||
}
|
||||
|
|
@ -173,7 +174,7 @@ impl PointerOwner for DefaultPointerOwner {
|
|||
serial,
|
||||
}));
|
||||
pn.node_seat_state().add_pointer_grab(seat);
|
||||
pn.node_on_button(seat, button, state, serial);
|
||||
pn.node_on_button(seat, time_usec, button, state, serial);
|
||||
}
|
||||
|
||||
fn axis_node(&self, seat: &Rc<WlSeatGlobal>) -> Option<Rc<dyn Node>> {
|
||||
|
|
@ -280,7 +281,7 @@ impl PointerOwner for DefaultPointerOwner {
|
|||
}
|
||||
|
||||
impl PointerOwner for GrabPointerOwner {
|
||||
fn button(&self, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) {
|
||||
fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: KeyState) {
|
||||
match state {
|
||||
KeyState::Released => {
|
||||
self.buttons.remove(&button);
|
||||
|
|
@ -300,7 +301,7 @@ impl PointerOwner for GrabPointerOwner {
|
|||
let serial = seat.state.next_serial(self.node.node_client().as_deref());
|
||||
self.node
|
||||
.clone()
|
||||
.node_on_button(seat, button, state, serial);
|
||||
.node_on_button(seat, time_usec, button, state, serial);
|
||||
}
|
||||
|
||||
fn axis_node(&self, _seat: &Rc<WlSeatGlobal>) -> Option<Rc<dyn Node>> {
|
||||
|
|
@ -400,7 +401,7 @@ impl PointerOwner for GrabPointerOwner {
|
|||
}
|
||||
|
||||
impl PointerOwner for DndPointerOwner {
|
||||
fn button(&self, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) {
|
||||
fn button(&self, seat: &Rc<WlSeatGlobal>, _time_usec: u64, button: u32, state: KeyState) {
|
||||
if button != self.button || state != KeyState::Released {
|
||||
return;
|
||||
}
|
||||
|
|
@ -468,7 +469,7 @@ impl PointerOwner for DndPointerOwner {
|
|||
target.node_seat_state().add_dnd_target(seat);
|
||||
self.target.set(target);
|
||||
} else if (self.pos_x.get(), self.pos_y.get()) != (x, y) {
|
||||
node.node_on_dnd_motion(&self.dnd, x, y);
|
||||
node.node_on_dnd_motion(&self.dnd, seat.pos_time_usec.get(), x, y);
|
||||
}
|
||||
self.pos_x.set(x);
|
||||
self.pos_y.set(y);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ pub struct PendingScroll {
|
|||
pub axis: [Cell<Option<Fixed>>; 2],
|
||||
pub stop: [Cell<bool>; 2],
|
||||
pub source: Cell<Option<u32>>,
|
||||
pub time_usec: Cell<u64>,
|
||||
}
|
||||
|
||||
impl PendingScroll {
|
||||
|
|
@ -58,6 +59,7 @@ impl PendingScroll {
|
|||
Cell::new(self.stop[1].take()),
|
||||
],
|
||||
source: Cell::new(self.source.take()),
|
||||
time_usec: Cell::new(self.time_usec.take()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -760,8 +760,8 @@ impl Node for WlSurface {
|
|||
self.toplevel.get()
|
||||
}
|
||||
|
||||
fn node_on_key(&self, seat: &WlSeatGlobal, key: u32, state: u32) {
|
||||
seat.key_surface(self, key, state);
|
||||
fn node_on_key(&self, seat: &WlSeatGlobal, time_usec: u64, key: u32, state: u32) {
|
||||
seat.key_surface(self, time_usec, key, state);
|
||||
}
|
||||
|
||||
fn node_on_mods(&self, seat: &WlSeatGlobal, mods: ModifierState) {
|
||||
|
|
@ -771,11 +771,12 @@ impl Node for WlSurface {
|
|||
fn node_on_button(
|
||||
self: Rc<Self>,
|
||||
seat: &Rc<WlSeatGlobal>,
|
||||
time_usec: u64,
|
||||
button: u32,
|
||||
state: KeyState,
|
||||
serial: u32,
|
||||
) {
|
||||
seat.button_surface(&self, button, state, serial);
|
||||
seat.button_surface(&self, time_usec, button, state, serial);
|
||||
}
|
||||
|
||||
fn node_on_axis_event(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, event: &PendingScroll) {
|
||||
|
|
@ -830,8 +831,8 @@ impl Node for WlSurface {
|
|||
dnd.seat.dnd_surface_enter(self, dnd, x, y, serial);
|
||||
}
|
||||
|
||||
fn node_on_dnd_motion(&self, dnd: &Dnd, x: Fixed, y: Fixed) {
|
||||
dnd.seat.dnd_surface_motion(self, dnd, x, y);
|
||||
fn node_on_dnd_motion(&self, dnd: &Dnd, time_usec: u64, x: Fixed, y: Fixed) {
|
||||
dnd.seat.dnd_surface_motion(self, dnd, time_usec, x, y);
|
||||
}
|
||||
|
||||
fn node_into_surface(self: Rc<Self>) -> Option<Rc<WlSurface>> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue