summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2018-04-20 19:43:08 +0200
committerCarlos Garnacho <carlosg@gnome.org>2018-12-06 16:53:17 +0100
commit78d02e675e08e58da6c3fdad4d635d9a84f27b0d (patch)
tree27f96565c9fff56494c5ffca76c8fe7cae3bf970 /plugins
parent66bf654b8d1edcf40c0ae1ed35828c6308c1aedc (diff)
downloadgnome-settings-daemon-78d02e675e08e58da6c3fdad4d635d9a84f27b0d.tar.gz
wacom: Replace GsdDeviceManager API with GDK
For the remaining things, we can do with poking GdkDevices. This finally drops the last usage of the GsdDeviceManager abstraction.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/wacom/gsd-wacom-manager.c144
-rw-r--r--plugins/wacom/gsd-wacom-oled.c22
-rw-r--r--plugins/wacom/gsd-wacom-oled.h3
-rw-r--r--plugins/wacom/main.c1
4 files changed, 102 insertions, 68 deletions
diff --git a/plugins/wacom/gsd-wacom-manager.c b/plugins/wacom/gsd-wacom-manager.c
index 7bd218fd..e0524613 100644
--- a/plugins/wacom/gsd-wacom-manager.c
+++ b/plugins/wacom/gsd-wacom-manager.c
@@ -30,17 +30,22 @@
#include <locale.h>
-#include <glib.h>
-#include <glib/gi18n-lib.h>
+#include <gdk/gdk.h>
+
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#endif
#include "gsd-enums.h"
#include "gnome-settings-profile.h"
#include "gnome-settings-bus.h"
#include "gsd-wacom-manager.h"
#include "gsd-wacom-oled.h"
-#include "gsd-shell-helper.h"
-#include "gsd-device-manager.h"
#include "gsd-settings-migrate.h"
+#include "gsd-input-helper.h"
#define GSD_WACOM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_WACOM_MANAGER, GsdWacomManagerPrivate))
@@ -54,6 +59,8 @@
#define GSD_WACOM_DBUS_PATH GSD_DBUS_PATH "/Wacom"
#define GSD_WACOM_DBUS_NAME GSD_DBUS_NAME ".Wacom"
+#define LEFT_HANDED_KEY "left-handed"
+
static const gchar introspection_xml[] =
"<node name='/org/gnome/SettingsDaemon/Wacom'>"
" <interface name='org.gnome.SettingsDaemon.Wacom'>"
@@ -72,7 +79,7 @@ static const gchar introspection_xml[] =
struct GsdWacomManagerPrivate
{
guint start_idle_id;
- GsdDeviceManager *device_manager;
+ GdkSeat *seat;
guint device_added_id;
GsdShell *shell_proxy;
@@ -91,10 +98,10 @@ static void gsd_wacom_manager_class_init (GsdWacomManagerClass *klass);
static void gsd_wacom_manager_init (GsdWacomManager *wacom_manager);
static void gsd_wacom_manager_finalize (GObject *object);
-static gboolean set_led (GsdDevice *device,
- guint group,
- guint index,
- GError **error);
+static gboolean set_led (const gchar *device_path,
+ guint group,
+ guint index,
+ GError **error);
G_DEFINE_TYPE (GsdWacomManager, gsd_wacom_manager, G_TYPE_OBJECT)
@@ -119,7 +126,7 @@ map_tablet_left_handed (GVariant *value)
static void
migrate_tablet_settings (GsdWacomManager *manager,
- GsdDevice *device)
+ GdkDevice *device)
{
GsdSettingsMigrateEntry tablet_settings[] = {
{ "is-absolute", "mapping", map_tablet_mapping },
@@ -129,7 +136,8 @@ migrate_tablet_settings (GsdWacomManager *manager,
gchar *old_path, *new_path;
const gchar *vendor, *product;
- gsd_device_get_device_ids (device, &vendor, &product);
+ vendor = gdk_device_get_vendor_id (device);
+ product = gdk_device_get_product_id (device);
old_path = g_strdup_printf ("/org/gnome/settings-daemon/peripherals/wacom/%s-usb:%s:%s/",
manager->priv->machine_id, vendor, product);
@@ -155,24 +163,59 @@ gsd_wacom_manager_class_init (GsdWacomManagerClass *klass)
g_type_class_add_private (klass, sizeof (GsdWacomManagerPrivate));
}
-static GsdDevice *
+static gchar *
+get_device_path (GdkDevice *device)
+{
+#ifdef HAVE_WAYLAND
+ if (gnome_settings_is_wayland ())
+ return g_strdup (gdk_wayland_device_get_node_path (device));
+ else
+#endif
+ return xdevice_get_device_node (gdk_x11_device_get_id (device));
+}
+
+static GdkDevice *
lookup_device_by_path (GsdWacomManager *manager,
const gchar *path)
{
GList *devices, *l;
- devices = gsd_device_manager_list_devices (manager->priv->device_manager,
- GSD_DEVICE_TYPE_TABLET);
+ devices = gdk_seat_get_slaves (manager->priv->seat,
+ GDK_SEAT_CAPABILITY_ALL);
for (l = devices; l; l = l->next) {
- if (g_strcmp0 (gsd_device_get_device_file (l->data),
- path) == 0)
- return l->data;
+ GdkDevice *device = l->data;
+ gchar *dev_path = get_device_path (device);
+
+ if (g_strcmp0 (dev_path, path) == 0) {
+ g_free (dev_path);
+ return device;
+ }
+
+ g_free (dev_path);
}
+ g_list_free (devices);
+
return NULL;
}
+static GSettings *
+device_get_settings (GdkDevice *device)
+{
+ GSettings *settings;
+ gchar *path;
+
+ path = g_strdup_printf ("/org/gnome/desktop/peripherals/tablets/%s:%s/",
+ gdk_device_get_vendor_id (device),
+ gdk_device_get_product_id (device));
+ settings = g_settings_new_with_path ("org.gnome.desktop.peripherals.tablet",
+ path);
+ g_free (path);
+
+ return settings;
+}
+
static void
handle_method_call (GDBusConnection *connection,
const gchar *sender,
@@ -185,7 +228,7 @@ handle_method_call (GDBusConnection *connection,
{
GsdWacomManager *self = GSD_WACOM_MANAGER (data);
GError *error = NULL;
- GsdDevice *device;
+ GdkDevice *device;
if (g_strcmp0 (method_name, "SetGroupModeLED") == 0) {
gchar *device_path;
@@ -198,12 +241,14 @@ handle_method_call (GDBusConnection *connection,
return;
}
- if (set_led (device, group, mode, &error))
+ if (set_led (device_path, group, mode, &error))
g_dbus_method_invocation_return_value (invocation, NULL);
else
g_dbus_method_invocation_return_gerror (invocation, error);
} else if (g_strcmp0 (method_name, "SetOLEDLabels") == 0) {
gchar *device_path, *label;
+ gboolean left_handed;
+ GSettings *settings;
GVariantIter *iter;
gint i = 0;
@@ -214,8 +259,12 @@ handle_method_call (GDBusConnection *connection,
return;
}
+ settings = device_get_settings (device);
+ left_handed = g_settings_get_boolean (settings, LEFT_HANDED_KEY);
+ g_object_unref (settings);
+
while (g_variant_iter_loop (iter, "s", &label)) {
- if (!set_oled (device, i, label, &error)) {
+ if (!set_oled (device_path, left_handed, i, label, &error)) {
g_free (label);
break;
}
@@ -239,12 +288,11 @@ static const GDBusInterfaceVTable interface_vtable =
};
static gboolean
-set_led (GsdDevice *device,
- guint group,
- guint index,
- GError **error)
+set_led (const gchar *device_path,
+ guint group,
+ guint index,
+ GError **error)
{
- const char *path;
char *command;
gboolean ret;
@@ -252,12 +300,11 @@ set_led (GsdDevice *device,
/* Not implemented on non-Linux systems */
return TRUE;
#endif
- path = gsd_device_get_device_file (device);
- g_debug ("Switching group ID %d to index %d for device %s", group, index, path);
+ g_debug ("Switching group ID %d to index %d for device %s", group, index, device_path);
command = g_strdup_printf ("pkexec " LIBEXECDIR "/gsd-wacom-led-helper --path %s --group %d --led %d",
- path, group, index);
+ device_path, group, index);
ret = g_spawn_command_line_sync (command,
NULL,
NULL,
@@ -269,40 +316,37 @@ set_led (GsdDevice *device,
}
static void
-device_added_cb (GsdDeviceManager *device_manager,
- GsdDevice *gsd_device,
- GsdWacomManager *manager)
+device_added_cb (GdkSeat *seat,
+ GdkDevice *device,
+ GsdWacomManager *manager)
{
- GsdDeviceType device_type;
-
- device_type = gsd_device_get_device_type (gsd_device);
-
- if (device_type & GSD_DEVICE_TYPE_TABLET)
- migrate_tablet_settings (manager, gsd_device);
+ if (gdk_device_get_source (device) == GDK_SOURCE_PEN &&
+ gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_SLAVE) {
+ migrate_tablet_settings (manager, device);
+ }
}
static void
-add_devices (GsdWacomManager *manager,
- GsdDeviceType device_type)
+add_devices (GsdWacomManager *manager,
+ GdkSeatCapabilities capabilities)
{
GList *devices, *l;
- devices = gsd_device_manager_list_devices (manager->priv->device_manager,
- device_type);
+ devices = gdk_seat_get_slaves (manager->priv->seat, capabilities);
for (l = devices; l ; l = l->next)
- device_added_cb (manager->priv->device_manager, l->data, manager);
+ device_added_cb (manager->priv->seat, l->data, manager);
g_list_free (devices);
}
static void
set_devicepresence_handler (GsdWacomManager *manager)
{
- GsdDeviceManager *device_manager;
+ GdkSeat *seat;
- device_manager = gsd_device_manager_get ();
- manager->priv->device_added_id = g_signal_connect (G_OBJECT (device_manager), "device-added",
+ seat = gdk_display_get_default_seat (gdk_display_get_default ());
+ manager->priv->device_added_id = g_signal_connect (seat, "device-added",
G_CALLBACK (device_added_cb), manager);
- manager->priv->device_manager = device_manager;
+ manager->priv->seat = seat;
}
static void
@@ -318,7 +362,7 @@ gsd_wacom_manager_idle_cb (GsdWacomManager *manager)
set_devicepresence_handler (manager);
- add_devices (manager, GSD_DEVICE_TYPE_TABLET);
+ add_devices (manager, GDK_SEAT_CAPABILITY_TABLET_STYLUS);
gnome_settings_profile_end (NULL);
@@ -443,9 +487,9 @@ gsd_wacom_manager_stop (GsdWacomManager *manager)
p->dbus_register_object_id = 0;
}
- if (p->device_manager != NULL) {
- g_signal_handler_disconnect (p->device_manager, p->device_added_id);
- p->device_manager = NULL;
+ if (p->seat != NULL) {
+ g_signal_handler_disconnect (p->seat, p->device_added_id);
+ p->seat = NULL;
}
}
diff --git a/plugins/wacom/gsd-wacom-oled.c b/plugins/wacom/gsd-wacom-oled.c
index b2e219f2..4c2daf1c 100644
--- a/plugins/wacom/gsd-wacom-oled.c
+++ b/plugins/wacom/gsd-wacom-oled.c
@@ -27,12 +27,10 @@
#include <stdlib.h>
#include <string.h>
-#include "gsd-device-manager.h"
#include "gsd-wacom-oled.h"
#define MAGIC_BASE64 "base64:" /*Label starting with base64: is treated as already encoded*/
#define MAGIC_BASE64_LEN strlen(MAGIC_BASE64)
-#define LEFT_HANDED_KEY "left-handed"
static void
oled_surface_to_image (guchar *image,
@@ -219,14 +217,12 @@ oled_encode_image (char *label,
}
gboolean
-set_oled (GsdDevice *device,
- guint button,
- char *label,
- GError **error)
+set_oled (const gchar *device_path,
+ gboolean left_handed,
+ guint button,
+ char *label,
+ GError **error)
{
- gboolean left_handed = FALSE;
- GSettings *settings;
- const char *path;
char *command;
gboolean ret;
char *buffer;
@@ -240,17 +236,13 @@ set_oled (GsdDevice *device,
if (g_str_has_prefix (label, MAGIC_BASE64)) {
buffer = g_strdup (label + MAGIC_BASE64_LEN);
} else {
- settings = gsd_device_get_settings (device);
- left_handed = g_settings_get_boolean (settings, LEFT_HANDED_KEY);
buffer = oled_encode_image (label, left_handed);
}
- path = gsd_device_get_device_file (device);
-
- g_debug ("Setting OLED label '%s' on button %d (device %s)", label, button, path);
+ g_debug ("Setting OLED label '%s' on button %d (device %s)", label, button, device_path);
command = g_strdup_printf ("pkexec " LIBEXECDIR "/gsd-wacom-oled-helper --path %s --button %d --buffer %s",
- path, button, buffer);
+ device_path, button, buffer);
ret = g_spawn_command_line_sync (command,
NULL,
NULL,
diff --git a/plugins/wacom/gsd-wacom-oled.h b/plugins/wacom/gsd-wacom-oled.h
index 9acee8c7..dc5d39c8 100644
--- a/plugins/wacom/gsd-wacom-oled.h
+++ b/plugins/wacom/gsd-wacom-oled.h
@@ -18,7 +18,6 @@
*/
#include "gsd-wacom-oled-constants.h"
-#include "gsd-device-manager.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
@@ -27,7 +26,7 @@
G_BEGIN_DECLS
-gboolean set_oled (GsdDevice *device, guint button, char *label, GError **error);
+gboolean set_oled (const gchar *device_path, gboolean left_handed, guint button, char *label, GError **error);
char *gsd_wacom_oled_gdkpixbuf_to_base64 (GdkPixbuf *pixbuf);
G_END_DECLS
diff --git a/plugins/wacom/main.c b/plugins/wacom/main.c
index c7ae3378..a19a71bb 100644
--- a/plugins/wacom/main.c
+++ b/plugins/wacom/main.c
@@ -2,7 +2,6 @@
#define START gsd_wacom_manager_start
#define STOP gsd_wacom_manager_stop
#define MANAGER GsdWacomManager
-#define GDK_BACKEND "x11"
#include "gsd-wacom-manager.h"
#include "daemon-skeleton-gtk.h"