Blame SOURCES/inherit-xrandr-metamodes.patch

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