[Xfce4-commits] <terminal:master> Properly handle colors that are not set in the rc file.

Nick Schermer noreply at xfce.org
Sun Dec 6 18:56:01 CET 2009


Updating branch refs/heads/master
         to be94a9a00e786e9aff3475db7a517a8d407ca4a2 (commit)
       from 196de052d86cffca0f9d480233ce26223d838e2a (commit)

commit be94a9a00e786e9aff3475db7a517a8d407ca4a2
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Dec 6 18:46:12 2009 +0100

    Properly handle colors that are not set in the rc file.

 terminal/terminal-preferences.c |   12 ++++++++----
 terminal/terminal-preferences.h |    2 +-
 terminal/terminal-screen.c      |   32 +++++++++++++++++++-------------
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/terminal/terminal-preferences.c b/terminal/terminal-preferences.c
index 00a27f2..0aa0814 100644
--- a/terminal/terminal-preferences.c
+++ b/terminal/terminal-preferences.c
@@ -1823,16 +1823,20 @@ terminal_preferences_get (void)
 
 
 
-void
+gboolean
 terminal_preferences_get_color (TerminalPreferences *preferences,
                                 const gchar         *property,
                                 GdkColor            *color_return)
 {
-  gchar *spec;
+  gchar    *spec;
+  gboolean  succeed = FALSE;
 
-  terminal_return_if_fail (TERMINAL_IS_PREFERENCES (preferences));
+  terminal_return_val_if_fail (TERMINAL_IS_PREFERENCES (preferences), FALSE);
 
   g_object_get (G_OBJECT (preferences), property, &spec, NULL);
-  gdk_color_parse (spec, color_return);
+  if (G_LIKELY (spec != NULL))
+    succeed = gdk_color_parse (spec, color_return);
   g_free (spec);
+
+  return succeed;
 }
diff --git a/terminal/terminal-preferences.h b/terminal/terminal-preferences.h
index ecd3c4f..b7bf33a 100644
--- a/terminal/terminal-preferences.h
+++ b/terminal/terminal-preferences.h
@@ -91,7 +91,7 @@ GType                terminal_preferences_get_type  (void) G_GNUC_CONST;
 
 TerminalPreferences *terminal_preferences_get       (void);
 
-void                 terminal_preferences_get_color (TerminalPreferences *preferences,
+gboolean             terminal_preferences_get_color (TerminalPreferences *preferences,
                                                      const gchar         *property,
                                                      GdkColor            *color_return);
 
diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index 0d54cc6..b77169a 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -751,28 +751,34 @@ terminal_screen_update_colors (TerminalScreen *screen)
   GdkColor fg;
   GdkColor cursor;
   GdkColor selection;
-  gboolean selection_use_default;
+  gboolean use_default;
   gchar    name[32];
   guint    n;
+  gboolean has_bg;
+  gboolean has_fg;
+  gboolean has_cursor;
 
-  terminal_preferences_get_color (screen->preferences, "color-background", &bg);
-  terminal_preferences_get_color (screen->preferences, "color-foreground", &fg);
-  terminal_preferences_get_color (screen->preferences, "color-cursor", &cursor);
+  has_bg = terminal_preferences_get_color (screen->preferences, "color-background", &bg);
+  has_fg = terminal_preferences_get_color (screen->preferences, "color-foreground", &fg);
+  has_cursor = terminal_preferences_get_color (screen->preferences, "color-cursor", &cursor);
 
   for (n = 0; n < 16; ++n)
     {
-      g_snprintf (name, 32, "color-palette%u", n + 1);
+      g_snprintf (name, sizeof (name), "color-palette%u", n + 1);
       terminal_preferences_get_color (screen->preferences, name, palette + n);
     }
 
-  vte_terminal_set_colors (VTE_TERMINAL (screen->terminal), &fg, &bg, palette, 16);
-  vte_terminal_set_background_tint_color (VTE_TERMINAL (screen->terminal), &bg);
-  vte_terminal_set_color_cursor (VTE_TERMINAL (screen->terminal), &cursor);
-
-  g_object_get (G_OBJECT (screen->preferences), "color-selection-use-default", &selection_use_default, NULL);
-  if (!selection_use_default)
-    terminal_preferences_get_color (screen->preferences, "color-selection", &selection);
-  vte_terminal_set_color_highlight (VTE_TERMINAL (screen->terminal), selection_use_default ? NULL : &selection);
+  vte_terminal_set_colors (VTE_TERMINAL (screen->terminal),
+                           has_fg ? &fg : NULL,
+                           has_bg ? &bg : NULL,
+                           palette, 16);
+  vte_terminal_set_background_tint_color (VTE_TERMINAL (screen->terminal), has_bg ? &bg : NULL);
+  vte_terminal_set_color_cursor (VTE_TERMINAL (screen->terminal), has_cursor ? &cursor : NULL);
+
+  g_object_get (G_OBJECT (screen->preferences), "color-selection-use-default", &use_default, NULL);
+  if (!use_default)
+    use_default = !terminal_preferences_get_color (screen->preferences, "color-selection", &selection);
+  vte_terminal_set_color_highlight (VTE_TERMINAL (screen->terminal), use_default ? NULL : &selection);
 }
 
 



More information about the Xfce4-commits mailing list