backends: Refactor MetaScreenDirection guessing into separate function

Make it a helper MetaLogicalMonitor API, and use it on the
MetaMonitorManager.

https://bugzilla.gnome.org/show_bug.cgi?id=778119
This commit is contained in:
Carlos Garnacho 2017-03-24 15:46:32 +01:00
parent e60dfd5b23
commit efae039ad9
3 changed files with 46 additions and 31 deletions

View File

@ -180,3 +180,43 @@ static void
meta_logical_monitor_class_init (MetaLogicalMonitorClass *klass) meta_logical_monitor_class_init (MetaLogicalMonitorClass *klass)
{ {
} }
gboolean
meta_logical_monitor_has_neighbor (MetaLogicalMonitor *logical_monitor,
MetaLogicalMonitor *neighbor,
MetaScreenDirection neighbor_direction)
{
switch (neighbor_direction)
{
case META_SCREEN_RIGHT:
if (neighbor->rect.x == (logical_monitor->rect.x +
logical_monitor->rect.width) &&
meta_rectangle_vert_overlap (&neighbor->rect,
&logical_monitor->rect))
return TRUE;
break;
case META_SCREEN_LEFT:
if (logical_monitor->rect.x == (neighbor->rect.x +
neighbor->rect.width) &&
meta_rectangle_vert_overlap (&neighbor->rect,
&logical_monitor->rect))
return TRUE;
break;
case META_SCREEN_UP:
if (logical_monitor->rect.y == (neighbor->rect.y +
neighbor->rect.height) &&
meta_rectangle_horiz_overlap (&neighbor->rect,
&logical_monitor->rect))
return TRUE;
break;
case META_SCREEN_DOWN:
if (neighbor->rect.y == (logical_monitor->rect.y +
logical_monitor->rect.height) &&
meta_rectangle_horiz_overlap (&neighbor->rect,
&logical_monitor->rect))
return TRUE;
break;
}
return FALSE;
}

View File

@ -80,4 +80,8 @@ int meta_logical_monitor_get_scale (MetaLogicalMonitor *logical_monitor);
GList * meta_logical_monitor_get_monitors (MetaLogicalMonitor *logical_monitor); GList * meta_logical_monitor_get_monitors (MetaLogicalMonitor *logical_monitor);
gboolean meta_logical_monitor_has_neighbor (MetaLogicalMonitor *logical_monitor,
MetaLogicalMonitor *neighbor,
MetaScreenDirection neighbor_dir);
#endif /* META_LOGICAL_MONITOR_H */ #endif /* META_LOGICAL_MONITOR_H */

View File

@ -1572,37 +1572,8 @@ meta_monitor_manager_get_logical_monitor_neighbor (MetaMonitorManager *manager,
{ {
MetaLogicalMonitor *other = l->data; MetaLogicalMonitor *other = l->data;
switch (direction) if (meta_logical_monitor_has_neighbor (logical_monitor, other, direction))
{ return other;
case META_SCREEN_RIGHT:
if (other->rect.x == (logical_monitor->rect.x +
logical_monitor->rect.width) &&
meta_rectangle_vert_overlap (&other->rect,
&logical_monitor->rect))
return other;
break;
case META_SCREEN_LEFT:
if (logical_monitor->rect.x == (other->rect.x +
other->rect.width) &&
meta_rectangle_vert_overlap (&other->rect,
&logical_monitor->rect))
return other;
break;
case META_SCREEN_UP:
if (logical_monitor->rect.y == (other->rect.y +
other->rect.height) &&
meta_rectangle_horiz_overlap (&other->rect,
&logical_monitor->rect))
return other;
break;
case META_SCREEN_DOWN:
if (other->rect.y == (logical_monitor->rect.y +
logical_monitor->rect.height) &&
meta_rectangle_horiz_overlap (&other->rect,
&logical_monitor->rect))
return other;
break;
}
} }
return NULL; return NULL;