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 @@ -95,3 +95,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 @@ -34,10 +34,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.20.0", default-features = false, features = [
# sctk = { package = "smithay-client-toolkit", version = "0.20.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.11.0", default-features = false, optional = true }
#sctk-adwaita = { version = "0.11.0", default-features = false, optional = true }
sctk-adwaita = { git = "https://github.com/ids1024/sctk-adwaita", branch = "dispatch2", 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.11", 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 @@ -716,8 +716,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 @@ -146,7 +146,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))
}

/// The default routine does floor, but we need round on Wayland.
Expand Down
43 changes: 19 additions & 24 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,14 +124,14 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
state.events_sink.push_window_event(WindowEvent::Focused(false), window_id);
}
},
WlKeyboardEvent::Key { key, state: WEnum::Value(key_state), .. }
WlKeyboardEvent::Key { key, state: key_state, .. }
if matches!(key_state, WlKeyState::Repeated | WlKeyState::Pressed) =>
{
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 @@ -204,13 +199,13 @@ impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
})
.ok();
},
WlKeyboardEvent::Key { key, state: WEnum::Value(WlKeyState::Released), .. } => {
WlKeyboardEvent::Key { key, state: WlKeyState::Released, .. } => {
let key = key + 8;

key_input(
keyboard_state,
&mut state.events_sink,
data,
self,
key,
ElementState::Released,
false,
Expand Down Expand Up @@ -239,7 +234,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
8 changes: 3 additions & 5 deletions winit-wayland/src/seat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl SeatHandler for WinitState {
.as_ref()
.map(|state| state.get_viewport(&surface, queue_handle));
let surface_id = surface.id();
let pointer_data = WinitPointerData::new(seat.clone(), viewport);
let pointer_data = WinitPointerData::new(viewport);
let themed_pointer = self
.seat_state
.get_pointer_with_theme_and_data(
Expand Down Expand Up @@ -233,8 +233,8 @@ impl SeatHandler for WinitState {
let _ = self.pointer_surfaces.remove(&surface_id);

// Remove the inner locks/confines before dropping the pointer.
pointer_data.unlock_pointer();
pointer_data.unconfine_pointer();
pointer_data.data().unlock_pointer();
pointer_data.data().unconfine_pointer();

if pointer.pointer().version() >= 3 {
pointer.pointer().release();
Expand Down Expand Up @@ -281,5 +281,3 @@ impl WinitState {
}
}
}

sctk::delegate_seat!(WinitState);
Loading
Loading