Blob Blame History Raw
From f14730e7307679cb979aa521b20f246dfc5082da Mon Sep 17 00:00:00 2001
From: Carlos Garnacho <carlosg@gnome.org>
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       | 11 ++++++++--
 3 files changed, 38 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 acc9b1618..571b3983c 100644
--- a/src/backends/meta-input-mapper.c
+++ b/src/backends/meta-input-mapper.c
@@ -684,3 +684,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 b7aec8d6d..a923aa971 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -1922,8 +1922,15 @@ meta_input_settings_get_tablet_logical_monitor (MetaInputSettings  *settings,
   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;
 }
 
-- 
2.23.0