Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
6 changes: 4 additions & 2 deletions winit-wayland/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 1 addition & 2 deletions winit-wayland/src/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) })
Expand Down
2 changes: 1 addition & 1 deletion winit-wayland/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 9 additions & 4 deletions winit-wayland/src/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,14 @@ impl rwh_06::HasWindowHandle for Popup {
fn window_handle(&self) -> Result<rwh_06::WindowHandle<'_>, 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())) }
Expand All @@ -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())) }
Expand Down
45 changes: 19 additions & 26 deletions winit-wayland/src/seat/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -19,16 +19,16 @@ use crate::WindowId;
use crate::event_loop::sink::EventSink;
use crate::state::WinitState;

impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
impl Dispatch<WlKeyboard, WinitState> for KeyboardData {
fn event(
&self,
state: &mut WinitState,
wl_keyboard: &WlKeyboard,
event: <WlKeyboard as Proxy>::Event,
data: &KeyboardData,
_: &Connection,
_: &QueueHandle<WinitState>,
) {
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");
Expand All @@ -45,19 +45,14 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> 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);
Expand All @@ -67,7 +62,7 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> 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,
Expand All @@ -79,7 +74,7 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> 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 {
Expand Down Expand Up @@ -109,15 +104,15 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> 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,
};

// 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.
Expand All @@ -129,15 +124,15 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> 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));
let key = key + 8;
key_input(
keyboard_state,
&mut state.events_sink,
data,
self,
key,
ElementState::Pressed,
key_state == WlKeyState::Repeated,
Expand Down Expand Up @@ -205,16 +200,14 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> 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,
Expand Down Expand Up @@ -243,7 +236,7 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> 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;
Expand Down
19 changes: 7 additions & 12 deletions winit-wayland/src/seat/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -415,7 +414,7 @@ impl PointerConstraintsState {
globals: &GlobalList,
queue_handle: &QueueHandle<WinitState>,
) -> Result<Self, BindError> {
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 })
}
}
Expand All @@ -428,42 +427,38 @@ impl Deref for PointerConstraintsState {
}
}

impl Dispatch<ZwpPointerConstraintsV1, GlobalData, WinitState> for PointerConstraintsState {
impl Dispatch<ZwpPointerConstraintsV1, WinitState> for GlobalData {
fn event(
&self,
_state: &mut WinitState,
_proxy: &ZwpPointerConstraintsV1,
_event: <ZwpPointerConstraintsV1 as wayland_client::Proxy>::Event,
_data: &GlobalData,
_conn: &Connection,
_qhandle: &QueueHandle<WinitState>,
) {
}
}

impl Dispatch<ZwpLockedPointerV1, GlobalData, WinitState> for PointerConstraintsState {
impl Dispatch<ZwpLockedPointerV1, WinitState> for GlobalData {
fn event(
&self,
_state: &mut WinitState,
_proxy: &ZwpLockedPointerV1,
_event: <ZwpLockedPointerV1 as wayland_client::Proxy>::Event,
_data: &GlobalData,
_conn: &Connection,
_qhandle: &QueueHandle<WinitState>,
) {
}
}

impl Dispatch<ZwpConfinedPointerV1, GlobalData, WinitState> for PointerConstraintsState {
impl Dispatch<ZwpConfinedPointerV1, WinitState> for GlobalData {
fn event(
&self,
_state: &mut WinitState,
_proxy: &ZwpConfinedPointerV1,
_event: <ZwpConfinedPointerV1 as wayland_client::Proxy>::Event,
_data: &GlobalData,
_conn: &Connection,
_qhandle: &QueueHandle<WinitState>,
) {
}
}

delegate_dispatch!(WinitState: [ZwpPointerConstraintsV1: GlobalData] => PointerConstraintsState);
delegate_dispatch!(WinitState: [ZwpLockedPointerV1: GlobalData] => PointerConstraintsState);
delegate_dispatch!(WinitState: [ZwpConfinedPointerV1: GlobalData] => PointerConstraintsState);
24 changes: 10 additions & 14 deletions winit-wayland/src/seat/pointer/pointer_gesture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -30,7 +30,7 @@ impl PointerGesturesState {
globals: &GlobalList,
queue_handle: &QueueHandle<WinitState>,
) -> Result<Self, BindError> {
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 })
}
}
Expand Down Expand Up @@ -60,29 +60,29 @@ impl Deref for PointerGesturesState {
}
}

impl Dispatch<ZwpPointerGesturesV1, GlobalData, WinitState> for PointerGesturesState {
impl Dispatch<ZwpPointerGesturesV1, WinitState> for GlobalData {
fn event(
&self,
_state: &mut WinitState,
_proxy: &ZwpPointerGesturesV1,
_event: <ZwpPointerGesturesV1 as wayland_client::Proxy>::Event,
_data: &GlobalData,
_conn: &Connection,
_qhandle: &QueueHandle<WinitState>,
) {
unreachable!("zwp_pointer_gestures_v1 has no events")
}
}

impl Dispatch<ZwpPointerGestureHoldV1, PointerGestureData, WinitState> for PointerGesturesState {
impl Dispatch<ZwpPointerGestureHoldV1, WinitState> for PointerGestureData {
fn event(
&self,
state: &mut WinitState,
_proxy: &ZwpPointerGestureHoldV1,
event: <ZwpPointerGestureHoldV1 as wayland_client::Proxy>::Event,
data: &PointerGestureData,
_conn: &Connection,
_qhandle: &QueueHandle<WinitState>,
) {
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 {
Expand Down Expand Up @@ -116,16 +116,16 @@ impl Dispatch<ZwpPointerGestureHoldV1, PointerGestureData, WinitState> for Point
}
}

impl Dispatch<ZwpPointerGesturePinchV1, PointerGestureData, WinitState> for PointerGesturesState {
impl Dispatch<ZwpPointerGesturePinchV1, WinitState> for PointerGestureData {
fn event(
&self,
state: &mut WinitState,
_proxy: &ZwpPointerGesturePinchV1,
event: <ZwpPointerGesturePinchV1 as Proxy>::Event,
data: &PointerGestureData,
_conn: &Connection,
_qhandle: &QueueHandle<WinitState>,
) {
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.
Expand Down Expand Up @@ -200,7 +200,3 @@ impl Dispatch<ZwpPointerGesturePinchV1, PointerGestureData, WinitState> for Poin
);
}
}

delegate_dispatch!(WinitState: [ZwpPointerGesturesV1: GlobalData] => PointerGesturesState);
delegate_dispatch!(WinitState: [ZwpPointerGesturePinchV1: PointerGestureData] => PointerGesturesState);
delegate_dispatch!(WinitState: [ZwpPointerGestureHoldV1: PointerGestureData] => PointerGesturesState);
Loading
Loading