wayland: Update sctk to 0.21

This uses `Dispatch2`, which will be how `Dispatch` is defined in the
upcoming wayland-rs release.
This commit is contained in:
Ian Douglas Scott
2026-05-13 18:45:47 -07:00
committed by Kirill Chibisov
parent 0e7ed677f1
commit a9e7bef8ff
11 changed files with 94 additions and 179 deletions

View File

@@ -35,10 +35,10 @@ foldhash.workspace = true
libc.workspace = true libc.workspace = true
memmap2.workspace = true memmap2.workspace = true
rustix = { workspace = true, features = ["std", "system", "thread", "process", "event", "pipe"] } rustix = { workspace = true, features = ["std", "system", "thread", "process", "event", "pipe"] }
sctk = { package = "smithay-client-toolkit", version = "0.20.0", default-features = false, features = [ sctk = { package = "smithay-client-toolkit", version = "0.21.0", default-features = false, features = [
"calloop", "calloop",
] } ] }
sctk-adwaita = { version = "0.11.0", default-features = false, optional = true } sctk-adwaita = { version = "0.12.0", default-features = false, optional = true }
wayland-backend = { version = "0.3.10", default-features = false, features = ["client_system"] } wayland-backend = { version = "0.3.10", default-features = false, features = ["client_system"] }
wayland-client = "0.31.10" wayland-client = "0.31.10"
wayland-protocols = { version = "0.32.12", features = ["staging", "unstable"] } wayland-protocols = { version = "0.32.12", features = ["staging", "unstable"] }

View File

@@ -801,5 +801,3 @@ impl DataDeviceHandler for WinitState {
} }
} }
} }
sctk::delegate_data_device!(WinitState);

View File

@@ -878,7 +878,8 @@ impl RootActiveEventLoop for ActiveEventLoop {
let serial = seat let serial = seat
.pointer_data() .pointer_data()
.ok_or(NotSupportedError::new(NO_POINTER_CAP_ERROR_MSG))? .ok_or(NotSupportedError::new(NO_POINTER_CAP_ERROR_MSG))?
.latest_button_serial(); .latest_button_serial()
.unwrap_or_default();
data_source.start_drag(data_device, source_surface, icon_surface.as_ref(), serial); data_source.start_drag(data_device, source_surface, icon_surface.as_ref(), serial);

View File

@@ -10,7 +10,7 @@ use sctk::reexports::client::protocol::wl_touch::WlTouch;
use sctk::reexports::client::{Connection, Proxy, QueueHandle}; use sctk::reexports::client::{Connection, Proxy, QueueHandle};
use sctk::reexports::protocols::wp::relative_pointer::zv1::client::zwp_relative_pointer_v1::ZwpRelativePointerV1; use sctk::reexports::protocols::wp::relative_pointer::zv1::client::zwp_relative_pointer_v1::ZwpRelativePointerV1;
use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::ZwpTextInputV3; use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::ZwpTextInputV3;
use sctk::seat::pointer::{ThemeSpec, ThemedPointer}; use sctk::seat::pointer::{PointerData, ThemeSpec, ThemedPointer};
use sctk::seat::{Capability as SeatCapability, SeatHandler, SeatState}; use sctk::seat::{Capability as SeatCapability, SeatHandler, SeatState};
use tracing::warn; use tracing::warn;
use wayland_protocols::wp::pointer_gestures::zv1::client::zwp_pointer_gesture_hold_v1::ZwpPointerGestureHoldV1; use wayland_protocols::wp::pointer_gestures::zv1::client::zwp_pointer_gesture_hold_v1::ZwpPointerGestureHoldV1;
@@ -87,7 +87,7 @@ impl WinitSeatState {
self.data_device.as_ref() self.data_device.as_ref()
} }
pub(crate) fn pointer_data(&self) -> Option<&WinitPointerData> { pub(crate) fn pointer_data(&self) -> Option<&PointerData<WinitPointerData>> {
self.pointer.as_ref().and_then(|pointer| pointer.pointer().data()) self.pointer.as_ref().and_then(|pointer| pointer.pointer().data())
} }
} }
@@ -128,7 +128,7 @@ impl SeatHandler for WinitState {
.as_ref() .as_ref()
.map(|state| state.get_viewport(&surface, queue_handle)); .map(|state| state.get_viewport(&surface, queue_handle));
let surface_id = surface.id(); let surface_id = surface.id();
let pointer_data = WinitPointerData::new(seat.clone(), viewport); let pointer_data = WinitPointerData::new(viewport);
let themed_pointer = self let themed_pointer = self
.seat_state .seat_state
.get_pointer_with_theme_and_data( .get_pointer_with_theme_and_data(
@@ -252,8 +252,8 @@ impl SeatHandler for WinitState {
let _ = self.pointer_surfaces.remove(&surface_id); let _ = self.pointer_surfaces.remove(&surface_id);
// Remove the inner locks/confines before dropping the pointer. // Remove the inner locks/confines before dropping the pointer.
pointer_data.unlock_pointer(); pointer_data.data().unlock_pointer();
pointer_data.unconfine_pointer(); pointer_data.data().unconfine_pointer();
if pointer.pointer().version() >= 3 { if pointer.pointer().version() >= 3 {
pointer.pointer().release(); pointer.pointer().release();
@@ -300,5 +300,3 @@ impl WinitState {
} }
} }
} }
sctk::delegate_seat!(WinitState);

View File

@@ -8,13 +8,10 @@ use tracing::warn;
use sctk::reexports::client::delegate_dispatch; use sctk::reexports::client::delegate_dispatch;
use sctk::reexports::client::protocol::wl_pointer::WlPointer; use sctk::reexports::client::protocol::wl_pointer::WlPointer;
use sctk::reexports::client::protocol::wl_seat::WlSeat;
use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::protocol::wl_surface::WlSurface;
use sctk::reexports::client::{Connection, Proxy, QueueHandle, Dispatch}; use sctk::reexports::client::{Connection, Proxy, QueueHandle, Dispatch};
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_confined_pointer_v1::ZwpConfinedPointerV1; use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_confined_pointer_v1::ZwpConfinedPointerV1;
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_locked_pointer_v1::ZwpLockedPointerV1; use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_locked_pointer_v1::ZwpLockedPointerV1;
use sctk::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::WpCursorShapeDeviceV1;
use sctk::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_manager_v1::WpCursorShapeManagerV1;
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_pointer_constraints_v1::{Lifetime, ZwpPointerConstraintsV1}; use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_pointer_constraints_v1::{Lifetime, ZwpPointerConstraintsV1};
use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::globals::{BindError, GlobalList};
use sctk::reexports::csd_frame::FrameClick; use sctk::reexports::csd_frame::FrameClick;
@@ -22,10 +19,7 @@ use sctk::reexports::protocols::wp::viewporter::client::wp_viewport::WpViewport;
use sctk::compositor::SurfaceData; use sctk::compositor::SurfaceData;
use sctk::globals::GlobalData; use sctk::globals::GlobalData;
use sctk::seat::SeatState; use sctk::seat::pointer::{PointerData, PointerEvent, PointerEventKind, PointerHandler};
use sctk::seat::pointer::{
PointerData, PointerDataExt, PointerEvent, PointerEventKind, PointerHandler,
};
use dpi::{LogicalPosition, PhysicalPosition}; use dpi::{LogicalPosition, PhysicalPosition};
use winit_core::event::{ use winit_core::event::{
@@ -68,7 +62,7 @@ impl PointerHandler for WinitState {
let surface = &event.surface; let surface = &event.surface;
// The parent surface. // The parent surface.
let parent_surface = match event.surface.data::<SurfaceData>() { let parent_surface = match event.surface.data::<SurfaceData<()>>() {
Some(data) => data.parent_surface().unwrap_or(surface), Some(data) => data.parent_surface().unwrap_or(surface),
None => continue, None => continue,
}; };
@@ -140,13 +134,13 @@ impl PointerHandler for WinitState {
window.pointer_entered(Arc::downgrade(themed_pointer)); window.pointer_entered(Arc::downgrade(themed_pointer));
// Set the currently focused surface. // Set the currently focused surface.
pointer.winit_data().inner.lock().unwrap().surface = Some(window_id); pointer.winit_data().data().inner.lock().unwrap().surface = Some(window_id);
}, },
PointerEventKind::Leave { .. } => { PointerEventKind::Leave { .. } => {
window.pointer_left(Arc::downgrade(themed_pointer)); window.pointer_left(Arc::downgrade(themed_pointer));
// Remove the active surface. // Remove the active surface.
pointer.winit_data().inner.lock().unwrap().surface = None; pointer.winit_data().data().inner.lock().unwrap().surface = None;
self.events_sink.push_window_event( self.events_sink.push_window_event(
WindowEvent::PointerLeft { WindowEvent::PointerLeft {
@@ -172,7 +166,7 @@ impl PointerHandler for WinitState {
ref kind @ PointerEventKind::Press { button, serial, .. } ref kind @ PointerEventKind::Press { button, serial, .. }
| ref kind @ PointerEventKind::Release { button, serial, .. } => { | ref kind @ PointerEventKind::Release { button, serial, .. } => {
// Update the last button serial. // Update the last button serial.
pointer.winit_data().inner.lock().unwrap().latest_button_serial = serial; pointer.winit_data().data().inner.lock().unwrap().latest_button_serial = serial;
let button = wayland_button_to_winit(button); let button = wayland_button_to_winit(button);
let state = if matches!(kind, PointerEventKind::Press { .. }) { let state = if matches!(kind, PointerEventKind::Press { .. }) {
@@ -193,7 +187,7 @@ impl PointerHandler for WinitState {
}, },
PointerEventKind::Axis { horizontal, vertical, .. } => { PointerEventKind::Axis { horizontal, vertical, .. } => {
// Get the current phase. // Get the current phase.
let mut pointer_data = pointer.winit_data().inner.lock().unwrap(); let mut pointer_data = pointer.winit_data().data().inner.lock().unwrap();
let has_value120_scroll = horizontal.value120 != 0 || vertical.value120 != 0; let has_value120_scroll = horizontal.value120 != 0 || vertical.value120 != 0;
let has_discrete_scroll = horizontal.discrete != 0 || vertical.discrete != 0; let has_discrete_scroll = horizontal.discrete != 0 || vertical.discrete != 0;
@@ -253,20 +247,13 @@ pub struct WinitPointerData {
/// The inner winit data associated with the pointer. /// The inner winit data associated with the pointer.
inner: Mutex<WinitPointerDataInner>, inner: Mutex<WinitPointerDataInner>,
/// The data required by the sctk.
sctk_data: PointerData,
/// Viewport for fractional cursor. /// Viewport for fractional cursor.
viewport: Option<WpViewport>, viewport: Option<WpViewport>,
} }
impl WinitPointerData { impl WinitPointerData {
pub fn new(seat: WlSeat, viewport: Option<WpViewport>) -> Self { pub fn new(viewport: Option<WpViewport>) -> Self {
Self { Self { inner: Mutex::new(WinitPointerDataInner::default()), viewport }
inner: Mutex::new(WinitPointerDataInner::default()),
sctk_data: PointerData::new(seat),
viewport,
}
} }
pub fn lock_pointer( pub fn lock_pointer(
@@ -320,26 +307,11 @@ impl WinitPointerData {
} }
} }
/// Seat associated with this pointer.
pub fn seat(&self) -> &WlSeat {
self.sctk_data.seat()
}
/// Active window. /// Active window.
pub fn focused_window(&self) -> Option<WindowId> { pub fn focused_window(&self) -> Option<WindowId> {
self.inner.lock().unwrap().surface self.inner.lock().unwrap().surface
} }
/// Last button serial.
pub fn latest_button_serial(&self) -> u32 {
self.sctk_data.latest_button_serial().unwrap_or_default()
}
/// Last enter serial.
pub fn latest_enter_serial(&self) -> u32 {
self.sctk_data.latest_enter_serial().unwrap_or_default()
}
pub fn set_locked_cursor_position(&self, surface_x: f64, surface_y: f64) { pub fn set_locked_cursor_position(&self, surface_x: f64, surface_y: f64) {
let inner = self.inner.lock().unwrap(); let inner = self.inner.lock().unwrap();
if let Some(locked_pointer) = inner.locked_pointer.as_ref() { if let Some(locked_pointer) = inner.locked_pointer.as_ref() {
@@ -360,12 +332,6 @@ impl Drop for WinitPointerData {
} }
} }
impl PointerDataExt for WinitPointerData {
fn pointer_data(&self) -> &PointerData {
&self.sctk_data
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct WinitPointerDataInner { pub struct WinitPointerDataInner {
/// The associated locked pointer. /// The associated locked pointer.
@@ -423,12 +389,12 @@ fn wayland_button_to_winit(button: u32) -> ButtonSource {
} }
pub trait WinitPointerDataExt { pub trait WinitPointerDataExt {
fn winit_data(&self) -> &WinitPointerData; fn winit_data(&self) -> &PointerData<WinitPointerData>;
} }
impl WinitPointerDataExt for WlPointer { impl WinitPointerDataExt for WlPointer {
fn winit_data(&self) -> &WinitPointerData { fn winit_data(&self) -> &PointerData<WinitPointerData> {
self.data::<WinitPointerData>().expect("failed to get pointer data.") self.data::<PointerData<WinitPointerData>>().expect("failed to get pointer data.")
} }
} }
@@ -491,35 +457,6 @@ impl Dispatch<ZwpConfinedPointerV1, GlobalData, WinitState> for PointerConstrain
} }
} }
impl Dispatch<WpCursorShapeDeviceV1, GlobalData, WinitState> for SeatState {
fn event(
_: &mut WinitState,
_: &WpCursorShapeDeviceV1,
_: <WpCursorShapeDeviceV1 as Proxy>::Event,
_: &GlobalData,
_: &Connection,
_: &QueueHandle<WinitState>,
) {
unreachable!("wp_cursor_shape_manager has no events")
}
}
impl Dispatch<WpCursorShapeManagerV1, GlobalData, WinitState> for SeatState {
fn event(
_: &mut WinitState,
_: &WpCursorShapeManagerV1,
_: <WpCursorShapeManagerV1 as Proxy>::Event,
_: &GlobalData,
_: &Connection,
_: &QueueHandle<WinitState>,
) {
unreachable!("wp_cursor_device_manager has no events")
}
}
delegate_dispatch!(WinitState: [ WlPointer: WinitPointerData] => SeatState);
delegate_dispatch!(WinitState: [ WpCursorShapeManagerV1: GlobalData] => SeatState);
delegate_dispatch!(WinitState: [ WpCursorShapeDeviceV1: GlobalData] => SeatState);
delegate_dispatch!(WinitState: [ZwpPointerConstraintsV1: GlobalData] => PointerConstraintsState); delegate_dispatch!(WinitState: [ZwpPointerConstraintsV1: GlobalData] => PointerConstraintsState);
delegate_dispatch!(WinitState: [ZwpLockedPointerV1: GlobalData] => PointerConstraintsState); delegate_dispatch!(WinitState: [ZwpLockedPointerV1: GlobalData] => PointerConstraintsState);
delegate_dispatch!(WinitState: [ZwpConfinedPointerV1: GlobalData] => PointerConstraintsState); delegate_dispatch!(WinitState: [ZwpConfinedPointerV1: GlobalData] => PointerConstraintsState);

View File

@@ -134,7 +134,9 @@ impl Dispatch<ZwpPointerGesturePinchV1, PointerGestureData, WinitState> for Poin
} }
// Don't handle events from a subsurface. // Don't handle events from a subsurface.
if surface.data::<SurfaceData>().is_none_or(|data| data.parent_surface().is_some()) if surface
.data::<SurfaceData<()>>()
.is_none_or(|data| data.parent_surface().is_some())
{ {
return; return;
} }

View File

@@ -247,8 +247,6 @@ pub trait TouchDataExt {
impl TouchDataExt for WlTouch { impl TouchDataExt for WlTouch {
fn seat(&self) -> &WlSeat { fn seat(&self) -> &WlSeat {
self.data::<TouchData>().expect("failed to get touch data.").seat() self.data::<TouchData<()>>().expect("failed to get touch data.").seat()
} }
} }
sctk::delegate_touch!(WinitState);

View File

@@ -268,7 +268,7 @@ impl WinitState {
self.window_compositor_updates[pos].scale_changed = true; self.window_compositor_updates[pos].scale_changed = true;
} else if let Some(pointer) = self.pointer_surfaces.get(&surface.id()) { } else if let Some(pointer) = self.pointer_surfaces.get(&surface.id()) {
// Get the window, where the pointer resides right now. // Get the window, where the pointer resides right now.
let focused_window = match pointer.pointer().winit_data().focused_window() { let focused_window = match pointer.pointer().winit_data().data().focused_window() {
Some(focused_window) => focused_window, Some(focused_window) => focused_window,
None => return, None => return,
}; };
@@ -467,10 +467,5 @@ impl WindowCompositorUpdate {
} }
} }
sctk::delegate_subcompositor!(WinitState); sctk::delegate_dispatch2!(WinitState);
sctk::delegate_compositor!(WinitState);
sctk::delegate_output!(WinitState);
sctk::delegate_registry!(WinitState); sctk::delegate_registry!(WinitState);
sctk::delegate_shm!(WinitState);
sctk::delegate_xdg_shell!(WinitState);
sctk::delegate_xdg_window!(WinitState);

View File

@@ -4,14 +4,12 @@ use std::sync::Mutex;
use dpi::LogicalPosition; use dpi::LogicalPosition;
use sctk::compositor::SurfaceData; use sctk::compositor::SurfaceData;
use sctk::globals::GlobalData; use sctk::dispatch2::Dispatch2;
use sctk::reexports::client::backend::smallvec::SmallVec; use sctk::reexports::client::backend::smallvec::SmallVec;
use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::globals::{BindError, GlobalList};
use sctk::reexports::client::protocol::wl_seat::WlSeat; use sctk::reexports::client::protocol::wl_seat::WlSeat;
use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::protocol::wl_surface::WlSurface;
use sctk::reexports::client::{ use sctk::reexports::client::{Connection, Proxy, QueueHandle, WEnum, event_created_child};
Connection, Dispatch, Proxy, QueueHandle, WEnum, delegate_dispatch, event_created_child,
};
use sctk::reexports::protocols::wp::tablet::zv2::client::zwp_tablet_manager_v2::ZwpTabletManagerV2; use sctk::reexports::protocols::wp::tablet::zv2::client::zwp_tablet_manager_v2::ZwpTabletManagerV2;
use sctk::reexports::protocols::wp::tablet::zv2::client::zwp_tablet_pad_v2::ZwpTabletPadV2; use sctk::reexports::protocols::wp::tablet::zv2::client::zwp_tablet_pad_v2::ZwpTabletPadV2;
use sctk::reexports::protocols::wp::tablet::zv2::client::zwp_tablet_seat_v2::{ use sctk::reexports::protocols::wp::tablet::zv2::client::zwp_tablet_seat_v2::{
@@ -47,7 +45,7 @@ impl TabletManager {
queue_handle: &QueueHandle<WinitState>, queue_handle: &QueueHandle<WinitState>,
) -> Result<Self, BindError> { ) -> Result<Self, BindError> {
// Ignore v2 since we are not interested in its events. // Ignore v2 since we are not interested in its events.
let manager = globals.bind(queue_handle, 1..=1, GlobalData)?; let manager = globals.bind(queue_handle, 1..=1, ())?;
Ok(Self { manager }) Ok(Self { manager })
} }
@@ -59,12 +57,12 @@ impl TabletManager {
self.manager.get_tablet_seat(seat, queue_handle, ()) self.manager.get_tablet_seat(seat, queue_handle, ())
} }
} }
impl Dispatch<ZwpTabletManagerV2, GlobalData, WinitState> for TabletManager { impl Dispatch2<ZwpTabletManagerV2, WinitState> for () {
fn event( fn event(
&self,
_: &mut WinitState, _: &mut WinitState,
_: &ZwpTabletManagerV2, _: &ZwpTabletManagerV2,
_: <ZwpTabletManagerV2 as Proxy>::Event, _: <ZwpTabletManagerV2 as Proxy>::Event,
_: &GlobalData,
_: &Connection, _: &Connection,
_: &QueueHandle<WinitState>, _: &QueueHandle<WinitState>,
) { ) {
@@ -72,47 +70,34 @@ impl Dispatch<ZwpTabletManagerV2, GlobalData, WinitState> for TabletManager {
} }
} }
impl Dispatch<ZwpTabletManagerV2, (), WinitState> for TabletManager { impl Dispatch2<ZwpTabletSeatV2, WinitState> for () {
fn event(
_: &mut WinitState,
_: &ZwpTabletManagerV2,
_: <ZwpTabletManagerV2 as Proxy>::Event,
_: &(),
_: &Connection,
_: &QueueHandle<WinitState>,
) {
unreachable!("no events defined for zwp_tablet_manager_v2");
}
}
impl Dispatch<ZwpTabletSeatV2, (), WinitState> for TabletManager {
event_created_child!(WinitState, ZwpTabletSeatV2, [ event_created_child!(WinitState, ZwpTabletSeatV2, [
zwp_tablet_seat_v2::EVT_TABLET_ADDED_OPCODE => (ZwpTabletV2, Default::default()), zwp_tablet_seat_v2::EVT_TABLET_ADDED_OPCODE => (ZwpTabletV2, ()),
zwp_tablet_seat_v2::EVT_TOOL_ADDED_OPCODE => (ZwpTabletToolV2, Default::default()), zwp_tablet_seat_v2::EVT_TOOL_ADDED_OPCODE => (ZwpTabletToolV2, TabletToolData::default()),
zwp_tablet_seat_v2::EVT_PAD_ADDED_OPCODE => (ZwpTabletPadV2, Default::default()) zwp_tablet_seat_v2::EVT_PAD_ADDED_OPCODE => (ZwpTabletPadV2, ())
]); ]);
fn event( fn event(
&self,
_: &mut WinitState, _: &mut WinitState,
_: &ZwpTabletSeatV2, _: &ZwpTabletSeatV2,
_: <ZwpTabletSeatV2 as Proxy>::Event, _: <ZwpTabletSeatV2 as Proxy>::Event,
_: &(),
_: &Connection, _: &Connection,
_: &QueueHandle<WinitState>, _: &QueueHandle<WinitState>,
) { ) {
} }
} }
impl Dispatch<ZwpTabletToolV2, TabletToolData, WinitState> for TabletManager { impl Dispatch2<ZwpTabletToolV2, WinitState> for TabletToolData {
fn event( fn event(
&self,
state: &mut WinitState, state: &mut WinitState,
_: &ZwpTabletToolV2, _: &ZwpTabletToolV2,
event: <ZwpTabletToolV2 as Proxy>::Event, event: <ZwpTabletToolV2 as Proxy>::Event,
data: &TabletToolData,
_: &Connection, _: &Connection,
_: &QueueHandle<WinitState>, _: &QueueHandle<WinitState>,
) { ) {
let mut data = data.inner.lock().unwrap(); let mut data = self.inner.lock().unwrap();
match event { match event {
ToolEvent::Type { tool_type: WEnum::Value(tool_type) } => { ToolEvent::Type { tool_type: WEnum::Value(tool_type) } => {
@@ -198,7 +183,7 @@ impl Dispatch<ZwpTabletToolV2, TabletToolData, WinitState> for TabletManager {
let surface = match data let surface = match data
.surface .surface
.as_ref() .as_ref()
.map(|surface| (surface, surface.data::<SurfaceData>())) .map(|surface| (surface, surface.data::<SurfaceData<()>>()))
{ {
Some((surface, Some(surface_data))) Some((surface, Some(surface_data)))
if surface_data.parent_surface().is_none() => if surface_data.parent_surface().is_none() =>
@@ -318,95 +303,84 @@ pub(crate) enum TabletEvent {
Button { button: TabletToolButton, state: ElementState, serial: Option<u32> }, Button { button: TabletToolButton, state: ElementState, serial: Option<u32> },
} }
impl Dispatch<ZwpTabletV2, (), WinitState> for TabletManager { impl Dispatch2<ZwpTabletV2, WinitState> for () {
fn event( fn event(
&self,
_: &mut WinitState, _: &mut WinitState,
_: &ZwpTabletV2, _: &ZwpTabletV2,
_: <ZwpTabletV2 as Proxy>::Event, _: <ZwpTabletV2 as Proxy>::Event,
_: &(),
_: &Connection, _: &Connection,
_: &QueueHandle<WinitState>, _: &QueueHandle<WinitState>,
) { ) {
} }
} }
impl Dispatch<ZwpTabletPadV2, (), WinitState> for TabletManager { impl Dispatch2<ZwpTabletPadV2, WinitState> for () {
event_created_child!(WinitState, ZwpTabletPadV2, [ event_created_child!(WinitState, ZwpTabletPadV2, [
zwp_tablet_pad_v2::EVT_GROUP_OPCODE => (ZwpTabletPadGroupV2, Default::default()), zwp_tablet_pad_v2::EVT_GROUP_OPCODE => (ZwpTabletPadGroupV2, ()),
]); ]);
fn event( fn event(
&self,
_: &mut WinitState, _: &mut WinitState,
_: &ZwpTabletPadV2, _: &ZwpTabletPadV2,
_: <ZwpTabletPadV2 as Proxy>::Event, _: <ZwpTabletPadV2 as Proxy>::Event,
_: &(),
_: &Connection, _: &Connection,
_: &QueueHandle<WinitState>, _: &QueueHandle<WinitState>,
) { ) {
} }
} }
impl Dispatch<ZwpTabletPadGroupV2, (), WinitState> for TabletManager { impl Dispatch2<ZwpTabletPadGroupV2, WinitState> for () {
event_created_child!(WinitState, ZwpTabletPadGroupV2, [ event_created_child!(WinitState, ZwpTabletPadGroupV2, [
zwp_tablet_pad_group_v2::EVT_RING_OPCODE => (ZwpTabletPadRingV2, Default::default()), zwp_tablet_pad_group_v2::EVT_RING_OPCODE => (ZwpTabletPadRingV2, ()),
zwp_tablet_pad_group_v2::EVT_STRIP_OPCODE => (ZwpTabletPadStripV2, Default::default()), zwp_tablet_pad_group_v2::EVT_STRIP_OPCODE => (ZwpTabletPadStripV2, ()),
zwp_tablet_pad_group_v2::EVT_DIAL_OPCODE => (ZwpTabletPadDialV2, Default::default()), zwp_tablet_pad_group_v2::EVT_DIAL_OPCODE => (ZwpTabletPadDialV2, ()),
]); ]);
fn event( fn event(
&self,
_: &mut WinitState, _: &mut WinitState,
_: &ZwpTabletPadGroupV2, _: &ZwpTabletPadGroupV2,
_: <ZwpTabletPadGroupV2 as Proxy>::Event, _: <ZwpTabletPadGroupV2 as Proxy>::Event,
_: &(),
_: &Connection, _: &Connection,
_: &QueueHandle<WinitState>, _: &QueueHandle<WinitState>,
) { ) {
} }
} }
impl Dispatch<ZwpTabletPadRingV2, (), WinitState> for TabletManager { impl Dispatch2<ZwpTabletPadRingV2, WinitState> for () {
fn event( fn event(
&self,
_: &mut WinitState, _: &mut WinitState,
_: &ZwpTabletPadRingV2, _: &ZwpTabletPadRingV2,
_: <ZwpTabletPadRingV2 as Proxy>::Event, _: <ZwpTabletPadRingV2 as Proxy>::Event,
_: &(),
_: &Connection, _: &Connection,
_: &QueueHandle<WinitState>, _: &QueueHandle<WinitState>,
) { ) {
} }
} }
impl Dispatch<ZwpTabletPadStripV2, (), WinitState> for TabletManager { impl Dispatch2<ZwpTabletPadStripV2, WinitState> for () {
fn event( fn event(
&self,
_: &mut WinitState, _: &mut WinitState,
_: &ZwpTabletPadStripV2, _: &ZwpTabletPadStripV2,
_: <ZwpTabletPadStripV2 as Proxy>::Event, _: <ZwpTabletPadStripV2 as Proxy>::Event,
_: &(),
_: &Connection, _: &Connection,
_: &QueueHandle<WinitState>, _: &QueueHandle<WinitState>,
) { ) {
} }
} }
impl Dispatch<ZwpTabletPadDialV2, (), WinitState> for TabletManager { impl Dispatch2<ZwpTabletPadDialV2, WinitState> for () {
fn event( fn event(
&self,
_: &mut WinitState, _: &mut WinitState,
_: &ZwpTabletPadDialV2, _: &ZwpTabletPadDialV2,
_: <ZwpTabletPadDialV2 as Proxy>::Event, _: <ZwpTabletPadDialV2 as Proxy>::Event,
_: &(),
_: &Connection, _: &Connection,
_: &QueueHandle<WinitState>, _: &QueueHandle<WinitState>,
) { ) {
} }
} }
delegate_dispatch!(WinitState: [ZwpTabletManagerV2: GlobalData] => TabletManager);
delegate_dispatch!(WinitState: [ZwpTabletManagerV2: ()] => TabletManager);
delegate_dispatch!(WinitState: [ZwpTabletSeatV2: ()] => TabletManager);
delegate_dispatch!(WinitState: [ZwpTabletV2: ()] => TabletManager);
delegate_dispatch!(WinitState: [ZwpTabletToolV2: TabletToolData] => TabletManager);
delegate_dispatch!(WinitState: [ZwpTabletPadV2: ()] => TabletManager);
delegate_dispatch!(WinitState: [ZwpTabletPadGroupV2: ()] => TabletManager);
delegate_dispatch!(WinitState: [ZwpTabletPadRingV2: ()] => TabletManager);
delegate_dispatch!(WinitState: [ZwpTabletPadStripV2: ()] => TabletManager);
delegate_dispatch!(WinitState: [ZwpTabletPadDialV2: ()] => TabletManager);

View File

@@ -637,7 +637,7 @@ impl CoreWindow for Window {
} }
fn current_monitor(&self) -> Option<CoreMonitorHandle> { fn current_monitor(&self) -> Option<CoreMonitorHandle> {
let data = self.window.wl_surface().data::<SurfaceData>()?; let data = self.window.wl_surface().data::<SurfaceData<()>>()?;
data.outputs() data.outputs()
.next() .next()
.map(MonitorHandle::new) .map(MonitorHandle::new)

View File

@@ -6,7 +6,7 @@ use std::time::Duration;
use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Size}; use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Size};
use foldhash::HashSet; use foldhash::HashSet;
use sctk::compositor::{CompositorState, Region, SurfaceData, SurfaceDataExt}; use sctk::compositor::{CompositorState, FrameCallbackData, Region, SurfaceData};
use sctk::globals::GlobalData; use sctk::globals::GlobalData;
use sctk::reexports::client::backend::ObjectId; use sctk::reexports::client::backend::ObjectId;
use sctk::reexports::client::protocol::wl_seat::WlSeat; use sctk::reexports::client::protocol::wl_seat::WlSeat;
@@ -20,7 +20,7 @@ use sctk::reexports::protocols::wp::fractional_scale::v1::client::wp_fractional_
use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::ZwpTextInputV3; use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::ZwpTextInputV3;
use sctk::reexports::protocols::wp::viewporter::client::wp_viewport::WpViewport; use sctk::reexports::protocols::wp::viewporter::client::wp_viewport::WpViewport;
use sctk::reexports::protocols::xdg::shell::client::xdg_toplevel::ResizeEdge as XdgResizeEdge; use sctk::reexports::protocols::xdg::shell::client::xdg_toplevel::ResizeEdge as XdgResizeEdge;
use sctk::seat::pointer::{PointerDataExt, ThemedPointer}; use sctk::seat::pointer::{PointerData, ThemedPointer};
use sctk::shell::WaylandSurface; use sctk::shell::WaylandSurface;
use sctk::shell::xdg::XdgSurface; use sctk::shell::xdg::XdgSurface;
use sctk::shell::xdg::window::{DecorationMode, Window, WindowConfigure}; use sctk::shell::xdg::window::{DecorationMode, Window, WindowConfigure};
@@ -250,7 +250,9 @@ impl WindowState {
} }
/// Apply closure on the given pointer. /// Apply closure on the given pointer.
fn apply_on_pointer<F: FnMut(&ThemedPointer<WinitPointerData>, &WinitPointerData)>( fn apply_on_pointer<
F: FnMut(&ThemedPointer<WinitPointerData>, &PointerData<WinitPointerData>),
>(
&self, &self,
mut callback: F, mut callback: F,
) { ) {
@@ -281,7 +283,7 @@ impl WindowState {
match self.frame_callback_state { match self.frame_callback_state {
FrameCallbackState::None | FrameCallbackState::Received => { FrameCallbackState::None | FrameCallbackState::Received => {
self.frame_callback_state = FrameCallbackState::Requested; self.frame_callback_state = FrameCallbackState::Requested;
surface.frame(&self.queue_handle, surface.clone()); surface.frame(&self.queue_handle, FrameCallbackData(surface.clone()));
}, },
FrameCallbackState::Requested => (), FrameCallbackState::Requested => (),
} }
@@ -460,9 +462,10 @@ impl WindowState {
// TODO(kchibisov) handle touch serials. // TODO(kchibisov) handle touch serials.
self.apply_on_pointer(|_, data| { self.apply_on_pointer(|_, data| {
let serial = data.latest_button_serial(); if let Some(serial) = data.latest_button_serial() {
let seat = data.seat(); let seat = data.seat();
xdg_toplevel.resize(seat, serial, resize_direction_to_xdg(direction)); xdg_toplevel.resize(seat, serial, resize_direction_to_xdg(direction));
}
}); });
Ok(()) Ok(())
@@ -473,9 +476,10 @@ impl WindowState {
let xdg_toplevel = self.window.xdg_toplevel(); let xdg_toplevel = self.window.xdg_toplevel();
// TODO(kchibisov) handle touch serials. // TODO(kchibisov) handle touch serials.
self.apply_on_pointer(|_, data| { self.apply_on_pointer(|_, data| {
let serial = data.latest_button_serial(); if let Some(serial) = data.latest_button_serial() {
let seat = data.seat(); let seat = data.seat();
xdg_toplevel._move(seat, serial); xdg_toplevel._move(seat, serial);
}
}); });
Ok(()) Ok(())
@@ -815,13 +819,13 @@ impl WindowState {
self.apply_on_pointer(|pointer, data| { self.apply_on_pointer(|pointer, data| {
let surface = pointer.surface(); let surface = pointer.surface();
let scale = if let Some(viewport) = data.viewport() { let scale = if let Some(viewport) = data.data().viewport() {
let scale = self.scale_factor(); let scale = self.scale_factor();
let size = PhysicalSize::new(cursor.w, cursor.h).to_logical(scale); let size = PhysicalSize::new(cursor.w, cursor.h).to_logical(scale);
viewport.set_destination(size.width, size.height); viewport.set_destination(size.width, size.height);
scale scale
} else if surface.version() >= 3 { } else if surface.version() >= 3 {
let scale = surface.data::<SurfaceData>().unwrap().surface_data().scale_factor(); let scale = surface.data::<SurfaceData<()>>().unwrap().scale_factor();
surface.set_buffer_scale(scale); surface.set_buffer_scale(scale);
scale as f64 scale as f64
} else { } else {
@@ -839,8 +843,8 @@ impl WindowState {
let serial = pointer let serial = pointer
.pointer() .pointer()
.data::<WinitPointerData>() .data::<PointerData<WinitPointerData>>()
.and_then(|data| data.pointer_data().latest_enter_serial()) .and_then(|data| data.latest_enter_serial())
.unwrap(); .unwrap();
let hotspot = let hotspot =
@@ -929,12 +933,12 @@ impl WindowState {
match self.cursor_grab_mode.current_grab_mode { match self.cursor_grab_mode.current_grab_mode {
CursorGrabMode::None => unset_old = true, CursorGrabMode::None => unset_old = true,
CursorGrabMode::Confined => self.apply_on_pointer(|_, data| { CursorGrabMode::Confined => self.apply_on_pointer(|_, data| {
data.unconfine_pointer(); data.data().unconfine_pointer();
unset_old = true; unset_old = true;
}), }),
CursorGrabMode::Locked => { CursorGrabMode::Locked => {
self.apply_on_pointer(|_, data| { self.apply_on_pointer(|_, data| {
data.unlock_pointer(); data.data().unlock_pointer();
unset_old = true; unset_old = true;
}); });
}, },
@@ -951,12 +955,17 @@ impl WindowState {
match mode { match mode {
CursorGrabMode::Locked => self.apply_on_pointer(|pointer, data| { CursorGrabMode::Locked => self.apply_on_pointer(|pointer, data| {
let pointer = pointer.pointer(); let pointer = pointer.pointer();
data.lock_pointer(pointer_constraints, surface, pointer, &self.queue_handle); data.data().lock_pointer(pointer_constraints, surface, pointer, &self.queue_handle);
set_mode = true; set_mode = true;
}), }),
CursorGrabMode::Confined => self.apply_on_pointer(|pointer, data| { CursorGrabMode::Confined => self.apply_on_pointer(|pointer, data| {
let pointer = pointer.pointer(); let pointer = pointer.pointer();
data.confine_pointer(pointer_constraints, surface, pointer, &self.queue_handle); data.data().confine_pointer(
pointer_constraints,
surface,
pointer,
&self.queue_handle,
);
set_mode = true; set_mode = true;
}), }),
CursorGrabMode::None => { CursorGrabMode::None => {
@@ -976,9 +985,10 @@ impl WindowState {
pub fn show_window_menu(&self, position: LogicalPosition<u32>) { pub fn show_window_menu(&self, position: LogicalPosition<u32>) {
// TODO(kchibisov) handle touch serials. // TODO(kchibisov) handle touch serials.
self.apply_on_pointer(|_, data| { self.apply_on_pointer(|_, data| {
let serial = data.latest_button_serial(); if let Some(serial) = data.latest_button_serial() {
let seat = data.seat(); let seat = data.seat();
self.window.show_window_menu(seat, serial, position.into()); self.window.show_window_menu(seat, serial, position.into());
}
}); });
} }
@@ -997,7 +1007,7 @@ impl WindowState {
} }
self.apply_on_pointer(|_, data| { self.apply_on_pointer(|_, data| {
data.set_locked_cursor_position(position.x, position.y); data.data().set_locked_cursor_position(position.x, position.y);
}); });
Ok(()) Ok(())
@@ -1014,9 +1024,11 @@ impl WindowState {
} }
} else { } else {
for pointer in self.pointers.iter().filter_map(|pointer| pointer.upgrade()) { for pointer in self.pointers.iter().filter_map(|pointer| pointer.upgrade()) {
let latest_enter_serial = pointer.pointer().winit_data().latest_enter_serial(); if let Some(latest_enter_serial) =
pointer.pointer().winit_data().latest_enter_serial()
pointer.pointer().set_cursor(latest_enter_serial, None, 0, 0); {
pointer.pointer().set_cursor(latest_enter_serial, None, 0, 0);
}
} }
} }
} }