[mutter] monitor-manager: Simplify reading the current configuration



commit 989bb6ebb1529e9b92117ee44354f4d39d1136d1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Oct 12 13:35:55 2014 -0700

    monitor-manager: Simplify reading the current configuration
    
    Make a wrapper in MetaMonitorManager that handles freeing the existing
    configuration for us.

 src/backends/meta-monitor-manager.c            |   59 ++++++++++++------------
 src/backends/meta-monitor-manager.h            |    5 +--
 src/backends/x11/meta-monitor-manager-xrandr.c |   23 +--------
 3 files changed, 33 insertions(+), 54 deletions(-)
---
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
index ac48685..000e890 100644
--- a/src/backends/meta-monitor-manager.c
+++ b/src/backends/meta-monitor-manager.c
@@ -58,14 +58,6 @@ meta_monitor_manager_init (MetaMonitorManager *manager)
 {
 }
 
-static void
-read_current_config (MetaMonitorManager *manager)
-{
-  manager->serial++;
-
-  META_MONITOR_MANAGER_GET_CLASS (manager)->read_current (manager);
-}
-
 /*
  * make_logical_config:
  *
@@ -198,7 +190,7 @@ meta_monitor_manager_constructed (GObject *object)
 
   manager->config = meta_monitor_config_new ();
 
-  read_current_config (manager);
+  meta_monitor_manager_read_current_config (manager);
 
   if (!meta_monitor_config_apply_stored (manager->config, manager))
     meta_monitor_config_make_default (manager->config, manager);
@@ -211,24 +203,7 @@ meta_monitor_manager_constructed (GObject *object)
      so this is not needed.
   */
   if (META_IS_MONITOR_MANAGER_XRANDR (manager))
-    {
-      MetaOutput *old_outputs;
-      MetaCRTC *old_crtcs;
-      MetaMonitorMode *old_modes;
-      unsigned int n_old_outputs, n_old_modes;
-
-      old_outputs = manager->outputs;
-      n_old_outputs = manager->n_outputs;
-      old_modes = manager->modes;
-      n_old_modes = manager->n_modes;
-      old_crtcs = manager->crtcs;
-
-      read_current_config (manager);
-
-      meta_monitor_manager_free_output_array (old_outputs, n_old_outputs);
-      meta_monitor_manager_free_mode_array (old_modes, n_old_modes);
-      g_free (old_crtcs);
-    }
+    meta_monitor_manager_read_current_config (manager);
 
   make_logical_config (manager);
   initialize_dbus_interface (manager);
@@ -236,7 +211,7 @@ meta_monitor_manager_constructed (GObject *object)
   manager->in_init = FALSE;
 }
 
-void
+static void
 meta_monitor_manager_free_output_array (MetaOutput *old_outputs,
                                         int         n_old_outputs)
 {
@@ -259,7 +234,7 @@ meta_monitor_manager_free_output_array (MetaOutput *old_outputs,
   g_free (old_outputs);
 }
 
-void
+static void
 meta_monitor_manager_free_mode_array (MetaMonitorMode *old_modes,
                                       int              n_old_modes)
 {
@@ -1163,6 +1138,31 @@ meta_monitor_manager_get_screen_limits (MetaMonitorManager *manager,
 }
 
 void
+meta_monitor_manager_read_current_config (MetaMonitorManager *manager)
+{
+  MetaOutput *old_outputs;
+  MetaCRTC *old_crtcs;
+  MetaMonitorMode *old_modes;
+  unsigned int n_old_outputs, n_old_modes;
+
+  /* Some implementations of read_current use the existing information
+   * we have available, so don't free the old configuration until after
+   * read_current finishes. */
+  old_outputs = manager->outputs;
+  n_old_outputs = manager->n_outputs;
+  old_modes = manager->modes;
+  n_old_modes = manager->n_modes;
+  old_crtcs = manager->crtcs;
+
+  manager->serial++;
+  META_MONITOR_MANAGER_GET_CLASS (manager)->read_current (manager);
+
+  meta_monitor_manager_free_output_array (old_outputs, n_old_outputs);
+  meta_monitor_manager_free_mode_array (old_modes, n_old_modes);
+  g_free (old_crtcs);
+}
+
+void
 meta_monitor_manager_rebuild_derived (MetaMonitorManager *manager)
 {
   MetaMonitorInfo *old_monitor_infos;
@@ -1178,4 +1178,3 @@ meta_monitor_manager_rebuild_derived (MetaMonitorManager *manager)
 
   g_free (old_monitor_infos);
 }
-
diff --git a/src/backends/meta-monitor-manager.h b/src/backends/meta-monitor-manager.h
index 77ab938..9452d9c 100644
--- a/src/backends/meta-monitor-manager.h
+++ b/src/backends/meta-monitor-manager.h
@@ -339,11 +339,8 @@ void                meta_monitor_manager_confirm_configuration (MetaMonitorManag
 void               meta_crtc_info_free   (MetaCRTCInfo   *info);
 void               meta_output_info_free (MetaOutputInfo *info);
 
-void               meta_monitor_manager_free_output_array (MetaOutput *old_outputs,
-                                                           int         n_old_outputs);
-void               meta_monitor_manager_free_mode_array (MetaMonitorMode *old_modes,
-                                                         int              n_old_modes);
 gboolean           meta_monitor_manager_has_hotplug_mode_update (MetaMonitorManager *manager);
+void               meta_monitor_manager_read_current_config (MetaMonitorManager *manager);
 
 /* Returns true if transform causes width and height to be inverted
    This is true for the odd transforms in the enum */
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
index 6369286..483b199 100644
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
@@ -1060,10 +1060,6 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
                                           XEvent                   *event)
 {
   MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
-  MetaOutput *old_outputs;
-  MetaCRTC *old_crtcs;
-  MetaMonitorMode *old_modes;
-  unsigned int n_old_outputs, n_old_modes;
   gboolean new_config;
   gboolean applied_config = FALSE;
 
@@ -1072,19 +1068,11 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
 
   XRRUpdateConfiguration (event);
 
-  /* Save the old structures, so they stay valid during the update */
-  old_outputs = manager->outputs;
-  n_old_outputs = manager->n_outputs;
-  old_modes = manager->modes;
-  n_old_modes = manager->n_modes;
-  old_crtcs = manager->crtcs;
-
-  manager->serial++;
-  meta_monitor_manager_xrandr_read_current (manager);
+  meta_monitor_manager_read_current_config (manager);
 
   /* If this config matches our existing one, don't bother doing anything. */
   if (meta_monitor_config_match_current (manager->config, manager))
-    goto out;
+    return TRUE;
 
   new_config = manager_xrandr->resources->timestamp >= manager_xrandr->resources->configTimestamp;
 
@@ -1094,7 +1082,7 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
   if (new_config)
     {
       meta_monitor_manager_rebuild_derived (manager);
-      goto out;
+      return TRUE;
     }
 
   /* If the monitor has hotplug_mode_update (which is used by VMs), don't bother
@@ -1111,10 +1099,5 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
   if (!applied_config)
     meta_monitor_config_make_default (manager->config, manager);
 
- out:
-  meta_monitor_manager_free_output_array (old_outputs, n_old_outputs);
-  meta_monitor_manager_free_mode_array (old_modes, n_old_modes);
-  g_free (old_crtcs);
-
   return TRUE;
 }


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