[gnome-flashback] backends: add gf_logical_monitor_has_neighbor
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] backends: add gf_logical_monitor_has_neighbor
- Date: Thu, 21 Sep 2017 00:08:39 +0000 (UTC)
commit 8f164e59c7b01bfbe43b9bf08c305160ac727771
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Wed Sep 20 21:52:54 2017 +0300
backends: add gf_logical_monitor_has_neighbor
backends/Makefile.am | 1 +
backends/gf-direction.h | 35 +++++++++++++++++++++++++++++
backends/gf-logical-monitor-private.h | 5 ++++
backends/gf-logical-monitor.c | 39 +++++++++++++++++++++++++++++++++
backends/gf-rectangle.c | 16 +++++++++++++
backends/gf-rectangle.h | 6 +++++
6 files changed, 102 insertions(+), 0 deletions(-)
---
diff --git a/backends/Makefile.am b/backends/Makefile.am
index c5ae5e8..befc14d 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -30,6 +30,7 @@ libbackends_la_SOURCES = \
gf-backend.c \
gf-backend.h \
gf-crtc-private.h \
+ gf-direction.h \
gf-display-config-shared.h \
gf-edid-parse.c \
gf-edid-private.h \
diff --git a/backends/gf-direction.h b/backends/gf-direction.h
new file mode 100644
index 0000000..4d62225
--- /dev/null
+++ b/backends/gf-direction.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GF_DIRECTION_H
+#define GF_DIRECTION_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+ GF_DIRECTION_UP,
+ GF_DIRECTION_DOWN,
+ GF_DIRECTION_LEFT,
+ GF_DIRECTION_RIGHT
+} GfDirection;
+
+G_END_DECLS
+
+#endif
diff --git a/backends/gf-logical-monitor-private.h b/backends/gf-logical-monitor-private.h
index 0341cee..e812247 100644
--- a/backends/gf-logical-monitor-private.h
+++ b/backends/gf-logical-monitor-private.h
@@ -22,6 +22,7 @@
#ifndef GF_LOGICAL_MONITOR_PRIVATE_H
#define GF_LOGICAL_MONITOR_PRIVATE_H
+#include "gf-direction.h"
#include "gf-logical-monitor-config-private.h"
#include "gf-monitor-config-manager-private.h"
#include "gf-monitor-manager-private.h"
@@ -83,6 +84,10 @@ GfRectangle gf_logical_monitor_get_layout (GfLogicalMonitor *lo
GList *gf_logical_monitor_get_monitors (GfLogicalMonitor *logical_monitor);
+gboolean gf_logical_monitor_has_neighbor (GfLogicalMonitor *monitor,
+ GfLogicalMonitor *neighbor,
+ GfDirection direction);
+
G_END_DECLS
#endif
diff --git a/backends/gf-logical-monitor.c b/backends/gf-logical-monitor.c
index b5b14df..f54c205 100644
--- a/backends/gf-logical-monitor.c
+++ b/backends/gf-logical-monitor.c
@@ -24,6 +24,7 @@
#include "gf-logical-monitor-private.h"
#include "gf-monitor-config-private.h"
#include "gf-output-private.h"
+#include "gf-rectangle-private.h"
typedef struct
{
@@ -212,3 +213,41 @@ gf_logical_monitor_get_monitors (GfLogicalMonitor *logical_monitor)
{
return logical_monitor->monitors;
}
+
+gboolean
+gf_logical_monitor_has_neighbor (GfLogicalMonitor *monitor,
+ GfLogicalMonitor *neighbor,
+ GfDirection direction)
+{
+ switch (direction)
+ {
+ case GF_DIRECTION_RIGHT:
+ if (neighbor->rect.x == (monitor->rect.x + monitor->rect.width) &&
+ gf_rectangle_vert_overlap (&neighbor->rect, &monitor->rect))
+ return TRUE;
+ break;
+
+ case GF_DIRECTION_LEFT:
+ if (monitor->rect.x == (neighbor->rect.x + neighbor->rect.width) &&
+ gf_rectangle_vert_overlap (&neighbor->rect, &monitor->rect))
+ return TRUE;
+ break;
+
+ case GF_DIRECTION_UP:
+ if (monitor->rect.y == (neighbor->rect.y + neighbor->rect.height) &&
+ gf_rectangle_horiz_overlap (&neighbor->rect, &monitor->rect))
+ return TRUE;
+ break;
+
+ case GF_DIRECTION_DOWN:
+ if (neighbor->rect.y == (monitor->rect.y + monitor->rect.height) &&
+ gf_rectangle_horiz_overlap (&neighbor->rect, &monitor->rect))
+ return TRUE;
+ break;
+
+ default:
+ break;
+ }
+
+ return FALSE;
+}
diff --git a/backends/gf-rectangle.c b/backends/gf-rectangle.c
index bddd481..2699ff3 100644
--- a/backends/gf-rectangle.c
+++ b/backends/gf-rectangle.c
@@ -36,6 +36,22 @@ gf_rectangle_overlap (const GfRectangle *rect1,
}
gboolean
+gf_rectangle_vert_overlap (const GfRectangle *rect1,
+ const GfRectangle *rect2)
+{
+ return (rect1->y < rect2->y + rect2->height &&
+ rect2->y < rect1->y + rect1->height);
+}
+
+gboolean
+gf_rectangle_horiz_overlap (const GfRectangle *rect1,
+ const GfRectangle *rect2)
+{
+ return (rect1->x < rect2->x + rect2->width &&
+ rect2->x < rect1->x + rect1->width);
+}
+
+gboolean
gf_rectangle_overlaps_with_region (const GList *spanning_rects,
const GfRectangle *rect)
{
diff --git a/backends/gf-rectangle.h b/backends/gf-rectangle.h
index 1365218..074370b 100644
--- a/backends/gf-rectangle.h
+++ b/backends/gf-rectangle.h
@@ -34,6 +34,12 @@ typedef struct
gint height;
} GfRectangle;
+gboolean gf_rectangle_vert_overlap (const GfRectangle *rect1,
+ const GfRectangle *rect2);
+
+gboolean gf_rectangle_horiz_overlap (const GfRectangle *rect1,
+ const GfRectangle *rect2);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]