[Xfce4-commits] [apps/xfce4-terminal] 01/01: Fix background color changing when changing focus

noreply at xfce.org noreply at xfce.org
Thu Jul 25 20:01:42 CEST 2019


This is an automated email from the git hooks/post-receive script.

f   2   4   0   4       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-terminal.

commit e480dcd028b0440b3b555700f522c2e540da2fe7
Author: Igor <f2404 at yandex.ru>
Date:   Thu Jul 25 13:56:34 2019 -0400

    Fix background color changing when changing focus
    
    If "Vary the background color for each tab" is enabled.
    
    This was happening due to the "style-updated" signal being emitted on each
    focus in/out event, as well as the actual theme change.
    Since there's no way to tell whether or not the theme has been changed, the
    solution is to remember that a tab already has a random background color and
    prevent it from generating a new one.
    
    Fixes bug #15740
---
 terminal/terminal-screen.c | 97 +++++++++++++++++++++++++++-------------------
 1 file changed, 58 insertions(+), 39 deletions(-)

diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index eddd2c9..061a43d 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -200,6 +200,7 @@ struct _TerminalScreen
 
   TerminalTitle        dynamic_title_mode;
   guint                hold : 1;
+  guint                has_random_bg_color : 1;
 #if !VTE_CHECK_VERSION (0, 51, 1)
   guint                scroll_on_output : 1;
 #endif
@@ -1075,18 +1076,6 @@ terminal_screen_update_colors (TerminalScreen *screen)
       valid_palette = (n == 16);
     }
 
-  if (G_LIKELY (screen->custom_bg_color == NULL))
-    {
-      has_bg = terminal_preferences_get_color (screen->preferences, "color-background", &bg);
-      if (use_theme || !has_bg)
-        {
-          gtk_style_context_get_background_color (context, GTK_STATE_FLAG_ACTIVE, &bg);
-          has_bg = TRUE;
-        }
-    }
-  else
-    has_bg = gdk_rgba_parse (&bg, screen->custom_bg_color);
-
   if (G_LIKELY (screen->custom_fg_color == NULL))
     {
       has_fg = terminal_preferences_get_color (screen->preferences, "color-foreground", &fg);
@@ -1099,45 +1088,75 @@ terminal_screen_update_colors (TerminalScreen *screen)
   else
     has_fg = gdk_rgba_parse (&fg, screen->custom_fg_color);
 
-  /* we pick a random hue value to keep readability */
-  if (G_LIKELY (screen->custom_bg_color == NULL) && vary_bg && has_bg)
+  if (G_LIKELY (screen->custom_bg_color == NULL))
     {
-      gtk_rgb_to_hsv (bg.red, bg.green, bg.blue,
-                      NULL, &hsv[HSV_SATURATION], &hsv[HSV_VALUE]);
-
-      /* pick random hue */
-      hsv[HSV_HUE] = g_random_double_range (0.00, 1.00);
+      has_bg = terminal_preferences_get_color (screen->preferences, "color-background", &bg);
+      if (use_theme || !has_bg)
+        {
+          gtk_style_context_get_background_color (context, GTK_STATE_FLAG_ACTIVE, &bg);
+          has_bg = TRUE;
+        }
 
-      /* saturation moving window, depending on the value */
-      if (hsv[HSV_SATURATION] <= SATURATION_WINDOW)
+      /* we pick a random hue value to keep readability */
+      if (vary_bg && !screen->has_random_bg_color)
         {
-          sat_min = 0.00;
-          sat_max = (2 * SATURATION_WINDOW);
+          gtk_rgb_to_hsv (bg.red, bg.green, 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],
+                          &bg.red, &bg.green, &bg.blue);
+
+          /* save the color */
+          screen->background_color.red = bg.red;
+          screen->background_color.green = bg.green;
+          screen->background_color.blue = bg.blue;
+
+          /* it seems that random color may not be generated on the first run
+           * so add a check here */
+          if (bg.red != 0 && bg.green != 0 && bg.blue != 0)
+            screen->has_random_bg_color = 1;
         }
-      else if (hsv[HSV_SATURATION] >= (1.00 - SATURATION_WINDOW))
+      else if (vary_bg && screen->has_random_bg_color)
         {
-          sat_min = 1.00 - (2 * SATURATION_WINDOW);
-          sat_max = 1.00;
+          /* we already have a random bg color - do nothing */
         }
-      else
+      else if (!vary_bg)
         {
-          sat_min = hsv[HSV_SATURATION] - SATURATION_WINDOW;
-          sat_max = hsv[HSV_SATURATION] + SATURATION_WINDOW;
+          /* update the color if the vary setting is unchecked */
+          screen->background_color.red = bg.red;
+          screen->background_color.green = bg.green;
+          screen->background_color.blue = bg.blue;
+          screen->has_random_bg_color = 0;
         }
-
-      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],
-                      &bg.red, &bg.green, &bg.blue);
     }
+  else
+    has_bg = gdk_rgba_parse (&screen->background_color, screen->custom_bg_color);
 
   if (G_LIKELY (valid_palette))
     {
-      screen->background_color.red = bg.red;
-      screen->background_color.green = bg.green;
-      screen->background_color.blue = bg.blue;
-
       vte_terminal_set_colors (VTE_TERMINAL (screen->terminal),
                                has_fg ? &fg : NULL,
                                has_bg ? &screen->background_color : NULL,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list