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 #[doc(alias = "gdk_wayland_surface_get_wl_surface")]
24 #[doc(alias = "get_wl_surface")]
25 #[cfg(feature = "wayland_crate")]
26 #[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
27 fn wl_surface(&self) -> Option<WlSurface> {
28 let display = self
29 .as_ref()
30 .display()
31 .downcast::<crate::WaylandDisplay>()
32 .unwrap();
33 unsafe {
34 let surface_ptr =
35 ffi::gdk_wayland_surface_get_wl_surface(self.as_ref().to_glib_none().0);
36 if surface_ptr.is_null() {
37 None
38 } else {
39 let cnx = display.connection();
40 let id = ObjectId::from_ptr(WlSurface::interface(), surface_ptr as *mut _).unwrap();
41
42 WlSurface::from_id(&cnx, id).ok()
43 }
44 }
45 }
46}
47
48impl<O: IsA<WaylandSurface>> WaylandSurfaceExtManual for O {}