simple_window/common/protocols_data/wayland/
wl_shell.rs

1//! create desktop-style surfaces
2//!
3//! This interface is implemented by servers that provide
4//! desktop-style user interfaces.
5//!
6//! It allows clients to associate a wl_shell_surface with
7//! a basic surface.
8//!
9//! Note! This protocol is deprecated and not intended for production use.
10//! For desktop-style user interfaces, use xdg_shell. Compositors and clients
11//! should not implement this interface.
12
13use {super::super::all_types::*, ::wl_client::builder::prelude::*};
14
15static INTERFACE: wl_interface = wl_interface {
16    name: c"wl_shell".as_ptr(),
17    version: 1,
18    method_count: 1,
19    methods: {
20        static MESSAGES: [wl_message; 1] = [wl_message {
21            name: c"get_shell_surface".as_ptr(),
22            signature: c"no".as_ptr(),
23            types: {
24                static TYPES: [Option<&'static wl_interface>; 2] = [
25                    Some(WlShellSurface::WL_INTERFACE),
26                    Some(WlSurface::WL_INTERFACE),
27                ];
28                TYPES.as_ptr().cast()
29            },
30        }];
31        MESSAGES.as_ptr()
32    },
33    event_count: 0,
34    events: ptr::null(),
35};
36
37/// An owned wl_shell proxy.
38///
39/// See the documentation of [the module][self] for the interface description.
40#[derive(Clone, Eq, PartialEq)]
41#[repr(transparent)]
42pub struct WlShell {
43    /// This proxy has the interface INTERFACE.
44    proxy: UntypedOwnedProxy,
45}
46
47/// A borrowed wl_shell proxy.
48///
49/// See the documentation of [the module][self] for the interface description.
50#[derive(Eq, PartialEq)]
51#[repr(transparent)]
52pub struct WlShellRef {
53    /// This proxy has the interface INTERFACE.
54    proxy: UntypedBorrowedProxy,
55}
56
57// SAFETY: WlShell is a transparent wrapper around UntypedOwnedProxy
58unsafe impl UntypedOwnedProxyWrapper for WlShell {}
59
60// SAFETY: - INTERFACE is a valid wl_interface
61//         - The only invariant is that self.proxy has a compatible interface
62unsafe impl OwnedProxy for WlShell {
63    const INTERFACE: &'static str = "wl_shell";
64    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
65    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
66        private::EventHandler(private::NoOpEventHandler);
67    const MAX_VERSION: u32 = 1;
68
69    type Borrowed = WlShellRef;
70    type Api = private::ProxyApi;
71    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
72}
73
74// SAFETY: WlShellRef is a transparent wrapper around UntypedBorrowedProxy
75unsafe impl UntypedBorrowedProxyWrapper for WlShellRef {}
76
77// SAFETY: - The only invariant is that self.proxy has a compatible interface
78unsafe impl BorrowedProxy for WlShellRef {
79    type Owned = WlShell;
80}
81
82impl Deref for WlShell {
83    type Target = WlShellRef;
84
85    fn deref(&self) -> &Self::Target {
86        proxy::low_level::deref(self)
87    }
88}
89
90mod private {
91    pub struct ProxyApi;
92
93    #[allow(dead_code)]
94    pub struct EventHandler<H>(pub(super) H);
95
96    #[allow(dead_code)]
97    pub struct NoOpEventHandler;
98}
99
100impl Debug for WlShell {
101    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
102        write!(f, "wl_shell#{}", self.proxy.id())
103    }
104}
105
106impl Debug for WlShellRef {
107    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
108        write!(f, "wl_shell#{}", self.proxy.id())
109    }
110}
111
112impl PartialEq<WlShellRef> for WlShell {
113    fn eq(&self, other: &WlShellRef) -> bool {
114        self.proxy == other.proxy
115    }
116}
117
118impl PartialEq<WlShell> for WlShellRef {
119    fn eq(&self, other: &WlShell) -> bool {
120        self.proxy == other.proxy
121    }
122}
123
124#[allow(dead_code)]
125impl WlShell {
126    /// Since when the get_shell_surface request is available.
127    #[allow(dead_code)]
128    pub const REQ__GET_SHELL_SURFACE__SINCE: u32 = 1;
129
130    /// create a shell surface from a surface
131    ///
132    /// Create a shell surface for an existing surface. This gives
133    /// the wl_surface the role of a shell surface. If the wl_surface
134    /// already has another role, it raises a protocol error.
135    ///
136    /// Only one shell surface can be associated with a given surface.
137    ///
138    /// # Arguments
139    ///
140    /// - `surface`: surface to be given the shell surface role
141    #[inline]
142    pub fn get_shell_surface(&self, surface: &WlSurfaceRef) -> WlShellSurface {
143        let (arg1,) = (surface,);
144        let obj1_lock = proxy::lock(arg1);
145        let obj1 = check_argument_proxy("surface", obj1_lock.wl_proxy());
146        let mut args = [wl_argument { n: 0 }, wl_argument { o: obj1 }];
147        // SAFETY: - self.proxy has the interface INTERFACE
148        //         - 0 < INTERFACE.method_count = 1
149        //         - the request signature is `no`
150        //         - OwnedProxy::WL_INTERFACE is always a valid interface
151        let data = unsafe {
152            self.proxy
153                .send_constructor::<false>(0, &mut args, WlShellSurface::WL_INTERFACE, None)
154        };
155        // SAFETY: data has the interface WlShellSurface::WL_INTERFACE
156        unsafe { proxy::low_level::from_untyped_owned(data) }
157    }
158}
159
160#[allow(dead_code)]
161impl WlShellRef {
162    /// create a shell surface from a surface
163    ///
164    /// Create a shell surface for an existing surface. This gives
165    /// the wl_surface the role of a shell surface. If the wl_surface
166    /// already has another role, it raises a protocol error.
167    ///
168    /// Only one shell surface can be associated with a given surface.
169    ///
170    /// # Arguments
171    ///
172    /// - `_queue`: The queue that the returned proxy is assigned to.
173    /// - `surface`: surface to be given the shell surface role
174    #[inline]
175    pub fn get_shell_surface(&self, _queue: &Queue, surface: &WlSurfaceRef) -> WlShellSurface {
176        let (arg1,) = (surface,);
177        let obj1_lock = proxy::lock(arg1);
178        let obj1 = check_argument_proxy("surface", obj1_lock.wl_proxy());
179        let mut args = [wl_argument { n: 0 }, wl_argument { o: obj1 }];
180        // SAFETY: - self.proxy has the interface INTERFACE
181        //         - 0 < INTERFACE.method_count = 1
182        //         - the request signature is `no`
183        //         - OwnedProxy::WL_INTERFACE is always a valid interface
184        let data = unsafe {
185            self.proxy
186                .send_constructor(_queue, 0, &mut args, WlShellSurface::WL_INTERFACE, None)
187        };
188        // SAFETY: data has the interface WlShellSurface::WL_INTERFACE
189        unsafe { proxy::low_level::from_untyped_owned(data) }
190    }
191}
192
193/// An event handler for [WlShell] proxies.
194#[allow(dead_code)]
195pub trait WlShellEventHandler {
196    type Data: 'static;
197}
198
199impl WlShellEventHandler for private::NoOpEventHandler {
200    type Data = ();
201}
202
203// SAFETY: - INTERFACE is a valid wl_interface
204//         - mutable_type always returns the same value
205unsafe impl<H> EventHandler for private::EventHandler<H>
206where
207    H: WlShellEventHandler,
208{
209    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
210
211    #[inline]
212    fn mutable_type() -> Option<(TypeId, &'static str)> {
213        let id = TypeId::of::<H::Data>();
214        let name = std::any::type_name::<H::Data>();
215        Some((id, name))
216    }
217
218    #[allow(unused_variables)]
219    unsafe fn handle_event(
220        &self,
221        queue: &Queue,
222        data: *mut u8,
223        slf: &UntypedBorrowedProxy,
224        opcode: u32,
225        args: *mut wl_argument,
226    ) {
227        invalid_opcode("wl_shell", opcode);
228    }
229}
230
231impl<H> CreateEventHandler<H> for private::ProxyApi
232where
233    H: WlShellEventHandler,
234{
235    type EventHandler = private::EventHandler<H>;
236
237    #[inline]
238    fn create_event_handler(handler: H) -> Self::EventHandler {
239        private::EventHandler(handler)
240    }
241}
242
243impl WlShell {
244    /// Since when the error.role enum variant is available.
245    #[allow(dead_code)]
246    pub const ENM__ERROR_ROLE__SINCE: u32 = 1;
247}
248
249#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
250#[allow(dead_code)]
251pub struct WlShellError(pub u32);
252
253impl WlShellError {
254    /// given wl_surface has another role
255    #[allow(dead_code)]
256    pub const ROLE: Self = Self(0);
257}
258
259impl Debug for WlShellError {
260    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
261        let name = match *self {
262            Self::ROLE => "ROLE",
263            _ => return Debug::fmt(&self.0, f),
264        };
265        f.write_str(name)
266    }
267}
268
269/// Functional event handlers.
270pub mod event_handlers {
271    use super::*;
272
273    impl WlShell {}
274}