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