gdk4_wayland/
wayland_device.rs1#[cfg(feature = "wayland_crate")]
4#[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
5use glib::translate::*;
6#[cfg(feature = "wayland_crate")]
7#[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
8use wayland_client::{
9 backend::ObjectId,
10 protocol::{wl_keyboard::WlKeyboard, wl_pointer::WlPointer, wl_seat::WlSeat},
11 Proxy,
12};
13
14use crate::WaylandDevice;
15#[cfg(feature = "wayland_crate")]
16#[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
17use crate::{ffi, prelude::*};
18
19impl WaylandDevice {
20 #[doc(alias = "gdk_wayland_device_get_wl_keyboard")]
21 #[doc(alias = "get_wl_keyboard")]
22 #[cfg(feature = "wayland_crate")]
23 #[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
24 pub fn wl_keyboard(&self) -> Option<WlKeyboard> {
25 let display = self.display().downcast::<crate::WaylandDisplay>().unwrap();
26 unsafe {
27 let keyboard_ptr = ffi::gdk_wayland_device_get_wl_keyboard(self.to_glib_none().0);
28 if keyboard_ptr.is_null() {
29 None
30 } else {
31 let cnx = display.connection();
32 let id =
33 ObjectId::from_ptr(WlKeyboard::interface(), keyboard_ptr as *mut _).unwrap();
34
35 WlKeyboard::from_id(&cnx, id).ok()
36 }
37 }
38 }
39
40 #[doc(alias = "gdk_wayland_device_get_wl_pointer")]
41 #[doc(alias = "get_wl_pointer")]
42 #[cfg(feature = "wayland_crate")]
43 #[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
44 pub fn wl_pointer(&self) -> Option<WlPointer> {
45 let display = self.display().downcast::<crate::WaylandDisplay>().unwrap();
46 unsafe {
47 let pointer_ptr = ffi::gdk_wayland_device_get_wl_pointer(self.to_glib_none().0);
48 if pointer_ptr.is_null() {
49 None
50 } else {
51 let cnx = display.connection();
52 let id = ObjectId::from_ptr(WlPointer::interface(), pointer_ptr as *mut _).unwrap();
53
54 WlPointer::from_id(&cnx, id).ok()
55 }
56 }
57 }
58
59 #[doc(alias = "gdk_wayland_device_get_wl_seat")]
60 #[doc(alias = "get_wl_seat")]
61 #[cfg(feature = "wayland_crate")]
62 #[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))]
63 pub fn wl_seat(&self) -> Option<WlSeat> {
64 let display = self.display().downcast::<crate::WaylandDisplay>().unwrap();
65 unsafe {
66 let seat_ptr = ffi::gdk_wayland_device_get_wl_seat(self.to_glib_none().0);
67 if seat_ptr.is_null() {
68 None
69 } else {
70 let cnx = display.connection();
71 let id = ObjectId::from_ptr(WlSeat::interface(), seat_ptr as *mut _).unwrap();
72
73 WlSeat::from_id(&cnx, id).ok()
74 }
75 }
76 }
77}