[mutter] screen: fix meta_screen_get_monitor_for_rect for 0x0 rects



commit de36d51b919dcb8f4ae5a688b4fbd962fb8c9cf5
Author: Ray Strode <rstrode redhat com>
Date:   Wed Feb 27 17:43:00 2013 -0500

    screen: fix meta_screen_get_monitor_for_rect for 0x0 rects
    
    meta_screen_get_monitor_for_rect will return the monitor that
    a given rect belongs in (choosing the "best" monitor based on
    overlap, if there are overlapping monitors).
    
    It doesn't work with 0x0 rects, though.
    
    This commit fixes that.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694725

 src/core/screen.c |   36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)
---
diff --git a/src/core/screen.c b/src/core/screen.c
index 076bf68..cb4827c 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -2000,27 +2000,39 @@ meta_screen_get_monitor_for_rect (MetaScreen    *screen,
                                   MetaRectangle *rect)
 {
   int i;
-  int best_monitor, monitor_score;
+  int best_monitor, monitor_score, rect_area;
 
   if (screen->n_monitor_infos == 1)
     return &screen->monitor_infos[0];
 
   best_monitor = 0;
-  monitor_score = 0;
+  monitor_score = -1;
 
+  rect_area = meta_rectangle_area (rect);
   for (i = 0; i < screen->n_monitor_infos; i++)
     {
-      MetaRectangle dest;
-      if (meta_rectangle_intersect (&screen->monitor_infos[i].rect,
-                                    rect,
-                                    &dest))
+      gboolean result;
+      int cur;
+
+      if (rect_area > 0)
         {
-          int cur = meta_rectangle_area (&dest);
-          if (cur > monitor_score)
-            {
-              monitor_score = cur;
-              best_monitor = i;
-            }
+          MetaRectangle dest;
+          result = meta_rectangle_intersect (&screen->monitor_infos[i].rect,
+                                             rect,
+                                             &dest);
+          cur = meta_rectangle_area (&dest);
+        }
+      else
+        {
+          result = meta_rectangle_contains_rect (&screen->monitor_infos[i].rect,
+                                                 rect);
+          cur = rect_area;
+        }
+
+      if (result && cur > monitor_score)
+        {
+          monitor_score = cur;
+          best_monitor = i;
         }
     }
 


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