Skip to main content

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