1 | /* GDK - The GIMP Drawing Kit |
2 | * Copyright (C) 2016 Red Hat |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | * |
17 | * Author: Carlos Garnacho <carlosg@gnome.org> |
18 | */ |
19 | |
20 | /** |
21 | * GdkDevicePad: |
22 | * |
23 | * `GdkDevicePad` is an interface implemented by devices of type |
24 | * %GDK_SOURCE_TABLET_PAD |
25 | * |
26 | * It allows querying the features provided by the pad device. |
27 | * |
28 | * Tablet pads may contain one or more groups, each containing a subset |
29 | * of the buttons/rings/strips available. [method@Gdk.DevicePad.get_n_groups] |
30 | * can be used to obtain the number of groups, [method@Gdk.DevicePad.get_n_features] |
31 | * and [method@Gdk.DevicePad.get_feature_group] can be combined to find out |
32 | * the number of buttons/rings/strips the device has, and how are they grouped. |
33 | * |
34 | * Each of those groups have different modes, which may be used to map each |
35 | * individual pad feature to multiple actions. Only one mode is effective |
36 | * (current) for each given group, different groups may have different |
37 | * current modes. The number of available modes in a group can be found |
38 | * out through [method@Gdk.DevicePad.get_group_n_modes], and the current mode |
39 | * for a given group will be notified through events of type `GDK_PAD_GROUP_MODE`. |
40 | */ |
41 | |
42 | #include "config.h" |
43 | |
44 | #include "gdkdevicepad.h" |
45 | #include "gdkdevicepadprivate.h" |
46 | #include "gdkdeviceprivate.h" |
47 | |
48 | G_DEFINE_INTERFACE (GdkDevicePad, gdk_device_pad, GDK_TYPE_DEVICE) |
49 | |
50 | static void |
51 | gdk_device_pad_default_init (GdkDevicePadInterface *pad) |
52 | { |
53 | } |
54 | |
55 | /** |
56 | * gdk_device_pad_get_n_groups: |
57 | * @pad: a `GdkDevicePad` |
58 | * |
59 | * Returns the number of groups this pad device has. |
60 | * |
61 | * Pads have at least one group. A pad group is a subcollection of |
62 | * buttons/strip/rings that is affected collectively by a same |
63 | * current mode. |
64 | * |
65 | * Returns: The number of button/ring/strip groups in the pad. |
66 | */ |
67 | int |
68 | gdk_device_pad_get_n_groups (GdkDevicePad *pad) |
69 | { |
70 | GdkDevicePadInterface *iface = GDK_DEVICE_PAD_GET_IFACE (pad); |
71 | |
72 | g_return_val_if_fail (GDK_IS_DEVICE_PAD (pad), 0); |
73 | |
74 | return iface->get_n_groups (pad); |
75 | } |
76 | |
77 | /** |
78 | * gdk_device_pad_get_group_n_modes: |
79 | * @pad: a `GdkDevicePad` |
80 | * @group_idx: group to get the number of available modes from |
81 | * |
82 | * Returns the number of modes that @group may have. |
83 | * |
84 | * Returns: The number of modes available in @group. |
85 | */ |
86 | int |
87 | gdk_device_pad_get_group_n_modes (GdkDevicePad *pad, |
88 | int group_idx) |
89 | { |
90 | GdkDevicePadInterface *iface = GDK_DEVICE_PAD_GET_IFACE (pad); |
91 | |
92 | g_return_val_if_fail (GDK_IS_DEVICE_PAD (pad), 0); |
93 | g_return_val_if_fail (group_idx >= 0, 0); |
94 | |
95 | return iface->get_group_n_modes (pad, group_idx); |
96 | } |
97 | |
98 | /** |
99 | * gdk_device_pad_get_n_features: |
100 | * @pad: a `GdkDevicePad` |
101 | * @feature: a pad feature |
102 | * |
103 | * Returns the number of features a tablet pad has. |
104 | * |
105 | * Returns: The amount of elements of type @feature that this pad has. |
106 | */ |
107 | int |
108 | gdk_device_pad_get_n_features (GdkDevicePad *pad, |
109 | GdkDevicePadFeature feature) |
110 | { |
111 | GdkDevicePadInterface *iface = GDK_DEVICE_PAD_GET_IFACE (pad); |
112 | |
113 | g_return_val_if_fail (GDK_IS_DEVICE_PAD (pad), 0); |
114 | |
115 | return iface->get_n_features (pad, feature); |
116 | } |
117 | |
118 | /** |
119 | * gdk_device_pad_get_feature_group: |
120 | * @pad: a `GdkDevicePad` |
121 | * @feature: the feature type to get the group from |
122 | * @feature_idx: the index of the feature to get the group from |
123 | * |
124 | * Returns the group the given @feature and @idx belong to. |
125 | * |
126 | * f the feature or index do not exist in @pad, -1 is returned. |
127 | * |
128 | * Returns: The group number of the queried pad feature. |
129 | */ |
130 | int |
131 | gdk_device_pad_get_feature_group (GdkDevicePad *pad, |
132 | GdkDevicePadFeature feature, |
133 | int idx) |
134 | { |
135 | GdkDevicePadInterface *iface = GDK_DEVICE_PAD_GET_IFACE (pad); |
136 | |
137 | g_return_val_if_fail (GDK_IS_DEVICE_PAD (pad), -1); |
138 | g_return_val_if_fail (idx >= 0, -1); |
139 | |
140 | return iface->get_feature_group (pad, feature, idx); |
141 | } |
142 | |