backends: Do not use device IDs on idle monitors

Device IDs are somewhat x11 specific, seems better to avoid those
on public API. We can rely everywhere on ClutterInputDevice, so use
it instead.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/852
This commit is contained in:
Carlos Garnacho 2019-10-09 16:03:24 +02:00
parent d3160d095d
commit e9fbbd5853
8 changed files with 56 additions and 56 deletions

View File

@ -121,8 +121,8 @@ void meta_init_backend (GType backend_gtype);
ClutterBackend * meta_backend_get_clutter_backend (MetaBackend *backend); ClutterBackend * meta_backend_get_clutter_backend (MetaBackend *backend);
MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend, MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend,
int device_id); ClutterInputDevice *device);
void meta_backend_foreach_device_monitor (MetaBackend *backend, void meta_backend_foreach_device_monitor (MetaBackend *backend,
GFunc func, GFunc func,
gpointer user_data); gpointer user_data);

View File

@ -81,8 +81,6 @@
#include "backends/native/meta-backend-native.h" #include "backends/native/meta-backend-native.h"
#endif #endif
#define META_IDLE_MONITOR_CORE_DEVICE 0
enum enum
{ {
KEYMAP_CHANGED, KEYMAP_CHANGED,
@ -311,44 +309,42 @@ meta_backend_foreach_device_monitor (MetaBackend *backend,
} }
static MetaIdleMonitor * static MetaIdleMonitor *
meta_backend_create_idle_monitor (MetaBackend *backend, meta_backend_create_idle_monitor (MetaBackend *backend,
int device_id) ClutterInputDevice *device)
{ {
return g_object_new (META_TYPE_IDLE_MONITOR, return g_object_new (META_TYPE_IDLE_MONITOR,
"device-id", device_id, "device", device,
NULL); NULL);
} }
static void static void
create_device_monitor (MetaBackend *backend, create_device_monitor (MetaBackend *backend,
int device_id) ClutterInputDevice *device)
{ {
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
MetaIdleMonitor *idle_monitor; MetaIdleMonitor *idle_monitor;
g_assert (g_hash_table_lookup (priv->device_monitors, &device_id) == NULL); if (g_hash_table_contains (priv->device_monitors, device))
return;
idle_monitor = meta_backend_create_idle_monitor (backend, device_id); idle_monitor = meta_backend_create_idle_monitor (backend, device);
g_hash_table_insert (priv->device_monitors, &idle_monitor->device_id, idle_monitor); g_hash_table_insert (priv->device_monitors, device, idle_monitor);
} }
static void static void
destroy_device_monitor (MetaBackend *backend, destroy_device_monitor (MetaBackend *backend,
int device_id) ClutterInputDevice *device)
{ {
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
g_hash_table_remove (priv->device_monitors, &device_id); g_hash_table_remove (priv->device_monitors, device);
} }
static void static void
meta_backend_monitor_device (MetaBackend *backend, meta_backend_monitor_device (MetaBackend *backend,
ClutterInputDevice *device) ClutterInputDevice *device)
{ {
int device_id; create_device_monitor (backend, device);
device_id = clutter_input_device_get_device_id (device);
create_device_monitor (backend, device_id);
} }
static void static void
@ -357,9 +353,8 @@ on_device_added (ClutterSeat *seat,
gpointer user_data) gpointer user_data)
{ {
MetaBackend *backend = META_BACKEND (user_data); MetaBackend *backend = META_BACKEND (user_data);
int device_id = clutter_input_device_get_device_id (device);
create_device_monitor (backend, device_id); create_device_monitor (backend, device);
} }
static inline gboolean static inline gboolean
@ -428,9 +423,8 @@ on_device_removed (ClutterSeat *seat,
{ {
MetaBackend *backend = META_BACKEND (user_data); MetaBackend *backend = META_BACKEND (user_data);
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
int device_id = clutter_input_device_get_device_id (device);
destroy_device_monitor (backend, device_id); destroy_device_monitor (backend, device);
/* If the device the user last interacted goes away, check again pointer /* If the device the user last interacted goes away, check again pointer
* visibility. * visibility.
@ -467,7 +461,8 @@ create_device_monitors (MetaBackend *backend,
{ {
GList *l, *devices; GList *l, *devices;
create_device_monitor (backend, META_IDLE_MONITOR_CORE_DEVICE); create_device_monitor (backend, clutter_seat_get_pointer (seat));
create_device_monitor (backend, clutter_seat_get_keyboard (seat));
devices = clutter_seat_list_devices (seat); devices = clutter_seat_list_devices (seat);
for (l = devices; l; l = l->next) for (l = devices; l; l = l->next)
@ -525,8 +520,7 @@ meta_backend_real_post_init (MetaBackend *backend)
priv->cursor_renderer = META_BACKEND_GET_CLASS (backend)->create_cursor_renderer (backend); priv->cursor_renderer = META_BACKEND_GET_CLASS (backend)->create_cursor_renderer (backend);
priv->device_monitors = priv->device_monitors =
g_hash_table_new_full (g_int_hash, g_int_equal, g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_object_unref);
NULL, (GDestroyNotify) g_object_unref);
create_device_monitors (backend, seat); create_device_monitors (backend, seat);
@ -934,12 +928,12 @@ meta_backend_post_init (MetaBackend *backend)
* meta_backend_get_idle_monitor: (skip) * meta_backend_get_idle_monitor: (skip)
*/ */
MetaIdleMonitor * MetaIdleMonitor *
meta_backend_get_idle_monitor (MetaBackend *backend, meta_backend_get_idle_monitor (MetaBackend *backend,
int device_id) ClutterInputDevice *device)
{ {
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
return g_hash_table_lookup (priv->device_monitors, &device_id); return g_hash_table_lookup (priv->device_monitors, device);
} }
/** /**

View File

@ -220,7 +220,7 @@ on_device_added (ClutterSeat *seat,
char *path; char *path;
device_id = clutter_input_device_get_device_id (device); device_id = clutter_input_device_get_device_id (device);
monitor = meta_idle_monitor_get_for_device (device_id); monitor = meta_idle_monitor_get_for_device (device);
path = g_strdup_printf ("/org/gnome/Mutter/IdleMonitor/Device%d", device_id); path = g_strdup_printf ("/org/gnome/Mutter/IdleMonitor/Device%d", device_id);
create_monitor_skeleton (manager, monitor, path); create_monitor_skeleton (manager, monitor, path);

View File

@ -45,7 +45,7 @@ struct _MetaIdleMonitor
GDBusProxy *session_proxy; GDBusProxy *session_proxy;
gboolean inhibited; gboolean inhibited;
GHashTable *watches; GHashTable *watches;
int device_id; ClutterInputDevice *device;
guint64 last_event_time; guint64 last_event_time;
}; };

View File

@ -46,7 +46,7 @@ G_STATIC_ASSERT(sizeof(unsigned long) == sizeof(gpointer));
enum enum
{ {
PROP_0, PROP_0,
PROP_DEVICE_ID, PROP_DEVICE,
PROP_LAST, PROP_LAST,
}; };
@ -99,8 +99,8 @@ meta_idle_monitor_get_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_DEVICE_ID: case PROP_DEVICE:
g_value_set_int (value, monitor->device_id); g_value_set_object (value, monitor->device);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -117,8 +117,8 @@ meta_idle_monitor_set_property (GObject *object,
MetaIdleMonitor *monitor = META_IDLE_MONITOR (object); MetaIdleMonitor *monitor = META_IDLE_MONITOR (object);
switch (prop_id) switch (prop_id)
{ {
case PROP_DEVICE_ID: case PROP_DEVICE:
monitor->device_id = g_value_get_int (value); monitor->device = g_value_get_object (value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -136,17 +136,18 @@ meta_idle_monitor_class_init (MetaIdleMonitorClass *klass)
object_class->set_property = meta_idle_monitor_set_property; object_class->set_property = meta_idle_monitor_set_property;
/** /**
* MetaIdleMonitor:device_id: * MetaIdleMonitor:device:
* *
* The device to listen to idletime on. * The device to listen to idletime on.
*/ */
obj_props[PROP_DEVICE_ID] = obj_props[PROP_DEVICE] =
g_param_spec_int ("device-id", g_param_spec_object ("device",
"Device ID", "Device",
"The device to listen to idletime on", "The device to listen to idletime on",
0, 255, 0, CLUTTER_TYPE_INPUT_DEVICE,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_DEVICE_ID, obj_props[PROP_DEVICE_ID]);
g_object_class_install_property (object_class, PROP_DEVICE, obj_props[PROP_DEVICE]);
} }
static void static void
@ -276,22 +277,25 @@ MetaIdleMonitor *
meta_idle_monitor_get_core (void) meta_idle_monitor_get_core (void)
{ {
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = meta_get_backend ();
return meta_backend_get_idle_monitor (backend, 0); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
return meta_backend_get_idle_monitor (backend, clutter_seat_get_pointer (seat));
} }
/** /**
* meta_idle_monitor_get_for_device: * meta_idle_monitor_get_for_device:
* @device_id: the device to get the idle time for. * @device: the device to get the idle time for.
* *
* Returns: (transfer none): a new #MetaIdleMonitor that tracks the * Returns: (transfer none): a new #MetaIdleMonitor that tracks the
* device-specific idletime for @device. To track server-global idletime * device-specific idletime for @device. To track server-global idletime
* for all devices, use meta_idle_monitor_get_core(). * for all devices, use meta_idle_monitor_get_core().
*/ */
MetaIdleMonitor * MetaIdleMonitor *
meta_idle_monitor_get_for_device (int device_id) meta_idle_monitor_get_for_device (ClutterInputDevice *device)
{ {
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = meta_get_backend ();
return meta_backend_get_idle_monitor (backend, device_id); return meta_backend_get_idle_monitor (backend, device);
} }
static guint32 static guint32

View File

@ -157,6 +157,9 @@ handle_alarm_notify (MetaBackend *backend,
MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11); MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
MetaIdleMonitor *idle_monitor; MetaIdleMonitor *idle_monitor;
XSyncAlarmAttributes attr; XSyncAlarmAttributes attr;
ClutterBackend *clutter_backend;
ClutterSeat *seat;
ClutterInputDevice *pointer;
if (alarm_event->state != XSyncAlarmActive || if (alarm_event->state != XSyncAlarmActive ||
alarm_event->alarm != priv->user_active_alarm) alarm_event->alarm != priv->user_active_alarm)
@ -166,7 +169,10 @@ handle_alarm_notify (MetaBackend *backend,
XSyncChangeAlarm (priv->xdisplay, priv->user_active_alarm, XSyncChangeAlarm (priv->xdisplay, priv->user_active_alarm,
XSyncCAEvents, &attr); XSyncCAEvents, &attr);
idle_monitor = meta_backend_get_idle_monitor (backend, 0); clutter_backend = meta_backend_get_clutter_backend (backend);
seat = clutter_backend_get_default_seat (clutter_backend);
pointer = clutter_seat_get_pointer (seat);
idle_monitor = meta_backend_get_idle_monitor (backend, pointer);
meta_idle_monitor_reset_idletime (idle_monitor); meta_idle_monitor_reset_idletime (idle_monitor);
} }

View File

@ -103,7 +103,6 @@ handle_idletime_for_event (const ClutterEvent *event)
{ {
ClutterInputDevice *device, *source_device; ClutterInputDevice *device, *source_device;
MetaIdleMonitor *core_monitor, *device_monitor; MetaIdleMonitor *core_monitor, *device_monitor;
int device_id;
device = clutter_event_get_device (event); device = clutter_event_get_device (event);
if (device == NULL) if (device == NULL)
@ -118,10 +117,8 @@ handle_idletime_for_event (const ClutterEvent *event)
event->type == CLUTTER_DELETE) event->type == CLUTTER_DELETE)
return; return;
device_id = clutter_input_device_get_device_id (device);
core_monitor = meta_idle_monitor_get_core (); core_monitor = meta_idle_monitor_get_core ();
device_monitor = meta_idle_monitor_get_for_device (device_id); device_monitor = meta_idle_monitor_get_for_device (device);
meta_idle_monitor_reset_idletime (core_monitor); meta_idle_monitor_reset_idletime (core_monitor);
meta_idle_monitor_reset_idletime (device_monitor); meta_idle_monitor_reset_idletime (device_monitor);
@ -129,8 +126,7 @@ handle_idletime_for_event (const ClutterEvent *event)
source_device = clutter_event_get_source_device (event); source_device = clutter_event_get_source_device (event);
if (source_device != device) if (source_device != device)
{ {
device_id = clutter_input_device_get_device_id (device); device_monitor = meta_idle_monitor_get_for_device (source_device);
device_monitor = meta_idle_monitor_get_for_device (device_id);
meta_idle_monitor_reset_idletime (device_monitor); meta_idle_monitor_reset_idletime (device_monitor);
} }
} }

View File

@ -44,7 +44,7 @@ META_EXPORT
MetaIdleMonitor *meta_idle_monitor_get_core (void); MetaIdleMonitor *meta_idle_monitor_get_core (void);
META_EXPORT META_EXPORT
MetaIdleMonitor *meta_idle_monitor_get_for_device (int device_id); MetaIdleMonitor *meta_idle_monitor_get_for_device (ClutterInputDevice *device);
META_EXPORT META_EXPORT
guint meta_idle_monitor_add_idle_watch (MetaIdleMonitor *monitor, guint meta_idle_monitor_add_idle_watch (MetaIdleMonitor *monitor,