Skip to main content

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