[mutter/wip/carlosg/input-thread: 154/185] backends: Use MetaViewportInfo to keep MetaSeatNative informed of layout




commit 2ce39baee9c6458858e0601a0d03f6e3fed9eeb6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jul 16 16:41:02 2020 +0200

    backends: Use MetaViewportInfo to keep MetaSeatNative informed of layout
    
    Use this for the calculations to keep absolute motion properly constrained,
    and relative motion properly scaled.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403

 src/backends/native/meta-backend-native.c |  29 +++++++-
 src/backends/native/meta-seat-native.c    | 110 ++++++++++++++++--------------
 src/backends/native/meta-seat-native.h    |   6 ++
 3 files changed, 91 insertions(+), 54 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 5bcee08fd2..63acb88667 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -145,6 +145,21 @@ maybe_disable_screen_cast_dma_bufs (MetaBackendNative *native)
 }
 #endif /* HAVE_REMOTE_DESKTOP */
 
+static void
+update_viewports (MetaBackend *backend)
+{
+  MetaMonitorManager *monitor_manager =
+    meta_backend_get_monitor_manager (backend);
+  ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
+  MetaSeatNative *seat =
+    META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
+  MetaViewportInfo *viewports;
+
+  viewports = meta_monitor_manager_get_viewports (monitor_manager);
+  meta_seat_native_set_viewports (seat, viewports);
+  g_object_unref (viewports);
+}
+
 static void
 meta_backend_native_post_init (MetaBackend *backend)
 {
@@ -170,6 +185,8 @@ meta_backend_native_post_init (MetaBackend *backend)
   maybe_disable_screen_cast_dma_bufs (META_BACKEND_NATIVE (backend));
 #endif
 
+  update_viewports (backend);
+
 #ifdef HAVE_WAYLAND
   meta_backend_init_wayland (backend);
 #endif
@@ -179,9 +196,15 @@ static MetaMonitorManager *
 meta_backend_native_create_monitor_manager (MetaBackend *backend,
                                             GError     **error)
 {
-  return g_initable_new (META_TYPE_MONITOR_MANAGER_KMS, NULL, error,
-                         "backend", backend,
-                         NULL);
+  MetaMonitorManager *manager;
+
+  manager = g_initable_new (META_TYPE_MONITOR_MANAGER_KMS, NULL, error,
+                            "backend", backend,
+                            NULL);
+  g_signal_connect_swapped (manager, "monitors-changed-internal",
+                            G_CALLBACK (update_viewports), backend);
+
+  return manager;
 }
 
 static MetaCursorRenderer *
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 1eeb9d7251..bfb53912f4 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -878,13 +878,13 @@ constrain_to_barriers (MetaSeatNative     *seat,
 
 static void
 constrain_all_screen_monitors (ClutterInputDevice *device,
-                               MetaMonitorManager *monitor_manager,
+                               MetaViewportInfo   *viewports,
                                float              *x,
                                float              *y)
 {
   graphene_point_t current;
   float cx, cy;
-  GList *logical_monitors, *l;
+  int i, n_views;
 
   clutter_input_device_get_coords (device, NULL, &current);
 
@@ -893,17 +893,19 @@ constrain_all_screen_monitors (ClutterInputDevice *device,
 
   /* if we're trying to escape, clamp to the CRTC we're coming from */
 
-  logical_monitors =
-    meta_monitor_manager_get_logical_monitors (monitor_manager);
-  for (l = logical_monitors; l; l = l->next)
+  n_views = meta_viewport_info_get_num_views (viewports);
+
+  for (i = 0; i < n_views; i++)
     {
-      MetaLogicalMonitor *logical_monitor = l->data;
       int left, right, top, bottom;
+      cairo_rectangle_int_t rect;
+
+      meta_viewport_info_get_view (viewports, i, &rect, NULL);
 
-      left = logical_monitor->rect.x;
-      right = left + logical_monitor->rect.width;
-      top = logical_monitor->rect.y;
-      bottom = top + logical_monitor->rect.height;
+      left = rect.x;
+      right = left + rect.width;
+      top = rect.y;
+      bottom = top + rect.height;
 
       if ((cx >= left) && (cx < right) && (cy >= top) && (cy < bottom))
         {
@@ -930,10 +932,6 @@ meta_seat_native_constrain_pointer (MetaSeatNative     *seat,
                                     float              *new_x,
                                     float              *new_y)
 {
-  MetaBackend *backend = meta_get_backend ();
-  MetaMonitorManager *monitor_manager =
-    meta_backend_get_monitor_manager (backend);
-
   constrain_to_barriers (seat, core_pointer,
                          us2ms (time_us),
                          new_x, new_y);
@@ -948,53 +946,59 @@ meta_seat_native_constrain_pointer (MetaSeatNative     *seat,
                                               new_x, new_y);
     }
 
-  /* if we're moving inside a monitor, we're fine */
-  if (meta_monitor_manager_get_logical_monitor_at (monitor_manager,
-                                                   *new_x, *new_y))
-    return;
+  if (seat->viewports)
+    {
+      /* if we're moving inside a monitor, we're fine */
+      if (meta_viewport_info_get_view_at (seat->viewports, *new_x, *new_y) >= 0)
+        return;
 
-  /* if we're trying to escape, clamp to the CRTC we're coming from */
-  constrain_all_screen_monitors (core_pointer, monitor_manager, new_x, new_y);
+      /* if we're trying to escape, clamp to the CRTC we're coming from */
+      constrain_all_screen_monitors (core_pointer, seat->viewports, new_x, new_y);
+    }
 }
 
 static void
-relative_motion_across_outputs (MetaMonitorManager *monitor_manager,
-                                MetaLogicalMonitor *current,
+relative_motion_across_outputs (MetaViewportInfo   *viewports,
+                                int                 view,
                                 float               cur_x,
                                 float               cur_y,
                                 float              *dx_inout,
                                 float              *dy_inout)
 {
-  MetaLogicalMonitor *cur = current;
+  int cur_view = view;
   float x = cur_x, y = cur_y;
   float target_x = cur_x, target_y = cur_y;
   float dx = *dx_inout, dy = *dy_inout;
   MetaDisplayDirection direction = -1;
 
-  while (cur)
+  while (cur_view >= 0)
     {
       MetaLine2 left, right, top, bottom, motion;
       MetaVector2 intersection;
+      cairo_rectangle_int_t rect;
+      float scale;
+
+      meta_viewport_info_get_view (viewports, cur_view, &rect, &scale);
 
       motion = (MetaLine2) {
         .a = { x, y },
-        .b = { x + (dx * cur->scale), y + (dy * cur->scale) }
+        .b = { x + (dx * scale), y + (dy * scale) }
       };
       left = (MetaLine2) {
-        { cur->rect.x, cur->rect.y },
-        { cur->rect.x, cur->rect.y + cur->rect.height }
+        { rect.x, rect.y },
+        { rect.x, rect.y + rect.height }
       };
       right = (MetaLine2) {
-        { cur->rect.x + cur->rect.width, cur->rect.y },
-        { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height }
+        { rect.x + rect.width, rect.y },
+        { rect.x + rect.width, rect.y + rect.height }
       };
       top = (MetaLine2) {
-        { cur->rect.x, cur->rect.y },
-        { cur->rect.x + cur->rect.width, cur->rect.y }
+        { rect.x, rect.y },
+        { rect.x + rect.width, rect.y }
       };
       bottom = (MetaLine2) {
-        { cur->rect.x, cur->rect.y + cur->rect.height },
-        { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height }
+        { rect.x, rect.y + rect.height },
+        { rect.x + rect.width, rect.y + rect.height }
       };
 
       target_x = motion.b.x;
@@ -1021,8 +1025,8 @@ relative_motion_across_outputs (MetaMonitorManager *monitor_manager,
       dx -= intersection.x - motion.a.x;
       dy -= intersection.y - motion.a.y;
 
-      cur = meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager,
-                                                               cur, direction);
+      cur_view = meta_viewport_info_get_neighbor (viewports, cur_view,
+                                                  direction);
     }
 
   *dx_inout = target_x - cur_x;
@@ -1037,35 +1041,32 @@ meta_seat_native_filter_relative_motion (MetaSeatNative     *seat,
                                          float              *dx,
                                          float              *dy)
 {
-  MetaBackend *backend = meta_get_backend ();
-  MetaMonitorManager *monitor_manager =
-    meta_backend_get_monitor_manager (backend);
-  MetaLogicalMonitor *logical_monitor, *dest_logical_monitor;
-  float new_dx, new_dy;
+  int view = -1, dest_view;
+  float new_dx, new_dy, scale;
 
   if (meta_is_stage_views_scaled ())
     return;
 
-  logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager,
-                                                                 x, y);
-  if (!logical_monitor)
+  if (seat->viewports)
+    view = meta_viewport_info_get_view_at (seat->viewports, x, y);
+  if (view < 0)
     return;
 
-  new_dx = (*dx) * logical_monitor->scale;
-  new_dy = (*dy) * logical_monitor->scale;
+  meta_viewport_info_get_view (seat->viewports, view, NULL, &scale);
+  new_dx = (*dx) * scale;
+  new_dy = (*dy) * scale;
 
-  dest_logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager,
-                                                                      x + new_dx,
-                                                                      y + new_dy);
-  if (dest_logical_monitor &&
-      dest_logical_monitor != logical_monitor)
+  dest_view = meta_viewport_info_get_view_at (seat->viewports,
+                                              x + new_dx,
+                                              y + new_dy);
+  if (dest_view >= 0 && dest_view != view)
     {
       /* If we are crossing monitors, attempt to bisect the distance on each
        * axis and apply the relative scale for each of them.
        */
       new_dx = *dx;
       new_dy = *dy;
-      relative_motion_across_outputs (monitor_manager, logical_monitor,
+      relative_motion_across_outputs (seat->viewports, view,
                                       x, y, &new_dx, &new_dy);
     }
 
@@ -3400,3 +3401,10 @@ meta_seat_native_get_cursor_renderer (MetaSeatNative     *seat,
 
   return NULL;
 }
+
+void
+meta_seat_native_set_viewports (MetaSeatNative   *seat,
+                                MetaViewportInfo *viewports)
+{
+  g_set_object (&seat->viewports, viewports);
+}
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index 0200ad0a48..7550dfe5dd 100644
--- a/src/backends/native/meta-seat-native.h
+++ b/src/backends/native/meta-seat-native.h
@@ -27,6 +27,7 @@
 #include <libinput.h>
 #include <linux/input-event-codes.h>
 
+#include "backends/meta-viewport-info.h"
 #include "backends/native/meta-barrier-native.h"
 #include "backends/native/meta-cursor-renderer-native.h"
 #include "backends/native/meta-keymap-native.h"
@@ -90,6 +91,8 @@ struct _MetaSeatNative
   MetaKmsCursorRenderer *kms_cursor_renderer;
   GHashTable *tablet_cursors;
 
+  MetaViewportInfo *viewports;
+
   GUdevClient *udev_client;
   guint tablet_mode_switch_state : 1;
   guint has_touchscreen          : 1;
@@ -265,4 +268,7 @@ void meta_seat_native_set_pointer_constraint (MetaSeatNative            *seat,
 MetaCursorRenderer * meta_seat_native_get_cursor_renderer (MetaSeatNative     *seat,
                                                            ClutterInputDevice *device);
 
+void meta_seat_native_set_viewports (MetaSeatNative   *seat,
+                                     MetaViewportInfo *viewports);
+
 #endif /* META_SEAT_NATIVE_H */


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