Skip to main content

gdkwayland/
wayland_device.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use gdk::prelude::*;
4use gdk::DevicePadFeature;
5use glib::translate::*;
6
7use wayland_client::backend::ObjectId;
8use wayland_client::protocol::{wl_keyboard::WlKeyboard, wl_pointer::WlPointer, wl_seat::WlSeat};
9use wayland_client::Proxy;
10
11glib::wrapper! {
12    #[doc(alias = "GdkWaylandDevice")]
13    pub struct WaylandDevice(Object<ffi::GdkWaylandDevice>) @extends gdk::Device;
14
15    match fn {
16        type_ => || ffi::gdk_wayland_device_get_type(),
17    }
18}
19
20impl WaylandDevice {
21    #[doc(alias = "gdk_wayland_device_pad_set_feedback")]
22    pub fn pad_set_feedback(&self, element: DevicePadFeature, idx: usize, label: &str) {
23        unsafe {
24            ffi::gdk_wayland_device_pad_set_feedback(
25                self.to_glib_none().0,
26                element.into_glib(),
27                idx as _,
28                label.to_glib_none().0,
29            )
30        }
31    }
32
33    #[doc(alias = "gdk_wayland_device_get_wl_seat")]
34    #[doc(alias = "get_wl_seat")]
35    pub fn wl_seat(&self) -> Option<WlSeat> {
36        unsafe {
37            let seat_ptr = ffi::gdk_wayland_device_get_wl_seat(self.to_glib_none().0);
38            if seat_ptr.is_null() {
39                None
40            } else {
41                let display = self.display().unsafe_cast::<crate::WaylandDisplay>();
42                let cnx = display.connection();
43                let id = ObjectId::from_ptr(WlSeat::interface(), seat_ptr as *mut _).unwrap();
44
45                WlSeat::from_id(&cnx, id).ok()
46            }
47        }
48    }
49
50    #[doc(alias = "gdk_wayland_device_get_wl_keyboard")]
51    #[doc(alias = "get_wl_keyboard")]
52    pub fn wl_keyboard(&self) -> Option<WlKeyboard> {
53        let display = self.display().downcast::<crate::WaylandDisplay>().unwrap();
54        unsafe {
55            let keyboard_ptr = ffi::gdk_wayland_device_get_wl_keyboard(self.to_glib_none().0);
56            if keyboard_ptr.is_null() {
57                None
58            } else {
59                let cnx = display.connection();
60                let id =
61                    ObjectId::from_ptr(WlKeyboard::interface(), keyboard_ptr as *mut _).unwrap();
62
63                WlKeyboard::from_id(&cnx, id).ok()
64            }
65        }
66    }
67
68    #[doc(alias = "gdk_wayland_device_get_wl_pointer")]
69    #[doc(alias = "get_wl_pointer")]
70    pub fn wl_pointer(&self) -> Option<WlPointer> {
71        let display = self.display().downcast::<crate::WaylandDisplay>().unwrap();
72        unsafe {
73            let pointer_ptr = ffi::gdk_wayland_device_get_wl_pointer(self.to_glib_none().0);
74            if pointer_ptr.is_null() {
75                None
76            } else {
77                let cnx = display.connection();
78                let id = ObjectId::from_ptr(WlPointer::interface(), pointer_ptr as *mut _).unwrap();
79
80                WlPointer::from_id(&cnx, id).ok()
81            }
82        }
83    }
84}