From 86994824756f1d096b9c21f5fa3650dd7c320ce1 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 13 Dec 2019 15:26:05 +0100 Subject: [PATCH] backends: Check both input settings and mapper for tablet monitors The upper layers (OSDs basically) want to know the monitor that a tablet is currently assigned to, not the monitor just as configured through settings. This broke proper OSD positioning for display-attached tablets since commit 87858a4e01d9, as the MetaInputMapper kicks in precisely when there is no configured monitor for the given device. Consulting both about the assigned output will make OSDs pop up again in the right place. https://gitlab.gnome.org/GNOME/mutter/merge_requests/971 --- src/backends/meta-input-mapper-private.h | 3 ++ src/backends/meta-input-mapper.c | 26 +++++++++++ src/backends/meta-input-settings.c | 56 +++++++++++++++++++++++- 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/backends/meta-input-mapper-private.h b/src/backends/meta-input-mapper-private.h index 34314577f..cdfdccde9 100644 --- a/src/backends/meta-input-mapper-private.h +++ b/src/backends/meta-input-mapper-private.h @@ -42,5 +42,8 @@ ClutterInputDevice * meta_input_mapper_get_logical_monitor_device (MetaInputMapper *mapper, MetaLogicalMonitor *logical_monitor, ClutterInputDeviceType device_type); +MetaLogicalMonitor * +meta_input_mapper_get_device_logical_monitor (MetaInputMapper *mapper, + ClutterInputDevice *device); #endif /* META_INPUT_MAPPER_H */ diff --git a/src/backends/meta-input-mapper.c b/src/backends/meta-input-mapper.c index 0e5a5f5c3..a241af3f5 100644 --- a/src/backends/meta-input-mapper.c +++ b/src/backends/meta-input-mapper.c @@ -675,3 +675,29 @@ meta_input_mapper_get_logical_monitor_device (MetaInputMapper *mapper, return NULL; } + +MetaLogicalMonitor * +meta_input_mapper_get_device_logical_monitor (MetaInputMapper *mapper, + ClutterInputDevice *device) +{ + MetaMapperOutputInfo *output; + MetaLogicalMonitor *logical_monitor; + GHashTableIter iter; + GList *l; + + g_hash_table_iter_init (&iter, mapper->output_devices); + + while (g_hash_table_iter_next (&iter, (gpointer *) &logical_monitor, + (gpointer *) &output)) + { + for (l = output->input_devices; l; l = l->next) + { + MetaMapperInputInfo *input = l->data; + + if (input->device == device) + return logical_monitor; + } + } + + return NULL; +} diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c index 73f4131fe..2028570c0 100644 --- a/src/backends/meta-input-settings.c +++ b/src/backends/meta-input-settings.c @@ -2064,6 +2064,44 @@ meta_input_settings_get_tablet_settings (MetaInputSettings *settings, return info ? g_object_ref (info->settings) : NULL; } +static ClutterInputDevice * +find_grouped_pen (MetaInputSettings *settings, + ClutterInputDevice *device) +{ + MetaInputSettingsPrivate *priv; + GList *l, *devices; + ClutterInputDeviceType device_type; + ClutterInputDevice *pen = NULL; + + device_type = clutter_input_device_get_device_type (device); + + if (device_type == CLUTTER_TABLET_DEVICE || + device_type == CLUTTER_PEN_DEVICE) + return device; + + priv = meta_input_settings_get_instance_private (settings); + devices = clutter_seat_list_devices (priv->seat); + + for (l = devices; l; l = l->next) + { + ClutterInputDevice *other_device = l->data; + + device_type = clutter_input_device_get_device_type (other_device); + + if ((device_type == CLUTTER_TABLET_DEVICE || + device_type == CLUTTER_PEN_DEVICE) && + clutter_input_device_is_grouped (device, other_device)) + { + pen = other_device; + break; + } + } + + g_list_free (devices); + + return pen; +} + MetaLogicalMonitor * meta_input_settings_get_tablet_logical_monitor (MetaInputSettings *settings, ClutterInputDevice *device) @@ -2075,13 +2113,27 @@ meta_input_settings_get_tablet_logical_monitor (MetaInputSettings *settings, g_return_val_if_fail (META_IS_INPUT_SETTINGS (settings), NULL); g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL); + if (clutter_input_device_get_device_type (device) == CLUTTER_PAD_DEVICE) + { + device = find_grouped_pen (settings, device); + if (!device) + return NULL; + } + priv = meta_input_settings_get_instance_private (settings); info = g_hash_table_lookup (priv->mappable_devices, device); if (!info) return NULL; - meta_input_settings_find_monitor (settings, info->settings, device, - NULL, &logical_monitor); + logical_monitor = + meta_input_mapper_get_device_logical_monitor (priv->input_mapper, device); + + if (!logical_monitor) + { + meta_input_settings_find_monitor (settings, info->settings, device, + NULL, &logical_monitor); + } + return logical_monitor; }