Skip to main content

gdkwayland/
wayland_seat.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_seat::WlSeat;
10
11glib::wrapper! {
12    #[doc(alias = "GdkWaylandSeat")]
13    pub struct WaylandSeat(Object<ffi::GdkWaylandSeat>) @extends gdk::Seat;
14
15    match fn {
16        type_ => || ffi::gdk_wayland_seat_get_type(),
17    }
18}
19
20impl WaylandSeat {
21    #[doc(alias = "gdk_wayland_seat_get_wl_seat")]
22    #[doc(alias = "get_wl_seat")]
23    pub fn wl_seat(&self) -> Option<WlSeat> {
24        unsafe {
25            let seat_ptr = ffi::gdk_wayland_seat_get_wl_seat(self.to_glib_none().0);
26            if seat_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(WlSeat::interface(), seat_ptr as *mut _).unwrap();
32
33                WlSeat::from_id(&cnx, id).ok()
34            }
35        }
36    }
37}