Skip to content

Commit 4e462ad

Browse files
committed
WIP update for wayland-rs git
1 parent 22adf65 commit 4e462ad

19 files changed

Lines changed: 110 additions & 155 deletions

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,14 @@ wasm-bindgen-futures = "0.4.43"
9595
wasm-bindgen-test = "0.3"
9696
web-time = "1"
9797
web_sys = { package = "web-sys", version = "0.3.70" }
98+
99+
[patch.crates-io]
100+
wayland-client = { git = "https://github.com/smithay/wayland-rs" }
101+
wayland-protocols = { git = "https://github.com/smithay/wayland-rs" }
102+
wayland-protocols-wlr = { git = "https://github.com/smithay/wayland-rs" }
103+
wayland-protocols-misc = { git = "https://github.com/smithay/wayland-rs" }
104+
wayland-protocols-plasma = { git = "https://github.com/smithay/wayland-rs" }
105+
wayland-protocols-experimental = { git = "https://github.com/smithay/wayland-rs" }
106+
wayland-cursor = { git = "https://github.com/smithay/wayland-rs" }
107+
wayland-backend = { git = "https://github.com/smithay/wayland-rs" }
108+
wayland-scanner = { git = "https://github.com/smithay/wayland-rs" }

winit-wayland/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ libc.workspace = true
3535
memmap2.workspace = true
3636
rustix = { workspace = true, features = ["std", "system", "thread", "process", "event", "pipe"] }
3737
# 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 = [
38+
sctk = { package = "smithay-client-toolkit", git = "https://github.com/ids1024/client-toolkit", branch = "wayland-update", default-features = false, features = [
3939
"calloop",
4040
] }
4141
#sctk-adwaita = { version = "0.11.0", default-features = false, optional = true }

winit-wayland/src/event_loop/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,7 @@ impl rwh_06::HasDisplayHandle for OwnedDisplayHandle {
716716
use sctk::reexports::client::Proxy;
717717

718718
let raw = rwh_06::WaylandDisplayHandle::new({
719-
let ptr = self.connection.display().id().as_ptr();
720-
std::ptr::NonNull::new(ptr as *mut _).expect("wl_display should never be null")
719+
self.connection.display().id().as_ptr().expect("wl_display should never be null").cast()
721720
});
722721

723722
Ok(unsafe { rwh_06::DisplayHandle::borrow_raw(raw.into()) })

winit-wayland/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl PlatformWindowAttributes for WindowAttributesWayland {
146146
/// Get the WindowId out of the surface.
147147
#[inline]
148148
fn make_wid(surface: &WlSurface) -> WindowId {
149-
WindowId::from_raw(surface.id().as_ptr() as usize)
149+
WindowId::from_raw(surface.id().as_ptr().map_or(0, |ptr| ptr.as_ptr() as usize))
150150
}
151151

152152
/// The default routine does floor, but we need round on Wayland.

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use sctk::reexports::client::protocol::wl_keyboard::{
99
Event as WlKeyboardEvent, KeyState as WlKeyState, KeymapFormat as WlKeymapFormat, WlKeyboard,
1010
};
1111
use sctk::reexports::client::protocol::wl_seat::WlSeat;
12-
use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, WEnum};
12+
use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle};
1313
use tracing::warn;
1414
use winit_common::xkb::Context;
1515
use winit_core::event::{ElementState, WindowEvent};
@@ -19,16 +19,16 @@ use crate::WindowId;
1919
use crate::event_loop::sink::EventSink;
2020
use crate::state::WinitState;
2121

22-
impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
22+
impl Dispatch<WlKeyboard, WinitState> for KeyboardData {
2323
fn event(
24+
&self,
2425
state: &mut WinitState,
2526
wl_keyboard: &WlKeyboard,
2627
event: <WlKeyboard as Proxy>::Event,
27-
data: &KeyboardData,
2828
_: &Connection,
2929
_: &QueueHandle<WinitState>,
3030
) {
31-
let seat_state = match state.seats.get_mut(&data.seat.id()) {
31+
let seat_state = match state.seats.get_mut(&self.seat.id()) {
3232
Some(seat_state) => seat_state,
3333
None => {
3434
warn!("Received keyboard event {event:?} without seat");
@@ -45,19 +45,14 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
4545

4646
match event {
4747
WlKeyboardEvent::Keymap { format, fd, size } => match format {
48-
WEnum::Value(format) => match format {
49-
WlKeymapFormat::NoKeymap => {
50-
warn!("non-xkb compatible keymap")
51-
},
52-
WlKeymapFormat::XkbV1 => {
53-
let context = &mut keyboard_state.xkb_context;
54-
context.set_keymap_from_fd(fd, size as usize);
55-
},
56-
_ => unreachable!(),
48+
WlKeymapFormat::NoKeymap => {
49+
warn!("non-xkb compatible keymap")
5750
},
58-
WEnum::Unknown(value) => {
59-
warn!("unknown keymap format 0x{:x}", value)
51+
WlKeymapFormat::XkbV1 => {
52+
let context = &mut keyboard_state.xkb_context;
53+
context.set_keymap_from_fd(fd, size as usize);
6054
},
55+
_ => warn!("unknown keymap format {:?}", format),
6156
},
6257
WlKeyboardEvent::Enter { surface, .. } => {
6358
let window_id = crate::make_wid(&surface);
@@ -67,7 +62,7 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
6762
Some(window) => {
6863
let mut window = window.lock().unwrap();
6964
let was_unfocused = !window.has_focus();
70-
window.add_seat_focus(data.seat.id());
65+
window.add_seat_focus(self.seat.id());
7166
was_unfocused
7267
},
7368
None => return,
@@ -79,7 +74,7 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
7974
keyboard_state.loop_handle.remove(token);
8075
}
8176

82-
*data.window_id.lock().unwrap() = Some(window_id);
77+
*self.window_id.lock().unwrap() = Some(window_id);
8378

8479
// The keyboard focus is considered as general focus.
8580
if was_unfocused {
@@ -109,15 +104,15 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
109104
let focused = match state.windows.get_mut().get(&window_id) {
110105
Some(window) => {
111106
let mut window = window.lock().unwrap();
112-
window.remove_seat_focus(&data.seat.id());
107+
window.remove_seat_focus(&self.seat.id());
113108
window.has_focus()
114109
},
115110
None => return,
116111
};
117112

118113
// We don't need to update it above, because the next `Enter` will overwrite
119114
// anyway.
120-
*data.window_id.lock().unwrap() = None;
115+
*self.window_id.lock().unwrap() = None;
121116

122117
if !focused {
123118
// Notify that no modifiers are being pressed.
@@ -129,14 +124,14 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
129124
state.events_sink.push_window_event(WindowEvent::Focused(false), window_id);
130125
}
131126
},
132-
WlKeyboardEvent::Key { key, state: WEnum::Value(key_state), .. }
127+
WlKeyboardEvent::Key { key, state: key_state, .. }
133128
if matches!(key_state, WlKeyState::Repeated | WlKeyState::Pressed) =>
134129
{
135130
let key = key + 8;
136131
key_input(
137132
keyboard_state,
138133
&mut state.events_sink,
139-
data,
134+
self,
140135
key,
141136
ElementState::Pressed,
142137
key_state == WlKeyState::Repeated,
@@ -204,13 +199,13 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
204199
})
205200
.ok();
206201
},
207-
WlKeyboardEvent::Key { key, state: WEnum::Value(WlKeyState::Released), .. } => {
202+
WlKeyboardEvent::Key { key, state: WlKeyState::Released, .. } => {
208203
let key = key + 8;
209204

210205
key_input(
211206
keyboard_state,
212207
&mut state.events_sink,
213-
data,
208+
self,
214209
key,
215210
ElementState::Released,
216211
false,
@@ -239,7 +234,7 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
239234
seat_state.modifiers = xkb_state.modifiers().into();
240235

241236
// HACK: part of the workaround from `WlKeyboardEvent::Enter`.
242-
let window_id = match *data.window_id.lock().unwrap() {
237+
let window_id = match *self.window_id.lock().unwrap() {
243238
Some(window_id) => window_id,
244239
None => {
245240
seat_state.modifiers_pending = true;

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::time::Duration;
66

77
use tracing::warn;
88

9-
use sctk::reexports::client::delegate_dispatch;
109
use sctk::reexports::client::protocol::wl_pointer::WlPointer;
1110
use sctk::reexports::client::protocol::wl_surface::WlSurface;
1211
use sctk::reexports::client::{Connection, Proxy, QueueHandle, Dispatch};
@@ -408,7 +407,7 @@ impl PointerConstraintsState {
408407
globals: &GlobalList,
409408
queue_handle: &QueueHandle<WinitState>,
410409
) -> Result<Self, BindError> {
411-
let pointer_constraints = globals.bind(queue_handle, 1..=1, GlobalData)?;
410+
let pointer_constraints = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?;
412411
Ok(Self { pointer_constraints })
413412
}
414413
}
@@ -421,42 +420,38 @@ impl Deref for PointerConstraintsState {
421420
}
422421
}
423422

424-
impl Dispatch<ZwpPointerConstraintsV1, GlobalData, WinitState> for PointerConstraintsState {
423+
impl Dispatch<ZwpPointerConstraintsV1, WinitState> for GlobalData {
425424
fn event(
425+
&self,
426426
_state: &mut WinitState,
427427
_proxy: &ZwpPointerConstraintsV1,
428428
_event: <ZwpPointerConstraintsV1 as wayland_client::Proxy>::Event,
429-
_data: &GlobalData,
430429
_conn: &Connection,
431430
_qhandle: &QueueHandle<WinitState>,
432431
) {
433432
}
434433
}
435434

436-
impl Dispatch<ZwpLockedPointerV1, GlobalData, WinitState> for PointerConstraintsState {
435+
impl Dispatch<ZwpLockedPointerV1, WinitState> for GlobalData {
437436
fn event(
437+
&self,
438438
_state: &mut WinitState,
439439
_proxy: &ZwpLockedPointerV1,
440440
_event: <ZwpLockedPointerV1 as wayland_client::Proxy>::Event,
441-
_data: &GlobalData,
442441
_conn: &Connection,
443442
_qhandle: &QueueHandle<WinitState>,
444443
) {
445444
}
446445
}
447446

448-
impl Dispatch<ZwpConfinedPointerV1, GlobalData, WinitState> for PointerConstraintsState {
447+
impl Dispatch<ZwpConfinedPointerV1, WinitState> for GlobalData {
449448
fn event(
449+
&self,
450450
_state: &mut WinitState,
451451
_proxy: &ZwpConfinedPointerV1,
452452
_event: <ZwpConfinedPointerV1 as wayland_client::Proxy>::Event,
453-
_data: &GlobalData,
454453
_conn: &Connection,
455454
_qhandle: &QueueHandle<WinitState>,
456455
) {
457456
}
458457
}
459-
460-
delegate_dispatch!(WinitState: [ZwpPointerConstraintsV1: GlobalData] => PointerConstraintsState);
461-
delegate_dispatch!(WinitState: [ZwpLockedPointerV1: GlobalData] => PointerConstraintsState);
462-
delegate_dispatch!(WinitState: [ZwpConfinedPointerV1: GlobalData] => PointerConstraintsState);

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use dpi::{LogicalPosition, PhysicalPosition};
55
use sctk::compositor::SurfaceData;
66
use sctk::globals::GlobalData;
77
use sctk::reexports::client::globals::{BindError, GlobalList};
8-
use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch};
8+
use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle};
99
use sctk::reexports::protocols::wp::pointer_gestures::zv1::client::zwp_pointer_gesture_pinch_v1::{
1010
Event as PinchEvent, ZwpPointerGesturePinchV1,
1111
};
@@ -30,7 +30,7 @@ impl PointerGesturesState {
3030
globals: &GlobalList,
3131
queue_handle: &QueueHandle<WinitState>,
3232
) -> Result<Self, BindError> {
33-
let pointer_gestures = globals.bind(queue_handle, 3..=3, GlobalData)?;
33+
let pointer_gestures = globals.bind_singleton(queue_handle, 3..=3, GlobalData)?;
3434
Ok(Self { pointer_gestures })
3535
}
3636
}
@@ -60,29 +60,29 @@ impl Deref for PointerGesturesState {
6060
}
6161
}
6262

63-
impl Dispatch<ZwpPointerGesturesV1, GlobalData, WinitState> for PointerGesturesState {
63+
impl Dispatch<ZwpPointerGesturesV1, WinitState> for GlobalData {
6464
fn event(
65+
&self,
6566
_state: &mut WinitState,
6667
_proxy: &ZwpPointerGesturesV1,
6768
_event: <ZwpPointerGesturesV1 as wayland_client::Proxy>::Event,
68-
_data: &GlobalData,
6969
_conn: &Connection,
7070
_qhandle: &QueueHandle<WinitState>,
7171
) {
7272
unreachable!("zwp_pointer_gestures_v1 has no events")
7373
}
7474
}
7575

76-
impl Dispatch<ZwpPointerGestureHoldV1, PointerGestureData, WinitState> for PointerGesturesState {
76+
impl Dispatch<ZwpPointerGestureHoldV1, WinitState> for PointerGestureData {
7777
fn event(
78+
&self,
7879
state: &mut WinitState,
7980
_proxy: &ZwpPointerGestureHoldV1,
8081
event: <ZwpPointerGestureHoldV1 as wayland_client::Proxy>::Event,
81-
data: &PointerGestureData,
8282
_conn: &Connection,
8383
_qhandle: &QueueHandle<WinitState>,
8484
) {
85-
let mut pointer_gesture_data = data.inner.lock().unwrap();
85+
let mut pointer_gesture_data = self.inner.lock().unwrap();
8686
let (window_id, phase) = match event {
8787
HoldEvent::Begin { surface, fingers, .. } => {
8888
if fingers < 2 {
@@ -116,16 +116,16 @@ impl Dispatch<ZwpPointerGestureHoldV1, PointerGestureData, WinitState> for Point
116116
}
117117
}
118118

119-
impl Dispatch<ZwpPointerGesturePinchV1, PointerGestureData, WinitState> for PointerGesturesState {
119+
impl Dispatch<ZwpPointerGesturePinchV1, WinitState> for PointerGestureData {
120120
fn event(
121+
&self,
121122
state: &mut WinitState,
122123
_proxy: &ZwpPointerGesturePinchV1,
123124
event: <ZwpPointerGesturePinchV1 as Proxy>::Event,
124-
data: &PointerGestureData,
125125
_conn: &Connection,
126126
_qhandle: &QueueHandle<WinitState>,
127127
) {
128-
let mut pointer_gesture_data = data.inner.lock().unwrap();
128+
let mut pointer_gesture_data = self.inner.lock().unwrap();
129129
let (window_id, phase, pan_delta, pinch_delta, rotation_delta) = match event {
130130
PinchEvent::Begin { surface, fingers, .. } => {
131131
// We only support two fingers for now.
@@ -200,7 +200,3 @@ impl Dispatch<ZwpPointerGesturePinchV1, PointerGestureData, WinitState> for Poin
200200
);
201201
}
202202
}
203-
204-
delegate_dispatch!(WinitState: [ZwpPointerGesturesV1: GlobalData] => PointerGesturesState);
205-
delegate_dispatch!(WinitState: [ZwpPointerGesturePinchV1: PointerGestureData] => PointerGesturesState);
206-
delegate_dispatch!(WinitState: [ZwpPointerGestureHoldV1: PointerGestureData] => PointerGesturesState);

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ops::Deref;
44

55
use sctk::reexports::client::globals::{BindError, GlobalList};
66
use sctk::reexports::client::{Connection, QueueHandle};
7-
use sctk::reexports::client::{Dispatch, delegate_dispatch};
7+
use sctk::reexports::client::{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},
@@ -27,7 +27,7 @@ impl RelativePointerState {
2727
globals: &GlobalList,
2828
queue_handle: &QueueHandle<WinitState>,
2929
) -> Result<Self, BindError> {
30-
let manager = globals.bind(queue_handle, 1..=1, GlobalData)?;
30+
let manager = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?;
3131
Ok(Self { manager })
3232
}
3333
}
@@ -40,24 +40,24 @@ impl Deref for RelativePointerState {
4040
}
4141
}
4242

43-
impl Dispatch<ZwpRelativePointerManagerV1, GlobalData, WinitState> for RelativePointerState {
43+
impl Dispatch<ZwpRelativePointerManagerV1, WinitState> for GlobalData {
4444
fn event(
45+
&self,
4546
_state: &mut WinitState,
4647
_proxy: &ZwpRelativePointerManagerV1,
4748
_event: <ZwpRelativePointerManagerV1 as wayland_client::Proxy>::Event,
48-
_data: &GlobalData,
4949
_conn: &Connection,
5050
_qhandle: &QueueHandle<WinitState>,
5151
) {
5252
}
5353
}
5454

55-
impl Dispatch<ZwpRelativePointerV1, GlobalData, WinitState> for RelativePointerState {
55+
impl Dispatch<ZwpRelativePointerV1, WinitState> for GlobalData {
5656
fn event(
57+
&self,
5758
state: &mut WinitState,
5859
_proxy: &ZwpRelativePointerV1,
5960
event: <ZwpRelativePointerV1 as wayland_client::Proxy>::Event,
60-
_data: &GlobalData,
6161
_conn: &Connection,
6262
_qhandle: &QueueHandle<WinitState>,
6363
) {
@@ -72,6 +72,3 @@ impl Dispatch<ZwpRelativePointerV1, GlobalData, WinitState> for RelativePointerS
7272
.push_device_event(DeviceEvent::PointerMotion { delta: (dx_unaccel, dy_unaccel) });
7373
}
7474
}
75-
76-
delegate_dispatch!(WinitState: [ZwpRelativePointerV1: GlobalData] => RelativePointerState);
77-
delegate_dispatch!(WinitState: [ZwpRelativePointerManagerV1: GlobalData] => RelativePointerState);

0 commit comments

Comments
 (0)