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
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 = "dispatch2", 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.8", features = ["staging"] }
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 @@ -112,7 +112,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 @@ -217,8 +217,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 @@ -265,5 +265,3 @@ impl WinitState {
}
}
}

sctk::delegate_seat!(WinitState);
91 changes: 14 additions & 77 deletions winit-wayland/src/seat/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,27 @@ use tracing::warn;

use sctk::reexports::client::delegate_dispatch;
use sctk::reexports::client::protocol::wl_pointer::WlPointer;
use sctk::reexports::client::protocol::wl_seat::WlSeat;
use sctk::reexports::client::protocol::wl_surface::WlSurface;
use sctk::reexports::client::{Connection, Proxy, QueueHandle, Dispatch};
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_confined_pointer_v1::ZwpConfinedPointerV1;
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_locked_pointer_v1::ZwpLockedPointerV1;
use sctk::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::WpCursorShapeDeviceV1;
use sctk::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_manager_v1::WpCursorShapeManagerV1;
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_pointer_constraints_v1::{Lifetime, ZwpPointerConstraintsV1};
use sctk::reexports::client::globals::{BindError, GlobalList};
use sctk::reexports::csd_frame::FrameClick;
use sctk::reexports::protocols::wp::viewporter::client::wp_viewport::WpViewport;

use sctk::compositor::SurfaceData;
use sctk::globals::GlobalData;
use sctk::seat::pointer::{
PointerData, PointerDataExt, PointerEvent, PointerEventKind, PointerHandler,
};
use sctk::seat::SeatState;
use sctk::seat::pointer::{PointerData, PointerEvent, PointerEventKind, PointerHandler};

use dpi::{LogicalPosition, PhysicalPosition};
use winit_core::event::{
ElementState, MouseButton, MouseScrollDelta, PointerKind, PointerSource, TouchPhase,
WindowEvent, ButtonSource,
ButtonSource, ElementState, MouseButton, MouseScrollDelta, PointerKind, PointerSource,
TouchPhase, WindowEvent,
};

use crate::state::WinitState;
use crate::WindowId;
use crate::state::WinitState;

pub mod pointer_gesture;
pub mod relative_pointer;
Expand Down Expand Up @@ -68,7 +62,7 @@ impl PointerHandler for WinitState {
let surface = &event.surface;

// The parent surface.
let parent_surface = match event.surface.data::<SurfaceData>() {
let parent_surface = match event.surface.data::<SurfaceData<()>>() {
Some(data) => data.parent_surface().unwrap_or(surface),
None => continue,
};
Expand Down Expand Up @@ -140,13 +134,13 @@ impl PointerHandler for WinitState {
window.pointer_entered(Arc::downgrade(themed_pointer));

// Set the currently focused surface.
pointer.winit_data().inner.lock().unwrap().surface = Some(window_id);
pointer.winit_data().data().inner.lock().unwrap().surface = Some(window_id);
},
PointerEventKind::Leave { .. } => {
window.pointer_left(Arc::downgrade(themed_pointer));

// Remove the active surface.
pointer.winit_data().inner.lock().unwrap().surface = None;
pointer.winit_data().data().inner.lock().unwrap().surface = None;

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

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

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

/// The data required by the sctk.
sctk_data: PointerData,

/// Viewport for fractional cursor.
viewport: Option<WpViewport>,
}

impl WinitPointerData {
pub fn new(seat: WlSeat, viewport: Option<WpViewport>) -> Self {
Self {
inner: Mutex::new(WinitPointerDataInner::default()),
sctk_data: PointerData::new(seat),
viewport,
}
pub fn new(viewport: Option<WpViewport>) -> Self {
Self { inner: Mutex::new(WinitPointerDataInner::default()), viewport }
}

pub fn lock_pointer(
Expand Down Expand Up @@ -320,26 +307,11 @@ impl WinitPointerData {
}
}

/// Seat associated with this pointer.
pub fn seat(&self) -> &WlSeat {
self.sctk_data.seat()
}

/// Active window.
pub fn focused_window(&self) -> Option<WindowId> {
self.inner.lock().unwrap().surface
}

/// Last button serial.
pub fn latest_button_serial(&self) -> u32 {
self.sctk_data.latest_button_serial().unwrap_or_default()
}

/// Last enter serial.
pub fn latest_enter_serial(&self) -> u32 {
self.sctk_data.latest_enter_serial().unwrap_or_default()
}

pub fn set_locked_cursor_position(&self, surface_x: f64, surface_y: f64) {
let inner = self.inner.lock().unwrap();
if let Some(locked_pointer) = inner.locked_pointer.as_ref() {
Expand All @@ -360,12 +332,6 @@ impl Drop for WinitPointerData {
}
}

impl PointerDataExt for WinitPointerData {
fn pointer_data(&self) -> &PointerData {
&self.sctk_data
}
}

#[derive(Debug)]
pub struct WinitPointerDataInner {
/// The associated locked pointer.
Expand Down Expand Up @@ -423,12 +389,12 @@ fn wayland_button_to_winit(button: u32) -> ButtonSource {
}

pub trait WinitPointerDataExt {
fn winit_data(&self) -> &WinitPointerData;
fn winit_data(&self) -> &PointerData<WinitPointerData>;
}

impl WinitPointerDataExt for WlPointer {
fn winit_data(&self) -> &WinitPointerData {
self.data::<WinitPointerData>().expect("failed to get pointer data.")
fn winit_data(&self) -> &PointerData<WinitPointerData> {
self.data::<PointerData<WinitPointerData>>().expect("failed to get pointer data.")
}
}

Expand Down Expand Up @@ -491,35 +457,6 @@ impl Dispatch<ZwpConfinedPointerV1, GlobalData, WinitState> for PointerConstrain
}
}

impl Dispatch<WpCursorShapeDeviceV1, GlobalData, WinitState> for SeatState {
fn event(
_: &mut WinitState,
_: &WpCursorShapeDeviceV1,
_: <WpCursorShapeDeviceV1 as Proxy>::Event,
_: &GlobalData,
_: &Connection,
_: &QueueHandle<WinitState>,
) {
unreachable!("wp_cursor_shape_manager has no events")
}
}

impl Dispatch<WpCursorShapeManagerV1, GlobalData, WinitState> for SeatState {
fn event(
_: &mut WinitState,
_: &WpCursorShapeManagerV1,
_: <WpCursorShapeManagerV1 as Proxy>::Event,
_: &GlobalData,
_: &Connection,
_: &QueueHandle<WinitState>,
) {
unreachable!("wp_cursor_device_manager has no events")
}
}

delegate_dispatch!(WinitState: [ WlPointer: WinitPointerData] => SeatState);
delegate_dispatch!(WinitState: [ WpCursorShapeManagerV1: GlobalData] => SeatState);
delegate_dispatch!(WinitState: [ WpCursorShapeDeviceV1: GlobalData] => SeatState);
delegate_dispatch!(WinitState: [ZwpPointerConstraintsV1: GlobalData] => PointerConstraintsState);
delegate_dispatch!(WinitState: [ZwpLockedPointerV1: GlobalData] => PointerConstraintsState);
delegate_dispatch!(WinitState: [ZwpConfinedPointerV1: GlobalData] => PointerConstraintsState);
4 changes: 3 additions & 1 deletion winit-wayland/src/seat/pointer/pointer_gesture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ impl Dispatch<ZwpPointerGesturePinchV1, PointerGestureData, WinitState> for Poin
}

// Don't handle events from a subsurface.
if surface.data::<SurfaceData>().is_none_or(|data| data.parent_surface().is_some())
if surface
.data::<SurfaceData<()>>()
.is_none_or(|data| data.parent_surface().is_some())
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions winit-wayland/src/seat/pointer/relative_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
use std::ops::Deref;

use sctk::reexports::client::globals::{BindError, GlobalList};
use sctk::reexports::client::{delegate_dispatch, Dispatch};
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},
};

use sctk::globals::GlobalData;

use winit_core::event::DeviceEvent;
use crate::state::WinitState;
use winit_core::event::DeviceEvent;

/// Wrapper around the relative pointer.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion winit-wayland/src/seat/touch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub trait TouchDataExt {

impl TouchDataExt for WlTouch {
fn seat(&self) -> &WlSeat {
self.data::<TouchData>().expect("failed to get touch data.").seat()
self.data::<TouchData<()>>().expect("failed to get touch data.").seat()
}
}

Expand Down
9 changes: 2 additions & 7 deletions winit-wayland/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl WinitState {
self.window_compositor_updates[pos].scale_changed = true;
} else if let Some(pointer) = self.pointer_surfaces.get(&surface.id()) {
// Get the window, where the pointer resides right now.
let focused_window = match pointer.pointer().winit_data().focused_window() {
let focused_window = match pointer.pointer().winit_data().data().focused_window() {
Some(focused_window) => focused_window,
None => return,
};
Expand Down Expand Up @@ -445,10 +445,5 @@ impl WindowCompositorUpdate {
}
}

sctk::delegate_subcompositor!(WinitState);
sctk::delegate_compositor!(WinitState);
sctk::delegate_output!(WinitState);
sctk::delegate_dispatch2!(WinitState);
sctk::delegate_registry!(WinitState);
sctk::delegate_shm!(WinitState);
sctk::delegate_xdg_shell!(WinitState);
sctk::delegate_xdg_window!(WinitState);
Loading
Loading