48957e
From ea252d6e8f0e882ad2868853babcb5de4b9d9a6a Mon Sep 17 00:00:00 2001
48957e
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
48957e
Date: Mon, 18 Mar 2019 17:08:11 +0100
48957e
Subject: [PATCH 1/2] monitor-config-manager: Use current mode when deriving
48957e
 current config
48957e
48957e
Instead of overriding the existing mode with the preferred mode of the monitor,
48957e
use the one already configured. Also use the MetaMonitor API for deriving the
48957e
position of the monitor in the screen coordinate space.
48957e
---
48957e
 src/backends/meta-monitor-config-manager.c | 77 +++++++++++++---------
48957e
 1 file changed, 47 insertions(+), 30 deletions(-)
48957e
48957e
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
48957e
index 1ad342a44..aa8105edf 100644
48957e
--- a/src/backends/meta-monitor-config-manager.c
48957e
+++ b/src/backends/meta-monitor-config-manager.c
48957e
@@ -508,20 +508,19 @@ create_monitor_config (MetaMonitor     *monitor,
48957e
 }
48957e
 
48957e
 static MetaLogicalMonitorConfig *
48957e
-create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_manager,
48957e
-                                         MetaMonitor                 *monitor,
48957e
-                                         int                          x,
48957e
-                                         int                          y,
48957e
-                                         MetaLogicalMonitorConfig    *primary_logical_monitor_config,
48957e
-                                         MetaLogicalMonitorLayoutMode layout_mode)
48957e
+create_logical_monitor_config (MetaMonitorManager           *monitor_manager,
48957e
+                               MetaMonitor                  *monitor,
48957e
+                               MetaMonitorMode              *mode,
48957e
+                               int                           x,
48957e
+                               int                           y,
48957e
+                               MetaLogicalMonitorConfig     *primary_logical_monitor_config,
48957e
+                               MetaLogicalMonitorLayoutMode  layout_mode)
48957e
 {
48957e
-  MetaMonitorMode *mode;
48957e
   int width, height;
48957e
   float scale;
48957e
   MetaMonitorConfig *monitor_config;
48957e
   MetaLogicalMonitorConfig *logical_monitor_config;
48957e
 
48957e
-  mode = meta_monitor_get_preferred_mode (monitor);
48957e
   meta_monitor_mode_get_resolution (mode, &width, &height);
48957e
 
48957e
   if ((meta_monitor_manager_get_capabilities (monitor_manager) &
48957e
@@ -561,22 +560,40 @@ create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_ma
48957e
 }
48957e
 
48957e
 static MetaLogicalMonitorConfig *
48957e
-create_logical_monitor_config_from_output (MetaMonitorManager           *monitor_manager,
48957e
-                                           MetaMonitor                  *monitor,
48957e
-                                           MetaLogicalMonitorConfig     *primary_logical_monitor_config,
48957e
-                                           MetaLogicalMonitorLayoutMode  layout_mode)
48957e
+create_preferred_logical_monitor_config (MetaMonitorManager           *monitor_manager,
48957e
+                                         MetaMonitor                  *monitor,
48957e
+                                         int                           x,
48957e
+                                         int                           y,
48957e
+                                         MetaLogicalMonitorConfig     *primary_logical_monitor_config,
48957e
+                                         MetaLogicalMonitorLayoutMode  layout_mode)
48957e
 {
48957e
-    MetaOutput *output;
48957e
-    MetaCrtc *crtc;
48957e
+  return create_logical_monitor_config (monitor_manager,
48957e
+                                        monitor,
48957e
+                                        meta_monitor_get_preferred_mode (monitor),
48957e
+                                        x, y,
48957e
+                                        primary_logical_monitor_config,
48957e
+                                        layout_mode);
48957e
+}
48957e
 
48957e
-    output = meta_monitor_get_main_output (monitor);
48957e
-    crtc = meta_output_get_assigned_crtc (output);
48957e
-    return create_preferred_logical_monitor_config (monitor_manager,
48957e
-                                                    monitor,
48957e
-                                                    crtc->rect.x,
48957e
-                                                    crtc->rect.y,
48957e
-                                                    primary_logical_monitor_config,
48957e
-                                                    layout_mode);
48957e
+static MetaLogicalMonitorConfig *
48957e
+create_logical_monitor_config_from_monitor (MetaMonitorManager           *monitor_manager,
48957e
+                                            MetaMonitor                  *monitor,
48957e
+                                            MetaLogicalMonitorConfig     *primary_logical_monitor_config,
48957e
+                                            MetaLogicalMonitorLayoutMode  layout_mode)
48957e
+{
48957e
+  MetaRectangle monitor_layout;
48957e
+  MetaMonitorMode *mode;
48957e
+
48957e
+  meta_monitor_derive_layout (monitor, &monitor_layout);
48957e
+  mode = meta_monitor_get_current_mode (monitor);
48957e
+
48957e
+  return create_logical_monitor_config (monitor_manager,
48957e
+                                        monitor,
48957e
+                                        mode,
48957e
+                                        monitor_layout.x,
48957e
+                                        monitor_layout.y,
48957e
+                                        primary_logical_monitor_config,
48957e
+                                        layout_mode);
48957e
 }
48957e
 
48957e
 MetaMonitorsConfig *
48957e
@@ -604,10 +621,10 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
48957e
   layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
48957e
 
48957e
   primary_logical_monitor_config =
48957e
-    create_logical_monitor_config_from_output (monitor_manager,
48957e
-                                               primary_monitor,
48957e
-                                               NULL,
48957e
-                                               layout_mode);
48957e
+    create_logical_monitor_config_from_monitor (monitor_manager,
48957e
+                                                primary_monitor,
48957e
+                                                NULL,
48957e
+                                                layout_mode);
48957e
 
48957e
   primary_logical_monitor_config->is_primary = TRUE;
48957e
   logical_monitor_configs = g_list_append (NULL,
48957e
@@ -626,10 +643,10 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
48957e
         continue;
48957e
 
48957e
       logical_monitor_config =
48957e
-        create_logical_monitor_config_from_output (monitor_manager,
48957e
-                                                   monitor,
48957e
-                                                   primary_logical_monitor_config,
48957e
-                                                   layout_mode);
48957e
+        create_logical_monitor_config_from_monitor (monitor_manager,
48957e
+                                                    monitor,
48957e
+                                                    primary_logical_monitor_config,
48957e
+                                                    layout_mode);
48957e
 
48957e
       logical_monitor_configs = g_list_append (logical_monitor_configs,
48957e
                                                logical_monitor_config);
48957e
-- 
48957e
2.20.1
48957e
48957e
48957e
From 77c07e77ad233b763c82928c1db6003114b0a479 Mon Sep 17 00:00:00 2001
48957e
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
48957e
Date: Mon, 18 Mar 2019 17:10:37 +0100
48957e
Subject: [PATCH 2/2] monitor-manager: Don't try to derive current config on
48957e
 non-X11
48957e
48957e
This commit also reworks the initial config state reading some. Appart from
48957e
avoiding trying to inherit from backends where it doesn't make sense, it does
48957e
the following changes:
48957e
48957e
 * Replace the name "initial" with "inherited", as the initial config in the
48957e
   context of monitor management is the one used initialization. E.g. if there is
48957e
   a applicable configuration in monitors.xml, the initial config is taken from
48957e
   there.
48957e
48957e
 * Don't make "_create_()" functions have side effects. Previously
48957e
   meta_monitor_config_manager_create_initial() also set state on the config
48957e
   manager object. Instead, add a meta_monitor_config_manager_ensure_inherited()
48957e
   and meta_monitor_manager_get_inherited_config() function to make things more
48957e
   explicit.
48957e
48957e
 * Don't recreate "is-applicable" logic, just use the existing helper.
48957e
---
48957e
 src/backends/meta-monitor-config-manager.c    | 39 +++++++++++--------
48957e
 src/backends/meta-monitor-config-manager.h    |  5 ++-
48957e
 src/backends/meta-monitor-manager-private.h   |  4 +-
48957e
 src/backends/meta-monitor-manager.c           | 32 ++++++++-------
48957e
 .../x11/meta-monitor-manager-xrandr.c         |  3 +-
48957e
 5 files changed, 48 insertions(+), 35 deletions(-)
48957e
48957e
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
48957e
index aa8105edf..cb67e11e7 100644
48957e
--- a/src/backends/meta-monitor-config-manager.c
48957e
+++ b/src/backends/meta-monitor-config-manager.c
48957e
@@ -40,7 +40,7 @@ struct _MetaMonitorConfigManager
48957e
   MetaMonitorConfigStore *config_store;
48957e
 
48957e
   MetaMonitorsConfig *current_config;
48957e
-  MetaMonitorsConfig *initial_config;
48957e
+  MetaMonitorsConfig *inherited_config;
48957e
   GQueue config_history;
48957e
 };
48957e
 
48957e
@@ -596,11 +596,10 @@ create_logical_monitor_config_from_monitor (MetaMonitorManager           *monito
48957e
                                         layout_mode);
48957e
 }
48957e
 
48957e
-MetaMonitorsConfig *
48957e
-meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager)
48957e
+static MetaMonitorsConfig *
48957e
+meta_monitor_config_manager_derive_current (MetaMonitorConfigManager *config_manager)
48957e
 {
48957e
   MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
48957e
-  MetaMonitorsConfig *initial_config;
48957e
   GList *logical_monitor_configs;
48957e
   MetaMonitor *primary_monitor;
48957e
   MetaLogicalMonitorLayoutMode layout_mode;
48957e
@@ -608,12 +607,6 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
48957e
   GList *monitors;
48957e
   GList *l;
48957e
 
48957e
-  if (config_manager->initial_config != NULL)
48957e
-    return g_object_ref (config_manager->initial_config);
48957e
-
48957e
-  if (meta_monitor_config_store_get_config_count (config_manager->config_store) > 0)
48957e
-    return NULL;
48957e
-
48957e
   primary_monitor = find_primary_monitor (monitor_manager);
48957e
   if (!primary_monitor || !meta_monitor_is_active (primary_monitor))
48957e
     return NULL;
48957e
@@ -652,14 +645,26 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
48957e
                                                logical_monitor_config);
48957e
     }
48957e
 
48957e
-  initial_config = meta_monitors_config_new (monitor_manager,
48957e
-                                             logical_monitor_configs,
48957e
-                                             layout_mode,
48957e
-                                             META_MONITORS_CONFIG_FLAG_NONE);
48957e
+  return meta_monitors_config_new (monitor_manager,
48957e
+                                   logical_monitor_configs,
48957e
+                                   layout_mode,
48957e
+                                   META_MONITORS_CONFIG_FLAG_NONE);
48957e
+}
48957e
+
48957e
+void
48957e
+meta_monitor_config_manager_ensure_inherited_config (MetaMonitorConfigManager *config_manager)
48957e
+{
48957e
+  if (config_manager->inherited_config)
48957e
+    return;
48957e
 
48957e
-  config_manager->initial_config = g_object_ref (initial_config);
48957e
+  config_manager->inherited_config =
48957e
+    meta_monitor_config_manager_derive_current (config_manager);
48957e
+}
48957e
 
48957e
-  return initial_config;
48957e
+MetaMonitorsConfig *
48957e
+meta_monitor_config_manager_get_inherited_config (MetaMonitorConfigManager *config_manager)
48957e
+{
48957e
+  return config_manager->inherited_config;
48957e
 }
48957e
 
48957e
 MetaMonitorsConfig *
48957e
@@ -1188,7 +1193,7 @@ meta_monitor_config_manager_dispose (GObject *object)
48957e
     META_MONITOR_CONFIG_MANAGER (object);
48957e
 
48957e
   g_clear_object (&config_manager->current_config);
48957e
-  g_clear_object (&config_manager->initial_config);
48957e
+  g_clear_object (&config_manager->inherited_config);
48957e
   meta_monitor_config_manager_clear_history (config_manager);
48957e
 
48957e
   G_OBJECT_CLASS (meta_monitor_config_manager_parent_class)->dispose (object);
48957e
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
48957e
index 16dff6d6a..25dcabcdc 100644
48957e
--- a/src/backends/meta-monitor-config-manager.h
48957e
+++ b/src/backends/meta-monitor-config-manager.h
48957e
@@ -88,7 +88,10 @@ gboolean meta_monitor_config_manager_assign (MetaMonitorManager *manager,
48957e
 
48957e
 MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager);
48957e
 
48957e
-MetaMonitorsConfig * meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager);
48957e
+void meta_monitor_config_manager_ensure_inherited_config (MetaMonitorConfigManager *config_manager);
48957e
+
48957e
+MetaMonitorsConfig * meta_monitor_config_manager_get_inherited_config (MetaMonitorConfigManager *config_manager);
48957e
+
48957e
 MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
48957e
 
48957e
 MetaMonitorsConfig * meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_manager);
48957e
diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h
48957e
index a7a0671ae..0d3ed6830 100644
48957e
--- a/src/backends/meta-monitor-manager-private.h
48957e
+++ b/src/backends/meta-monitor-manager-private.h
48957e
@@ -77,7 +77,8 @@ typedef enum _MetaMonitorManagerCapability
48957e
   META_MONITOR_MANAGER_CAPABILITY_NONE = 0,
48957e
   META_MONITOR_MANAGER_CAPABILITY_MIRRORING = (1 << 0),
48957e
   META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE = (1 << 1),
48957e
-  META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED = (1 << 2)
48957e
+  META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED = (1 << 2),
48957e
+  META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT = (1 << 3),
48957e
 } MetaMonitorManagerCapability;
48957e
 
48957e
 /* Equivalent to the 'method' enum in org.gnome.Mutter.DisplayConfig */
48957e
@@ -178,6 +179,7 @@ struct _MetaMonitorManager
48957e
   int persistent_timeout_id;
48957e
 
48957e
   MetaMonitorConfigManager *config_manager;
48957e
+  MetaMonitorsConfig *initial_config;
48957e
 
48957e
   GnomePnpIds *pnp_ids;
48957e
   UpClient *up_client;
48957e
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
48957e
index f7ada0136..68af15e76 100644
48957e
--- a/src/backends/meta-monitor-manager.c
48957e
+++ b/src/backends/meta-monitor-manager.c
48957e
@@ -493,14 +493,21 @@ should_use_stored_config (MetaMonitorManager *manager)
48957e
           !meta_monitor_manager_has_hotplug_mode_update (manager));
48957e
 }
48957e
 
48957e
+static gboolean
48957e
+can_derive_current_config (MetaMonitorManager *manager)
48957e
+{
48957e
+  MetaMonitorManagerCapability capabilities;
48957e
+
48957e
+  capabilities = meta_monitor_manager_get_capabilities (manager);
48957e
+  return !!(capabilities & META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT);
48957e
+}
48957e
+
48957e
 MetaMonitorsConfig *
48957e
 meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
48957e
 {
48957e
-  g_autoptr (MetaMonitorsConfig) initial_config = NULL;
48957e
   MetaMonitorsConfig *config = NULL;
48957e
   GError *error = NULL;
48957e
   gboolean use_stored_config;
48957e
-  MetaMonitorsConfigKey *current_state_key;
48957e
   MetaMonitorsConfigMethod method;
48957e
   MetaMonitorsConfigMethod fallback_method =
48957e
     META_MONITORS_CONFIG_METHOD_TEMPORARY;
48957e
@@ -511,17 +518,8 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
48957e
   else
48957e
     method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
48957e
 
48957e
-  initial_config = meta_monitor_config_manager_create_initial (manager->config_manager);
48957e
-
48957e
-  if (initial_config)
48957e
-    {
48957e
-      current_state_key = meta_create_monitors_config_key_for_current_state (manager);
48957e
-
48957e
-      /* don't ever reuse initial configuration, if the monitor topology changed
48957e
-       */
48957e
-      if (current_state_key && !meta_monitors_config_key_equal (current_state_key, initial_config->key))
48957e
-        g_clear_object (&initial_config);
48957e
-    }
48957e
+  if (can_derive_current_config (manager))
48957e
+    meta_monitor_config_manager_ensure_inherited_config (manager->config_manager);
48957e
 
48957e
   if (use_stored_config)
48957e
     {
48957e
@@ -590,9 +588,13 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
48957e
       g_clear_object (&config);
48957e
     }
48957e
 
48957e
-  config = g_steal_pointer (&initial_config);
48957e
-  if (config)
48957e
+  config =
48957e
+    meta_monitor_config_manager_get_inherited_config (manager->config_manager);
48957e
+  if (config &&
48957e
+      meta_monitor_manager_is_config_complete (manager, config))
48957e
     {
48957e
+      config = g_object_ref (config);
48957e
+
48957e
       if (!meta_monitor_manager_apply_monitors_config (manager,
48957e
                                                        config,
48957e
                                                        method,
48957e
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
48957e
index d0da2c539..2c14983e2 100644
48957e
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
48957e
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
48957e
@@ -949,7 +949,8 @@ static MetaMonitorManagerCapability
48957e
 meta_monitor_manager_xrandr_get_capabilities (MetaMonitorManager *manager)
48957e
 {
48957e
   return (META_MONITOR_MANAGER_CAPABILITY_MIRRORING |
48957e
-          META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED);
48957e
+          META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED |
48957e
+          META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT);
48957e
 }
48957e
 
48957e
 static gboolean
48957e
-- 
48957e
2.20.1
48957e