Skip to main content

gdkwayland/
wayland_monitor.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use gdk::prelude::*;
4use glib::translate::ToGlibPtr;
5
6use wayland_client::backend::ObjectId;
7use wayland_client::protocol::wl_output::WlOutput;
8use wayland_client::Proxy;
9
10glib::wrapper! {
11    #[doc(alias = "GdkWaylandMonitor")]
12    pub struct WaylandMonitor(Object<ffi::GdkWaylandMonitor>) @extends gdk::Monitor;
13
14    match fn {
15        type_ => || ffi::gdk_wayland_monitor_get_type(),
16    }
17}
18
19impl WaylandMonitor {
20    #[doc(alias = "gdk_wayland_monitor_get_wl_output")]
21    #[doc(alias = "get_wl_output")]
22    pub fn wl_output(&self) -> Option<WlOutput> {
23        unsafe {
24            let output_ptr = ffi::gdk_wayland_monitor_get_wl_output(self.to_glib_none().0);
25            if output_ptr.is_null() {
26                None
27            } else {
28                let display = self.display()?.unsafe_cast::<crate::WaylandDisplay>();
29                let cnx = display.connection();
30                let id = ObjectId::from_ptr(WlOutput::interface(), output_ptr as *mut _).unwrap();
31
32                WlOutput::from_id(&cnx, id).ok()
33            }
34        }
35    }
36}