Skip to main content

gdk4_wayland/
wayland_surface.rs

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