[gnome-control-center] wacom: Add CcWacomDevice
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] wacom: Add CcWacomDevice
- Date: Fri, 4 Nov 2016 22:40:11 +0000 (UTC)
commit 2b75f5dfcc4d3fc3b9ca076397b9b5c768eeefca
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Jun 6 13:25:56 2016 +0200
wacom: Add CcWacomDevice
This is a vast oversimplification of GsdWacomDevice. This one
has code that is largely unnecessary here (mostly devised for g-s-d),
plus it will be even eventually removed from g-s-d (the functionality
is moving into compositor domain), so the code sharing argument
remains pretty weak.
So, CcWacomDevice is thought to take over, just offering the basic
API we after all need in the gnome-control-center side.
panels/wacom/Makefile.am | 4 +
panels/wacom/cc-wacom-device.c | 235 ++++++++++++++++++++++++++++++++++++++++
panels/wacom/cc-wacom-device.h | 52 +++++++++
3 files changed, 291 insertions(+), 0 deletions(-)
---
diff --git a/panels/wacom/Makefile.am b/panels/wacom/Makefile.am
index b1f3146..a80f0c8 100644
--- a/panels/wacom/Makefile.am
+++ b/panels/wacom/Makefile.am
@@ -21,6 +21,8 @@ libwacom_properties_la_SOURCES = \
$(BUILT_SOURCES) \
cc-drawing-area.c \
cc-drawing-area.h \
+ cc-wacom-device.c \
+ cc-wacom-device.h \
cc-wacom-panel.c \
cc-wacom-panel.h \
gsd-wacom-key-shortcut-button.c \
@@ -46,6 +48,8 @@ noinst_PROGRAMS = test-wacom
test_wacom_SOURCES = \
$(BUILT_SOURCES) \
test-wacom.c \
+ cc-wacom-device.c \
+ cc-wacom-device.h \
cc-wacom-button-row.c \
cc-wacom-button-row.h \
gsd-wacom-key-shortcut-button.c \
diff --git a/panels/wacom/cc-wacom-device.c b/panels/wacom/cc-wacom-device.c
new file mode 100644
index 0000000..17a62e4
--- /dev/null
+++ b/panels/wacom/cc-wacom-device.c
@@ -0,0 +1,235 @@
+/*
+ * Copyright © 2016 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Carlos Garnacho <carlosg gnome org>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include "cc-wacom-device.h"
+
+enum {
+ PROP_0,
+ PROP_DEVICE,
+ N_PROPS
+};
+
+GParamSpec *props[N_PROPS] = { 0 };
+
+typedef struct _CcWacomDevice CcWacomDevice;
+
+struct _CcWacomDevice {
+ GObject parent_instance;
+
+ GsdDevice *device;
+ WacomDevice *wdevice;
+};
+
+static void cc_wacom_device_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (CcWacomDevice, cc_wacom_device, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ cc_wacom_device_initable_iface_init))
+
+WacomDeviceDatabase *
+cc_wacom_device_database_get (void)
+{
+ static WacomDeviceDatabase *db = NULL;
+
+ if (g_once_init_enter (&db)) {
+ gpointer p = libwacom_database_new ();
+ g_once_init_leave (&db, p);
+ }
+
+ return db;
+}
+
+static void
+cc_wacom_device_init (CcWacomDevice *device)
+{
+}
+
+static void
+cc_wacom_device_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ CcWacomDevice *device = CC_WACOM_DEVICE (object);
+
+ switch (prop_id) {
+ case PROP_DEVICE:
+ device->device = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+cc_wacom_device_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ CcWacomDevice *device = CC_WACOM_DEVICE (object);
+
+ switch (prop_id) {
+ case PROP_DEVICE:
+ g_value_set_object (value, device->device);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+cc_wacom_device_finalize (GObject *object)
+{
+ CcWacomDevice *device = CC_WACOM_DEVICE (object);
+
+ g_clear_pointer (&device->wdevice, libwacom_destroy);
+
+ G_OBJECT_CLASS (cc_wacom_device_parent_class)->finalize (object);
+}
+
+static void
+cc_wacom_device_class_init (CcWacomDeviceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = cc_wacom_device_set_property;
+ object_class->get_property = cc_wacom_device_get_property;
+ object_class->finalize = cc_wacom_device_finalize;
+
+ props[PROP_DEVICE] =
+ g_param_spec_object ("device",
+ "device",
+ "device",
+ GSD_TYPE_DEVICE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (object_class, N_PROPS, props);
+}
+
+static gboolean
+cc_wacom_device_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CcWacomDevice *device = CC_WACOM_DEVICE (initable);
+ WacomDeviceDatabase *wacom_db;
+ const gchar *node_path;
+
+ wacom_db = cc_wacom_device_database_get ();
+ node_path = gsd_device_get_device_file (device->device);
+ device->wdevice = libwacom_new_from_path (wacom_db, node_path, FALSE, NULL);
+
+ if (!device->wdevice) {
+ g_set_error (error, 0, 0, "Tablet description not found");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+cc_wacom_device_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = cc_wacom_device_initable_init;
+}
+
+CcWacomDevice *
+cc_wacom_device_new (GsdDevice *device)
+{
+ return g_initable_new (CC_TYPE_WACOM_DEVICE,
+ NULL, NULL,
+ "device", device,
+ NULL);
+}
+
+const gchar *
+cc_wacom_device_get_name (CcWacomDevice *device)
+{
+ g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), NULL);
+
+ return libwacom_get_name (device->wdevice);
+}
+
+const gchar *
+cc_wacom_device_get_icon_name (CcWacomDevice *device)
+{
+ WacomIntegrationFlags integration_flags;
+
+ g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), NULL);
+
+ integration_flags = libwacom_get_integration_flags (device->wdevice);
+
+ if (integration_flags & WACOM_DEVICE_INTEGRATED_SYSTEM) {
+ return "wacom-tablet-pc";
+ } else if (integration_flags & WACOM_DEVICE_INTEGRATED_DISPLAY) {
+ return "wacom-tablet-cintiq";
+ } else {
+ return "wacom-tablet";
+ }
+}
+
+gboolean
+cc_wacom_device_is_reversible (CcWacomDevice *device)
+{
+ g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), FALSE);
+
+ return libwacom_is_reversible (device->wdevice);
+}
+
+WacomIntegrationFlags
+cc_wacom_device_get_integration_flags (CcWacomDevice *device)
+{
+ g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), 0);
+
+ return libwacom_get_integration_flags (device->wdevice);
+}
+
+GsdDevice *
+cc_wacom_device_get_device (CcWacomDevice *device)
+{
+ g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), NULL);
+
+ return device->device;
+}
+
+GSettings *
+cc_wacom_device_get_settings (CcWacomDevice *device)
+{
+ g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), NULL);
+
+ return gsd_device_get_settings (device->device);
+}
+
+const gint *
+cc_wacom_device_get_supported_tools (CcWacomDevice *device,
+ gint *n_tools)
+{
+ *n_tools = 0;
+
+ g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), NULL);
+
+ return libwacom_get_supported_styli (device->wdevice, n_tools);
+}
diff --git a/panels/wacom/cc-wacom-device.h b/panels/wacom/cc-wacom-device.h
new file mode 100644
index 0000000..1fb721b
--- /dev/null
+++ b/panels/wacom/cc-wacom-device.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2016 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Carlos Garnacho <carlosg gnome org>
+ *
+ */
+#ifndef __CC_WACOM_DEVICE_H__
+#define __CC_WACOM_DEVICE_H__
+
+#include "config.h"
+#include <glib-object.h>
+#include <libwacom/libwacom.h>
+
+#include "gsd-device-manager.h"
+
+#define CC_TYPE_WACOM_DEVICE (cc_wacom_device_get_type ())
+
+G_DECLARE_FINAL_TYPE (CcWacomDevice, cc_wacom_device, CC, WACOM_DEVICE, GObject)
+
+WacomDeviceDatabase *
+ cc_wacom_device_database_get (void);
+
+CcWacomDevice * cc_wacom_device_new (GsdDevice *device);
+
+const gchar * cc_wacom_device_get_name (CcWacomDevice *device);
+const gchar * cc_wacom_device_get_icon_name (CcWacomDevice *device);
+
+gboolean cc_wacom_device_is_reversible (CcWacomDevice *device);
+
+WacomIntegrationFlags
+ cc_wacom_device_get_integration_flags (CcWacomDevice *device);
+
+GsdDevice * cc_wacom_device_get_device (CcWacomDevice *device);
+GSettings * cc_wacom_device_get_settings (CcWacomDevice *device);
+
+const gint * cc_wacom_device_get_supported_tools (CcWacomDevice *device,
+ gint *n_tools);
+
+#endif /* __CC_WACOM_DEVICE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]