Blame SOURCES/inherit-xrandr-metamodes.patch

88c283
From 2fd3910c29d2af2a7c64b82f075cd3647d7e4bee Mon Sep 17 00:00:00 2001
88c283
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
88c283
Date: Mon, 18 Mar 2019 17:08:11 +0100
88c283
Subject: [PATCH 1/2] monitor-config-manager: Use current mode when deriving
88c283
 current config
88c283
88c283
Instead of overriding the existing mode with the preferred mode of the monitor,
88c283
use the one already configured. Also use the MetaMonitor API for deriving the
88c283
position of the monitor in the screen coordinate space.
88c283
---
88c283
 src/backends/meta-monitor-config-manager.c | 77 +++++++++++++---------
88c283
 1 file changed, 47 insertions(+), 30 deletions(-)
88c283
88c283
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
88c283
index c09edbe00..a3387aa0f 100644
88c283
--- a/src/backends/meta-monitor-config-manager.c
88c283
+++ b/src/backends/meta-monitor-config-manager.c
88c283
@@ -592,20 +592,19 @@ create_monitor_config (MetaMonitor     *monitor,
88c283
 }
88c283
 
88c283
 static MetaLogicalMonitorConfig *
88c283
-create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_manager,
88c283
-                                         MetaMonitor                 *monitor,
88c283
-                                         int                          x,
88c283
-                                         int                          y,
88c283
-                                         MetaLogicalMonitorConfig    *primary_logical_monitor_config,
88c283
-                                         MetaLogicalMonitorLayoutMode layout_mode)
88c283
+create_logical_monitor_config (MetaMonitorManager           *monitor_manager,
88c283
+                               MetaMonitor                  *monitor,
88c283
+                               MetaMonitorMode              *mode,
88c283
+                               int                           x,
88c283
+                               int                           y,
88c283
+                               MetaLogicalMonitorConfig     *primary_logical_monitor_config,
88c283
+                               MetaLogicalMonitorLayoutMode  layout_mode)
88c283
 {
88c283
-  MetaMonitorMode *mode;
88c283
   int width, height;
88c283
   float scale;
88c283
   MetaMonitorConfig *monitor_config;
88c283
   MetaLogicalMonitorConfig *logical_monitor_config;
88c283
 
88c283
-  mode = meta_monitor_get_preferred_mode (monitor);
88c283
   meta_monitor_mode_get_resolution (mode, &width, &height);
88c283
 
88c283
   if ((meta_monitor_manager_get_capabilities (monitor_manager) &
88c283
@@ -645,22 +644,40 @@ create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_ma
88c283
 }
88c283
 
88c283
 static MetaLogicalMonitorConfig *
88c283
-create_logical_monitor_config_from_output (MetaMonitorManager           *monitor_manager,
88c283
-                                           MetaMonitor                  *monitor,
88c283
-                                           MetaLogicalMonitorConfig     *primary_logical_monitor_config,
88c283
-                                           MetaLogicalMonitorLayoutMode  layout_mode)
88c283
+create_preferred_logical_monitor_config (MetaMonitorManager           *monitor_manager,
88c283
+                                         MetaMonitor                  *monitor,
88c283
+                                         int                           x,
88c283
+                                         int                           y,
88c283
+                                         MetaLogicalMonitorConfig     *primary_logical_monitor_config,
88c283
+                                         MetaLogicalMonitorLayoutMode  layout_mode)
88c283
 {
88c283
-    MetaOutput *output;
88c283
-    MetaCrtc *crtc;
88c283
+  return create_logical_monitor_config (monitor_manager,
88c283
+                                        monitor,
88c283
+                                        meta_monitor_get_preferred_mode (monitor),
88c283
+                                        x, y,
88c283
+                                        primary_logical_monitor_config,
88c283
+                                        layout_mode);
88c283
+}
88c283
 
88c283
-    output = meta_monitor_get_main_output (monitor);
88c283
-    crtc = meta_output_get_assigned_crtc (output);
88c283
-    return create_preferred_logical_monitor_config (monitor_manager,
88c283
-                                                    monitor,
88c283
-                                                    crtc->rect.x,
88c283
-                                                    crtc->rect.y,
88c283
-                                                    primary_logical_monitor_config,
88c283
-                                                    layout_mode);
88c283
+static MetaLogicalMonitorConfig *
88c283
+create_logical_monitor_config_from_monitor (MetaMonitorManager           *monitor_manager,
88c283
+                                            MetaMonitor                  *monitor,
88c283
+                                            MetaLogicalMonitorConfig     *primary_logical_monitor_config,
88c283
+                                            MetaLogicalMonitorLayoutMode  layout_mode)
88c283
+{
88c283
+  MetaRectangle monitor_layout;
88c283
+  MetaMonitorMode *mode;
88c283
+
88c283
+  meta_monitor_derive_layout (monitor, &monitor_layout);
88c283
+  mode = meta_monitor_get_current_mode (monitor);
88c283
+
88c283
+  return create_logical_monitor_config (monitor_manager,
88c283
+                                        monitor,
88c283
+                                        mode,
88c283
+                                        monitor_layout.x,
88c283
+                                        monitor_layout.y,
88c283
+                                        primary_logical_monitor_config,
88c283
+                                        layout_mode);
88c283
 }
88c283
 
88c283
 MetaMonitorsConfig *
88c283
@@ -688,10 +705,10 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
88c283
   layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
88c283
 
88c283
   primary_logical_monitor_config =
88c283
-    create_logical_monitor_config_from_output (monitor_manager,
88c283
-                                               primary_monitor,
88c283
-                                               NULL,
88c283
-                                               layout_mode);
88c283
+    create_logical_monitor_config_from_monitor (monitor_manager,
88c283
+                                                primary_monitor,
88c283
+                                                NULL,
88c283
+                                                layout_mode);
88c283
 
88c283
   primary_logical_monitor_config->is_primary = TRUE;
88c283
   logical_monitor_configs = g_list_append (NULL,
88c283
@@ -710,10 +727,10 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
88c283
         continue;
88c283
 
88c283
       logical_monitor_config =
88c283
-        create_logical_monitor_config_from_output (monitor_manager,
88c283
-                                                   monitor,
88c283
-                                                   primary_logical_monitor_config,
88c283
-                                                   layout_mode);
88c283
+        create_logical_monitor_config_from_monitor (monitor_manager,
88c283
+                                                    monitor,
88c283
+                                                    primary_logical_monitor_config,
88c283
+                                                    layout_mode);
88c283
 
88c283
       logical_monitor_configs = g_list_append (logical_monitor_configs,
88c283
                                                logical_monitor_config);
88c283
-- 
88c283
2.21.0
88c283
88c283
88c283
From d8c34e4cd7e500567e72e0f219295d7c2162dcf3 Mon Sep 17 00:00:00 2001
88c283
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
88c283
Date: Mon, 18 Mar 2019 17:10:37 +0100
88c283
Subject: [PATCH 2/2] monitor-manager: Don't try to derive current config on
88c283
 non-X11
88c283
88c283
This commit also reworks the initial config state reading some. Appart from
88c283
avoiding trying to inherit from backends where it doesn't make sense, it does
88c283
the following changes:
88c283
88c283
 * Replace the name "initial" with "inherited", as the initial config in the
88c283
   context of monitor management is the one used initialization. E.g. if there is
88c283
   a applicable configuration in monitors.xml, the initial config is taken from
88c283
   there.
88c283
88c283
 * Don't make "_create_()" functions have side effects. Previously
88c283
   meta_monitor_config_manager_create_initial() also set state on the config
88c283
   manager object. Instead, add a meta_monitor_config_manager_ensure_inherited()
88c283
   and meta_monitor_manager_get_inherited_config() function to make things more
88c283
   explicit.
88c283
88c283
 * Don't recreate "is-applicable" logic, just use the existing helper.
88c283
---
88c283
 src/backends/meta-monitor-config-manager.c    | 39 +++++++++++--------
88c283
 src/backends/meta-monitor-config-manager.h    |  5 +++
88c283
 src/backends/meta-monitor-manager-private.h   |  4 +-
88c283
 src/backends/meta-monitor-manager.c           | 32 ++++++++-------
88c283
 .../x11/meta-monitor-manager-xrandr.c         |  3 +-
88c283
 5 files changed, 49 insertions(+), 34 deletions(-)
88c283
88c283
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
88c283
index a3387aa0f..bc1a39db8 100644
88c283
--- a/src/backends/meta-monitor-config-manager.c
88c283
+++ b/src/backends/meta-monitor-config-manager.c
88c283
@@ -42,7 +42,7 @@ struct _MetaMonitorConfigManager
88c283
   MetaMonitorConfigStore *config_store;
88c283
 
88c283
   MetaMonitorsConfig *current_config;
88c283
-  MetaMonitorsConfig *initial_config;
88c283
+  MetaMonitorsConfig *inherited_config;
88c283
   GQueue config_history;
88c283
 };
88c283
 
88c283
@@ -680,11 +680,10 @@ create_logical_monitor_config_from_monitor (MetaMonitorManager           *monito
88c283
                                         layout_mode);
88c283
 }
88c283
 
88c283
-MetaMonitorsConfig *
88c283
-meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager)
88c283
+static MetaMonitorsConfig *
88c283
+meta_monitor_config_manager_derive_current (MetaMonitorConfigManager *config_manager)
88c283
 {
88c283
   MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
88c283
-  MetaMonitorsConfig *initial_config;
88c283
   GList *logical_monitor_configs;
88c283
   MetaMonitor *primary_monitor;
88c283
   MetaLogicalMonitorLayoutMode layout_mode;
88c283
@@ -692,12 +691,6 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
88c283
   GList *monitors;
88c283
   GList *l;
88c283
 
88c283
-  if (config_manager->initial_config != NULL)
88c283
-    return g_object_ref (config_manager->initial_config);
88c283
-
88c283
-  if (meta_monitor_config_store_get_config_count (config_manager->config_store) > 0)
88c283
-    return NULL;
88c283
-
88c283
   primary_monitor = find_primary_monitor (monitor_manager);
88c283
   if (!primary_monitor || !meta_monitor_is_active (primary_monitor))
88c283
     return NULL;
88c283
@@ -736,14 +729,26 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
88c283
                                                logical_monitor_config);
88c283
     }
88c283
 
88c283
-  initial_config = meta_monitors_config_new (monitor_manager,
88c283
-                                             logical_monitor_configs,
88c283
-                                             layout_mode,
88c283
-                                             META_MONITORS_CONFIG_FLAG_NONE);
88c283
+  return meta_monitors_config_new (monitor_manager,
88c283
+                                   logical_monitor_configs,
88c283
+                                   layout_mode,
88c283
+                                   META_MONITORS_CONFIG_FLAG_NONE);
88c283
+}
88c283
+
88c283
+void
88c283
+meta_monitor_config_manager_ensure_inherited_config (MetaMonitorConfigManager *config_manager)
88c283
+{
88c283
+  if (config_manager->inherited_config)
88c283
+    return;
88c283
 
88c283
-  config_manager->initial_config = g_object_ref (initial_config);
88c283
+  config_manager->inherited_config =
88c283
+    meta_monitor_config_manager_derive_current (config_manager);
88c283
+}
88c283
 
88c283
-  return initial_config;
88c283
+MetaMonitorsConfig *
88c283
+meta_monitor_config_manager_get_inherited_config (MetaMonitorConfigManager *config_manager)
88c283
+{
88c283
+  return config_manager->inherited_config;
88c283
 }
88c283
 
88c283
 MetaMonitorsConfig *
88c283
@@ -1282,7 +1287,7 @@ meta_monitor_config_manager_dispose (GObject *object)
88c283
     META_MONITOR_CONFIG_MANAGER (object);
88c283
 
88c283
   g_clear_object (&config_manager->current_config);
88c283
-  g_clear_object (&config_manager->initial_config);
88c283
+  g_clear_object (&config_manager->inherited_config);
88c283
   meta_monitor_config_manager_clear_history (config_manager);
88c283
 
88c283
   G_OBJECT_CLASS (meta_monitor_config_manager_parent_class)->dispose (object);
88c283
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
88c283
index 409611bb0..bb847b96e 100644
88c283
--- a/src/backends/meta-monitor-config-manager.h
88c283
+++ b/src/backends/meta-monitor-config-manager.h
88c283
@@ -96,6 +96,11 @@ MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigMa
88c283
 
88c283
 META_EXPORT_TEST
88c283
 MetaMonitorsConfig * meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager);
88c283
+
88c283
+void meta_monitor_config_manager_ensure_inherited_config (MetaMonitorConfigManager *config_manager);
88c283
+
88c283
+MetaMonitorsConfig * meta_monitor_config_manager_get_inherited_config (MetaMonitorConfigManager *config_manager);
88c283
+
88c283
 META_EXPORT_TEST
88c283
 MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
88c283
 
88c283
diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h
88c283
index cdb8f4209..223b5dfbd 100644
88c283
--- a/src/backends/meta-monitor-manager-private.h
88c283
+++ b/src/backends/meta-monitor-manager-private.h
88c283
@@ -44,7 +44,8 @@ typedef enum _MetaMonitorManagerCapability
88c283
   META_MONITOR_MANAGER_CAPABILITY_NONE = 0,
88c283
   META_MONITOR_MANAGER_CAPABILITY_MIRRORING = (1 << 0),
88c283
   META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE = (1 << 1),
88c283
-  META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED = (1 << 2)
88c283
+  META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED = (1 << 2),
88c283
+  META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT = (1 << 3),
88c283
 } MetaMonitorManagerCapability;
88c283
 
88c283
 /* Equivalent to the 'method' enum in org.gnome.Mutter.DisplayConfig */
88c283
@@ -133,6 +134,7 @@ struct _MetaMonitorManager
88c283
   int persistent_timeout_id;
88c283
 
88c283
   MetaMonitorConfigManager *config_manager;
88c283
+  MetaMonitorsConfig *initial_config;
88c283
 
88c283
   GnomePnpIds *pnp_ids;
88c283
 
88c283
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
88c283
index bb4b44188..076dca8cb 100644
88c283
--- a/src/backends/meta-monitor-manager.c
88c283
+++ b/src/backends/meta-monitor-manager.c
88c283
@@ -531,14 +531,21 @@ should_use_stored_config (MetaMonitorManager *manager)
88c283
           !meta_monitor_manager_has_hotplug_mode_update (manager));
88c283
 }
88c283
 
88c283
+static gboolean
88c283
+can_derive_current_config (MetaMonitorManager *manager)
88c283
+{
88c283
+  MetaMonitorManagerCapability capabilities;
88c283
+
88c283
+  capabilities = meta_monitor_manager_get_capabilities (manager);
88c283
+  return !!(capabilities & META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT);
88c283
+}
88c283
+
88c283
 MetaMonitorsConfig *
88c283
 meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
88c283
 {
88c283
-  g_autoptr (MetaMonitorsConfig) initial_config = NULL;
88c283
   MetaMonitorsConfig *config = NULL;
88c283
   GError *error = NULL;
88c283
   gboolean use_stored_config;
88c283
-  MetaMonitorsConfigKey *current_state_key;
88c283
   MetaMonitorsConfigMethod method;
88c283
   MetaMonitorsConfigMethod fallback_method =
88c283
     META_MONITORS_CONFIG_METHOD_TEMPORARY;
88c283
@@ -549,17 +556,8 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
88c283
   else
88c283
     method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
88c283
 
88c283
-  initial_config = meta_monitor_config_manager_create_initial (manager->config_manager);
88c283
-
88c283
-  if (initial_config)
88c283
-    {
88c283
-      current_state_key = meta_create_monitors_config_key_for_current_state (manager);
88c283
-
88c283
-      /* don't ever reuse initial configuration, if the monitor topology changed
88c283
-       */
88c283
-      if (current_state_key && !meta_monitors_config_key_equal (current_state_key, initial_config->key))
88c283
-        g_clear_object (&initial_config);
88c283
-    }
88c283
+  if (can_derive_current_config (manager))
88c283
+    meta_monitor_config_manager_ensure_inherited_config (manager->config_manager);
88c283
 
88c283
   if (use_stored_config)
88c283
     {
88c283
@@ -628,9 +626,13 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
88c283
       g_clear_object (&config);
88c283
     }
88c283
 
88c283
-  config = g_steal_pointer (&initial_config);
88c283
-  if (config)
88c283
+  config =
88c283
+    meta_monitor_config_manager_get_inherited_config (manager->config_manager);
88c283
+  if (config &&
88c283
+      meta_monitor_manager_is_config_complete (manager, config))
88c283
     {
88c283
+      config = g_object_ref (config);
88c283
+
88c283
       if (!meta_monitor_manager_apply_monitors_config (manager,
88c283
                                                        config,
88c283
                                                        method,
88c283
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
88c283
index d60f00325..b8d6342b6 100644
88c283
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
88c283
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
88c283
@@ -999,7 +999,8 @@ static MetaMonitorManagerCapability
88c283
 meta_monitor_manager_xrandr_get_capabilities (MetaMonitorManager *manager)
88c283
 {
88c283
   return (META_MONITOR_MANAGER_CAPABILITY_MIRRORING |
88c283
-          META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED);
88c283
+          META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED |
88c283
+          META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT);
88c283
 }
88c283
 
88c283
 static gboolean
88c283
-- 
88c283
2.21.0
88c283