1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::WaylandDevice;
#[cfg(any(feature = "wayland_crate", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "wayland_crate")))]
use glib::translate::ToGlibPtr;
#[cfg(any(feature = "wayland_crate", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "wayland_crate")))]
use wayland_client::{
    protocol::{wl_keyboard::WlKeyboard, wl_pointer::WlPointer, wl_seat::WlSeat},
    sys::client::wl_proxy,
    Proxy,
};

#[cfg(any(all(feature = "v4_4", feature = "xkb_crate"), feature = "dox"))]
#[cfg_attr(
    feature = "dox",
    doc(cfg(all(feature = "v4_4", feature = "xkb_crate")))
)]
use xkb::Keymap;

impl WaylandDevice {
    /// Returns the Wayland `wl_keyboard` of a [`gdk::Device`][crate::gdk::Device].
    ///
    /// # Returns
    ///
    /// a Wayland `wl_keyboard`
    #[doc(alias = "gdk_wayland_device_get_wl_keyboard")]
    #[doc(alias = "get_wl_keyboard")]
    #[cfg(any(feature = "wayland_crate", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "wayland_crate")))]
    pub fn wl_keyboard(&self) -> WlKeyboard {
        unsafe {
            let ptr = ffi::gdk_wayland_device_get_wl_keyboard(self.to_glib_none().0);
            Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
        }
    }

    /// Returns the Wayland `wl_pointer` of a [`gdk::Device`][crate::gdk::Device].
    ///
    /// # Returns
    ///
    /// a Wayland `wl_pointer`
    #[doc(alias = "gdk_wayland_device_get_wl_pointer")]
    #[doc(alias = "get_wl_pointer")]
    #[cfg(any(feature = "wayland_crate", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "wayland_crate")))]
    pub fn wl_pointer(&self) -> WlPointer {
        unsafe {
            let ptr = ffi::gdk_wayland_device_get_wl_pointer(self.to_glib_none().0);
            Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
        }
    }

    /// Returns the Wayland `wl_seat` of a [`gdk::Device`][crate::gdk::Device].
    ///
    /// # Returns
    ///
    /// a Wayland `wl_seat`
    #[doc(alias = "gdk_wayland_device_get_wl_seat")]
    #[doc(alias = "get_wl_seat")]
    #[cfg(any(feature = "wayland_crate", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "wayland_crate")))]
    pub fn wl_seat(&self) -> WlSeat {
        unsafe {
            let ptr = ffi::gdk_wayland_device_get_wl_seat(self.to_glib_none().0);
            Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
        }
    }

    #[cfg(any(all(feature = "v4_4", feature = "xkb_crate"), feature = "dox"))]
    #[cfg_attr(
        feature = "dox",
        doc(cfg(all(feature = "v4_4", feature = "xkb_crate")))
    )]
    /// Returns the `xkb_keymap` of a [`gdk::Device`][crate::gdk::Device].
    ///
    /// # Returns
    ///
    /// a `struct xkb_keymap`
    #[doc(alias = "gdk_wayland_device_get_xkb_keymap")]
    #[doc(alias = "get_xkb_keymap")]
    pub fn xkb_keymap(&self) -> Option<Keymap> {
        unsafe {
            let ptr = ffi::gdk_wayland_device_get_xkb_keymap(self.to_glib_none().0);
            if ptr.is_null() {
                None
            } else {
                Some(Keymap::from_ptr(ptr))
            }
        }
    }
}