gdk4_wayland/
wayland_surface.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#[cfg(feature = "wayland_crate")]
4#[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
5use glib::translate::*;
6#[cfg(feature = "wayland_crate")]
7#[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
8use wayland_client::{backend::ObjectId, protocol::wl_surface::WlSurface, Proxy};
9
10#[cfg(feature = "wayland_crate")]
11use crate::ffi;
12use crate::{prelude::*, WaylandSurface};
13
14mod sealed {
15    pub trait Sealed {}
16    impl<T: super::IsA<super::WaylandSurface>> Sealed for T {}
17}
18
19// rustdoc-stripper-ignore-next
20/// Trait containing manually implemented methods of
21/// [`WaylandSurface`](crate::WaylandSurface).
22pub trait WaylandSurfaceExtManual: sealed::Sealed + IsA<WaylandSurface> + 'static {
23    /// Returns the Wayland `wl_surface` of a [`gdk::Surface`][crate::gdk::Surface].
24    ///
25    /// # Returns
26    ///
27    /// a Wayland `wl_surface`
28    #[doc(alias = "gdk_wayland_surface_get_wl_surface")]
29    #[doc(alias = "get_wl_surface")]
30    #[cfg(feature = "wayland_crate")]
31    #[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
32    fn wl_surface(&self) -> Option<WlSurface> {
33        let display = self
34            .as_ref()
35            .display()
36            .downcast::<crate::WaylandDisplay>()
37            .unwrap();
38        unsafe {
39            let surface_ptr =
40                ffi::gdk_wayland_surface_get_wl_surface(self.as_ref().to_glib_none().0);
41            if surface_ptr.is_null() {
42                None
43            } else {
44                let cnx = display.connection();
45                let id = ObjectId::from_ptr(WlSurface::interface(), surface_ptr as *mut _).unwrap();
46
47                WlSurface::from_id(&cnx, id).ok()
48            }
49        }
50    }
51}
52
53impl<O: IsA<WaylandSurface>> WaylandSurfaceExtManual for O {}