simple_window/common/protocols_data/wayland/
wl_compositor.rs

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