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
This commit is contained in:
Ray Strode 2013-02-27 17:43:00 -05:00
parent e6d5e98c9d
commit de36d51b91

View File

@ -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;
}
}