From efae039ad94c48bacdeaeb779513ff83eddcbe98 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 24 Mar 2017 15:46:32 +0100 Subject: [PATCH] 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 --- src/backends/meta-logical-monitor.c | 40 +++++++++++++++++++++++++++++ src/backends/meta-logical-monitor.h | 4 +++ src/backends/meta-monitor-manager.c | 33 ++---------------------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/backends/meta-logical-monitor.c b/src/backends/meta-logical-monitor.c index 4385fe982..e400e0eae 100644 --- a/src/backends/meta-logical-monitor.c +++ b/src/backends/meta-logical-monitor.c @@ -180,3 +180,43 @@ static void 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; +} diff --git a/src/backends/meta-logical-monitor.h b/src/backends/meta-logical-monitor.h index a7e3a9d70..de1af1bd0 100644 --- a/src/backends/meta-logical-monitor.h +++ b/src/backends/meta-logical-monitor.h @@ -80,4 +80,8 @@ int meta_logical_monitor_get_scale (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 */ diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index e03b5cb6f..dc1d96021 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -1572,37 +1572,8 @@ meta_monitor_manager_get_logical_monitor_neighbor (MetaMonitorManager *manager, { MetaLogicalMonitor *other = l->data; - switch (direction) - { - 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; - } + if (meta_logical_monitor_has_neighbor (logical_monitor, other, direction)) + return other; } return NULL;