Add wl_touch support

Fixes #1
This commit is contained in:
Shawn Wallace 2024-04-29 19:35:46 -04:00
parent 7aaf98e5e0
commit e70cb81751
4 changed files with 78 additions and 3 deletions

View file

@ -27,7 +27,7 @@ use wayland_server::{
protocol::{
wl_buffer::WlBuffer, wl_callback::WlCallback, wl_compositor::WlCompositor,
wl_keyboard::WlKeyboard, wl_output::WlOutput, wl_pointer::WlPointer, wl_seat::WlSeat,
wl_shm::WlShm, wl_shm_pool::WlShmPool, wl_surface::WlSurface,
wl_shm::WlShm, wl_shm_pool::WlShmPool, wl_surface::WlSurface, wl_touch::WlTouch,
},
Dispatch, DisplayHandle, GlobalDispatch, Resource,
};
@ -313,6 +313,27 @@ impl<C: XConnection> Dispatch<WlKeyboard, ObjectKey> for ServerState<C> {
}
}
impl<C: XConnection> Dispatch<WlTouch, ObjectKey> for ServerState<C> {
fn request(
state: &mut Self,
_: &wayland_server::Client,
_: &WlTouch,
request: <WlTouch as Resource>::Request,
key: &ObjectKey,
_: &DisplayHandle,
_: &mut wayland_server::DataInit<'_, Self>,
) {
match request {
Request::<WlTouch>::Release => {
let Touch { client, .. }: &_ = state.objects[*key].as_ref();
client.release();
state.objects.remove(*key);
}
_ => unreachable!(),
}
}
}
impl<C: XConnection> Dispatch<WlSeat, ObjectKey> for ServerState<C> {
fn request(
state: &mut Self,
@ -345,6 +366,16 @@ impl<C: XConnection> Dispatch<WlSeat, ObjectKey> for ServerState<C> {
Keyboard { client, server }.into()
});
}
Request::<WlSeat>::GetTouch { id } => {
state
.objects
.insert_from_other_objects([*key], |[seat_obj], key| {
let Seat { client, .. }: &Seat = seat_obj.try_into().unwrap();
let client = client.get_touch(&state.qh, key);
let server = data_init.init(id, key);
Touch { client, server }.into()
});
}
other => warn!("unhandled seat request: {other:?}"),
}
}