gdk4_wayland/
wayland_surface.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Take a look at the license at the top of the repository in the LICENSE file.

#[cfg(feature = "wayland_crate")]
#[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
use glib::translate::*;
#[cfg(feature = "wayland_crate")]
#[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
use wayland_client::{backend::ObjectId, protocol::wl_surface::WlSurface, Proxy};

#[cfg(feature = "wayland_crate")]
use crate::ffi;
use crate::{prelude::*, WaylandSurface};

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::WaylandSurface>> Sealed for T {}
}

// rustdoc-stripper-ignore-next
/// Trait containing manually implemented methods of
/// [`WaylandSurface`](crate::WaylandSurface).
pub trait WaylandSurfaceExtManual: sealed::Sealed + IsA<WaylandSurface> + 'static {
    /// Returns the Wayland `wl_surface` of a [`gdk::Surface`][crate::gdk::Surface].
    ///
    /// # Returns
    ///
    /// a Wayland `wl_surface`
    #[doc(alias = "gdk_wayland_surface_get_wl_surface")]
    #[doc(alias = "get_wl_surface")]
    #[cfg(feature = "wayland_crate")]
    #[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
    fn wl_surface(&self) -> Option<WlSurface> {
        let display = self
            .as_ref()
            .display()
            .downcast::<crate::WaylandDisplay>()
            .unwrap();
        unsafe {
            let surface_ptr =
                ffi::gdk_wayland_surface_get_wl_surface(self.as_ref().to_glib_none().0);
            if surface_ptr.is_null() {
                None
            } else {
                let cnx = display.connection();
                let id = ObjectId::from_ptr(WlSurface::interface(), surface_ptr as *mut _).unwrap();

                WlSurface::from_id(&cnx, id).ok()
            }
        }
    }
}

impl<O: IsA<WaylandSurface>> WaylandSurfaceExtManual for O {}