1
0
Fork 0
forked from wry/wry

wayland: add times to all input events

This commit is contained in:
Julian Orth 2022-05-26 12:25:59 +02:00
parent 568341a3d0
commit 145e4dbc24
16 changed files with 235 additions and 101 deletions

View file

@ -25,6 +25,7 @@ use {
logind::{LogindError, Session},
render::RenderError,
state::State,
time::now_usec,
udev::{Udev, UdevError, UdevMonitor},
utils::{
clonecell::{CloneCell, UnsafeCellCloneSafe},
@ -341,11 +342,20 @@ impl MetalInputDevice {
}
fn pre_pause(&self) {
let time_usec = now_usec();
for (key, _) in self.pressed_keys.take() {
self.event(InputEvent::Key(key, KeyState::Released));
self.event(InputEvent::Key {
time_usec,
key,
state: KeyState::Released,
});
}
for (button, _) in self.pressed_buttons.take() {
self.event(InputEvent::Button(button, KeyState::Released));
self.event(InputEvent::Button {
time_usec,
button,
state: KeyState::Released,
});
}
}
}

View file

@ -119,7 +119,11 @@ impl MetalBackend {
}
KeyState::Released
};
dev.event(InputEvent::Key(event.key(), state));
dev.event(InputEvent::Key {
time_usec: event.time_usec(),
key: event.key(),
state,
});
}
fn handle_pointer_axis(self: &Rc<Self>, event: LibInputEvent, source: AxisSource) {
@ -132,7 +136,7 @@ impl MetalBackend {
),
(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, ScrollAxis::Vertical),
];
dev.event(InputEvent::AxisSource(source));
dev.event(InputEvent::AxisSource { source });
for (axis, sa) in axes {
if !event.has_axis(axis) {
continue;
@ -142,17 +146,25 @@ impl MetalBackend {
_ => event.scroll_value(axis),
};
if scroll == 0.0 {
dev.event(InputEvent::AxisStop(sa));
dev.event(InputEvent::AxisStop { axis: sa });
} else {
if source == AxisSource::Wheel {
let scroll_discrete = scroll / ONE_TWENTRY;
dev.event(InputEvent::AxisDiscrete(scroll_discrete as _, sa));
dev.event(InputEvent::AxisDiscrete {
dist: scroll_discrete as _,
axis: sa,
});
scroll = PX_PER_SCROLL * scroll_discrete;
}
dev.event(InputEvent::Axis(Fixed::from_f64(scroll), sa));
dev.event(InputEvent::Axis {
dist: Fixed::from_f64(scroll),
axis: sa,
});
}
}
dev.event(InputEvent::Frame);
dev.event(InputEvent::AxisFrame {
time_usec: event.time_usec(),
});
}
fn handle_pointer_button(self: &Rc<Self>, event: LibInputEvent) {
@ -168,7 +180,11 @@ impl MetalBackend {
}
KeyState::Released
};
dev.event(InputEvent::Button(event.button(), state));
dev.event(InputEvent::Button {
time_usec: event.time_usec(),
button: event.button(),
state,
});
}
fn handle_pointer_motion(self: &Rc<Self>, event: LibInputEvent) {

View file

@ -12,6 +12,7 @@ use {
ifs::wl_seat::PX_PER_SCROLL,
render::{Framebuffer, RenderContext, RenderError, RenderResult, Texture},
state::State,
time::now_usec,
utils::{
clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, numcell::NumCell,
queue::AsyncQueue, syncqueue::SyncQueue,
@ -761,13 +762,17 @@ impl XBackend {
7 => (ScrollAxis::Horizontal, 1),
_ => unreachable!(),
};
seat.mouse_event(InputEvent::AxisSource(AxisSource::Wheel));
seat.mouse_event(InputEvent::AxisDiscrete(val, axis));
seat.mouse_event(InputEvent::Axis(
Fixed::from_f64(val as f64 * PX_PER_SCROLL),
seat.mouse_event(InputEvent::AxisSource {
source: AxisSource::Wheel,
});
seat.mouse_event(InputEvent::AxisDiscrete { dist: val, axis });
seat.mouse_event(InputEvent::Axis {
dist: Fixed::from_f64(val as f64 * PX_PER_SCROLL),
axis,
));
seat.mouse_event(InputEvent::Frame);
});
seat.mouse_event(InputEvent::AxisFrame {
time_usec: now_usec(),
});
}
} else {
const BTN_LEFT: u32 = 0x110;
@ -781,7 +786,11 @@ impl XBackend {
3 => BTN_RIGHT,
n => BTN_SIDE + n - 8,
};
seat.mouse_event(InputEvent::Button(button, state));
seat.mouse_event(InputEvent::Button {
time_usec: now_usec(),
button,
state,
});
}
}
Ok(())
@ -794,7 +803,11 @@ impl XBackend {
) -> Result<(), XBackendError> {
let event: XiKeyPress = event.parse()?;
if let Some(seat) = self.seats.get(&event.deviceid) {
seat.kb_event(InputEvent::Key(event.detail - 8, state));
seat.kb_event(InputEvent::Key {
time_usec: now_usec(),
key: event.detail - 8,
state,
});
}
Ok(())
}
@ -824,11 +837,12 @@ impl XBackend {
self.outputs.get(&event.event),
self.mouse_seats.get(&event.deviceid),
) {
seat.mouse_event(InputEvent::ConnectorPosition(
win.id,
Fixed::from_1616(event.event_x),
Fixed::from_1616(event.event_y),
));
seat.mouse_event(InputEvent::ConnectorPosition {
time_usec: now_usec(),
connector: win.id,
x: Fixed::from_1616(event.event_x),
y: Fixed::from_1616(event.event_y),
});
}
Ok(())
}
@ -842,11 +856,12 @@ impl XBackend {
(Some(a), Some(b)) => (a, b),
_ => return Ok(()),
};
seat.mouse_event(InputEvent::ConnectorPosition(
win.id,
Fixed::from_1616(event.event_x),
Fixed::from_1616(event.event_y),
));
seat.mouse_event(InputEvent::ConnectorPosition {
time_usec: now_usec(),
connector: win.id,
x: Fixed::from_1616(event.event_x),
y: Fixed::from_1616(event.event_y),
});
Ok(())
}