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