[gnome-flashback] backends: add GfLogicalMonitorConfig
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] backends: add GfLogicalMonitorConfig
- Date: Thu, 21 Sep 2017 00:08:09 +0000 (UTC)
commit 79347d1cde86c45ba3ec52bc5602b385728ff1c6
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Wed Sep 20 18:19:51 2017 +0300
backends: add GfLogicalMonitorConfig
backends/Makefile.am | 2 +
backends/gf-logical-monitor-config-private.h | 49 ++++++++++++
backends/gf-logical-monitor-config.c | 105 ++++++++++++++++++++++++++
backends/gf-logical-monitor-private.h | 1 +
backends/gf-monitor-config-manager-private.h | 10 ---
backends/gf-monitor-manager-private.h | 6 ++
6 files changed, 163 insertions(+), 10 deletions(-)
---
diff --git a/backends/Makefile.am b/backends/Makefile.am
index cd5621c..1eeb37b 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -33,6 +33,8 @@ libbackends_la_SOURCES = \
gf-display-config-shared.h \
gf-edid-parse.c \
gf-edid-private.h \
+ gf-logical-monitor-config-private.h \
+ gf-logical-monitor-config.c \
gf-logical-monitor-private.h \
gf-logical-monitor.c \
gf-monitor-config-manager-private.h \
diff --git a/backends/gf-logical-monitor-config-private.h b/backends/gf-logical-monitor-config-private.h
new file mode 100644
index 0000000..618e9ef
--- /dev/null
+++ b/backends/gf-logical-monitor-config-private.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ * 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/>.
+ *
+ * Adapted from mutter:
+ * - src/backends/meta-monitor-config-manager.h
+ */
+
+#ifndef GF_LOGICAL_MONITOR_CONFIG_PRIVATE_H
+#define GF_LOGICAL_MONITOR_CONFIG_PRIVATE_H
+
+#include "gf-monitor-manager-private.h"
+#include "gf-rectangle.h"
+
+G_BEGIN_DECLS
+
+typedef struct
+{
+ GfRectangle layout;
+ GList *monitor_configs;
+ GfMonitorTransform transform;
+ gfloat scale;
+ gboolean is_primary;
+ gboolean is_presentation;
+} GfLogicalMonitorConfig;
+
+void gf_logical_monitor_config_free (GfLogicalMonitorConfig *config);
+
+gboolean gf_verify_logical_monitor_config (GfLogicalMonitorConfig *config,
+ GfLogicalMonitorLayoutMode layout_mode,
+ GfMonitorManager *monitor_manager,
+ GError **error);
+
+G_END_DECLS
+
+#endif
diff --git a/backends/gf-logical-monitor-config.c b/backends/gf-logical-monitor-config.c
new file mode 100644
index 0000000..6b687ee
--- /dev/null
+++ b/backends/gf-logical-monitor-config.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ * 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/>.
+ *
+ * Adapted from mutter:
+ * - src/backends/meta-monitor-config-manager.c
+ */
+
+#include "config.h"
+
+#include <math.h>
+
+#include "gf-logical-monitor-config-private.h"
+#include "gf-monitor-config-private.h"
+
+void
+gf_logical_monitor_config_free (GfLogicalMonitorConfig *config)
+{
+ GList *monitor_configs;
+
+ monitor_configs = config->monitor_configs;
+
+ g_list_free_full (monitor_configs, (GDestroyNotify) gf_monitor_config_free);
+ g_free (config);
+}
+
+gboolean
+gf_verify_logical_monitor_config (GfLogicalMonitorConfig *config,
+ GfLogicalMonitorLayoutMode layout_mode,
+ GfMonitorManager *monitor_manager,
+ GError **error)
+{
+ GList *l;
+ gint expected_mode_width = 0;
+ gint expected_mode_height = 0;
+
+ if (config->layout.x < 0 || config->layout.y < 0)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid logical monitor position (%d, %d)",
+ config->layout.x, config->layout.y);
+
+ return FALSE;
+ }
+
+ if (!config->monitor_configs)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Logical monitor is empty");
+
+ return FALSE;
+ }
+
+ if (gf_monitor_transform_is_rotated (config->transform))
+ {
+ expected_mode_width = config->layout.height;
+ expected_mode_height = config->layout.width;
+ }
+ else
+ {
+ expected_mode_width = config->layout.width;
+ expected_mode_height = config->layout.height;
+ }
+
+ switch (layout_mode)
+ {
+ case GF_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
+ expected_mode_width = roundf (expected_mode_width * config->scale);
+ expected_mode_height = roundf (expected_mode_height * config->scale);
+ break;
+
+ case GF_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
+ default:
+ break;
+ }
+
+ for (l = config->monitor_configs; l; l = l->next)
+ {
+ GfMonitorConfig *monitor_config = l->data;
+
+ if (monitor_config->mode_spec->width != expected_mode_width ||
+ monitor_config->mode_spec->height != expected_mode_height)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Monitor modes in logical monitor conflict");
+
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
diff --git a/backends/gf-logical-monitor-private.h b/backends/gf-logical-monitor-private.h
index 00b6f8d..0341cee 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-logical-monitor-config-private.h"
#include "gf-monitor-config-manager-private.h"
#include "gf-monitor-manager-private.h"
#include "gf-monitor-private.h"
diff --git a/backends/gf-monitor-config-manager-private.h b/backends/gf-monitor-config-manager-private.h
index 7385e27..8d2d6bc 100644
--- a/backends/gf-monitor-config-manager-private.h
+++ b/backends/gf-monitor-config-manager-private.h
@@ -27,16 +27,6 @@
G_BEGIN_DECLS
-typedef struct
-{
- GfRectangle layout;
- GList *monitor_configs;
- GfMonitorTransform transform;
- gfloat scale;
- gboolean is_primary;
- gboolean is_presentation;
-} GfLogicalMonitorConfig;
-
G_END_DECLS
#endif
diff --git a/backends/gf-monitor-manager-private.h b/backends/gf-monitor-manager-private.h
index 06dbf0b..d56db1d 100644
--- a/backends/gf-monitor-manager-private.h
+++ b/backends/gf-monitor-manager-private.h
@@ -168,6 +168,12 @@ void gf_monitor_manager_tiled_monitor_added (GfMonitorManager *manager,
void gf_monitor_manager_tiled_monitor_removed (GfMonitorManager *manager,
GfMonitor *monitor);
+static inline gboolean
+gf_monitor_transform_is_rotated (GfMonitorTransform transform)
+{
+ return (transform % 2);
+}
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]