Skip to content

Commit bf771a6

Browse files
committed
WIP: wayland: sctk with Dispatch2
Prototyping API change in upcoming wayland-rs API release. Smithay/client-toolkit#519
1 parent c4afadb commit bf771a6

11 files changed

Lines changed: 104 additions & 181 deletions

File tree

winit-wayland/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ foldhash.workspace = true
3434
libc.workspace = true
3535
memmap2.workspace = true
3636
rustix = { workspace = true, features = ["std", "system", "thread", "process", "event", "pipe"] }
37-
sctk = { package = "smithay-client-toolkit", version = "0.20.0", default-features = false, features = [
37+
# sctk = { package = "smithay-client-toolkit", version = "0.20.0", default-features = false, features = [
38+
sctk = { package = "smithay-client-toolkit", git = "https://github.com/ids1024/client-toolkit", branch = "dispatch2", default-features = false, features = [
3839
"calloop",
3940
] }
40-
sctk-adwaita = { version = "0.11.0", default-features = false, optional = true }
41+
#sctk-adwaita = { version = "0.11.0", default-features = false, optional = true }
42+
sctk-adwaita = { git = "https://github.com/ids1024/sctk-adwaita", branch = "dispatch2", default-features = false, optional = true }
4143
wayland-backend = { version = "0.3.10", default-features = false, features = ["client_system"] }
4244
wayland-client = "0.31.10"
4345
wayland-protocols = { version = "0.32.8", features = ["staging"] }

winit-wayland/src/seat/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl SeatHandler for WinitState {
112112
.as_ref()
113113
.map(|state| state.get_viewport(&surface, queue_handle));
114114
let surface_id = surface.id();
115-
let pointer_data = WinitPointerData::new(seat.clone(), viewport);
115+
let pointer_data = WinitPointerData::new(viewport);
116116
let themed_pointer = self
117117
.seat_state
118118
.get_pointer_with_theme_and_data(
@@ -217,8 +217,8 @@ impl SeatHandler for WinitState {
217217
let _ = self.pointer_surfaces.remove(&surface_id);
218218

219219
// Remove the inner locks/confines before dropping the pointer.
220-
pointer_data.unlock_pointer();
221-
pointer_data.unconfine_pointer();
220+
pointer_data.data().unlock_pointer();
221+
pointer_data.data().unconfine_pointer();
222222

223223
if pointer.pointer().version() >= 3 {
224224
pointer.pointer().release();
@@ -265,5 +265,3 @@ impl WinitState {
265265
}
266266
}
267267
}
268-
269-
sctk::delegate_seat!(WinitState);

winit-wayland/src/seat/pointer/mod.rs

Lines changed: 14 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,27 @@ use tracing::warn;
88

99
use sctk::reexports::client::delegate_dispatch;
1010
use sctk::reexports::client::protocol::wl_pointer::WlPointer;
11-
use sctk::reexports::client::protocol::wl_seat::WlSeat;
1211
use sctk::reexports::client::protocol::wl_surface::WlSurface;
1312
use sctk::reexports::client::{Connection, Proxy, QueueHandle, Dispatch};
1413
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_confined_pointer_v1::ZwpConfinedPointerV1;
1514
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_locked_pointer_v1::ZwpLockedPointerV1;
16-
use sctk::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::WpCursorShapeDeviceV1;
17-
use sctk::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_manager_v1::WpCursorShapeManagerV1;
1815
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_pointer_constraints_v1::{Lifetime, ZwpPointerConstraintsV1};
1916
use sctk::reexports::client::globals::{BindError, GlobalList};
2017
use sctk::reexports::csd_frame::FrameClick;
2118
use sctk::reexports::protocols::wp::viewporter::client::wp_viewport::WpViewport;
2219

2320
use sctk::compositor::SurfaceData;
2421
use sctk::globals::GlobalData;
25-
use sctk::seat::pointer::{
26-
PointerData, PointerDataExt, PointerEvent, PointerEventKind, PointerHandler,
27-
};
28-
use sctk::seat::SeatState;
22+
use sctk::seat::pointer::{PointerData, PointerEvent, PointerEventKind, PointerHandler};
2923

3024
use dpi::{LogicalPosition, PhysicalPosition};
3125
use winit_core::event::{
32-
ElementState, MouseButton, MouseScrollDelta, PointerKind, PointerSource, TouchPhase,
33-
WindowEvent, ButtonSource,
26+
ButtonSource, ElementState, MouseButton, MouseScrollDelta, PointerKind, PointerSource,
27+
TouchPhase, WindowEvent,
3428
};
3529

36-
use crate::state::WinitState;
3730
use crate::WindowId;
31+
use crate::state::WinitState;
3832

3933
pub mod pointer_gesture;
4034
pub mod relative_pointer;
@@ -68,7 +62,7 @@ impl PointerHandler for WinitState {
6862
let surface = &event.surface;
6963

7064
// The parent surface.
71-
let parent_surface = match event.surface.data::<SurfaceData>() {
65+
let parent_surface = match event.surface.data::<SurfaceData<()>>() {
7266
Some(data) => data.parent_surface().unwrap_or(surface),
7367
None => continue,
7468
};
@@ -140,13 +134,13 @@ impl PointerHandler for WinitState {
140134
window.pointer_entered(Arc::downgrade(themed_pointer));
141135

142136
// Set the currently focused surface.
143-
pointer.winit_data().inner.lock().unwrap().surface = Some(window_id);
137+
pointer.winit_data().data().inner.lock().unwrap().surface = Some(window_id);
144138
},
145139
PointerEventKind::Leave { .. } => {
146140
window.pointer_left(Arc::downgrade(themed_pointer));
147141

148142
// Remove the active surface.
149-
pointer.winit_data().inner.lock().unwrap().surface = None;
143+
pointer.winit_data().data().inner.lock().unwrap().surface = None;
150144

151145
self.events_sink.push_window_event(
152146
WindowEvent::PointerLeft {
@@ -172,7 +166,7 @@ impl PointerHandler for WinitState {
172166
ref kind @ PointerEventKind::Press { button, serial, .. }
173167
| ref kind @ PointerEventKind::Release { button, serial, .. } => {
174168
// Update the last button serial.
175-
pointer.winit_data().inner.lock().unwrap().latest_button_serial = serial;
169+
pointer.winit_data().data().inner.lock().unwrap().latest_button_serial = serial;
176170

177171
let button = wayland_button_to_winit(button);
178172
let state = if matches!(kind, PointerEventKind::Press { .. }) {
@@ -193,7 +187,7 @@ impl PointerHandler for WinitState {
193187
},
194188
PointerEventKind::Axis { horizontal, vertical, .. } => {
195189
// Get the current phase.
196-
let mut pointer_data = pointer.winit_data().inner.lock().unwrap();
190+
let mut pointer_data = pointer.winit_data().data().inner.lock().unwrap();
197191

198192
let has_value120_scroll = horizontal.value120 != 0 || vertical.value120 != 0;
199193
let has_discrete_scroll = horizontal.discrete != 0 || vertical.discrete != 0;
@@ -253,20 +247,13 @@ pub struct WinitPointerData {
253247
/// The inner winit data associated with the pointer.
254248
inner: Mutex<WinitPointerDataInner>,
255249

256-
/// The data required by the sctk.
257-
sctk_data: PointerData,
258-
259250
/// Viewport for fractional cursor.
260251
viewport: Option<WpViewport>,
261252
}
262253

263254
impl WinitPointerData {
264-
pub fn new(seat: WlSeat, viewport: Option<WpViewport>) -> Self {
265-
Self {
266-
inner: Mutex::new(WinitPointerDataInner::default()),
267-
sctk_data: PointerData::new(seat),
268-
viewport,
269-
}
255+
pub fn new(viewport: Option<WpViewport>) -> Self {
256+
Self { inner: Mutex::new(WinitPointerDataInner::default()), viewport }
270257
}
271258

272259
pub fn lock_pointer(
@@ -320,26 +307,11 @@ impl WinitPointerData {
320307
}
321308
}
322309

323-
/// Seat associated with this pointer.
324-
pub fn seat(&self) -> &WlSeat {
325-
self.sctk_data.seat()
326-
}
327-
328310
/// Active window.
329311
pub fn focused_window(&self) -> Option<WindowId> {
330312
self.inner.lock().unwrap().surface
331313
}
332314

333-
/// Last button serial.
334-
pub fn latest_button_serial(&self) -> u32 {
335-
self.sctk_data.latest_button_serial().unwrap_or_default()
336-
}
337-
338-
/// Last enter serial.
339-
pub fn latest_enter_serial(&self) -> u32 {
340-
self.sctk_data.latest_enter_serial().unwrap_or_default()
341-
}
342-
343315
pub fn set_locked_cursor_position(&self, surface_x: f64, surface_y: f64) {
344316
let inner = self.inner.lock().unwrap();
345317
if let Some(locked_pointer) = inner.locked_pointer.as_ref() {
@@ -360,12 +332,6 @@ impl Drop for WinitPointerData {
360332
}
361333
}
362334

363-
impl PointerDataExt for WinitPointerData {
364-
fn pointer_data(&self) -> &PointerData {
365-
&self.sctk_data
366-
}
367-
}
368-
369335
#[derive(Debug)]
370336
pub struct WinitPointerDataInner {
371337
/// The associated locked pointer.
@@ -423,12 +389,12 @@ fn wayland_button_to_winit(button: u32) -> ButtonSource {
423389
}
424390

425391
pub trait WinitPointerDataExt {
426-
fn winit_data(&self) -> &WinitPointerData;
392+
fn winit_data(&self) -> &PointerData<WinitPointerData>;
427393
}
428394

429395
impl WinitPointerDataExt for WlPointer {
430-
fn winit_data(&self) -> &WinitPointerData {
431-
self.data::<WinitPointerData>().expect("failed to get pointer data.")
396+
fn winit_data(&self) -> &PointerData<WinitPointerData> {
397+
self.data::<PointerData<WinitPointerData>>().expect("failed to get pointer data.")
432398
}
433399
}
434400

@@ -491,35 +457,6 @@ impl Dispatch<ZwpConfinedPointerV1, GlobalData, WinitState> for PointerConstrain
491457
}
492458
}
493459

494-
impl Dispatch<WpCursorShapeDeviceV1, GlobalData, WinitState> for SeatState {
495-
fn event(
496-
_: &mut WinitState,
497-
_: &WpCursorShapeDeviceV1,
498-
_: <WpCursorShapeDeviceV1 as Proxy>::Event,
499-
_: &GlobalData,
500-
_: &Connection,
501-
_: &QueueHandle<WinitState>,
502-
) {
503-
unreachable!("wp_cursor_shape_manager has no events")
504-
}
505-
}
506-
507-
impl Dispatch<WpCursorShapeManagerV1, GlobalData, WinitState> for SeatState {
508-
fn event(
509-
_: &mut WinitState,
510-
_: &WpCursorShapeManagerV1,
511-
_: <WpCursorShapeManagerV1 as Proxy>::Event,
512-
_: &GlobalData,
513-
_: &Connection,
514-
_: &QueueHandle<WinitState>,
515-
) {
516-
unreachable!("wp_cursor_device_manager has no events")
517-
}
518-
}
519-
520-
delegate_dispatch!(WinitState: [ WlPointer: WinitPointerData] => SeatState);
521-
delegate_dispatch!(WinitState: [ WpCursorShapeManagerV1: GlobalData] => SeatState);
522-
delegate_dispatch!(WinitState: [ WpCursorShapeDeviceV1: GlobalData] => SeatState);
523460
delegate_dispatch!(WinitState: [ZwpPointerConstraintsV1: GlobalData] => PointerConstraintsState);
524461
delegate_dispatch!(WinitState: [ZwpLockedPointerV1: GlobalData] => PointerConstraintsState);
525462
delegate_dispatch!(WinitState: [ZwpConfinedPointerV1: GlobalData] => PointerConstraintsState);

winit-wayland/src/seat/pointer/pointer_gesture.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ impl Dispatch<ZwpPointerGesturePinchV1, PointerGestureData, WinitState> for Poin
8888
}
8989

9090
// Don't handle events from a subsurface.
91-
if surface.data::<SurfaceData>().is_none_or(|data| data.parent_surface().is_some())
91+
if surface
92+
.data::<SurfaceData<()>>()
93+
.is_none_or(|data| data.parent_surface().is_some())
9294
{
9395
return;
9496
}

winit-wayland/src/seat/pointer/relative_pointer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
use std::ops::Deref;
44

55
use sctk::reexports::client::globals::{BindError, GlobalList};
6-
use sctk::reexports::client::{delegate_dispatch, Dispatch};
76
use sctk::reexports::client::{Connection, QueueHandle};
7+
use sctk::reexports::client::{Dispatch, delegate_dispatch};
88
use sctk::reexports::protocols::wp::relative_pointer::zv1::{
99
client::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1,
1010
client::zwp_relative_pointer_v1::{self, ZwpRelativePointerV1},
1111
};
1212

1313
use sctk::globals::GlobalData;
1414

15-
use winit_core::event::DeviceEvent;
1615
use crate::state::WinitState;
16+
use winit_core::event::DeviceEvent;
1717

1818
/// Wrapper around the relative pointer.
1919
#[derive(Debug)]

winit-wayland/src/seat/touch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub trait TouchDataExt {
247247

248248
impl TouchDataExt for WlTouch {
249249
fn seat(&self) -> &WlSeat {
250-
self.data::<TouchData>().expect("failed to get touch data.").seat()
250+
self.data::<TouchData<()>>().expect("failed to get touch data.").seat()
251251
}
252252
}
253253

winit-wayland/src/state.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl WinitState {
246246
self.window_compositor_updates[pos].scale_changed = true;
247247
} else if let Some(pointer) = self.pointer_surfaces.get(&surface.id()) {
248248
// Get the window, where the pointer resides right now.
249-
let focused_window = match pointer.pointer().winit_data().focused_window() {
249+
let focused_window = match pointer.pointer().winit_data().data().focused_window() {
250250
Some(focused_window) => focused_window,
251251
None => return,
252252
};
@@ -445,10 +445,5 @@ impl WindowCompositorUpdate {
445445
}
446446
}
447447

448-
sctk::delegate_subcompositor!(WinitState);
449-
sctk::delegate_compositor!(WinitState);
450-
sctk::delegate_output!(WinitState);
448+
sctk::delegate_dispatch2!(WinitState);
451449
sctk::delegate_registry!(WinitState);
452-
sctk::delegate_shm!(WinitState);
453-
sctk::delegate_xdg_shell!(WinitState);
454-
sctk::delegate_xdg_window!(WinitState);

0 commit comments

Comments
 (0)