[gnome-flashback] monitor-manager: apply built-in monitor orientation to previous configurations



commit 8ec751a045bee0171035d99d7e5ad9ec8760fc63
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Sep 13 13:58:49 2021 +0300

    monitor-manager: apply built-in monitor orientation to previous configurations
    
    Based on mutter commit:
    https://gitlab.gnome.org/GNOME/mutter/-/commit/d773aaf7a914

 backends/gf-monitor-config-manager-private.h |  4 ++
 backends/gf-monitor-config-manager.c         | 44 +++++++++++++++---
 backends/gf-monitor-manager.c                | 67 ++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 7 deletions(-)
---
diff --git a/backends/gf-monitor-config-manager-private.h b/backends/gf-monitor-config-manager-private.h
index 1498899..abe3350 100644
--- a/backends/gf-monitor-config-manager-private.h
+++ b/backends/gf-monitor-config-manager-private.h
@@ -52,8 +52,12 @@ GfMonitorsConfig       *gf_monitor_config_manager_create_fallback           (GfM
 GfMonitorsConfig       *gf_monitor_config_manager_create_suggested          (GfMonitorConfigManager      
*config_manager);
 
 GfMonitorsConfig       *gf_monitor_config_manager_create_for_orientation    (GfMonitorConfigManager      
*config_manager,
+                                                                             GfMonitorsConfig            
*base_config,
                                                                              GfMonitorTransform           
transform);
 
+GfMonitorsConfig       *gf_monitor_config_manager_create_for_builtin_orientation (GfMonitorConfigManager 
*config_manager,
+                                                                                  GfMonitorsConfig       
*base_config);
+
 GfMonitorsConfig       *gf_monitor_config_manager_create_for_rotate_monitor (GfMonitorConfigManager      
*config_manager);
 
 GfMonitorsConfig       *gf_monitor_config_manager_create_for_switch_config  (GfMonitorConfigManager      
*config_manager,
diff --git a/backends/gf-monitor-config-manager.c b/backends/gf-monitor-config-manager.c
index 951473e..981b1d4 100644
--- a/backends/gf-monitor-config-manager.c
+++ b/backends/gf-monitor-config-manager.c
@@ -559,6 +559,7 @@ find_logical_config_for_builtin_display_rotation (GfMonitorConfigManager *config
 
 static GfMonitorsConfig *
 create_for_builtin_display_rotation (GfMonitorConfigManager *config_manager,
+                                     GfMonitorsConfig       *base_config,
                                      gboolean                rotate,
                                      GfMonitorTransform      transform)
 {
@@ -570,10 +571,9 @@ create_for_builtin_display_rotation (GfMonitorConfigManager *config_manager,
   GfLogicalMonitorLayoutMode layout_mode;
   GList *current_monitor_configs;
 
-  if (!config_manager->current_config)
-    return NULL;
+  g_return_val_if_fail (base_config, NULL);
 
-  current_configs = config_manager->current_config->logical_monitor_configs;
+  current_configs = base_config->logical_monitor_configs;
   current_logical_monitor_config = find_logical_config_for_builtin_display_rotation (config_manager,
                                                                                      current_configs);
 
@@ -600,7 +600,7 @@ create_for_builtin_display_rotation (GfMonitorConfigManager *config_manager,
   if (current_logical_monitor_config->transform == transform)
     return NULL;
 
-  current_monitor_configs = config_manager->current_config->logical_monitor_configs;
+  current_monitor_configs = base_config->logical_monitor_configs;
   logical_monitor_configs = clone_logical_monitor_config_list (current_monitor_configs);
 
   logical_monitor_config = find_logical_config_for_builtin_display_rotation (config_manager,
@@ -616,7 +616,7 @@ create_for_builtin_display_rotation (GfMonitorConfigManager *config_manager,
       logical_monitor_config->layout.height = temp;
     }
 
-  layout_mode = config_manager->current_config->layout_mode;
+  layout_mode = base_config->layout_mode;
 
   return gf_monitors_config_new (monitor_manager, logical_monitor_configs,
                                  layout_mode, GF_MONITORS_CONFIG_FLAG_NONE);
@@ -1295,15 +1295,45 @@ gf_monitor_config_manager_create_suggested (GfMonitorConfigManager *config_manag
 
 GfMonitorsConfig *
 gf_monitor_config_manager_create_for_orientation (GfMonitorConfigManager *config_manager,
+                                                  GfMonitorsConfig       *base_config,
                                                   GfMonitorTransform      transform)
 {
-  return create_for_builtin_display_rotation (config_manager, FALSE, transform);
+  return create_for_builtin_display_rotation (config_manager,
+                                              base_config,
+                                              FALSE,
+                                              transform);
+}
+
+GfMonitorsConfig *
+gf_monitor_config_manager_create_for_builtin_orientation (GfMonitorConfigManager *config_manager,
+                                                          GfMonitorsConfig       *base_config)
+{
+  GfMonitorManager *monitor_manager;
+  gboolean panel_orientation_managed;
+  GfMonitorTransform current_transform;
+  GfMonitor *laptop_panel;
+
+  monitor_manager = config_manager->monitor_manager;
+  panel_orientation_managed = gf_monitor_manager_get_panel_orientation_managed (monitor_manager);
+
+  g_return_val_if_fail (panel_orientation_managed, NULL);
+
+  laptop_panel = gf_monitor_manager_get_laptop_panel (monitor_manager);
+  current_transform = get_monitor_transform (monitor_manager, laptop_panel);
+
+  return create_for_builtin_display_rotation (config_manager,
+                                              base_config,
+                                              FALSE,
+                                              current_transform);
 }
 
 GfMonitorsConfig *
 gf_monitor_config_manager_create_for_rotate_monitor (GfMonitorConfigManager *config_manager)
 {
-  return create_for_builtin_display_rotation (config_manager, TRUE, GF_MONITOR_TRANSFORM_NORMAL);
+  return create_for_builtin_display_rotation (config_manager,
+                                              config_manager->current_config,
+                                              TRUE,
+                                              GF_MONITOR_TRANSFORM_NORMAL);
 }
 
 GfMonitorsConfig *
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index ec85167..0d2e9da 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -609,6 +609,7 @@ handle_orientation_change (GfOrientationManager *orientation_manager,
   GfMonitorsConfig *config;
   GfMonitor *laptop_panel;
   GfLogicalMonitor *laptop_logical_monitor;
+  GfMonitorsConfig *current_config;
 
   laptop_panel = gf_monitor_manager_get_laptop_panel (manager);
   g_return_if_fail (laptop_panel);
@@ -640,7 +641,9 @@ handle_orientation_change (GfOrientationManager *orientation_manager,
   if (gf_logical_monitor_get_transform (laptop_logical_monitor) == transform)
     return;
 
+  current_config = gf_monitor_config_manager_get_current (manager->config_manager);
   config = gf_monitor_config_manager_create_for_orientation (manager->config_manager,
+                                                             current_config,
                                                              transform);
 
   if (!config)
@@ -763,6 +766,20 @@ restore_previous_config (GfMonitorManager *manager)
       GfMonitorsConfigMethod method;
       GError *error;
 
+      if (manager->panel_orientation_managed)
+        {
+          GfMonitorsConfig *oriented_config;
+
+          oriented_config = gf_monitor_config_manager_create_for_builtin_orientation 
(manager->config_manager,
+                                                                                      previous_config);
+
+          if (oriented_config != NULL)
+            {
+              g_object_unref (previous_config);
+              previous_config = oriented_config;
+            }
+        }
+
       method = GF_MONITORS_CONFIG_METHOD_TEMPORARY;
       error = NULL;
 
@@ -2653,10 +2670,25 @@ gf_monitor_manager_ensure_configured (GfMonitorManager *manager)
 
       if (config)
         {
+          GfMonitorsConfig *oriented_config;
+
+          oriented_config = NULL;
+
+          if (manager->panel_orientation_managed)
+            {
+              oriented_config = gf_monitor_config_manager_create_for_builtin_orientation 
(manager->config_manager,
+                                                                                          config);
+
+              if (oriented_config != NULL)
+                config = oriented_config;
+            }
+
           if (!gf_monitor_manager_apply_monitors_config (manager, config,
                                                          method, &error))
             {
               config = NULL;
+              g_clear_object (&oriented_config);
+
               g_warning ("Failed to use stored monitor configuration: %s",
                          error->message);
               g_clear_error (&error);
@@ -2664,6 +2696,41 @@ gf_monitor_manager_ensure_configured (GfMonitorManager *manager)
           else
             {
               g_object_ref (config);
+              g_clear_object (&oriented_config);
+              goto done;
+            }
+        }
+    }
+
+  if (manager->panel_orientation_managed)
+    {
+      GfMonitorsConfig *current_config;
+
+      current_config = gf_monitor_config_manager_get_current (manager->config_manager);
+
+      if (current_config != NULL)
+        {
+          config = gf_monitor_config_manager_create_for_builtin_orientation (manager->config_manager,
+                                                                             current_config);
+        }
+    }
+
+  if (config != NULL)
+    {
+      if (gf_monitor_manager_is_config_complete (manager, config))
+        {
+          if (!gf_monitor_manager_apply_monitors_config (manager,
+                                                         config,
+                                                         method,
+                                                         &error))
+            {
+              g_clear_object (&config);
+              g_warning ("Failed to use current monitor configuration: %s",
+                         error->message);
+              g_clear_error (&error);
+            }
+          else
+            {
               goto done;
             }
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]