remove unnecessary reencoding

This commit is contained in:
Ferdinand Schober
2022-09-19 20:21:28 +02:00
parent da7558b33b
commit af719ede32
3 changed files with 128 additions and 91 deletions

View File

@@ -12,7 +12,7 @@ use wayland_protocols_misc::zwp_virtual_keyboard_v1::client::{
};
use wayland_client::{
protocol::{wl_registry, wl_seat, wl_keyboard},
protocol::{wl_registry, wl_seat, wl_pointer, wl_keyboard},
Connection, Dispatch, EventQueue, QueueHandle,
};
@@ -113,14 +113,35 @@ fn udp_loop(connection: &protocol::Connection, pointer: &Vp, keyboard: &Vk, q: E
loop {
if let Some(event) = connection.receive_event() {
match event {
protocol::Event::Mouse { t, x, y } => { pointer.motion(t, x, y); pointer.frame(); }
protocol::Event::Button { t, b, s } => { pointer.button(t, b, s); pointer.frame(); }
protocol::Event::Axis { t, a, v } => { pointer.axis(t, a, v); pointer.frame(); }
protocol::Event::Frame { } => { pointer.frame(); },
protocol::Event::Key { t, k, s } => { keyboard.key(t, k, u32::from(s)); },
protocol::Event::KeyModifier { mods_depressed, mods_latched, mods_locked, group } => {
keyboard.modifiers(mods_depressed, mods_latched, mods_locked, group);
},
protocol::Event::Pointer(e) => {
match e {
wl_pointer::Event::Motion { time, surface_x, surface_y } => {
pointer.motion(time, surface_x, surface_y);
pointer.frame();
}
wl_pointer::Event::Button { serial: _, time: t, button: b, state: s } => {
pointer.button( t, b, s.into_result().unwrap());
pointer.frame();
}
wl_pointer::Event::Axis { time: t, axis: a, value: v } => {
pointer.axis(t, a.into_result().unwrap(), v);
pointer.frame();
}
wl_pointer::Event::Frame {} => {}
_ => todo!(),
}
}
protocol::Event::Keyboard(e) => {
match e {
wl_keyboard::Event::Key { serial: _, time: t, key: k, state: s } => {
keyboard.key(t, k, u32::from(s));
},
wl_keyboard::Event::Modifiers { serial: _, mods_depressed, mods_latched, mods_locked, group } => {
keyboard.modifiers(mods_depressed, mods_latched, mods_locked, group);
},
_ => todo!(),
}
}
}
}
q.flush().unwrap();

View File

@@ -355,16 +355,14 @@ impl Dispatch<wl_pointer::WlPointer, ()> for App {
);
}
}
wl_pointer::Event::Button { serial:_, time, button, state } => {
let e = protocol::Event::Button { t: (time), b: button, s: (state.into_result().unwrap()) };
app.connection.send_event(&e);
wl_pointer::Event::Button {..} => {
app.connection.send_event(event);
}
wl_pointer::Event::Axis { time, axis, value } => {
let e = protocol::Event::Axis { t: time, a: (axis.into_result().unwrap()), v: value };
app.connection.send_event(&e);
wl_pointer::Event::Axis {..} => {
app.connection.send_event(event);
}
wl_pointer::Event::Frame => {
app.connection.send_event(&protocol::Event::Frame{});
wl_pointer::Event::Frame {..} => {
app.connection.send_event(event);
}
_ => {},
}
@@ -381,7 +379,7 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for App {
_: &QueueHandle<Self>,
) {
match event {
wl_keyboard::Event::Key { serial: _, time, key, state } => {
wl_keyboard::Event::Key { serial: _, time: _, key, state: _ } => {
if key == 1 {
// ESC key
if let Some(pointer_lock) = app.pointer_lock.as_ref() {
@@ -393,11 +391,11 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for App {
app.rel_pointer = None;
}
} else {
app.connection.send_event(&protocol::Event::Key{ t: (time), k: (key), s: (state.into_result().unwrap()) });
app.connection.send_event(event);
}
}
wl_keyboard::Event::Modifiers { serial: _, mods_depressed, mods_latched, mods_locked, group } => {
app.connection.send_event(&protocol::Event::KeyModifier{ mods_depressed, mods_latched, mods_locked, group });
wl_keyboard::Event::Modifiers {..} => {
app.connection.send_event(event);
}
wl_keyboard::Event::Keymap { format:_ , fd, size:_ } => {
let mmap = unsafe { Mmap::map(&File::from_raw_fd(fd.as_raw_fd())).unwrap() };
@@ -464,12 +462,11 @@ impl Dispatch<zwp_relative_pointer_v1::ZwpRelativePointerV1, ()> for App {
utime_lo,
dx: _,
dy: _,
dx_unaccel,
dy_unaccel,
dx_unaccel: surface_x,
dy_unaccel: surface_y,
} = event {
let time = ((utime_hi as u64) << 32 | utime_lo as u64) / 1000;
let e = protocol::Event::Mouse { t: (time as u32), x: (dx_unaccel), y: (dy_unaccel) };
app.connection.send_event(&e);
let time = (((utime_hi as u64) << 32 | utime_lo as u64) / 1000) as u32;
app.connection.send_event(wl_pointer::Event::Motion{ time, surface_x, surface_y });
}
}
}