[Xfce4-commits] <terminal:master> Add background color vary option.

Nick Schermer noreply at xfce.org
Sat Dec 22 22:22:06 CET 2012


Updating branch refs/heads/master
         to 72dd24cce9aa867ac05070876e555e34333963e7 (commit)
       from d4d09c0734fa48335496a710e184090686f159a9 (commit)

commit 72dd24cce9aa867ac05070876e555e34333963e7
Author: Nick Schermer <nick at xfce.org>
Date:   Fri Dec 21 23:41:58 2012 +0100

    Add background color vary option.

 terminal/terminal-preferences-dialog.c |    3 +-
 terminal/terminal-preferences.c        |   11 ++
 terminal/terminal-screen.c             |   70 +++++++++-
 xfce4-terminal.glade                   |  244 +++++++++++++++++---------------
 4 files changed, 213 insertions(+), 115 deletions(-)

diff --git a/terminal/terminal-preferences-dialog.c b/terminal/terminal-preferences-dialog.c
index 8d0a5a5..da21184 100644
--- a/terminal/terminal-preferences-dialog.c
+++ b/terminal/terminal-preferences-dialog.c
@@ -121,7 +121,8 @@ terminal_preferences_dialog_init (TerminalPreferencesDialog *dialog)
                                        "misc-borders-default", "color-selection-use-default",
                                        "shortcuts-no-mnemonics", "shortcuts-no-menukey",
                                        "binding-backspace", "binding-delete",
-                                       "background-mode", "background-image-style"
+                                       "background-mode", "background-image-style",
+                                       "color-background-vary"
                                      };
   const gchar      *props_color[] =  { "color-foreground", "color-cursor",
                                        "color-background", "tab-activity-color",
diff --git a/terminal/terminal-preferences.c b/terminal/terminal-preferences.c
index 9eaa6fa..491edc6 100644
--- a/terminal/terminal-preferences.c
+++ b/terminal/terminal-preferences.c
@@ -52,6 +52,7 @@ enum
   PROP_BINDING_DELETE,
   PROP_COLOR_FOREGROUND,
   PROP_COLOR_BACKGROUND,
+  PROP_COLOR_BACKGROUND_VARY,
   PROP_COLOR_CURSOR,
   PROP_COLOR_SELECTION,
   PROP_COLOR_SELECTION_USE_DEFAULT,
@@ -351,6 +352,16 @@ terminal_preferences_class_init (TerminalPreferencesClass *klass)
                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   /**
+   * TerminalPreferences:color-background-vary:
+   **/
+  preferences_props[PROP_COLOR_BACKGROUND_VARY] =
+      g_param_spec_boolean ("color-background-vary",
+                            "color-background-vary",
+                            "ColorBackgroundVary",
+                            FALSE,
+                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  /**
    * TerminalPreferences:color-cursor:
    **/
   preferences_props[PROP_COLOR_CURSOR] =
diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index 799fd5e..f6a2141 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -55,6 +55,12 @@
 #endif
 #include <glib/gstdio.h>
 
+/* gdkcolor to [0-1] range conversion */
+#define SCALE(i)   (i / 65535.)
+#define UNSCALE(d) ((guint16)(d * 65535 + 0.5))
+
+/* offset of saturation random value */
+#define SATURATION_WINDOW 0.20
 
 
 enum
@@ -71,6 +77,22 @@ enum
   LAST_SIGNAL
 };
 
+enum
+{
+  RGB_RED,
+  RGB_GREEN,
+  RGB_BLUE,
+  N_RGB
+};
+
+enum
+{
+  HSV_HUE,
+  HSV_SATURATION,
+  HSV_VALUE,
+  N_HSV
+};
+
 
 
 static void       terminal_screen_finalize                      (GObject               *object);
@@ -249,7 +271,6 @@ terminal_screen_init (TerminalScreen *screen)
                     "signal::selection-changed", G_CALLBACK (terminal_screen_vte_selection_changed), screen,
                     "signal::window-title-changed", G_CALLBACK (terminal_screen_vte_window_title_changed), screen,
                     "signal::resize-window", G_CALLBACK (terminal_screen_vte_resize_window), screen,
-                    "swapped-signal::style-set", G_CALLBACK (terminal_screen_update_colors), screen,
                     NULL);
   gtk_box_pack_start (GTK_BOX (screen), screen->terminal, TRUE, TRUE, 0);
 
@@ -268,6 +289,7 @@ terminal_screen_init (TerminalScreen *screen)
                     "swapped-signal::notify::binding-delete", G_CALLBACK (terminal_screen_update_binding_delete), screen,
                     "swapped-signal::notify::color-foreground", G_CALLBACK (terminal_screen_update_colors), screen,
                     "swapped-signal::notify::color-background", G_CALLBACK (terminal_screen_update_colors), screen,
+                    "swapped-signal::notify::color-background-vary", G_CALLBACK (terminal_screen_update_colors), screen,
                     "swapped-signal::notify::color-cursor", G_CALLBACK (terminal_screen_update_colors), screen,
                     "swapped-signal::notify::color-selection", G_CALLBACK (terminal_screen_update_colors), screen,
                     "swapped-signal::notify::color-selection-use-default", G_CALLBACK (terminal_screen_update_colors), screen,
@@ -302,7 +324,8 @@ terminal_screen_init (TerminalScreen *screen)
   terminal_screen_update_scrolling_on_output (screen);
   terminal_screen_update_scrolling_on_keystroke (screen);
   terminal_screen_update_word_chars (screen);
-  terminal_screen_timer_background (TERMINAL_SCREEN (screen));
+  terminal_screen_timer_background (screen);
+  terminal_screen_update_colors (screen);
 
   /* Last, connect contents-changed to avoid a race with updates above */
   g_signal_connect (G_OBJECT (screen->terminal), "contents-changed",
@@ -806,10 +829,15 @@ terminal_screen_update_colors (TerminalScreen *screen)
   gboolean   valid_palette = FALSE;
   gchar     *palette_str;
   gchar    **colors;
+  gboolean   vary_bg;
+  gdouble    hsv[N_HSV];
+  gdouble    rgb[N_RGB];
+  gdouble    sat_min, sat_max;
 
   g_object_get (screen->preferences,
                 "color-palette", &palette_str,
                 "color-selection-use-default", &use_default,
+                "color-background-vary", &vary_bg,
                 NULL);
 
   if (G_LIKELY (palette_str != NULL))
@@ -830,6 +858,44 @@ terminal_screen_update_colors (TerminalScreen *screen)
   has_fg = terminal_preferences_get_color (screen->preferences, "color-foreground", &fg);
   has_cursor = terminal_preferences_get_color (screen->preferences, "color-cursor", &cursor);
 
+  /* we pick a random hue value to keep readability */
+  if (vary_bg && has_bg)
+    {
+      gtk_rgb_to_hsv (SCALE (bg.red), SCALE (bg.green), SCALE (bg.blue),
+                      NULL, &hsv[HSV_SATURATION], &hsv[HSV_VALUE]);
+
+      /* pick random hue */
+      hsv[HSV_HUE] = g_random_double_range (0.00, 1.00);
+
+      /* saturation moving window, depending on the value */
+      if (hsv[HSV_SATURATION] <= SATURATION_WINDOW)
+        {
+          sat_min = 0.00;
+          sat_max = (2 * SATURATION_WINDOW);
+        }
+      else if (hsv[HSV_SATURATION] >= (1.00 - SATURATION_WINDOW))
+        {
+          sat_min = 1.00 - (2 * SATURATION_WINDOW);
+          sat_max = 1.00;
+        }
+      else
+        {
+          sat_min = hsv[HSV_SATURATION] - SATURATION_WINDOW;
+          sat_max = hsv[HSV_SATURATION] + SATURATION_WINDOW;
+        }
+
+      hsv[HSV_SATURATION] = g_random_double_range (sat_min, sat_max);
+
+      /* and back to a rgb color */
+      gtk_hsv_to_rgb (hsv[HSV_HUE], hsv[HSV_SATURATION], hsv[HSV_VALUE],
+                      &rgb[RGB_RED], &rgb[RGB_GREEN], &rgb[RGB_BLUE]);
+
+      /* set new gdk color */
+      bg.red = UNSCALE (rgb[RGB_RED]);
+      bg.green = UNSCALE (rgb[RGB_GREEN]);
+      bg.blue = UNSCALE (rgb[RGB_BLUE]);
+    }
+
   if (G_LIKELY (valid_palette))
     {
       vte_terminal_set_colors (VTE_TERMINAL (screen->terminal),
diff --git a/xfce4-terminal.glade b/xfce4-terminal.glade
index 513d548..9a60b3b 100644
--- a/xfce4-terminal.glade
+++ b/xfce4-terminal.glade
@@ -1032,184 +1032,204 @@
                         <property name="can_focus">False</property>
                         <property name="left_padding">12</property>
                         <child>
-                          <object class="GtkHBox" id="hbox2">
+                          <object class="GtkTable" id="table3">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="border_width">6</property>
-                            <property name="spacing">12</property>
-                            <property name="homogeneous">True</property>
+                            <property name="n_rows">3</property>
+                            <property name="n_columns">4</property>
+                            <property name="column_spacing">12</property>
+                            <property name="row_spacing">6</property>
                             <child>
-                              <object class="GtkTable" id="table3">
+                              <object class="GtkLabel" id="label15">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="n_rows">2</property>
-                                <property name="n_columns">2</property>
-                                <property name="column_spacing">12</property>
-                                <property name="row_spacing">6</property>
-                                <child>
-                                  <object class="GtkLabel" id="label15">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="xalign">0</property>
-                                    <property name="label" translatable="yes">_Text color:</property>
-                                    <property name="use_underline">True</property>
-                                    <property name="mnemonic_widget">color-foreground</property>
-                                  </object>
-                                  <packing>
-                                    <property name="x_options">GTK_FILL</property>
-                                  </packing>
-                                </child>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">_Text color:</property>
+                                <property name="use_underline">True</property>
+                                <property name="mnemonic_widget">color-foreground</property>
+                              </object>
+                              <packing>
+                                <property name="x_options">GTK_FILL</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label38">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">_Background color:</property>
+                                <property name="use_underline">True</property>
+                                <property name="mnemonic_widget">color-background</property>
+                              </object>
+                              <packing>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
+                                <property name="x_options">GTK_FILL</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label37">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">Tab activit_y color:</property>
+                                <property name="use_underline">True</property>
+                                <property name="mnemonic_widget">tab-activity-color</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">2</property>
+                                <property name="right_attach">3</property>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
+                                <property name="x_options">GTK_FILL</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label35">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">Cu_rsor color:</property>
+                                <property name="use_underline">True</property>
+                                <property name="mnemonic_widget">color-cursor</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">2</property>
+                                <property name="right_attach">3</property>
+                                <property name="x_options">GTK_FILL</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkCheckButton" id="color-background-vary">
+                                <property name="label" translatable="yes">_Vary the background color for each tab</property>
+                                <property name="use_action_appearance">False</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="right_attach">4</property>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkAlignment" id="alignment10">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="xscale">0</property>
                                 <child>
-                                  <object class="GtkColorButton" id="color-foreground">
+                                  <object class="GtkColorButton" id="color-background">
                                     <property name="use_action_appearance">False</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="title" translatable="yes">Choose terminal text color</property>
+                                    <property name="title" translatable="yes">Choose terminal background color</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
-                                      <object class="AtkObject" id="color-foreground-atkobject">
+                                      <object class="AtkObject" id="color-background-atkobject">
                                         <property name="AtkObject::accessible-name" translatable="yes">Color Selector</property>
                                         <property name="AtkObject::accessible-description" translatable="yes">Open a dialog to specify the color</property>
                                       </object>
                                     </child>
                                   </object>
-                                  <packing>
-                                    <property name="left_attach">1</property>
-                                    <property name="right_attach">2</property>
-                                    <property name="x_options">GTK_FILL</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <object class="GtkLabel" id="label38">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="xalign">0</property>
-                                    <property name="label" translatable="yes">_Background color:</property>
-                                    <property name="use_underline">True</property>
-                                    <property name="mnemonic_widget">color-background</property>
-                                  </object>
-                                  <packing>
-                                    <property name="top_attach">1</property>
-                                    <property name="bottom_attach">2</property>
-                                    <property name="x_options">GTK_FILL</property>
-                                  </packing>
                                 </child>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkAlignment" id="alignment13">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="xscale">0</property>
                                 <child>
-                                  <object class="GtkColorButton" id="color-background">
+                                  <object class="GtkColorButton" id="color-foreground">
                                     <property name="use_action_appearance">False</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="title" translatable="yes">Choose terminal background color</property>
+                                    <property name="title" translatable="yes">Choose terminal text color</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
-                                      <object class="AtkObject" id="color-background-atkobject">
+                                      <object class="AtkObject" id="color-foreground-atkobject">
                                         <property name="AtkObject::accessible-name" translatable="yes">Color Selector</property>
                                         <property name="AtkObject::accessible-description" translatable="yes">Open a dialog to specify the color</property>
                                       </object>
                                     </child>
                                   </object>
-                                  <packing>
-                                    <property name="left_attach">1</property>
-                                    <property name="right_attach">2</property>
-                                    <property name="top_attach">1</property>
-                                    <property name="bottom_attach">2</property>
-                                    <property name="x_options">GTK_FILL</property>
-                                  </packing>
                                 </child>
                               </object>
                               <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">True</property>
-                                <property name="position">0</property>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkTable" id="table6">
+                              <object class="GtkAlignment" id="alignment19">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="n_rows">2</property>
-                                <property name="n_columns">2</property>
-                                <property name="column_spacing">12</property>
-                                <property name="row_spacing">6</property>
+                                <property name="xalign">0</property>
+                                <property name="xscale">0</property>
                                 <child>
-                                  <object class="GtkColorButton" id="tab-activity-color">
+                                  <object class="GtkColorButton" id="color-cursor">
                                     <property name="use_action_appearance">False</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="title" translatable="yes">Choose tab activity color</property>
+                                    <property name="title" translatable="yes">Choose terminal cursor color</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
-                                      <object class="AtkObject" id="tab-activity-color-atkobject">
+                                      <object class="AtkObject" id="color-cursor-atkobject">
                                         <property name="AtkObject::accessible-name" translatable="yes">Color Selector</property>
                                         <property name="AtkObject::accessible-description" translatable="yes">Open a dialog to specify the color</property>
                                       </object>
                                     </child>
                                   </object>
-                                  <packing>
-                                    <property name="left_attach">1</property>
-                                    <property name="right_attach">2</property>
-                                    <property name="top_attach">1</property>
-                                    <property name="bottom_attach">2</property>
-                                    <property name="x_options">GTK_FILL</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <object class="GtkLabel" id="label37">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="xalign">0</property>
-                                    <property name="label" translatable="yes">Tab activit_y color:</property>
-                                    <property name="use_underline">True</property>
-                                    <property name="mnemonic_widget">tab-activity-color</property>
-                                  </object>
-                                  <packing>
-                                    <property name="top_attach">1</property>
-                                    <property name="bottom_attach">2</property>
-                                    <property name="x_options">GTK_FILL</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <object class="GtkLabel" id="label35">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="xalign">0</property>
-                                    <property name="label" translatable="yes">Cu_rsor color:</property>
-                                    <property name="use_underline">True</property>
-                                    <property name="mnemonic_widget">color-cursor</property>
-                                  </object>
-                                  <packing>
-                                    <property name="x_options">GTK_FILL</property>
-                                  </packing>
                                 </child>
+                              </object>
+                              <packing>
+                                <property name="left_attach">3</property>
+                                <property name="right_attach">4</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkAlignment" id="alignment20">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="xscale">0</property>
                                 <child>
-                                  <object class="GtkColorButton" id="color-cursor">
+                                  <object class="GtkColorButton" id="tab-activity-color">
                                     <property name="use_action_appearance">False</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="title" translatable="yes">Choose terminal cursor color</property>
+                                    <property name="title" translatable="yes">Choose tab activity color</property>
                                     <property name="color">#000000000000</property>
                                     <child internal-child="accessible">
-                                      <object class="AtkObject" id="color-cursor-atkobject">
+                                      <object class="AtkObject" id="tab-activity-color-atkobject">
                                         <property name="AtkObject::accessible-name" translatable="yes">Color Selector</property>
                                         <property name="AtkObject::accessible-description" translatable="yes">Open a dialog to specify the color</property>
                                       </object>
                                     </child>
                                   </object>
-                                  <packing>
-                                    <property name="left_attach">1</property>
-                                    <property name="right_attach">2</property>
-                                    <property name="x_options">GTK_FILL</property>
-                                  </packing>
                                 </child>
                               </object>
                               <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">True</property>
-                                <property name="position">1</property>
+                                <property name="left_attach">3</property>
+                                <property name="right_attach">4</property>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
                               </packing>
                             </child>
                           </object>
@@ -1951,7 +1971,7 @@ different terminal behavior.</property>
               <object class="GtkLabel" id="label21">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Com_patibility</property>
+                <property name="label" translatable="yes">Co_mpatibility</property>
                 <property name="use_underline">True</property>
               </object>
               <packing>


More information about the Xfce4-commits mailing list