simple_window/common/protocols_data/wayland/
wl_region.rs

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