1use crate::{ffi, AsRaw, FromRaw};
2
3ffi_ref_struct! {
4 /// A mode on a tablet pad is a virtual grouping of functionality, usually based on
5 /// some visual feedback like LEDs on the pad.
6 ///
7 /// The set of buttons, rings and strips that share the same mode are a "mode
8 /// group". Whenever the mode changes, all buttons, rings and strips within this
9 /// mode group are affected. See
10 /// [Tablet pad modes](https://wayland.freedesktop.org/libinput/doc/latest/tablet-support.html#tablet-pad-modes)
11 /// for detail.
12 ///
13 /// Most tablets only have a single mode group, some tablets provide multiple mode
14 /// groups through independent banks of LEDs (e.g. the Wacom Cintiq 24HD). libinput
15 /// guarantees that at least one mode group is always available.
16 struct TabletPadModeGroup, ffi::libinput_tablet_pad_mode_group, ffi::libinput_tablet_pad_mode_group_ref, ffi::libinput_tablet_pad_mode_group_unref
17}
18
19impl TabletPadModeGroup {
20 /// The toggle button in a mode group is the button assigned to cycle to or
21 /// directly assign a new mode when pressed.
22 ///
23 /// Not all devices have a toggle button and some devices may have more than
24 /// one toggle button. For example, the Wacom Cintiq 24HD has six toggle
25 /// buttons in two groups, each directly selecting one of the three modes per
26 /// group.
27 ///
28 /// Devices without mode switching capabilities return `false` for every button.
29 pub fn button_is_toggle(&self, button: u32) -> bool {
30 unsafe {
31 ffi::libinput_tablet_pad_mode_group_button_is_toggle(self.as_raw_mut(), button) != 0
32 }
33 }
34
35 ffi_func!(
36 /// The returned number is the same index as passed to `Device::tablet_pad_mode_group`.
37 ///
38 /// For tablets with only one mode this number is always 0.
39 pub fn index, ffi::libinput_tablet_pad_mode_group_get_index, u32);
40 ffi_func!(
41 /// Return the current mode this mode group is in.
42 ///
43 /// Note that the returned mode is the mode valid as of completing the last
44 /// `Libinput::dispatch`. The returned mode may thus be different than the mode
45 /// returned by `TabletPadEvent::mode`.
46 ///
47 /// For example, if the mode was toggled three times between the call to
48 /// `Libinput::dispatch`, this function returns the third mode but the events in the
49 /// event queue will return the modes 1, 2 and 3, respectively.
50 pub fn mode, ffi::libinput_tablet_pad_mode_group_get_mode, u32);
51 ffi_func!(
52 /// Query the mode group for the number of available modes.
53 ///
54 /// The number of modes is usually decided by the number of physical LEDs available on
55 /// the device. Different mode groups may have a different number of modes. Use
56 /// `TabletPadModeGroup::mode` to get the currently active mode.
57 ///
58 /// libinput guarantees that at least one mode is available. A device without mode
59 /// switching capability has a single mode group and a single mode.
60 pub fn number_of_modes, ffi::libinput_tablet_pad_mode_group_get_num_modes, u32);
61
62 /// Devices without mode switching capabilities return `true` for every button.
63 pub fn has_button(&self, button: u32) -> bool {
64 unsafe { ffi::libinput_tablet_pad_mode_group_has_button(self.as_raw_mut(), button) != 0 }
65 }
66
67 /// Devices without mode switching capabilities return `true` for every ring.
68 pub fn has_ring(&self, ring: u32) -> bool {
69 unsafe { ffi::libinput_tablet_pad_mode_group_has_ring(self.as_raw_mut(), ring) != 0 }
70 }
71
72 /// Devices without mode switching capabilities return `true` for every strip.
73 pub fn has_strip(&self, strip: u32) -> bool {
74 unsafe { ffi::libinput_tablet_pad_mode_group_has_strip(self.as_raw_mut(), strip) != 0 }
75 }
76}
77