1 /*
2 * Copyright © 2020 Red Hat Ltd.
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 #include "config.h"
21
22 #include "backends/meta-backend-private.h"
23 #include "meta-input-device-private.h"
24
25 typedef struct _MetaInputDevicePrivate MetaInputDevicePrivate;
26
27 struct _MetaInputDevicePrivate
28 {
29 #ifdef HAVE_LIBWACOM
30 WacomDevice *wacom_device;
31 #else
32 /* Just something to have non-zero sized struct otherwise */
33 gpointer wacom_device;
34 #endif
35 };
36
37 enum
38 {
39 PROP_WACOM_DEVICE = 1,
40 N_PROPS
41 };
42
43 static GParamSpec *props[N_PROPS] = { 0 };
44
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(MetaInputDevice,meta_input_device,CLUTTER_TYPE_INPUT_DEVICE)45 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaInputDevice,
46 meta_input_device,
47 CLUTTER_TYPE_INPUT_DEVICE)
48
49 static void
50 meta_input_device_init (MetaInputDevice *input_device)
51 {
52 }
53
54 static void
meta_input_device_constructed(GObject * object)55 meta_input_device_constructed (GObject *object)
56 {
57 #ifdef HAVE_LIBWACOM
58 MetaInputDevice *input_device;
59 WacomDeviceDatabase *wacom_db;
60 MetaInputDevicePrivate *priv;
61 const char *node;
62 #endif
63
64 G_OBJECT_CLASS (meta_input_device_parent_class)->constructed (object);
65
66 #ifdef HAVE_LIBWACOM
67 input_device = META_INPUT_DEVICE (object);
68 priv = meta_input_device_get_instance_private (input_device);
69 wacom_db = meta_backend_get_wacom_database (meta_get_backend ());
70 node = clutter_input_device_get_device_node (CLUTTER_INPUT_DEVICE (input_device));
71 priv->wacom_device = libwacom_new_from_path (wacom_db, node,
72 WFALLBACK_NONE, NULL);
73 #endif /* HAVE_LIBWACOM */
74 }
75
76 static void
meta_input_device_finalize(GObject * object)77 meta_input_device_finalize (GObject *object)
78 {
79 #ifdef HAVE_LIBWACOM
80 MetaInputDevicePrivate *priv;
81
82 priv = meta_input_device_get_instance_private (META_INPUT_DEVICE (object));
83
84 g_clear_pointer (&priv->wacom_device, libwacom_destroy);
85 #endif /* HAVE_LIBWACOM */
86
87 G_OBJECT_CLASS (meta_input_device_parent_class)->finalize (object);
88 }
89
90 static void
meta_input_device_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)91 meta_input_device_get_property (GObject *object,
92 guint prop_id,
93 GValue *value,
94 GParamSpec *pspec)
95 {
96 MetaInputDevicePrivate *priv;
97
98 priv = meta_input_device_get_instance_private (META_INPUT_DEVICE (object));
99
100 switch (prop_id)
101 {
102 case PROP_WACOM_DEVICE:
103 g_value_set_pointer (value, priv->wacom_device);
104 break;
105 default:
106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
107 }
108 }
109
110 static void
meta_input_device_class_init(MetaInputDeviceClass * klass)111 meta_input_device_class_init (MetaInputDeviceClass *klass)
112 {
113 GObjectClass *object_class = G_OBJECT_CLASS (klass);
114
115 object_class->constructed = meta_input_device_constructed;
116 object_class->finalize = meta_input_device_finalize;
117 object_class->get_property = meta_input_device_get_property;
118
119 props[PROP_WACOM_DEVICE] =
120 g_param_spec_pointer ("wacom-device",
121 "Wacom device",
122 "Wacom device",
123 G_PARAM_READABLE);
124
125 g_object_class_install_properties (object_class, N_PROPS, props);
126 }
127
128 #ifdef HAVE_LIBWACOM
129 WacomDevice *
meta_input_device_get_wacom_device(MetaInputDevice * input_device)130 meta_input_device_get_wacom_device (MetaInputDevice *input_device)
131 {
132 MetaInputDevicePrivate *priv;
133
134 priv = meta_input_device_get_instance_private (input_device);
135
136 return priv->wacom_device;
137 }
138 #endif /* HAVE_LIBWACOM */
139