winit-core:winit: add tablet input support

The API is integrated into the `WindowEvent::Pointer*` API and is
present in form of `TabletTool` variant on corresponding data entries.

For now implemented for Web, Windows, and with limitations for Wayland.

Fixes #99.

Co-authored-by: daxpedda <daxpedda@gmail.com>
This commit is contained in:
Kirill Chibisov
2025-10-07 21:42:36 +09:00
committed by GitHub
parent ffcdf80192
commit f046e778aa
23 changed files with 1206 additions and 204 deletions

View File

@@ -13,6 +13,7 @@ use sctk::seat::pointer::{ThemeSpec, ThemedPointer};
use sctk::seat::{Capability as SeatCapability, SeatHandler, SeatState};
use tracing::warn;
use wayland_protocols::wp::pointer_gestures::zv1::client::zwp_pointer_gesture_pinch_v1::ZwpPointerGesturePinchV1;
use wayland_protocols::wp::tablet::zv2::client::zwp_tablet_seat_v2::ZwpTabletSeatV2;
use winit_core::event::WindowEvent;
use winit_core::keyboard::ModifiersState;
@@ -50,6 +51,9 @@ pub struct WinitSeatState {
/// The text input bound on the seat.
text_input: Option<Arc<ZwpTextInputV3>>,
/// The tablet input bound on the seat.
tablet: Option<Arc<ZwpTabletSeatV2>>,
/// The relative pointer bound on the seat.
relative_pointer: Option<ZwpRelativePointerV1>,
@@ -156,6 +160,12 @@ impl SeatHandler for WinitState {
TextInputData::default(),
)));
}
if let Some(tablet_state) =
seat_state.tablet.is_none().then_some(self.tablet_state.as_ref()).flatten()
{
seat_state.tablet = Some(Arc::new(tablet_state.get_tablet_seat(&seat, queue_handle)));
}
}
fn remove_capability(
@@ -177,6 +187,11 @@ impl SeatHandler for WinitState {
text_input.destroy();
}
// NOTE: figure out when this should actually be destroyed.
if let Some(tablet) = seat_state.tablet.take() {
tablet.destroy();
}
match capability {
SeatCapability::Touch => {
if let Some(touch) = seat_state.touch.take() {