Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

- Make `DataDeviceManagerState`'s `create_{copy_paste,drag_and_drop}_source` accept `IntoIterator<Item = T: ToString>`.
- Add support for `zwp_primary_selection_v1`.
- `CursorShapeManager` providing handling for `cursor-shape-v1` protocol.
- `SeatState::get_pointer_with_theme` will now automatically use `wp_cursor_shape_v1` when available.

## 0.17.0 - 2023-03-28

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ thiserror = "1.0.30"
wayland-backend = "0.1.0"
wayland-client = "0.30.1"
wayland-cursor = "0.30.0"
wayland-protocols = { version = "0.30.0", features = ["client", "unstable"] }
wayland-protocols = { version = "0.30.1", features = ["client", "staging", "unstable"] }
wayland-protocols-wlr = { version = "0.1.0", features = ["client"] }
wayland-scanner = "0.30.0"
wayland-csd-frame = "0.1.0"
Expand Down
107 changes: 80 additions & 27 deletions src/seat/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#[cfg(feature = "xkbcommon")]
pub mod keyboard;
pub mod pointer;
pub mod pointer_constraints;
pub mod relative_pointer;
pub mod touch;

use std::{
fmt::{self, Display, Formatter},
sync::{
Expand All @@ -13,21 +6,29 @@ use std::{
},
};

use wayland_client::{
globals::GlobalList,
protocol::{wl_pointer, wl_seat, wl_shm, wl_surface, wl_touch},
use crate::reexports::client::{
globals::{Global, GlobalList},
protocol::{wl_pointer, wl_registry::WlRegistry, wl_seat, wl_shm, wl_surface, wl_touch},
Connection, Dispatch, Proxy, QueueHandle,
};

use crate::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::WpCursorShapeDeviceV1;
use crate::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_manager_v1::WpCursorShapeManagerV1;
use crate::{
compositor::SurfaceDataExt,
globals::GlobalData,
registry::{ProvidesRegistryState, RegistryHandler},
};

use self::{
pointer::{PointerData, PointerDataExt, PointerHandler, ThemeSpec, ThemedPointer, Themes},
touch::{TouchData, TouchDataExt, TouchHandler},
};
#[cfg(feature = "xkbcommon")]
pub mod keyboard;
pub mod pointer;
pub mod pointer_constraints;
pub mod relative_pointer;
pub mod touch;

use pointer::cursor_shape::CursorShapeManager;
use pointer::{PointerData, PointerDataExt, PointerHandler, ThemeSpec, ThemedPointer, Themes};
use touch::{TouchData, TouchDataExt, TouchHandler};

#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -64,25 +65,49 @@ pub enum SeatError {
pub struct SeatState {
// (name, seat)
seats: Vec<SeatInner>,
cursor_shape_manager_state: CursorShapeManagerState,
}

#[derive(Debug)]
enum CursorShapeManagerState {
NotPresent,
Pending { registry: WlRegistry, global: Global },
Bound(CursorShapeManager),
}

impl SeatState {
pub fn new<D: Dispatch<wl_seat::WlSeat, SeatData> + 'static>(
global_list: &GlobalList,
qh: &QueueHandle<D>,
) -> SeatState {
let seats = global_list.contents().with_list(|globals| {
crate::registry::bind_all(global_list.registry(), globals, qh, 1..=7, |id| SeatData {
has_keyboard: Arc::new(AtomicBool::new(false)),
has_pointer: Arc::new(AtomicBool::new(false)),
has_touch: Arc::new(AtomicBool::new(false)),
name: Arc::new(Mutex::new(None)),
id,
})
.expect("failed to bind global")
let (seats, cursor_shape_manager) = global_list.contents().with_list(|globals| {
let global = globals
.iter()
.find(|global| global.interface == WpCursorShapeManagerV1::interface().name)
.map(|global| CursorShapeManagerState::Pending {
registry: global_list.registry().clone(),
global: global.clone(),
})
.unwrap_or(CursorShapeManagerState::NotPresent);

(
crate::registry::bind_all(global_list.registry(), globals, qh, 1..=7, |id| {
SeatData {
has_keyboard: Arc::new(AtomicBool::new(false)),
has_pointer: Arc::new(AtomicBool::new(false)),
has_touch: Arc::new(AtomicBool::new(false)),
name: Arc::new(Mutex::new(None)),
id,
}
})
.expect("failed to bind global"),
global,
)
});

let mut state = SeatState { seats: vec![] };
let mut state =
SeatState { seats: vec![], cursor_shape_manager_state: cursor_shape_manager };

for seat in seats {
let data = seat.data::<SeatData>().unwrap().clone();

Expand Down Expand Up @@ -130,6 +155,8 @@ impl SeatState {

/// Creates a pointer from a seat with the provided theme.
///
/// This will use [`CursorShapeManager`] under the hood when it's available.
///
/// ## Errors
///
/// This will return [`SeatError::UnsupportedCapability`] if the seat does not support a pointer.
Expand All @@ -144,6 +171,8 @@ impl SeatState {
where
D: Dispatch<wl_pointer::WlPointer, PointerData>
+ Dispatch<wl_surface::WlSurface, S>
+ Dispatch<WpCursorShapeManagerV1, GlobalData>
+ Dispatch<WpCursorShapeDeviceV1, GlobalData>
+ PointerHandler
+ 'static,
S: SurfaceDataExt + 'static,
Expand Down Expand Up @@ -200,6 +229,8 @@ impl SeatState {
where
D: Dispatch<wl_pointer::WlPointer, U>
+ Dispatch<wl_surface::WlSurface, S>
+ Dispatch<WpCursorShapeManagerV1, GlobalData>
+ Dispatch<WpCursorShapeDeviceV1, GlobalData>
+ PointerHandler
+ 'static,
S: SurfaceDataExt + 'static,
Expand All @@ -213,11 +244,33 @@ impl SeatState {
}

let wl_ptr = seat.get_pointer(qh, pointer_data);

if let CursorShapeManagerState::Pending { registry, global } =
&self.cursor_shape_manager_state
{
self.cursor_shape_manager_state =
match crate::registry::bind_one(registry, &[global.clone()], qh, 1..=1, GlobalData)
{
Ok(bound) => {
CursorShapeManagerState::Bound(CursorShapeManager::from_existing(bound))
}
Err(_) => CursorShapeManagerState::NotPresent,
}
}

let shape_device =
if let CursorShapeManagerState::Bound(ref bound) = self.cursor_shape_manager_state {
Some(bound.get_shape_device(&wl_ptr, qh))
} else {
None
};

Ok(ThemedPointer {
themes: Arc::new(Mutex::new(Themes::new(theme))),
pointer: wl_ptr,
shm: shm.clone(),
surface,
shape_device,
_marker: std::marker::PhantomData,
_surface_data: std::marker::PhantomData,
})
Expand Down Expand Up @@ -458,7 +511,7 @@ where
interface: &str,
_: u32,
) {
if interface == "wl_seat" {
if interface == wl_seat::WlSeat::interface().name {
let seat = state
.registry()
.bind_specific(
Expand Down Expand Up @@ -489,7 +542,7 @@ where
name: u32,
interface: &str,
) {
if interface == "wl_seat" {
if interface == wl_seat::WlSeat::interface().name {
if let Some(seat) = state.seat_state().seats.iter().find(|inner| inner.data.id == name)
{
let seat = seat.seat.clone();
Expand Down
118 changes: 118 additions & 0 deletions src/seat/pointer/cursor_shape.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
use cursor_icon::CursorIcon;

use crate::globals::GlobalData;
use crate::reexports::client::globals::{BindError, GlobalList};
use crate::reexports::client::protocol::wl_pointer::WlPointer;
use crate::reexports::client::{Connection, Dispatch, Proxy, QueueHandle};
use crate::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::Shape;
use crate::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::WpCursorShapeDeviceV1;
use crate::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_manager_v1::WpCursorShapeManagerV1;

#[derive(Debug)]
pub struct CursorShapeManager {
cursor_shape_manager: WpCursorShapeManagerV1,
}

impl CursorShapeManager {
pub fn bind<State>(
globals: &GlobalList,
queue_handle: &QueueHandle<State>,
) -> Result<Self, BindError>
where
State: Dispatch<WpCursorShapeManagerV1, GlobalData> + 'static,
{
let cursor_shape_manager = globals.bind(queue_handle, 1..=1, GlobalData)?;
Ok(Self { cursor_shape_manager })
}

pub(crate) fn from_existing(cursor_shape_manager: WpCursorShapeManagerV1) -> Self {
Self { cursor_shape_manager }
}

pub fn get_shape_device<State>(
&self,
pointer: &WlPointer,
queue_handle: &QueueHandle<State>,
) -> WpCursorShapeDeviceV1
where
State: Dispatch<WpCursorShapeDeviceV1, GlobalData> + 'static,
{
self.cursor_shape_manager.get_pointer(pointer, queue_handle, GlobalData)
}

pub fn inner(&self) -> &WpCursorShapeManagerV1 {
&self.cursor_shape_manager
}
}

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

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

pub(crate) fn cursor_icon_to_shape(cursor_icon: CursorIcon) -> Shape {
match cursor_icon {
CursorIcon::Default => Shape::Default,
CursorIcon::ContextMenu => Shape::ContextMenu,
CursorIcon::Help => Shape::Help,
CursorIcon::Pointer => Shape::Pointer,
CursorIcon::Progress => Shape::Progress,
CursorIcon::Wait => Shape::Wait,
CursorIcon::Cell => Shape::Cell,
CursorIcon::Crosshair => Shape::Crosshair,
CursorIcon::Text => Shape::Text,
CursorIcon::VerticalText => Shape::VerticalText,
CursorIcon::Alias => Shape::Alias,
CursorIcon::Copy => Shape::Copy,
CursorIcon::Move => Shape::Move,
CursorIcon::NoDrop => Shape::NoDrop,
CursorIcon::NotAllowed => Shape::NotAllowed,
CursorIcon::Grab => Shape::Grab,
CursorIcon::Grabbing => Shape::Grabbing,
CursorIcon::EResize => Shape::EResize,
CursorIcon::NResize => Shape::NResize,
CursorIcon::NeResize => Shape::NeResize,
CursorIcon::NwResize => Shape::NwResize,
CursorIcon::SResize => Shape::SResize,
CursorIcon::SeResize => Shape::SeResize,
CursorIcon::SwResize => Shape::SwResize,
CursorIcon::WResize => Shape::WResize,
CursorIcon::EwResize => Shape::EwResize,
CursorIcon::NsResize => Shape::NsResize,
CursorIcon::NeswResize => Shape::NeswResize,
CursorIcon::NwseResize => Shape::NwseResize,
CursorIcon::ColResize => Shape::ColResize,
CursorIcon::RowResize => Shape::RowResize,
CursorIcon::AllScroll => Shape::AllScroll,
CursorIcon::ZoomIn => Shape::ZoomIn,
CursorIcon::ZoomOut => Shape::ZoomOut,
_ => Shape::Default,
}
}
Loading