[mutter] backends/native: Fix relative motion calculation if monitor isn't found



commit c4fa30ac7ddf529e489fd3d59f50b19c26f59f7c
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Sun Dec 8 12:02:51 2019 +0100

    backends/native: Fix relative motion calculation if monitor isn't found
    
    The method `relative_motion_across_outputs` is used to adjust the
    distance/delta of a mouse movement across multiple monitors to take the
    different scale factors of those monitors into account. This works by
    getting the adjacent monitors that the movement-line/vector intersects
    with and adjusting the final position (or end point of the
    movement-line) by multiplying the parts of the line spanning across
    different monitors with the scale factors of those monitors.
    
    In the end of this calculation, we always want to set the new end
    coordinates of the relative motion to the new end coordinates of the
    adjusted movement-line. We currently only do that if all adjacent
    monitors the line is crossing actually exist, because only then we end
    up inside the "We reached the dest logical monitor" else-block and set
    `x` and `y` to the correct values. Fix that and make sure the returned
    values are also correct in case an adjacent monitor doesn't exist by
    adding separate `target_x` and `target_y` variables which we update during
    each pass of the while loop so we're always prepared for the while loop
    exiting before the destination monitor was found.
    
    Thanks to Axel Kittenberger for reporting the initial bug and tracking
    the issue down to `relative_motion_across_outputs`.
    
    Fixes https://gitlab.gnome.org/GNOME/mutter/issues/774

 src/backends/native/meta-backend-native.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 5e4a8dd97..469cd0cc1 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -227,6 +227,7 @@ relative_motion_across_outputs (MetaMonitorManager *monitor_manager,
 {
   MetaLogicalMonitor *cur = current;
   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;
 
@@ -256,6 +257,9 @@ relative_motion_across_outputs (MetaMonitorManager *monitor_manager,
               { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height }
       };
 
+      target_x = motion.b.x;
+      target_y = motion.b.y;
+
       if (direction != META_DISPLAY_RIGHT &&
           meta_line2_intersects_with (&motion, &left, &intersection))
         direction = META_DISPLAY_LEFT;
@@ -269,12 +273,8 @@ relative_motion_across_outputs (MetaMonitorManager *monitor_manager,
                meta_line2_intersects_with (&motion, &bottom, &intersection))
         direction = META_DISPLAY_DOWN;
       else
-        {
-          /* We reached the dest logical monitor */
-          x = motion.b.x;
-          y = motion.b.y;
-          break;
-        }
+        /* We reached the dest logical monitor */
+        break;
 
       x = intersection.x;
       y = intersection.y;
@@ -285,8 +285,8 @@ relative_motion_across_outputs (MetaMonitorManager *monitor_manager,
                                                                cur, direction);
     }
 
-  *dx_inout = x - cur_x;
-  *dy_inout = y - cur_y;
+  *dx_inout = target_x - cur_x;
+  *dy_inout = target_y - cur_y;
 }
 
 static void


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