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 * SECTION:gdkdevicepad
22 * @Short_description: Pad device interface
23 * @Title: GtkDevicePad
24 *
25 * #GdkDevicePad is an interface implemented by devices of type
26 * %GDK_SOURCE_TABLET_PAD, it allows querying the features provided
27 * by the pad device.
28 *
29 * Tablet pads may contain one or more groups, each containing a subset
30 * of the buttons/rings/strips available. gdk_device_pad_get_n_groups()
31 * can be used to obtain the number of groups, gdk_device_pad_get_n_features()
32 * and gdk_device_pad_get_feature_group() can be combined to find out the
33 * number of buttons/rings/strips the device has, and how are they grouped.
34 *
35 * Each of those groups have different modes, which may be used to map
36 * each individual pad feature to multiple actions. Only one mode is
37 * effective (current) for each given group, different groups may have
38 * different current modes. The number of available modes in a group can
39 * be found out through gdk_device_pad_get_group_n_modes(), and the current
40 * mode for a given group will be notified through the #GdkEventPadGroupMode
41 * event.
42 *
43 */
44
45 #include "config.h"
46
47 #include "gdkdevicepad.h"
48 #include "gdkdevicepadprivate.h"
49 #include "gdkdeviceprivate.h"
50
G_DEFINE_INTERFACE(GdkDevicePad,gdk_device_pad,GDK_TYPE_DEVICE)51 G_DEFINE_INTERFACE (GdkDevicePad, gdk_device_pad, GDK_TYPE_DEVICE)
52
53 static void
54 gdk_device_pad_default_init (GdkDevicePadInterface *pad)
55 {
56 }
57
58 /**
59 * gdk_device_pad_get_n_groups:
60 * @pad: a #GdkDevicePad
61 *
62 * Returns the number of groups this pad device has. Pads have
63 * at least one group. A pad group is a subcollection of
64 * buttons/strip/rings that is affected collectively by a same
65 * current mode.
66 *
67 * Returns: The number of button/ring/strip groups in the pad.
68 *
69 * Since: 3.22
70 **/
71 gint
gdk_device_pad_get_n_groups(GdkDevicePad * pad)72 gdk_device_pad_get_n_groups (GdkDevicePad *pad)
73 {
74 GdkDevicePadInterface *iface = GDK_DEVICE_PAD_GET_IFACE (pad);
75
76 g_return_val_if_fail (GDK_IS_DEVICE_PAD (pad), 0);
77
78 return iface->get_n_groups (pad);
79 }
80
81 /**
82 * gdk_device_pad_get_group_n_modes:
83 * @pad: a #GdkDevicePad
84 * @group_idx: group to get the number of available modes from
85 *
86 * Returns the number of modes that @group may have.
87 *
88 * Returns: The number of modes available in @group.
89 *
90 * Since: 3.22
91 **/
92 gint
gdk_device_pad_get_group_n_modes(GdkDevicePad * pad,gint group_idx)93 gdk_device_pad_get_group_n_modes (GdkDevicePad *pad,
94 gint group_idx)
95 {
96 GdkDevicePadInterface *iface = GDK_DEVICE_PAD_GET_IFACE (pad);
97
98 g_return_val_if_fail (GDK_IS_DEVICE_PAD (pad), 0);
99 g_return_val_if_fail (group_idx >= 0, 0);
100
101 return iface->get_group_n_modes (pad, group_idx);
102 }
103
104 /**
105 * gdk_device_pad_get_n_features:
106 * @pad: a #GdkDevicePad
107 * @feature: a pad feature
108 *
109 * Returns the number of features a tablet pad has.
110 *
111 * Returns: The amount of elements of type @feature that this pad has.
112 *
113 * Since: 3.22
114 **/
115 gint
gdk_device_pad_get_n_features(GdkDevicePad * pad,GdkDevicePadFeature feature)116 gdk_device_pad_get_n_features (GdkDevicePad *pad,
117 GdkDevicePadFeature feature)
118 {
119 GdkDevicePadInterface *iface = GDK_DEVICE_PAD_GET_IFACE (pad);
120
121 g_return_val_if_fail (GDK_IS_DEVICE_PAD (pad), 0);
122
123 return iface->get_n_features (pad, feature);
124 }
125
126 /**
127 * gdk_device_pad_get_feature_group:
128 * @pad: a #GdkDevicePad
129 * @feature: the feature type to get the group from
130 * @feature_idx: the index of the feature to get the group from
131 *
132 * Returns the group the given @feature and @idx belong to,
133 * or -1 if feature/index do not exist in @pad.
134 *
135 * Returns: The group number of the queried pad feature.
136 *
137 * Since: 3.22
138 **/
139 gint
gdk_device_pad_get_feature_group(GdkDevicePad * pad,GdkDevicePadFeature feature,gint idx)140 gdk_device_pad_get_feature_group (GdkDevicePad *pad,
141 GdkDevicePadFeature feature,
142 gint idx)
143 {
144 GdkDevicePadInterface *iface = GDK_DEVICE_PAD_GET_IFACE (pad);
145
146 g_return_val_if_fail (GDK_IS_DEVICE_PAD (pad), -1);
147 g_return_val_if_fail (idx >= 0, -1);
148
149 return iface->get_feature_group (pad, feature, idx);
150 }
151