Skip to main content

gdk4_wayland/
wayland_monitor.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
6#[cfg(feature = "wayland_crate")]
7#[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
8use wayland_client::{Proxy, backend::ObjectId, protocol::wl_output::WlOutput};
9
10#[cfg(feature = "wayland_crate")]
11#[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
12use crate::prelude::*;
13use crate::{WaylandMonitor, ffi};
14use glib::translate::*;
15
16impl WaylandMonitor {
17    #[doc(alias = "gdk_wayland_monitor_get_wl_output")]
18    #[doc(alias = "get_wl_output")]
19    pub fn wl_output_raw(&self) -> Option<NonNull<c_void>> {
20        NonNull::new(unsafe { ffi::gdk_wayland_monitor_get_wl_output(self.to_glib_none().0) })
21    }
22
23    /// Returns the Wayland `wl_output` of a [`gdk::Monitor`][crate::gdk::Monitor].
24    ///
25    /// # Returns
26    ///
27    /// a Wayland `wl_output`
28    #[doc(alias = "gdk_wayland_monitor_get_wl_output")]
29    #[doc(alias = "get_wl_output")]
30    #[cfg(feature = "wayland_crate")]
31    #[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
32    pub fn wl_output(&self) -> Option<WlOutput> {
33        let display = self.display().downcast::<crate::WaylandDisplay>().unwrap();
34        let ptr = self.wl_output_raw()?;
35        unsafe {
36            let cnx = display.connection();
37            let id = ObjectId::from_ptr(WlOutput::interface(), ptr.as_ptr() as *mut _).unwrap();
38
39            WlOutput::from_id(&cnx, id).ok()
40        }
41    }
42}