simple_window/common/protocols_data/viewporter/
wp_viewporter.rs

1//! surface cropping and scaling
2//!
3//! The global interface exposing surface cropping and scaling
4//! capabilities is used to instantiate an interface extension for a
5//! wl_surface object. This extended interface will then allow
6//! cropping and scaling the surface contents, effectively
7//! disconnecting the direct relationship between the buffer and the
8//! surface size.
9
10use {super::super::all_types::*, ::wl_client::builder::prelude::*};
11
12static INTERFACE: wl_interface = wl_interface {
13    name: c"wp_viewporter".as_ptr(),
14    version: 1,
15    method_count: 2,
16    methods: {
17        static MESSAGES: [wl_message; 2] = [
18            wl_message {
19                name: c"destroy".as_ptr(),
20                signature: c"".as_ptr(),
21                types: {
22                    static TYPES: [Option<&'static wl_interface>; 0] = [];
23                    TYPES.as_ptr().cast()
24                },
25            },
26            wl_message {
27                name: c"get_viewport".as_ptr(),
28                signature: c"no".as_ptr(),
29                types: {
30                    static TYPES: [Option<&'static wl_interface>; 2] = [
31                        Some(WpViewport::WL_INTERFACE),
32                        Some(WlSurface::WL_INTERFACE),
33                    ];
34                    TYPES.as_ptr().cast()
35                },
36            },
37        ];
38        MESSAGES.as_ptr()
39    },
40    event_count: 0,
41    events: ptr::null(),
42};
43
44/// An owned wp_viewporter proxy.
45///
46/// See the documentation of [the module][self] for the interface description.
47#[derive(Clone, Eq, PartialEq)]
48#[repr(transparent)]
49pub struct WpViewporter {
50    /// This proxy has the interface INTERFACE.
51    proxy: UntypedOwnedProxy,
52}
53
54/// A borrowed wp_viewporter proxy.
55///
56/// See the documentation of [the module][self] for the interface description.
57#[derive(Eq, PartialEq)]
58#[repr(transparent)]
59pub struct WpViewporterRef {
60    /// This proxy has the interface INTERFACE.
61    proxy: UntypedBorrowedProxy,
62}
63
64// SAFETY: WpViewporter is a transparent wrapper around UntypedOwnedProxy
65unsafe impl UntypedOwnedProxyWrapper for WpViewporter {}
66
67// SAFETY: - INTERFACE is a valid wl_interface
68//         - The only invariant is that self.proxy has a compatible interface
69unsafe impl OwnedProxy for WpViewporter {
70    const INTERFACE: &'static str = "wp_viewporter";
71    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
72    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
73        private::EventHandler(private::NoOpEventHandler);
74    const MAX_VERSION: u32 = 1;
75
76    type Borrowed = WpViewporterRef;
77    type Api = private::ProxyApi;
78    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
79}
80
81// SAFETY: WpViewporterRef is a transparent wrapper around UntypedBorrowedProxy
82unsafe impl UntypedBorrowedProxyWrapper for WpViewporterRef {}
83
84// SAFETY: - The only invariant is that self.proxy has a compatible interface
85unsafe impl BorrowedProxy for WpViewporterRef {
86    type Owned = WpViewporter;
87}
88
89impl Deref for WpViewporter {
90    type Target = WpViewporterRef;
91
92    fn deref(&self) -> &Self::Target {
93        proxy::low_level::deref(self)
94    }
95}
96
97mod private {
98    pub struct ProxyApi;
99
100    #[allow(dead_code)]
101    pub struct EventHandler<H>(pub(super) H);
102
103    #[allow(dead_code)]
104    pub struct NoOpEventHandler;
105}
106
107impl Debug for WpViewporter {
108    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
109        write!(f, "wp_viewporter#{}", self.proxy.id())
110    }
111}
112
113impl Debug for WpViewporterRef {
114    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
115        write!(f, "wp_viewporter#{}", self.proxy.id())
116    }
117}
118
119impl PartialEq<WpViewporterRef> for WpViewporter {
120    fn eq(&self, other: &WpViewporterRef) -> bool {
121        self.proxy == other.proxy
122    }
123}
124
125impl PartialEq<WpViewporter> for WpViewporterRef {
126    fn eq(&self, other: &WpViewporter) -> bool {
127        self.proxy == other.proxy
128    }
129}
130
131#[allow(dead_code)]
132impl WpViewporter {
133    /// Since when the destroy request is available.
134    #[allow(dead_code)]
135    pub const REQ__DESTROY__SINCE: u32 = 1;
136
137    /// unbind from the cropping and scaling interface
138    ///
139    /// Informs the server that the client will not be using this
140    /// protocol object anymore. This does not affect any other objects,
141    /// wp_viewport objects included.
142    #[inline]
143    pub fn destroy(&self) {
144        let mut args = [];
145        // SAFETY: - self.proxy has the interface INTERFACE
146        //         - 0 < INTERFACE.method_count = 2
147        //         - the request signature is ``
148        unsafe {
149            self.proxy.send_destructor(0, &mut args);
150        }
151    }
152
153    /// Since when the get_viewport request is available.
154    #[allow(dead_code)]
155    pub const REQ__GET_VIEWPORT__SINCE: u32 = 1;
156
157    /// extend surface interface for crop and scale
158    ///
159    /// Instantiate an interface extension for the given wl_surface to
160    /// crop and scale its content. If the given wl_surface already has
161    /// a wp_viewport object associated, the viewport_exists
162    /// protocol error is raised.
163    ///
164    /// # Arguments
165    ///
166    /// - `surface`: the surface
167    #[inline]
168    pub fn get_viewport(&self, surface: &WlSurfaceRef) -> WpViewport {
169        let (arg1,) = (surface,);
170        let obj1_lock = proxy::lock(arg1);
171        let obj1 = check_argument_proxy("surface", obj1_lock.wl_proxy());
172        let mut args = [wl_argument { n: 0 }, wl_argument { o: obj1 }];
173        // SAFETY: - self.proxy has the interface INTERFACE
174        //         - 1 < INTERFACE.method_count = 2
175        //         - the request signature is `no`
176        //         - OwnedProxy::WL_INTERFACE is always a valid interface
177        let data = unsafe {
178            self.proxy
179                .send_constructor::<false>(1, &mut args, WpViewport::WL_INTERFACE, None)
180        };
181        // SAFETY: data has the interface WpViewport::WL_INTERFACE
182        unsafe { proxy::low_level::from_untyped_owned(data) }
183    }
184}
185
186#[allow(dead_code)]
187impl WpViewporterRef {
188    /// extend surface interface for crop and scale
189    ///
190    /// Instantiate an interface extension for the given wl_surface to
191    /// crop and scale its content. If the given wl_surface already has
192    /// a wp_viewport object associated, the viewport_exists
193    /// protocol error is raised.
194    ///
195    /// # Arguments
196    ///
197    /// - `_queue`: The queue that the returned proxy is assigned to.
198    /// - `surface`: the surface
199    #[inline]
200    pub fn get_viewport(&self, _queue: &Queue, surface: &WlSurfaceRef) -> WpViewport {
201        let (arg1,) = (surface,);
202        let obj1_lock = proxy::lock(arg1);
203        let obj1 = check_argument_proxy("surface", obj1_lock.wl_proxy());
204        let mut args = [wl_argument { n: 0 }, wl_argument { o: obj1 }];
205        // SAFETY: - self.proxy has the interface INTERFACE
206        //         - 1 < INTERFACE.method_count = 2
207        //         - the request signature is `no`
208        //         - OwnedProxy::WL_INTERFACE is always a valid interface
209        let data = unsafe {
210            self.proxy
211                .send_constructor(_queue, 1, &mut args, WpViewport::WL_INTERFACE, None)
212        };
213        // SAFETY: data has the interface WpViewport::WL_INTERFACE
214        unsafe { proxy::low_level::from_untyped_owned(data) }
215    }
216}
217
218/// An event handler for [WpViewporter] proxies.
219#[allow(dead_code)]
220pub trait WpViewporterEventHandler {
221    type Data: 'static;
222}
223
224impl WpViewporterEventHandler for private::NoOpEventHandler {
225    type Data = ();
226}
227
228// SAFETY: - INTERFACE is a valid wl_interface
229//         - mutable_type always returns the same value
230unsafe impl<H> EventHandler for private::EventHandler<H>
231where
232    H: WpViewporterEventHandler,
233{
234    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
235
236    #[inline]
237    fn mutable_type() -> Option<(TypeId, &'static str)> {
238        let id = TypeId::of::<H::Data>();
239        let name = std::any::type_name::<H::Data>();
240        Some((id, name))
241    }
242
243    #[allow(unused_variables)]
244    unsafe fn handle_event(
245        &self,
246        queue: &Queue,
247        data: *mut u8,
248        slf: &UntypedBorrowedProxy,
249        opcode: u32,
250        args: *mut wl_argument,
251    ) {
252        invalid_opcode("wp_viewporter", opcode);
253    }
254}
255
256impl<H> CreateEventHandler<H> for private::ProxyApi
257where
258    H: WpViewporterEventHandler,
259{
260    type EventHandler = private::EventHandler<H>;
261
262    #[inline]
263    fn create_event_handler(handler: H) -> Self::EventHandler {
264        private::EventHandler(handler)
265    }
266}
267
268impl WpViewporter {
269    /// Since when the error.viewport_exists enum variant is available.
270    #[allow(dead_code)]
271    pub const ENM__ERROR_VIEWPORT_EXISTS__SINCE: u32 = 1;
272}
273
274#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
275#[allow(dead_code)]
276pub struct WpViewporterError(pub u32);
277
278impl WpViewporterError {
279    /// the surface already has a viewport object associated
280    #[allow(dead_code)]
281    pub const VIEWPORT_EXISTS: Self = Self(0);
282}
283
284impl Debug for WpViewporterError {
285    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
286        let name = match *self {
287            Self::VIEWPORT_EXISTS => "VIEWPORT_EXISTS",
288            _ => return Debug::fmt(&self.0, f),
289        };
290        f.write_str(name)
291    }
292}
293
294/// Functional event handlers.
295pub mod event_handlers {
296    use super::*;
297
298    impl WpViewporter {}
299}