Skip to main content

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