[gnome-settings-daemon] Centralize the use of gnome_rr_config_apply_with_time()



commit e8f4e035b486b8ad5a08d0059c1a64dae2532b5e
Author: Federico Mena Quintero <federico novell com>
Date:   Mon Nov 30 13:28:48 2009 -0600

    Centralize the use of gnome_rr_config_apply_with_time()
    
    This removes code duplication and should hopefully make it easier for distros
    to use a central point to hook their extra customizations when the RANDR
    configuration is changed.
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 plugins/xrandr/gsd-xrandr-manager.c |   48 +++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 19 deletions(-)
---
diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c
index 6ef956c..17b9f11 100644
--- a/plugins/xrandr/gsd-xrandr-manager.c
+++ b/plugins/xrandr/gsd-xrandr-manager.c
@@ -166,7 +166,9 @@ show_timestamps_dialog (GsdXrandrManager *manager, const char *msg)
 #endif
 }
 
-/* Optionally filters out GNOME_RR_ERROR_NO_MATCHING_CONFIG from
+/* This function centralizes the use of gnome_rr_config_apply_from_filename_with_time().
+ *
+ * Optionally filters out GNOME_RR_ERROR_NO_MATCHING_CONFIG from
  * gnome_rr_config_apply_from_filename_with_time(), since that is not usually an error.
  */
 static gboolean
@@ -206,6 +208,28 @@ fail:
         return FALSE;
 }
 
+/* This function centralizes the use of gnome_rr_config_apply_with_time().
+ *
+ * Applies a configuration and displays an error message if an error happens.
+ * We just return whether setting the configuration succeeded.
+ */
+static gboolean
+apply_configuration_and_display_error (GsdXrandrManager *manager, GnomeGnomeRRConfig *config, guint32 timestamp)
+{
+        GsdXrandrManagerPrivate *priv = manager->priv;
+        GError *error;
+        gboolean success;
+
+        error = NULL;
+        success = gnome_rr_config_apply_with_time (config, priv->rw_screen, timestamp, &error);
+        if (!success) {
+                error_message (manager, _("Could not switch the monitor configuration"), error, NULL);
+                g_error_free (error);
+        }
+
+        return success;
+}
+
 static void
 restore_backup_configuration_without_messages (const char *backup_filename, const char *intended_filename)
 {
@@ -995,11 +1019,7 @@ handle_fn_f7 (GsdXrandrManager *mgr, guint32 timestamp)
 
                 g_debug ("applying");
 
-                error = NULL;
-                if (!gnome_rr_config_apply_with_time (priv->fn_f7_configs[mgr->priv->current_fn_f7_config], screen, timestamp, &error)) {
-                        error_message (mgr, _("Could not switch the monitor configuration"), error, NULL);
-                        g_error_free (error);
-                }
+                apply_configuration_and_display_error (mgr, priv->fn_f7_configs[mgr->priv->current_fn_f7_config], timestamp);
         }
         else {
                 g_debug ("no configurations generated");
@@ -1077,7 +1097,6 @@ handle_rotate_windows (GsdXrandrManager *mgr, guint32 timestamp)
         GsdXrandrManagerPrivate *priv = mgr->priv;
         GnomeRRScreen *screen = priv->rw_screen;
         GnomeRRConfig *current;
-        GError *error;
         GnomeOutputInfo *rotatable_output_info;
         int num_allowed_rotations;
         GnomeRRRotation allowed_rotations;
@@ -1109,11 +1128,7 @@ handle_rotate_windows (GsdXrandrManager *mgr, guint32 timestamp)
 
         rotatable_output_info->rotation = next_rotation;
 
-        error = NULL;
-        if (!gnome_rr_config_apply_with_time (current, screen, timestamp, &error)) {
-                error_message (mgr, _("Could not switch the monitor configuration"), error, NULL);
-                g_error_free (error);
-        }
+        apply_configuration_and_display_error (mgr, current, timestamp);
 
 out:
         gnome_rr_config_free (current);
@@ -1275,13 +1290,8 @@ auto_configure_outputs (GsdXrandrManager *manager, guint32 timestamp)
 
         /* Apply the configuration! */
 
-        if (applicable) {
-                error = NULL;
-                if (!gnome_rr_config_apply_with_time (config, priv->rw_screen, timestamp, &error)) {
-                        error_message (manager, _("Could not switch the monitor configuration"), error, NULL);
-                        g_error_free (error);
-                }
-        }
+        if (applicable)
+                apply_configuration_and_display_error (manager, config, timestamp);
 
         g_list_free (just_turned_on);
         gnome_rr_config_free (config);



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