[mutter] input-settings/native: Check mapping mode in input thread



commit 90eab428676cf0ebfee3da4faf1c7a82e734b7fd
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Thu Mar 18 12:07:08 2021 +0100

    input-settings/native: Check mapping mode in input thread
    
    When we set the matrix, we checked the device mapping mode in the main
    thread, then passed along the calculated matrix to the input thread for
    application. This could however be racy, as the mapping mode is managed
    in the input thread. Fix this by sending the unaltered matrix, having
    the input thread checking the mapping mode.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1806>

 src/backends/native/meta-input-settings-native.c | 42 +++++++++++-------------
 1 file changed, 20 insertions(+), 22 deletions(-)
---
diff --git a/src/backends/native/meta-input-settings-native.c 
b/src/backends/native/meta-input-settings-native.c
index 18aafcc789..5d85bb47e4 100644
--- a/src/backends/native/meta-input-settings-native.c
+++ b/src/backends/native/meta-input-settings-native.c
@@ -134,12 +134,25 @@ meta_input_settings_native_set_send_events (MetaInputSettings        *settings,
 static gboolean
 set_matrix (GTask *task)
 {
-  ClutterInputDevice *device;
-  cairo_matrix_t *dev_matrix;
+  ClutterInputDevice *device = g_task_get_source_object (task);
+  float *matrix = g_task_get_task_data (task);
+  cairo_matrix_t dev_matrix;
 
-  device = g_task_get_source_object (task);
-  dev_matrix = g_task_get_task_data (task);
-  g_object_set (device, "device-matrix", dev_matrix, NULL);
+  if (clutter_input_device_get_device_type (device) ==
+      CLUTTER_TOUCHSCREEN_DEVICE ||
+      meta_input_device_native_get_mapping_mode_in_impl (device) ==
+      META_INPUT_DEVICE_MAPPING_ABSOLUTE)
+    {
+      cairo_matrix_init (&dev_matrix,
+                         matrix[0], matrix[3], matrix[1],
+                         matrix[4], matrix[2], matrix[5]);
+    }
+  else
+    {
+      cairo_matrix_init_identity (&dev_matrix);
+    }
+
+  g_object_set (device, "device-matrix", &dev_matrix, NULL);
 
   return G_SOURCE_REMOVE;
 }
@@ -150,26 +163,11 @@ meta_input_settings_native_set_matrix (MetaInputSettings  *settings,
                                        const float         matrix[6])
 {
   MetaInputSettingsNative *input_settings_native;
-  cairo_matrix_t *dev_matrix;
   GTask *task;
 
-  dev_matrix = g_new0 (cairo_matrix_t, 1);
-
-  if (clutter_input_device_get_device_type (device) ==
-      CLUTTER_TOUCHSCREEN_DEVICE ||
-      meta_input_device_native_get_mapping_mode_in_impl (device) ==
-      META_INPUT_DEVICE_MAPPING_ABSOLUTE)
-    {
-      cairo_matrix_init (dev_matrix, matrix[0], matrix[3], matrix[1],
-                         matrix[4], matrix[2], matrix[5]);
-    }
-  else
-    {
-      cairo_matrix_init_identity (dev_matrix);
-    }
-
   task = g_task_new (device, NULL, NULL, NULL);
-  g_task_set_task_data (task, dev_matrix, g_free);
+
+  g_task_set_task_data (task, g_memdup2 (matrix, sizeof (float) * 6), g_free);
 
   input_settings_native = META_INPUT_SETTINGS_NATIVE (settings);
   meta_seat_impl_run_input_task (input_settings_native->seat_impl,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]