Skip to main content

smithay_client_toolkit/seat/pointer/
cursor_shape.rs

1use cursor_icon::CursorIcon;
2
3use crate::dispatch2::Dispatch2;
4use crate::globals::GlobalData;
5use crate::reexports::client::globals::{BindError, GlobalList};
6use crate::reexports::client::protocol::wl_pointer::WlPointer;
7use crate::reexports::client::{Connection, Dispatch, Proxy, QueueHandle};
8use crate::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::Shape;
9use crate::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::WpCursorShapeDeviceV1;
10use crate::reexports::protocols::wp::cursor_shape::v1::client::wp_cursor_shape_manager_v1::WpCursorShapeManagerV1;
11
12#[derive(Debug)]
13pub struct CursorShapeManager {
14    cursor_shape_manager: WpCursorShapeManagerV1,
15}
16
17impl CursorShapeManager {
18    pub fn bind<State>(
19        globals: &GlobalList,
20        queue_handle: &QueueHandle<State>,
21    ) -> Result<Self, BindError>
22    where
23        State: Dispatch<WpCursorShapeManagerV1, GlobalData> + 'static,
24    {
25        let cursor_shape_manager = globals.bind(queue_handle, 1..=2, GlobalData)?;
26        Ok(Self { cursor_shape_manager })
27    }
28
29    pub(crate) fn from_existing(cursor_shape_manager: WpCursorShapeManagerV1) -> Self {
30        Self { cursor_shape_manager }
31    }
32
33    pub fn get_shape_device<State>(
34        &self,
35        pointer: &WlPointer,
36        queue_handle: &QueueHandle<State>,
37    ) -> WpCursorShapeDeviceV1
38    where
39        State: Dispatch<WpCursorShapeDeviceV1, GlobalData> + 'static,
40    {
41        self.cursor_shape_manager.get_pointer(pointer, queue_handle, GlobalData)
42    }
43
44    pub fn inner(&self) -> &WpCursorShapeManagerV1 {
45        &self.cursor_shape_manager
46    }
47}
48
49impl<State> Dispatch2<WpCursorShapeManagerV1, State> for GlobalData {
50    fn event(
51        &self,
52        _: &mut State,
53        _: &WpCursorShapeManagerV1,
54        _: <WpCursorShapeManagerV1 as Proxy>::Event,
55        _: &Connection,
56        _: &QueueHandle<State>,
57    ) {
58        unreachable!("wl_cursor_shape_manager_v1 has no events")
59    }
60}
61
62impl<State> Dispatch2<WpCursorShapeDeviceV1, State> for GlobalData {
63    fn event(
64        &self,
65        _: &mut State,
66        _: &WpCursorShapeDeviceV1,
67        _: <WpCursorShapeDeviceV1 as Proxy>::Event,
68        _: &Connection,
69        _: &QueueHandle<State>,
70    ) {
71        unreachable!("wl_cursor_shape_device_v1 has no events")
72    }
73}
74
75pub(crate) fn cursor_icon_to_shape(cursor_icon: CursorIcon, version: u32) -> Shape {
76    match cursor_icon {
77        CursorIcon::Default => Shape::Default,
78        CursorIcon::ContextMenu => Shape::ContextMenu,
79        CursorIcon::Help => Shape::Help,
80        CursorIcon::Pointer => Shape::Pointer,
81        CursorIcon::Progress => Shape::Progress,
82        CursorIcon::Wait => Shape::Wait,
83        CursorIcon::Cell => Shape::Cell,
84        CursorIcon::Crosshair => Shape::Crosshair,
85        CursorIcon::Text => Shape::Text,
86        CursorIcon::VerticalText => Shape::VerticalText,
87        CursorIcon::Alias => Shape::Alias,
88        CursorIcon::Copy => Shape::Copy,
89        CursorIcon::Move => Shape::Move,
90        CursorIcon::NoDrop => Shape::NoDrop,
91        CursorIcon::NotAllowed => Shape::NotAllowed,
92        CursorIcon::Grab => Shape::Grab,
93        CursorIcon::Grabbing => Shape::Grabbing,
94        CursorIcon::EResize => Shape::EResize,
95        CursorIcon::NResize => Shape::NResize,
96        CursorIcon::NeResize => Shape::NeResize,
97        CursorIcon::NwResize => Shape::NwResize,
98        CursorIcon::SResize => Shape::SResize,
99        CursorIcon::SeResize => Shape::SeResize,
100        CursorIcon::SwResize => Shape::SwResize,
101        CursorIcon::WResize => Shape::WResize,
102        CursorIcon::EwResize => Shape::EwResize,
103        CursorIcon::NsResize => Shape::NsResize,
104        CursorIcon::NeswResize => Shape::NeswResize,
105        CursorIcon::NwseResize => Shape::NwseResize,
106        CursorIcon::ColResize => Shape::ColResize,
107        CursorIcon::RowResize => Shape::RowResize,
108        CursorIcon::AllScroll => Shape::AllScroll,
109        CursorIcon::ZoomIn => Shape::ZoomIn,
110        CursorIcon::ZoomOut => Shape::ZoomOut,
111        CursorIcon::DndAsk if version >= 2 => Shape::DndAsk,
112        CursorIcon::AllResize if version >= 2 => Shape::AllResize,
113        _ => Shape::Default,
114    }
115}