Blame SOURCES/inherit-xrandr-metamodes.patch

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