From a924527f8d01b1d4b482bcba17b3a5ce53195a42 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Tue, 16 Jun 2026 15:28:19 -0700 Subject: [PATCH] WIP update for wayland-rs git --- Cargo.toml | 11 +++++ winit-wayland/Cargo.toml | 6 ++- winit-wayland/src/event_loop/mod.rs | 3 +- winit-wayland/src/lib.rs | 2 +- winit-wayland/src/popup.rs | 13 ++++-- winit-wayland/src/seat/keyboard/mod.rs | 45 ++++++++----------- winit-wayland/src/seat/pointer/mod.rs | 19 +++----- .../src/seat/pointer/pointer_gesture.rs | 24 +++++----- .../src/seat/pointer/relative_pointer.rs | 15 +++---- winit-wayland/src/seat/text_input/mod.rs | 17 +++---- winit-wayland/src/state.rs | 17 +------ .../src/types/ext_background_effect.rs | 15 +++---- winit-wayland/src/types/kwin_blur.rs | 15 +++---- .../src/types/wp_fractional_scaling.rs | 17 +++---- winit-wayland/src/types/wp_tablet_input_v2.rs | 28 ++++++------ winit-wayland/src/types/wp_viewporter.rs | 15 +++---- winit-wayland/src/types/xdg_activation.rs | 17 +++---- .../src/types/xdg_toplevel_icon_manager.rs | 15 +++---- winit-wayland/src/window/mod.rs | 8 ++-- 19 files changed, 132 insertions(+), 170 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5a49c19522..6e7e1d2963 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,3 +96,14 @@ wasm-bindgen-futures = "0.4.43" wasm-bindgen-test = "0.3" web-time = "1" web_sys = { package = "web-sys", version = "0.3.70" } + +[patch.crates-io] +wayland-client = { git = "https://github.com/smithay/wayland-rs" } +wayland-protocols = { git = "https://github.com/smithay/wayland-rs" } +wayland-protocols-wlr = { git = "https://github.com/smithay/wayland-rs" } +wayland-protocols-misc = { git = "https://github.com/smithay/wayland-rs" } +wayland-protocols-plasma = { git = "https://github.com/smithay/wayland-rs" } +wayland-protocols-experimental = { git = "https://github.com/smithay/wayland-rs" } +wayland-cursor = { git = "https://github.com/smithay/wayland-rs" } +wayland-backend = { git = "https://github.com/smithay/wayland-rs" } +wayland-scanner = { git = "https://github.com/smithay/wayland-rs" } diff --git a/winit-wayland/Cargo.toml b/winit-wayland/Cargo.toml index 7303e877cd..2758995738 100644 --- a/winit-wayland/Cargo.toml +++ b/winit-wayland/Cargo.toml @@ -35,10 +35,12 @@ foldhash.workspace = true libc.workspace = true memmap2.workspace = true rustix = { workspace = true, features = ["std", "system", "thread", "process", "event", "pipe"] } -sctk = { package = "smithay-client-toolkit", version = "0.21.0", default-features = false, features = [ +# sctk = { package = "smithay-client-toolkit", version = "0.21.0", default-features = false, features = [ +sctk = { package = "smithay-client-toolkit", git = "https://github.com/ids1024/client-toolkit", branch = "wayland-update", default-features = false, features = [ "calloop", ] } -sctk-adwaita = { version = "0.12.0", default-features = false, optional = true } +#sctk-adwaita = { version = "0.12.0", default-features = false, optional = true } +sctk-adwaita = { git = "https://github.com/ids1024/sctk-adwaita", branch = "wayland-update", default-features = false, optional = true } wayland-backend = { version = "0.3.10", default-features = false, features = ["client_system"] } wayland-client = "0.31.10" wayland-protocols = { version = "0.32.12", features = ["staging", "unstable"] } diff --git a/winit-wayland/src/event_loop/mod.rs b/winit-wayland/src/event_loop/mod.rs index ed0f66925b..eb5ad1fc6f 100644 --- a/winit-wayland/src/event_loop/mod.rs +++ b/winit-wayland/src/event_loop/mod.rs @@ -1011,8 +1011,7 @@ impl rwh_06::HasDisplayHandle for OwnedDisplayHandle { use sctk::reexports::client::Proxy; let raw = rwh_06::WaylandDisplayHandle::new({ - let ptr = self.connection.display().id().as_ptr(); - std::ptr::NonNull::new(ptr as *mut _).expect("wl_display should never be null") + self.connection.display().id().as_ptr().expect("wl_display should never be null").cast() }); Ok(unsafe { rwh_06::DisplayHandle::borrow_raw(raw.into()) }) diff --git a/winit-wayland/src/lib.rs b/winit-wayland/src/lib.rs index de640aed97..2e61dc4301 100644 --- a/winit-wayland/src/lib.rs +++ b/winit-wayland/src/lib.rs @@ -336,7 +336,7 @@ impl PlatformWindowAttributes for WindowAttributesWayland { /// Get the WindowId out of the surface. #[inline] fn make_wid(surface: &WlSurface) -> WindowId { - WindowId::from_raw(surface.id().as_ptr() as usize) + WindowId::from_raw(surface.id().as_ptr().map_or(0, |ptr| ptr.as_ptr() as usize)) } /// Create a `DataTransferId` for the given data device and serial. diff --git a/winit-wayland/src/popup.rs b/winit-wayland/src/popup.rs index cdfd20909b..db731f78ba 100644 --- a/winit-wayland/src/popup.rs +++ b/winit-wayland/src/popup.rs @@ -646,8 +646,14 @@ impl rwh_06::HasWindowHandle for Popup { fn window_handle(&self) -> Result, rwh_06::HandleError> { let state = self.popup_state.upgrade().ok_or(rwh_06::HandleError::Unavailable)?; let raw = rwh_06::WaylandWindowHandle::new({ - let ptr = state.lock().unwrap().window.wl_surface().id().as_ptr(); - std::ptr::NonNull::new(ptr as *mut _).expect("wl_surface will never be null") + state + .lock() + .unwrap() + .window + .wl_surface() + .id() + .as_ptr() + .expect("wl_surface will never be null") }); unsafe { Ok(rwh_06::WindowHandle::borrow_raw(raw.into())) } @@ -660,8 +666,7 @@ impl rwh_06::HasDisplayHandle for Popup { return Err(rwh_06::HandleError::Unavailable); }; let raw = rwh_06::WaylandDisplayHandle::new({ - let ptr = self.display.id().as_ptr(); - std::ptr::NonNull::new(ptr as *mut _).expect("wl_proxy should never be null") + self.display.id().as_ptr().expect("wl_proxy should never be null") }); unsafe { Ok(rwh_06::DisplayHandle::borrow_raw(raw.into())) } diff --git a/winit-wayland/src/seat/keyboard/mod.rs b/winit-wayland/src/seat/keyboard/mod.rs index feb913ca95..2106dce296 100644 --- a/winit-wayland/src/seat/keyboard/mod.rs +++ b/winit-wayland/src/seat/keyboard/mod.rs @@ -9,7 +9,7 @@ use sctk::reexports::client::protocol::wl_keyboard::{ Event as WlKeyboardEvent, KeyState as WlKeyState, KeymapFormat as WlKeymapFormat, WlKeyboard, }; use sctk::reexports::client::protocol::wl_seat::WlSeat; -use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, WEnum}; +use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle}; use tracing::warn; use winit_common::xkb::Context; use winit_core::event::{ElementState, WindowEvent}; @@ -19,16 +19,16 @@ use crate::WindowId; use crate::event_loop::sink::EventSink; use crate::state::WinitState; -impl Dispatch for WinitState { +impl Dispatch for KeyboardData { fn event( + &self, state: &mut WinitState, wl_keyboard: &WlKeyboard, event: ::Event, - data: &KeyboardData, _: &Connection, _: &QueueHandle, ) { - let seat_state = match state.seats.get_mut(&data.seat.id()) { + let seat_state = match state.seats.get_mut(&self.seat.id()) { Some(seat_state) => seat_state, None => { warn!("Received keyboard event {event:?} without seat"); @@ -45,19 +45,14 @@ impl Dispatch for WinitState { match event { WlKeyboardEvent::Keymap { format, fd, size } => match format { - WEnum::Value(format) => match format { - WlKeymapFormat::NoKeymap => { - warn!("non-xkb compatible keymap") - }, - WlKeymapFormat::XkbV1 => { - let context = &mut keyboard_state.xkb_context; - context.set_keymap_from_fd(fd, size as usize); - }, - _ => unreachable!(), + WlKeymapFormat::NoKeymap => { + warn!("non-xkb compatible keymap") }, - WEnum::Unknown(value) => { - warn!("unknown keymap format 0x{:x}", value) + WlKeymapFormat::XkbV1 => { + let context = &mut keyboard_state.xkb_context; + context.set_keymap_from_fd(fd, size as usize); }, + _ => warn!("unknown keymap format {:?}", format), }, WlKeyboardEvent::Enter { surface, .. } => { let window_id = crate::make_wid(&surface); @@ -67,7 +62,7 @@ impl Dispatch for WinitState { Some(window) => { let mut window = window.lock().unwrap(); let was_unfocused = !window.has_focus(); - window.add_seat_focus(data.seat.id()); + window.add_seat_focus(self.seat.id()); was_unfocused }, None => return, @@ -79,7 +74,7 @@ impl Dispatch for WinitState { keyboard_state.loop_handle.remove(token); } - *data.window_id.lock().unwrap() = Some(window_id); + *self.window_id.lock().unwrap() = Some(window_id); // The keyboard focus is considered as general focus. if was_unfocused { @@ -109,7 +104,7 @@ impl Dispatch for WinitState { let focused = match state.windows.get_mut().get(&window_id) { Some(window) => { let mut window = window.lock().unwrap(); - window.remove_seat_focus(&data.seat.id()); + window.remove_seat_focus(&self.seat.id()); window.has_focus() }, None => return, @@ -117,7 +112,7 @@ impl Dispatch for WinitState { // We don't need to update it above, because the next `Enter` will overwrite // anyway. - *data.window_id.lock().unwrap() = None; + *self.window_id.lock().unwrap() = None; if !focused { // Notify that no modifiers are being pressed. @@ -129,7 +124,7 @@ impl Dispatch for WinitState { state.events_sink.push_window_event(WindowEvent::Focused(false), window_id); } }, - WlKeyboardEvent::Key { serial, key, state: WEnum::Value(key_state), .. } + WlKeyboardEvent::Key { serial, key, state: key_state, .. } if matches!(key_state, WlKeyState::Repeated | WlKeyState::Pressed) => { seat_state.latest_input_serial.set(Some(serial)); @@ -137,7 +132,7 @@ impl Dispatch for WinitState { key_input( keyboard_state, &mut state.events_sink, - data, + self, key, ElementState::Pressed, key_state == WlKeyState::Repeated, @@ -205,16 +200,14 @@ impl Dispatch for WinitState { }) .ok(); }, - WlKeyboardEvent::Key { - serial, key, state: WEnum::Value(WlKeyState::Released), .. - } => { + WlKeyboardEvent::Key { serial, key, state: WlKeyState::Released, .. } => { seat_state.latest_input_serial.set(Some(serial)); let key = key + 8; key_input( keyboard_state, &mut state.events_sink, - data, + self, key, ElementState::Released, false, @@ -243,7 +236,7 @@ impl Dispatch for WinitState { seat_state.modifiers = xkb_state.modifiers().into(); // HACK: part of the workaround from `WlKeyboardEvent::Enter`. - let window_id = match *data.window_id.lock().unwrap() { + let window_id = match *self.window_id.lock().unwrap() { Some(window_id) => window_id, None => { seat_state.modifiers_pending = true; diff --git a/winit-wayland/src/seat/pointer/mod.rs b/winit-wayland/src/seat/pointer/mod.rs index e4e113e382..c9923f644c 100644 --- a/winit-wayland/src/seat/pointer/mod.rs +++ b/winit-wayland/src/seat/pointer/mod.rs @@ -6,7 +6,6 @@ use std::time::Duration; use tracing::warn; -use sctk::reexports::client::delegate_dispatch; use sctk::reexports::client::protocol::wl_pointer::WlPointer; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{Connection, Proxy, QueueHandle, Dispatch}; @@ -415,7 +414,7 @@ impl PointerConstraintsState { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let pointer_constraints = globals.bind(queue_handle, 1..=1, GlobalData)?; + let pointer_constraints = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?; Ok(Self { pointer_constraints }) } } @@ -428,42 +427,38 @@ impl Deref for PointerConstraintsState { } } -impl Dispatch for PointerConstraintsState { +impl Dispatch for GlobalData { fn event( + &self, _state: &mut WinitState, _proxy: &ZwpPointerConstraintsV1, _event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { } } -impl Dispatch for PointerConstraintsState { +impl Dispatch for GlobalData { fn event( + &self, _state: &mut WinitState, _proxy: &ZwpLockedPointerV1, _event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { } } -impl Dispatch for PointerConstraintsState { +impl Dispatch for GlobalData { fn event( + &self, _state: &mut WinitState, _proxy: &ZwpConfinedPointerV1, _event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { } } - -delegate_dispatch!(WinitState: [ZwpPointerConstraintsV1: GlobalData] => PointerConstraintsState); -delegate_dispatch!(WinitState: [ZwpLockedPointerV1: GlobalData] => PointerConstraintsState); -delegate_dispatch!(WinitState: [ZwpConfinedPointerV1: GlobalData] => PointerConstraintsState); diff --git a/winit-wayland/src/seat/pointer/pointer_gesture.rs b/winit-wayland/src/seat/pointer/pointer_gesture.rs index 1385a2c102..6a2f7ba6e7 100644 --- a/winit-wayland/src/seat/pointer/pointer_gesture.rs +++ b/winit-wayland/src/seat/pointer/pointer_gesture.rs @@ -5,7 +5,7 @@ use dpi::{LogicalPosition, PhysicalPosition}; use sctk::compositor::SurfaceData; use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; -use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; +use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle}; use sctk::reexports::protocols::wp::pointer_gestures::zv1::client::zwp_pointer_gesture_pinch_v1::{ Event as PinchEvent, ZwpPointerGesturePinchV1, }; @@ -30,7 +30,7 @@ impl PointerGesturesState { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let pointer_gestures = globals.bind(queue_handle, 3..=3, GlobalData)?; + let pointer_gestures = globals.bind_singleton(queue_handle, 3..=3, GlobalData)?; Ok(Self { pointer_gestures }) } } @@ -60,12 +60,12 @@ impl Deref for PointerGesturesState { } } -impl Dispatch for PointerGesturesState { +impl Dispatch for GlobalData { fn event( + &self, _state: &mut WinitState, _proxy: &ZwpPointerGesturesV1, _event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { @@ -73,16 +73,16 @@ impl Dispatch for PointerGesturesS } } -impl Dispatch for PointerGesturesState { +impl Dispatch for PointerGestureData { fn event( + &self, state: &mut WinitState, _proxy: &ZwpPointerGestureHoldV1, event: ::Event, - data: &PointerGestureData, _conn: &Connection, _qhandle: &QueueHandle, ) { - let mut pointer_gesture_data = data.inner.lock().unwrap(); + let mut pointer_gesture_data = self.inner.lock().unwrap(); let (window_id, phase) = match event { HoldEvent::Begin { surface, fingers, .. } => { if fingers < 2 { @@ -116,16 +116,16 @@ impl Dispatch for Point } } -impl Dispatch for PointerGesturesState { +impl Dispatch for PointerGestureData { fn event( + &self, state: &mut WinitState, _proxy: &ZwpPointerGesturePinchV1, event: ::Event, - data: &PointerGestureData, _conn: &Connection, _qhandle: &QueueHandle, ) { - let mut pointer_gesture_data = data.inner.lock().unwrap(); + let mut pointer_gesture_data = self.inner.lock().unwrap(); let (window_id, phase, pan_delta, pinch_delta, rotation_delta) = match event { PinchEvent::Begin { surface, fingers, .. } => { // We only support two fingers for now. @@ -200,7 +200,3 @@ impl Dispatch for Poin ); } } - -delegate_dispatch!(WinitState: [ZwpPointerGesturesV1: GlobalData] => PointerGesturesState); -delegate_dispatch!(WinitState: [ZwpPointerGesturePinchV1: PointerGestureData] => PointerGesturesState); -delegate_dispatch!(WinitState: [ZwpPointerGestureHoldV1: PointerGestureData] => PointerGesturesState); diff --git a/winit-wayland/src/seat/pointer/relative_pointer.rs b/winit-wayland/src/seat/pointer/relative_pointer.rs index c130d57398..00ba0a1952 100644 --- a/winit-wayland/src/seat/pointer/relative_pointer.rs +++ b/winit-wayland/src/seat/pointer/relative_pointer.rs @@ -2,9 +2,9 @@ use std::ops::Deref; +use sctk::reexports::client::Dispatch; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::{Connection, QueueHandle}; -use sctk::reexports::client::{Dispatch, delegate_dispatch}; use sctk::reexports::protocols::wp::relative_pointer::zv1::{ client::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1, client::zwp_relative_pointer_v1::{self, ZwpRelativePointerV1}, @@ -27,7 +27,7 @@ impl RelativePointerState { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let manager = globals.bind(queue_handle, 1..=1, GlobalData)?; + let manager = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?; Ok(Self { manager }) } } @@ -40,24 +40,24 @@ impl Deref for RelativePointerState { } } -impl Dispatch for RelativePointerState { +impl Dispatch for GlobalData { fn event( + &self, _state: &mut WinitState, _proxy: &ZwpRelativePointerManagerV1, _event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { } } -impl Dispatch for RelativePointerState { +impl Dispatch for GlobalData { fn event( + &self, state: &mut WinitState, _proxy: &ZwpRelativePointerV1, event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { @@ -72,6 +72,3 @@ impl Dispatch for RelativePointerS .push_device_event(DeviceEvent::PointerMotion { delta: (dx_unaccel, dy_unaccel) }); } } - -delegate_dispatch!(WinitState: [ZwpRelativePointerV1: GlobalData] => RelativePointerState); -delegate_dispatch!(WinitState: [ZwpRelativePointerManagerV1: GlobalData] => RelativePointerState); diff --git a/winit-wayland/src/seat/text_input/mod.rs b/winit-wayland/src/seat/text_input/mod.rs index 60ee711d01..b0d6152c60 100644 --- a/winit-wayland/src/seat/text_input/mod.rs +++ b/winit-wayland/src/seat/text_input/mod.rs @@ -4,7 +4,7 @@ use dpi::{LogicalPosition, LogicalSize}; use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; +use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle}; use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_manager_v3::ZwpTextInputManagerV3; use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::{ ContentHint, ContentPurpose, Event as TextInputEvent, ZwpTextInputV3, @@ -27,7 +27,7 @@ impl TextInputState { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let text_input_manager = globals.bind(queue_handle, 1..=1, GlobalData)?; + let text_input_manager = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?; Ok(Self { text_input_manager }) } } @@ -40,29 +40,29 @@ impl Deref for TextInputState { } } -impl Dispatch for TextInputState { +impl Dispatch for GlobalData { fn event( + &self, _state: &mut WinitState, _proxy: &ZwpTextInputManagerV3, _event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { } } -impl Dispatch for TextInputState { +impl Dispatch for TextInputData { fn event( + &self, state: &mut WinitState, text_input: &ZwpTextInputV3, event: ::Event, - data: &TextInputData, _conn: &Connection, _qhandle: &QueueHandle, ) { let windows = state.windows.get_mut(); - let mut text_input_data = data.inner.lock().unwrap(); + let mut text_input_data = self.inner.lock().unwrap(); match event { TextInputEvent::Enter { surface } => { let window_id = crate::make_wid(&surface); @@ -462,6 +462,3 @@ impl Default for ContentType { ContentType { purpose: ContentPurpose::Normal, hint: ContentHint::None } } } - -delegate_dispatch!(WinitState: [ZwpTextInputManagerV3: GlobalData] => TextInputState); -delegate_dispatch!(WinitState: [ZwpTextInputV3: TextInputData] => TextInputState); diff --git a/winit-wayland/src/state.rs b/winit-wayland/src/state.rs index 3380db4864..8ed568d542 100644 --- a/winit-wayland/src/state.rs +++ b/winit-wayland/src/state.rs @@ -8,11 +8,10 @@ use sctk::data_device_manager::DataDeviceManagerState; use sctk::output::{OutputHandler, OutputState}; use sctk::reexports::calloop::LoopHandle; use sctk::reexports::client::backend::ObjectId; -use sctk::reexports::client::globals::GlobalList; +use sctk::reexports::client::globals::{GlobalList, GlobalListHandler}; use sctk::reexports::client::protocol::wl_output::WlOutput; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{Connection, Proxy, QueueHandle}; -use sctk::registry::{ProvidesRegistryState, RegistryState}; use sctk::seat::SeatState; use sctk::seat::pointer::ThemedPointer; use sctk::shell::WaylandSurface; @@ -44,9 +43,6 @@ use crate::window::handles::WindowRequests; /// Winit's Wayland state. #[derive(Debug)] pub struct WinitState { - /// The WlRegistry. - pub registry_state: RegistryState, - /// The state of the WlOutput handling. pub output_state: OutputState, @@ -146,7 +142,6 @@ impl WinitState { queue_handle: &QueueHandle, loop_handle: LoopHandle<'static, WinitState>, ) -> Result { - let registry_state = RegistryState::new(globals); let compositor_state = CompositorState::bind(globals, queue_handle).map_err(|err| os_error!(err))?; let subcompositor_state = match SubcompositorState::bind( @@ -193,7 +188,6 @@ impl WinitState { let image_pool = Arc::new(Mutex::new(SlotPool::new(2, &shm).unwrap())); Ok(Self { - registry_state, compositor_state: Arc::new(compositor_state), subcompositor_state: subcompositor_state.map(Arc::new), output_state, @@ -490,12 +484,8 @@ impl CompositorHandler for WinitState { } } -impl ProvidesRegistryState for WinitState { +impl GlobalListHandler for WinitState { sctk::registry_handlers![OutputState, SeatState]; - - fn registry(&mut self) -> &mut RegistryState { - &mut self.registry_state - } } // The window update coming from the compositor. @@ -519,6 +509,3 @@ impl WindowCompositorUpdate { Self { window_id, resized: false, scale_changed: false, close_window: false } } } - -sctk::delegate_dispatch2!(WinitState); -sctk::delegate_registry!(WinitState); diff --git a/winit-wayland/src/types/ext_background_effect.rs b/winit-wayland/src/types/ext_background_effect.rs index 6ef1e27c43..490f411081 100644 --- a/winit-wayland/src/types/ext_background_effect.rs +++ b/winit-wayland/src/types/ext_background_effect.rs @@ -1,7 +1,7 @@ use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; +use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle}; use wayland_protocols::ext::background_effect::v1::client::ext_background_effect_manager_v1::ExtBackgroundEffectManagerV1; use wayland_protocols::ext::background_effect::v1::client::ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1; @@ -17,7 +17,7 @@ impl ExtBackgroundEffectManager { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let manager = globals.bind(queue_handle, 1..=1, GlobalData)?; + let manager = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?; Ok(Self { manager }) } @@ -30,30 +30,27 @@ impl ExtBackgroundEffectManager { } } -impl Dispatch for ExtBackgroundEffectManager { +impl Dispatch for GlobalData { fn event( + &self, _: &mut WinitState, _: &ExtBackgroundEffectManagerV1, _: ::Event, - _: &GlobalData, _: &Connection, _: &QueueHandle, ) { } } -impl Dispatch for ExtBackgroundEffectManager { +impl Dispatch for () { fn event( + &self, _: &mut WinitState, _: &ExtBackgroundEffectSurfaceV1, _: ::Event, - _: &(), _: &Connection, _: &QueueHandle, ) { // There is no event } } - -delegate_dispatch!(WinitState: [ExtBackgroundEffectManagerV1: GlobalData] => ExtBackgroundEffectManager); -delegate_dispatch!(WinitState: [ExtBackgroundEffectSurfaceV1: ()] => ExtBackgroundEffectManager); diff --git a/winit-wayland/src/types/kwin_blur.rs b/winit-wayland/src/types/kwin_blur.rs index 29ef5d68e2..39798bbb1c 100644 --- a/winit-wayland/src/types/kwin_blur.rs +++ b/winit-wayland/src/types/kwin_blur.rs @@ -3,7 +3,7 @@ use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; +use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle}; use wayland_protocols_plasma::blur::client::org_kde_kwin_blur::OrgKdeKwinBlur; use wayland_protocols_plasma::blur::client::org_kde_kwin_blur_manager::OrgKdeKwinBlurManager; @@ -20,7 +20,7 @@ impl KWinBlurManager { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let manager = globals.bind(queue_handle, 1..=1, GlobalData)?; + let manager = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?; Ok(Self { manager }) } @@ -37,12 +37,12 @@ impl KWinBlurManager { } } -impl Dispatch for KWinBlurManager { +impl Dispatch for GlobalData { fn event( + &self, _: &mut WinitState, _: &OrgKdeKwinBlurManager, _: ::Event, - _: &GlobalData, _: &Connection, _: &QueueHandle, ) { @@ -50,18 +50,15 @@ impl Dispatch for KWinBlurManager } } -impl Dispatch for KWinBlurManager { +impl Dispatch for () { fn event( + &self, _: &mut WinitState, _: &OrgKdeKwinBlur, _: ::Event, - _: &(), _: &Connection, _: &QueueHandle, ) { unreachable!("no events defined for org_kde_kwin_blur"); } } - -delegate_dispatch!(WinitState: [OrgKdeKwinBlurManager: GlobalData] => KWinBlurManager); -delegate_dispatch!(WinitState: [OrgKdeKwinBlur: ()] => KWinBlurManager); diff --git a/winit-wayland/src/types/wp_fractional_scaling.rs b/winit-wayland/src/types/wp_fractional_scaling.rs index 13c0aef960..639da4bd66 100644 --- a/winit-wayland/src/types/wp_fractional_scaling.rs +++ b/winit-wayland/src/types/wp_fractional_scaling.rs @@ -3,7 +3,7 @@ use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; +use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle}; use sctk::reexports::protocols::wp::fractional_scale::v1::client::wp_fractional_scale_manager_v1::WpFractionalScaleManagerV1; use sctk::reexports::protocols::wp::fractional_scale::v1::client::wp_fractional_scale_v1::{ Event as FractionalScalingEvent, WpFractionalScaleV1, @@ -31,7 +31,7 @@ impl FractionalScalingManager { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let manager = globals.bind(queue_handle, 1..=1, GlobalData)?; + let manager = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?; Ok(Self { manager }) } @@ -45,12 +45,12 @@ impl FractionalScalingManager { } } -impl Dispatch for FractionalScalingManager { +impl Dispatch for GlobalData { fn event( + &self, _: &mut WinitState, _: &WpFractionalScaleManagerV1, _: ::Event, - _: &GlobalData, _: &Connection, _: &QueueHandle, ) { @@ -58,20 +58,17 @@ impl Dispatch for Fractional } } -impl Dispatch for FractionalScalingManager { +impl Dispatch for FractionalScaling { fn event( + &self, state: &mut WinitState, _: &WpFractionalScaleV1, event: ::Event, - data: &FractionalScaling, _: &Connection, _: &QueueHandle, ) { if let FractionalScalingEvent::PreferredScale { scale } = event { - state.scale_factor_changed(&data.surface, scale as f64 / SCALE_DENOMINATOR, false); + state.scale_factor_changed(&self.surface, scale as f64 / SCALE_DENOMINATOR, false); } } } - -delegate_dispatch!(WinitState: [WpFractionalScaleManagerV1: GlobalData] => FractionalScalingManager); -delegate_dispatch!(WinitState: [WpFractionalScaleV1: FractionalScaling] => FractionalScalingManager); diff --git a/winit-wayland/src/types/wp_tablet_input_v2.rs b/winit-wayland/src/types/wp_tablet_input_v2.rs index 1b02ddbd38..a7d3606470 100644 --- a/winit-wayland/src/types/wp_tablet_input_v2.rs +++ b/winit-wayland/src/types/wp_tablet_input_v2.rs @@ -4,12 +4,11 @@ use std::sync::Mutex; use dpi::LogicalPosition; use sctk::compositor::SurfaceData; -use sctk::dispatch2::Dispatch2; use sctk::reexports::client::backend::smallvec::SmallVec; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_seat::WlSeat; use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::client::{Connection, Proxy, QueueHandle, WEnum, event_created_child}; +use sctk::reexports::client::{Connection, Proxy, QueueHandle, 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_pad_v2::ZwpTabletPadV2; use sctk::reexports::protocols::wp::tablet::zv2::client::zwp_tablet_seat_v2::{ @@ -19,6 +18,7 @@ use sctk::reexports::protocols::wp::tablet::zv2::client::zwp_tablet_tool_v2::{ ButtonState, Event as ToolEvent, Type as ToolType, ZwpTabletToolV2, }; use sctk::reexports::protocols::wp::tablet::zv2::client::zwp_tablet_v2::ZwpTabletV2; +use wayland_client::Dispatch; use wayland_protocols::wp::tablet::zv2::client::zwp_tablet_pad_dial_v2::ZwpTabletPadDialV2; use wayland_protocols::wp::tablet::zv2::client::zwp_tablet_pad_group_v2::{ self, ZwpTabletPadGroupV2, @@ -45,7 +45,7 @@ impl TabletManager { queue_handle: &QueueHandle, ) -> Result { // Ignore v2 since we are not interested in its events. - let manager = globals.bind(queue_handle, 1..=1, ())?; + let manager = globals.bind_singleton(queue_handle, 1..=1, ())?; Ok(Self { manager }) } @@ -57,7 +57,7 @@ impl TabletManager { self.manager.get_tablet_seat(seat, queue_handle, ()) } } -impl Dispatch2 for () { +impl Dispatch for () { fn event( &self, _: &mut WinitState, @@ -70,7 +70,7 @@ impl Dispatch2 for () { } } -impl Dispatch2 for () { +impl Dispatch for () { event_created_child!(WinitState, ZwpTabletSeatV2, [ zwp_tablet_seat_v2::EVT_TABLET_ADDED_OPCODE => (ZwpTabletV2, ()), zwp_tablet_seat_v2::EVT_TOOL_ADDED_OPCODE => (ZwpTabletToolV2, TabletToolData::default()), @@ -88,7 +88,7 @@ impl Dispatch2 for () { } } -impl Dispatch2 for TabletToolData { +impl Dispatch for TabletToolData { fn event( &self, state: &mut WinitState, @@ -100,7 +100,7 @@ impl Dispatch2 for TabletToolData { let mut data = self.inner.lock().unwrap(); match event { - ToolEvent::Type { tool_type: WEnum::Value(tool_type) } => { + ToolEvent::Type { tool_type } => { data.ty = match tool_type { ToolType::Pen => TabletToolKind::Pen, ToolType::Eraser => TabletToolKind::Eraser, @@ -150,7 +150,7 @@ impl Dispatch2 for TabletToolData { ToolEvent::Rotation { degrees } => { data.tool_state.twist = Some(degrees as u16); }, - ToolEvent::Button { serial, button, state: WEnum::Value(state) } => { + ToolEvent::Button { serial, button, state } => { let state = match state { ButtonState::Released => ElementState::Released, ButtonState::Pressed => ElementState::Pressed, @@ -304,7 +304,7 @@ pub(crate) enum TabletEvent { Button { button: TabletToolButton, state: ElementState, serial: Option }, } -impl Dispatch2 for () { +impl Dispatch for () { fn event( &self, _: &mut WinitState, @@ -316,7 +316,7 @@ impl Dispatch2 for () { } } -impl Dispatch2 for () { +impl Dispatch for () { event_created_child!(WinitState, ZwpTabletPadV2, [ zwp_tablet_pad_v2::EVT_GROUP_OPCODE => (ZwpTabletPadGroupV2, ()), ]); @@ -332,7 +332,7 @@ impl Dispatch2 for () { } } -impl Dispatch2 for () { +impl Dispatch for () { event_created_child!(WinitState, ZwpTabletPadGroupV2, [ zwp_tablet_pad_group_v2::EVT_RING_OPCODE => (ZwpTabletPadRingV2, ()), zwp_tablet_pad_group_v2::EVT_STRIP_OPCODE => (ZwpTabletPadStripV2, ()), @@ -350,7 +350,7 @@ impl Dispatch2 for () { } } -impl Dispatch2 for () { +impl Dispatch for () { fn event( &self, _: &mut WinitState, @@ -362,7 +362,7 @@ impl Dispatch2 for () { } } -impl Dispatch2 for () { +impl Dispatch for () { fn event( &self, _: &mut WinitState, @@ -374,7 +374,7 @@ impl Dispatch2 for () { } } -impl Dispatch2 for () { +impl Dispatch for () { fn event( &self, _: &mut WinitState, diff --git a/winit-wayland/src/types/wp_viewporter.rs b/winit-wayland/src/types/wp_viewporter.rs index 4bfa46469f..9100321940 100644 --- a/winit-wayland/src/types/wp_viewporter.rs +++ b/winit-wayland/src/types/wp_viewporter.rs @@ -3,7 +3,7 @@ use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; +use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle}; use sctk::reexports::protocols::wp::viewporter::client::wp_viewport::WpViewport; use sctk::reexports::protocols::wp::viewporter::client::wp_viewporter::WpViewporter; @@ -21,7 +21,7 @@ impl ViewporterState { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let viewporter = globals.bind(queue_handle, 1..=1, GlobalData)?; + let viewporter = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?; Ok(Self { viewporter }) } @@ -35,30 +35,27 @@ impl ViewporterState { } } -impl Dispatch for ViewporterState { +impl Dispatch for GlobalData { fn event( + &self, _: &mut WinitState, _: &WpViewporter, _: ::Event, - _: &GlobalData, _: &Connection, _: &QueueHandle, ) { // No events. } } -impl Dispatch for ViewporterState { +impl Dispatch for GlobalData { fn event( + &self, _: &mut WinitState, _: &WpViewport, _: ::Event, - _: &GlobalData, _: &Connection, _: &QueueHandle, ) { // No events. } } - -delegate_dispatch!(WinitState: [WpViewporter: GlobalData] => ViewporterState); -delegate_dispatch!(WinitState: [WpViewport: GlobalData] => ViewporterState); diff --git a/winit-wayland/src/types/xdg_activation.rs b/winit-wayland/src/types/xdg_activation.rs index 7c2cbd5fa4..dfd09e8e34 100644 --- a/winit-wayland/src/types/xdg_activation.rs +++ b/winit-wayland/src/types/xdg_activation.rs @@ -6,7 +6,7 @@ use std::sync::atomic::AtomicBool; use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; +use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle}; use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_token_v1::{ Event as ActivationTokenEvent, XdgActivationTokenV1, }; @@ -26,7 +26,7 @@ impl XdgActivationState { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let xdg_activation = globals.bind(queue_handle, 1..=1, GlobalData)?; + let xdg_activation = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?; Ok(Self { xdg_activation }) } @@ -35,24 +35,24 @@ impl XdgActivationState { } } -impl Dispatch for XdgActivationState { +impl Dispatch for GlobalData { fn event( + &self, _state: &mut WinitState, _proxy: &XdgActivationV1, _event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { } } -impl Dispatch for XdgActivationState { +impl Dispatch for XdgActivationTokenData { fn event( + &self, state: &mut WinitState, proxy: &XdgActivationTokenV1, event: ::Event, - data: &XdgActivationTokenData, _: &Connection, _: &QueueHandle, ) { @@ -67,7 +67,7 @@ impl Dispatch for XdgA .expect("got xdg_activation event without global.") .global(); - match data { + match self { XdgActivationTokenData::Attention((surface, fence)) => { global.activate(token, surface); // Mark that no request attention is in process. @@ -97,6 +97,3 @@ pub enum XdgActivationTokenData { /// Get a token to be passed outside of the winit. Obtain((WindowId, AsyncRequestSerial)), } - -delegate_dispatch!(WinitState: [ XdgActivationV1: GlobalData] => XdgActivationState); -delegate_dispatch!(WinitState: [ XdgActivationTokenV1: XdgActivationTokenData] => XdgActivationState); diff --git a/winit-wayland/src/types/xdg_toplevel_icon_manager.rs b/winit-wayland/src/types/xdg_toplevel_icon_manager.rs index c898e07e40..52f8050d96 100644 --- a/winit-wayland/src/types/xdg_toplevel_icon_manager.rs +++ b/winit-wayland/src/types/xdg_toplevel_icon_manager.rs @@ -7,7 +7,7 @@ use sctk::globals::GlobalData; use sctk::shm::slot::{Buffer, SlotPool}; use wayland_client::globals::{BindError, GlobalList}; use wayland_client::protocol::wl_shm::Format; -use wayland_client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; +use wayland_client::{Connection, Dispatch, Proxy, QueueHandle}; use wayland_protocols::xdg::toplevel_icon::v1::client::xdg_toplevel_icon_manager_v1::XdgToplevelIconManagerV1; use wayland_protocols::xdg::toplevel_icon::v1::client::xdg_toplevel_icon_v1::XdgToplevelIconV1; use winit_core::icon::{Icon, RgbaIcon}; @@ -69,7 +69,7 @@ impl XdgToplevelIconManagerState { globals: &GlobalList, queue_handle: &QueueHandle, ) -> Result { - let xdg_toplevel_icon_manager = globals.bind(queue_handle, 1..=1, GlobalData)?; + let xdg_toplevel_icon_manager = globals.bind_singleton(queue_handle, 1..=1, GlobalData)?; Ok(Self { xdg_toplevel_icon_manager }) } @@ -78,12 +78,12 @@ impl XdgToplevelIconManagerState { } } -impl Dispatch for XdgToplevelIconManagerState { +impl Dispatch for GlobalData { fn event( + &self, _state: &mut WinitState, _proxy: &XdgToplevelIconManagerV1, _event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { @@ -91,18 +91,15 @@ impl Dispatch for XdgToplevelI } } -impl Dispatch for XdgToplevelIconManagerState { +impl Dispatch for GlobalData { fn event( + &self, _state: &mut WinitState, _proxy: &XdgToplevelIconV1, _event: ::Event, - _data: &GlobalData, _conn: &Connection, _qhandle: &QueueHandle, ) { // No events. } } - -delegate_dispatch!(WinitState: [XdgToplevelIconManagerV1: GlobalData] => XdgToplevelIconManagerState); -delegate_dispatch!(WinitState: [XdgToplevelIconV1: GlobalData] => XdgToplevelIconManagerState); diff --git a/winit-wayland/src/window/mod.rs b/winit-wayland/src/window/mod.rs index 32e40835f2..848344715b 100644 --- a/winit-wayland/src/window/mod.rs +++ b/winit-wayland/src/window/mod.rs @@ -230,7 +230,7 @@ impl Window { } pub(crate) fn xdg_toplevel(&self) -> Option> { - NonNull::new(self.window.xdg_toplevel().id().as_ptr().cast()) + Some(self.window.xdg_toplevel().id().as_ptr().ok()?.cast()) } } @@ -268,8 +268,7 @@ impl Drop for Window { impl rwh_06::HasWindowHandle for Window { fn window_handle(&self) -> Result, rwh_06::HandleError> { let raw = rwh_06::WaylandWindowHandle::new({ - let ptr = self.window.wl_surface().id().as_ptr(); - std::ptr::NonNull::new(ptr as *mut _).expect("wl_surface will never be null") + self.window.wl_surface().id().as_ptr().expect("wl_surface will never be null").cast() }); unsafe { Ok(rwh_06::WindowHandle::borrow_raw(raw.into())) } @@ -279,8 +278,7 @@ impl rwh_06::HasWindowHandle for Window { impl rwh_06::HasDisplayHandle for Window { fn display_handle(&self) -> Result, rwh_06::HandleError> { let raw = rwh_06::WaylandDisplayHandle::new({ - let ptr = self.display.id().as_ptr(); - std::ptr::NonNull::new(ptr as *mut _).expect("wl_proxy should never be null") + self.display.id().as_ptr().expect("wl_proxy should never be null").cast() }); unsafe { Ok(rwh_06::DisplayHandle::borrow_raw(raw.into())) }