Skip to main content

get_registry/common/protocols/wayland/
wl_subcompositor.rs

1//! sub-surface compositing
2//!
3//! The global interface exposing sub-surface compositing capabilities.
4//! A wl_surface, that has sub-surfaces associated, is called the
5//! parent surface. Sub-surfaces can be arbitrarily nested and create
6//! a tree of sub-surfaces.
7//!
8//! The root surface in a tree of sub-surfaces is the main
9//! surface. The main surface cannot be a sub-surface, because
10//! sub-surfaces must always have a parent.
11//!
12//! A main surface with its sub-surfaces forms a (compound) window.
13//! For window management purposes, this set of wl_surface objects is
14//! to be considered as a single window, and it should also behave as
15//! such.
16//!
17//! The aim of sub-surfaces is to offload some of the compositing work
18//! within a window from clients to the compositor. A prime example is
19//! a video player with decorations and video in separate wl_surface
20//! objects. This should allow the compositor to pass YUV video buffer
21//! processing to dedicated overlay hardware when possible.
22
23use super::super::all_types::*;
24use ::wl_client::builder::prelude::*;
25
26static INTERFACE: wl_interface = wl_interface {
27    name: c"wl_subcompositor".as_ptr(),
28    version: 1,
29    method_count: 2,
30    methods: {
31        static MESSAGES: [wl_message; 2] = [
32            wl_message {
33                name: c"destroy".as_ptr(),
34                signature: c"".as_ptr(),
35                types: {
36                    static TYPES: [Option<&'static wl_interface>; 0] = [];
37                    TYPES.as_ptr().cast()
38                },
39            },
40            wl_message {
41                name: c"get_subsurface".as_ptr(),
42                signature: c"noo".as_ptr(),
43                types: {
44                    static TYPES: [Option<&'static wl_interface>; 3] = [
45                        Some(WlSubsurface::WL_INTERFACE),
46                        Some(WlSurface::WL_INTERFACE),
47                        Some(WlSurface::WL_INTERFACE),
48                    ];
49                    TYPES.as_ptr().cast()
50                },
51            },
52        ];
53        MESSAGES.as_ptr()
54    },
55    event_count: 0,
56    events: ptr::null(),
57};
58
59/// An owned wl_subcompositor proxy.
60///
61/// See the documentation of [the module][self] for the interface description.
62#[derive(Clone, Eq, PartialEq)]
63#[repr(transparent)]
64pub struct WlSubcompositor {
65    /// This proxy has the interface INTERFACE.
66    proxy: UntypedOwnedProxy,
67}
68
69/// A borrowed wl_subcompositor proxy.
70///
71/// See the documentation of [the module][self] for the interface description.
72#[derive(Eq, PartialEq)]
73#[repr(transparent)]
74pub struct WlSubcompositorRef {
75    /// This proxy has the interface INTERFACE.
76    proxy: UntypedBorrowedProxy,
77}
78
79// SAFETY: WlSubcompositor is a transparent wrapper around UntypedOwnedProxy
80unsafe impl UntypedOwnedProxyWrapper for WlSubcompositor {}
81
82// SAFETY: - INTERFACE is a valid wl_interface
83//         - The only invariant is that self.proxy has a compatible interface
84unsafe impl OwnedProxy for WlSubcompositor {
85    const INTERFACE: &'static str = "wl_subcompositor";
86    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
87    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
88        private::EventHandler(private::NoOpEventHandler);
89    const MAX_VERSION: u32 = 1;
90
91    type Borrowed = WlSubcompositorRef;
92    type Api = private::ProxyApi;
93    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
94}
95
96// SAFETY: WlSubcompositorRef is a transparent wrapper around UntypedBorrowedProxy
97unsafe impl UntypedBorrowedProxyWrapper for WlSubcompositorRef {}
98
99// SAFETY: - The only invariant is that self.proxy has a compatible interface
100unsafe impl BorrowedProxy for WlSubcompositorRef {
101    type Owned = WlSubcompositor;
102}
103
104impl Deref for WlSubcompositor {
105    type Target = WlSubcompositorRef;
106
107    fn deref(&self) -> &Self::Target {
108        proxy::low_level::deref(self)
109    }
110}
111
112mod private {
113    pub struct ProxyApi;
114
115    #[allow(dead_code)]
116    pub struct EventHandler<H>(pub(super) H);
117
118    #[allow(dead_code)]
119    pub struct NoOpEventHandler;
120}
121
122impl Debug for WlSubcompositor {
123    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
124        write!(f, "wl_subcompositor#{}", self.proxy.id())
125    }
126}
127
128impl Debug for WlSubcompositorRef {
129    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
130        write!(f, "wl_subcompositor#{}", self.proxy.id())
131    }
132}
133
134impl PartialEq<WlSubcompositorRef> for WlSubcompositor {
135    fn eq(&self, other: &WlSubcompositorRef) -> bool {
136        self.proxy == other.proxy
137    }
138}
139
140impl PartialEq<WlSubcompositor> for WlSubcompositorRef {
141    fn eq(&self, other: &WlSubcompositor) -> bool {
142        self.proxy == other.proxy
143    }
144}
145
146#[allow(dead_code)]
147impl WlSubcompositor {
148    /// Since when the destroy request is available.
149    #[allow(dead_code)]
150    pub const REQ__DESTROY__SINCE: u32 = 1;
151
152    /// Since when the get_subsurface request is available.
153    #[allow(dead_code)]
154    pub const REQ__GET_SUBSURFACE__SINCE: u32 = 1;
155}
156
157#[allow(dead_code)]
158impl WlSubcompositor {
159    /// unbind from the subcompositor interface
160    ///
161    /// Informs the server that the client will not be using this
162    /// protocol object anymore. This does not affect any other
163    /// objects, wl_subsurface objects included.
164    #[inline]
165    pub fn destroy(&self) {
166        let mut args = [];
167        // SAFETY: - self.proxy has the interface INTERFACE
168        //         - 0 < INTERFACE.method_count = 2
169        //         - the request signature is ``
170        unsafe {
171            self.proxy.send_destructor(0, &mut args);
172        }
173    }
174
175    /// give a surface the role sub-surface
176    ///
177    /// Create a sub-surface interface for the given surface, and
178    /// associate it with the given parent surface. This turns a
179    /// plain wl_surface into a sub-surface.
180    ///
181    /// The to-be sub-surface must not already have another role, and it
182    /// must not have an existing wl_subsurface object. Otherwise the
183    /// bad_surface protocol error is raised.
184    ///
185    /// Adding sub-surfaces to a parent is a double-buffered operation on the
186    /// parent (see wl_surface.commit). The effect of adding a sub-surface
187    /// becomes visible on the next time the state of the parent surface is
188    /// applied.
189    ///
190    /// The parent surface must not be one of the child surface's descendants,
191    /// and the parent must be different from the child surface, otherwise the
192    /// bad_parent protocol error is raised.
193    ///
194    /// This request modifies the behaviour of wl_surface.commit request on
195    /// the sub-surface, see the documentation on wl_subsurface interface.
196    ///
197    /// # Arguments
198    ///
199    /// - `surface`: the surface to be turned into a sub-surface
200    /// - `parent`: the parent surface
201    #[inline]
202    pub fn get_subsurface(&self, surface: &WlSurfaceRef, parent: &WlSurfaceRef) -> WlSubsurface {
203        let (arg1, arg2) = (surface, parent);
204        let obj1_lock = proxy::lock(arg1);
205        let obj1 = check_argument_proxy("surface", obj1_lock.wl_proxy());
206        let obj2_lock = proxy::lock(arg2);
207        let obj2 = check_argument_proxy("parent", obj2_lock.wl_proxy());
208        let mut args = [
209            wl_argument { n: 0 },
210            wl_argument { o: obj1 },
211            wl_argument { o: obj2 },
212        ];
213        // SAFETY: - self.proxy has the interface INTERFACE
214        //         - 1 < INTERFACE.method_count = 2
215        //         - the request signature is `noo`
216        //         - OwnedProxy::WL_INTERFACE is always a valid interface
217        let data = unsafe {
218            self.proxy
219                .send_constructor::<false>(1, &mut args, WlSubsurface::WL_INTERFACE, None)
220        };
221        // SAFETY: data has the interface WlSubsurface::WL_INTERFACE
222        unsafe { proxy::low_level::from_untyped_owned(data) }
223    }
224}
225
226#[allow(dead_code)]
227impl WlSubcompositorRef {
228    /// give a surface the role sub-surface
229    ///
230    /// Create a sub-surface interface for the given surface, and
231    /// associate it with the given parent surface. This turns a
232    /// plain wl_surface into a sub-surface.
233    ///
234    /// The to-be sub-surface must not already have another role, and it
235    /// must not have an existing wl_subsurface object. Otherwise the
236    /// bad_surface protocol error is raised.
237    ///
238    /// Adding sub-surfaces to a parent is a double-buffered operation on the
239    /// parent (see wl_surface.commit). The effect of adding a sub-surface
240    /// becomes visible on the next time the state of the parent surface is
241    /// applied.
242    ///
243    /// The parent surface must not be one of the child surface's descendants,
244    /// and the parent must be different from the child surface, otherwise the
245    /// bad_parent protocol error is raised.
246    ///
247    /// This request modifies the behaviour of wl_surface.commit request on
248    /// the sub-surface, see the documentation on wl_subsurface interface.
249    ///
250    /// # Arguments
251    ///
252    /// - `_queue`: The queue that the returned proxy is assigned to.
253    /// - `surface`: the surface to be turned into a sub-surface
254    /// - `parent`: the parent surface
255    #[inline]
256    pub fn get_subsurface(
257        &self,
258        _queue: &Queue,
259        surface: &WlSurfaceRef,
260        parent: &WlSurfaceRef,
261    ) -> WlSubsurface {
262        let (arg1, arg2) = (surface, parent);
263        let obj1_lock = proxy::lock(arg1);
264        let obj1 = check_argument_proxy("surface", obj1_lock.wl_proxy());
265        let obj2_lock = proxy::lock(arg2);
266        let obj2 = check_argument_proxy("parent", obj2_lock.wl_proxy());
267        let mut args = [
268            wl_argument { n: 0 },
269            wl_argument { o: obj1 },
270            wl_argument { o: obj2 },
271        ];
272        // SAFETY: - self.proxy has the interface INTERFACE
273        //         - 1 < INTERFACE.method_count = 2
274        //         - the request signature is `noo`
275        //         - OwnedProxy::WL_INTERFACE is always a valid interface
276        let data = unsafe {
277            self.proxy
278                .send_constructor(_queue, 1, &mut args, WlSubsurface::WL_INTERFACE, None)
279        };
280        // SAFETY: data has the interface WlSubsurface::WL_INTERFACE
281        unsafe { proxy::low_level::from_untyped_owned(data) }
282    }
283}
284
285/// An event handler for [WlSubcompositor] proxies.
286#[allow(dead_code)]
287pub trait WlSubcompositorEventHandler {}
288
289impl WlSubcompositorEventHandler for private::NoOpEventHandler {}
290
291// SAFETY: - INTERFACE is a valid wl_interface
292unsafe impl<H> EventHandler for private::EventHandler<H>
293where
294    H: WlSubcompositorEventHandler,
295{
296    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
297
298    #[allow(unused_variables)]
299    unsafe fn handle_event(
300        &self,
301        queue: &Queue,
302        data: *mut u8,
303        slf: &UntypedBorrowedProxy,
304        opcode: u32,
305        args: *mut wl_argument,
306    ) {
307        invalid_opcode("wl_subcompositor", opcode);
308    }
309}
310
311impl<H> CreateEventHandler<H> for private::ProxyApi
312where
313    H: WlSubcompositorEventHandler,
314{
315    type EventHandler = private::EventHandler<H>;
316
317    #[inline]
318    fn create_event_handler(handler: H) -> Self::EventHandler {
319        private::EventHandler(handler)
320    }
321}
322
323impl WlSubcompositor {
324    /// Since when the error.bad_surface enum variant is available.
325    #[allow(dead_code)]
326    pub const ENM__ERROR_BAD_SURFACE__SINCE: u32 = 1;
327    /// Since when the error.bad_parent enum variant is available.
328    #[allow(dead_code)]
329    pub const ENM__ERROR_BAD_PARENT__SINCE: u32 = 1;
330}
331
332#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
333#[allow(dead_code)]
334pub struct WlSubcompositorError(pub u32);
335
336impl WlSubcompositorError {
337    /// the to-be sub-surface is invalid
338    #[allow(dead_code)]
339    pub const BAD_SURFACE: Self = Self(0);
340
341    /// the to-be sub-surface parent is invalid
342    #[allow(dead_code)]
343    pub const BAD_PARENT: Self = Self(1);
344}
345
346impl Debug for WlSubcompositorError {
347    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
348        let name = match *self {
349            Self::BAD_SURFACE => "BAD_SURFACE",
350            Self::BAD_PARENT => "BAD_PARENT",
351            _ => return Debug::fmt(&self.0, f),
352        };
353        f.write_str(name)
354    }
355}
356
357/// Functional event handlers.
358pub mod event_handlers {
359    use super::*;
360
361    impl WlSubcompositor {}
362}