Skip to main content

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