From a0af7e94a6e9485ad98eff8de18467c4ecd36393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 9 Jan 2017 15:38:17 +0800 Subject: [PATCH] monitor-config-manager: Add support for suggested configuration Create a suggested configuration, if such configuration is provided. https://bugzilla.gnome.org/show_bug.cgi?id=777732 --- src/backends/meta-monitor-config-manager.c | 71 ++++++++++++++++++++++ src/backends/meta-monitor-config-manager.h | 2 + src/backends/meta-monitor-manager.c | 16 +++++ 3 files changed, 89 insertions(+) diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c index 6445f840c..e4e274f89 100644 --- a/src/backends/meta-monitor-config-manager.c +++ b/src/backends/meta-monitor-config-manager.c @@ -24,6 +24,7 @@ #include "backends/meta-monitor-config-manager.h" #include "backends/meta-monitor-manager-private.h" +#include "core/boxes-private.h" struct _MetaMonitorConfigManager { @@ -40,6 +41,9 @@ G_DEFINE_TYPE (MetaMonitorConfigManager, meta_monitor_config_manager, G_DEFINE_TYPE (MetaMonitorsConfig, meta_monitors_config, G_TYPE_OBJECT) +static void +meta_logical_monitor_config_free (MetaLogicalMonitorConfig *logical_monitor_config); + MetaMonitorConfigManager * meta_monitor_config_manager_new (MetaMonitorManager *monitor_manager) { @@ -449,6 +453,73 @@ meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_ma return config; } +MetaMonitorsConfig * +meta_monitor_config_manager_create_suggested (MetaMonitorConfigManager *config_manager) +{ + MetaMonitorManager *monitor_manager = config_manager->monitor_manager; + MetaMonitorsConfig *config; + MetaLogicalMonitorConfig *primary_logical_monitor_config = NULL; + MetaMonitor *primary_monitor; + GList *logical_monitor_configs; + GList *region; + GList *monitors; + GList *l; + + primary_monitor = find_primary_monitor (monitor_manager); + if (!primary_monitor) + return NULL; + + logical_monitor_configs = NULL; + region = NULL; + monitors = meta_monitor_manager_get_monitors (monitor_manager); + for (l = monitors; l; l = l->next) + { + MetaMonitor *monitor = l->data; + MetaLogicalMonitorConfig *logical_monitor_config; + int x, y; + + if (!meta_monitor_get_suggested_position (monitor, &x, &y)) + continue; + + logical_monitor_config = + create_preferred_logical_monitor_config (monitor, x, y); + logical_monitor_configs = g_list_append (logical_monitor_configs, + logical_monitor_config); + + if (meta_rectangle_overlaps_with_region (region, + &logical_monitor_config->layout)) + { + g_warning ("Suggested monitor config has overlapping region, rejecting"); + g_list_free (region); + g_list_free_full (logical_monitor_configs, + (GDestroyNotify) meta_logical_monitor_config_free); + return NULL; + } + + region = g_list_prepend (region, &logical_monitor_config->layout); + + if (monitor == primary_monitor) + primary_logical_monitor_config = logical_monitor_config; + } + + g_list_free (region); + + if (!logical_monitor_configs) + return NULL; + + if (!primary_logical_monitor_config) + primary_logical_monitor_config = + g_list_first (logical_monitor_configs)->data; + + primary_logical_monitor_config->is_primary = TRUE; + + config = g_object_new (META_TYPE_MONITORS_CONFIG, NULL); + + config->logical_monitor_configs = logical_monitor_configs; + + return config; +} + void meta_monitor_config_manager_set_current (MetaMonitorConfigManager *config_manager, MetaMonitorsConfig *config) diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h index 1d0771c13..fa6bf4c9a 100644 --- a/src/backends/meta-monitor-config-manager.h +++ b/src/backends/meta-monitor-config-manager.h @@ -66,6 +66,8 @@ MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfi MetaMonitorsConfig * meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_manager); +MetaMonitorsConfig * meta_monitor_config_manager_create_suggested (MetaMonitorConfigManager *config_manager); + void meta_monitor_config_manager_set_current (MetaMonitorConfigManager *config_manager, MetaMonitorsConfig *config); diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index 940c5bdb3..ad09621d3 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -332,6 +332,22 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager) return NULL; } + config = meta_monitor_config_manager_create_suggested (manager->config_manager); + if (config) + { + if (!meta_monitor_manager_apply_monitors_config (manager, config, &error)) + { + g_clear_object (&config); + g_warning ("Failed to use suggested monitor configuration: %s", + error->message); + g_clear_error (&error); + } + else + { + goto done; + } + } + config = meta_monitor_config_manager_create_linear (manager->config_manager); if (!meta_monitor_manager_apply_monitors_config (manager, config, &error)) {