Blame SOURCES/inherit-xrandr-metamodes.patch

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