wl_client/test_protocols/core/
wl_surface.rs

1use {super::super::all_types::*, crate::builder::prelude::*};
2
3static INTERFACE: wl_interface = wl_interface {
4    name: c"wl_surface".as_ptr(),
5    version: 1,
6    method_count: 0,
7    methods: ptr::null(),
8    event_count: 0,
9    events: ptr::null(),
10};
11
12/// An owned wl_surface proxy.
13///
14/// See the documentation of [the module][self] for the interface description.
15#[derive(Clone, Eq, PartialEq)]
16#[repr(transparent)]
17pub struct WlSurface {
18    /// This proxy has the interface INTERFACE.
19    proxy: UntypedOwnedProxy,
20}
21
22/// A borrowed wl_surface proxy.
23///
24/// See the documentation of [the module][self] for the interface description.
25#[derive(Eq, PartialEq)]
26#[repr(transparent)]
27pub struct WlSurfaceRef {
28    /// This proxy has the interface INTERFACE.
29    proxy: UntypedBorrowedProxy,
30}
31
32// SAFETY: WlSurface is a transparent wrapper around UntypedOwnedProxy
33unsafe impl UntypedOwnedProxyWrapper for WlSurface {}
34
35// SAFETY: - INTERFACE is a valid wl_interface
36//         - The only invariant is that self.proxy has a compatible interface
37unsafe impl OwnedProxy for WlSurface {
38    const INTERFACE: &'static str = "wl_surface";
39    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
40    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
41        private::EventHandler(private::NoOpEventHandler);
42    const MAX_VERSION: u32 = 1;
43
44    type Borrowed = WlSurfaceRef;
45    type Api = private::ProxyApi;
46    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
47}
48
49// SAFETY: WlSurfaceRef is a transparent wrapper around UntypedBorrowedProxy
50unsafe impl UntypedBorrowedProxyWrapper for WlSurfaceRef {}
51
52// SAFETY: - The only invariant is that self.proxy has a compatible interface
53unsafe impl BorrowedProxy for WlSurfaceRef {
54    type Owned = WlSurface;
55}
56
57impl Deref for WlSurface {
58    type Target = WlSurfaceRef;
59
60    fn deref(&self) -> &Self::Target {
61        proxy::low_level::deref(self)
62    }
63}
64
65mod private {
66    pub struct ProxyApi;
67
68    #[allow(dead_code)]
69    pub struct EventHandler<H>(pub(super) H);
70
71    #[allow(dead_code)]
72    pub struct NoOpEventHandler;
73}
74
75impl Debug for WlSurface {
76    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
77        write!(f, "wl_surface#{}", self.proxy.id())
78    }
79}
80
81impl Debug for WlSurfaceRef {
82    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
83        write!(f, "wl_surface#{}", self.proxy.id())
84    }
85}
86
87impl PartialEq<WlSurfaceRef> for WlSurface {
88    fn eq(&self, other: &WlSurfaceRef) -> bool {
89        self.proxy == other.proxy
90    }
91}
92
93impl PartialEq<WlSurface> for WlSurfaceRef {
94    fn eq(&self, other: &WlSurface) -> bool {
95        self.proxy == other.proxy
96    }
97}
98
99/// An event handler for [WlSurface] proxies.
100#[allow(dead_code)]
101pub trait WlSurfaceEventHandler {}
102
103impl WlSurfaceEventHandler for private::NoOpEventHandler {}
104
105// SAFETY: INTERFACE is a valid wl_interface
106unsafe impl<H> EventHandler for private::EventHandler<H>
107where
108    H: WlSurfaceEventHandler,
109{
110    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
111
112    #[allow(unused_variables)]
113    unsafe fn handle_event(
114        &self,
115        queue: &Queue,
116        slf: &UntypedBorrowedProxy,
117        opcode: u32,
118        args: *mut wl_argument,
119    ) {
120        invalid_opcode("wl_surface", opcode);
121    }
122}
123
124impl<H> CreateEventHandler<H> for private::ProxyApi
125where
126    H: WlSurfaceEventHandler,
127{
128    type EventHandler = private::EventHandler<H>;
129
130    #[inline]
131    fn create_event_handler(handler: H) -> Self::EventHandler {
132        private::EventHandler(handler)
133    }
134}
135
136/// Functional event handlers.
137pub mod event_handlers {
138    use super::*;
139
140    impl WlSurface {}
141}