From 9e3bac0237c9746c52fe66d70bac82f07f3a7f4d Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 11 Feb 2015 14:59:21 +0100 Subject: [PATCH] backend: Add meta_backend_update_last_device() This function can be used to trigger changes depending on the device type that is currently emitting the events. So far, it is used to switch cursor visibility on/off on touchscreen interaction. A "last-device-updated" signal has also been added, in order allow hooking other behavior changes (eg. OSK) when the last device changes. https://bugzilla.gnome.org/show_bug.cgi?id=712775 --- src/backends/meta-backend-private.h | 4 +++ src/backends/meta-backend.c | 46 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h index 9a0c806fd..d2c627657 100644 --- a/src/backends/meta-backend-private.h +++ b/src/backends/meta-backend-private.h @@ -50,6 +50,7 @@ struct _MetaBackend GObject parent; GHashTable *device_monitors; + gint current_device_id; }; struct _MetaBackendClass @@ -106,4 +107,7 @@ void meta_backend_warp_pointer (MetaBackend *backend, struct xkb_keymap * meta_backend_get_keymap (MetaBackend *backend); +void meta_backend_update_last_device (MetaBackend *backend, + int device_id); + #endif /* META_BACKEND_PRIVATE_H */ diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index dd9641f9d..474184aae 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -29,6 +29,7 @@ #include "meta-input-settings-private.h" #include "backends/x11/meta-backend-x11.h" +#include "meta-cursor-tracker-private.h" #include "meta-stage.h" #ifdef HAVE_NATIVE_BACKEND @@ -268,6 +269,12 @@ meta_backend_class_init (MetaBackendClass *klass) 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT); + g_signal_new ("last-device-changed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, NULL, + G_TYPE_NONE, 1, G_TYPE_INT); } static void @@ -388,6 +395,45 @@ meta_backend_get_stage (MetaBackend *backend) return priv->stage; } +void +meta_backend_update_last_device (MetaBackend *backend, + int device_id) +{ + ClutterInputDeviceType device_type; + MetaCursorTracker *cursor_tracker; + ClutterDeviceManager *manager; + ClutterInputDevice *device; + + if (backend->current_device_id == device_id) + return; + + manager = clutter_device_manager_get_default (); + device = clutter_device_manager_get_device (manager, device_id); + + if (!device || + clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER) + return; + + device_type = clutter_input_device_get_device_type (device); + + cursor_tracker = meta_cursor_tracker_get_for_screen (NULL); + backend->current_device_id = device_id; + g_signal_emit_by_name (backend, "last-device-changed", device_id); + + if (device_type == CLUTTER_KEYBOARD_DEVICE) + return; + + switch (device_type) + { + case CLUTTER_TOUCHSCREEN_DEVICE: + meta_cursor_tracker_set_pointer_visible (cursor_tracker, FALSE); + break; + default: + meta_cursor_tracker_set_pointer_visible (cursor_tracker, TRUE); + break; + } +} + static GType get_backend_type (void) {