[vte/vte-next] Add 'reverse-background-color' style property



commit d3e1bcfa6e216a195f63a71b1f6f26199f3fd490
Author: Christian Persch <chpe gnome org>
Date:   Tue May 24 20:20:51 2011 +0200

    Add 'reverse-background-color' style property
    
    By default it's unset, so reverse just reverses background and foreground.
    
    Bug #307073, adapted from the patch by kir at sacred dot ru.

 src/palette.c        |    7 ++++++-
 src/vte-private.h    |    1 +
 src/vte.c            |   36 +++++++++++++++++++++++++++++++++++-
 src/vtepalettedefs.h |   12 ++++++++++++
 src/vterowdata.h     |    3 ++-
 5 files changed, 56 insertions(+), 3 deletions(-)
---
diff --git a/src/palette.c b/src/palette.c
index ce5e383..5a73151 100644
--- a/src/palette.c
+++ b/src/palette.c
@@ -105,7 +105,8 @@ write_css_property (const char *property_name,
         if (strcmp (property_name, "selection-background-color") == 0 ||
             strcmp (property_name, "bold-foreground-color") == 0 ||
             strcmp (property_name, "dim-foreground-color") == 0 ||
-            strcmp (property_name, "cursor-background-color") == 0)
+            strcmp (property_name, "cursor-background-color") == 0 ||
+            strcmp (property_name, "reverse-background-color") == 0)
                 return;
 
         color_string = gdk_rgba_to_string (color);
@@ -209,6 +210,10 @@ write_properties (PropertyWriteFunc func)
         color.red = color.green = color.blue = .75;
         color.alpha = 1.;
         write_property_va (func, &color, "cursor-background-color");
+
+        color.red = color.green = color.blue = 1.;
+        color.alpha = 1.;
+        write_property_va (func, &color, "reverse-background-color");
 }
 
 int
diff --git a/src/vte-private.h b/src/vte-private.h
index 88354bc..f1522cb 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -338,6 +338,7 @@ struct _VteTerminalPrivate {
 
 	gboolean highlight_color_set;
 	gboolean cursor_color_set;
+        gboolean reverse_color_set;
 	GdkRGBA palette[VTE_PALETTE_SIZE];
         guint32 palette_set[(VTE_PALETTE_SIZE + 31) / 32];
 
diff --git a/src/vte.c b/src/vte.c
index c3cd50a..0dfe9d2 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -2386,6 +2386,34 @@ _vte_terminal_set_color_cursor_rgba(VteTerminal *terminal,
 }
 
 /*
+ * _vte_terminal_set_color_reverse_rgba:
+ * @terminal: a #VteTerminal
+ * @reverse_background: (allow-none): the new color to use for the text reverse, or %NULL
+ * @override: whether to override the style
+ *
+ * Sets the background color for text which is under the reverse.  If %NULL, the color
+ * will be taken from the style, or, if unset there, text under the reverse will be drawn
+ * with foreground and background colors reversed.
+ */
+static void
+vte_terminal_set_color_reverse_rgba(VteTerminal *terminal,
+                                    const GdkRGBA *rgba)
+{
+        if (rgba != NULL) {
+                _vte_debug_print(VTE_DEBUG_MISC | VTE_DEBUG_STYLE,
+                                 "Set reverse color to rgba(%.3f,%.3f,%.3f,%.3f).\n",
+                                 rgba->red, rgba->green, rgba->blue, rgba->alpha);
+                vte_terminal_set_color_internal(terminal, VTE_REV_BG, rgba, FALSE);
+                terminal->pvt->reverse_color_set = TRUE;
+        } else {
+                _vte_debug_print(VTE_DEBUG_MISC | VTE_DEBUG_STYLE,
+                                "Cleared reverse color.\n");
+                _vte_invalidate_all(terminal);
+                terminal->pvt->reverse_color_set = FALSE;
+        }
+}
+
+/*
  *_ vte_terminal_set_color_highlight_rgba:
  * @terminal: a #VteTerminal
  * @highlight_background: (allow-none): the new color to use for highlighted text, or %NULL
@@ -4192,6 +4220,9 @@ vte_terminal_update_style_colors(VteTerminal *terminal,
 
         color = _vte_style_context_get_color(context, "selection-background-color", &rgba);
         _vte_terminal_set_color_highlight_rgba(terminal, color);
+
+          color = _vte_style_context_get_color(context, "reverse-background-color", &rgba);
+        vte_terminal_set_color_reverse_rgba(terminal, color);
 }
 
 static void
@@ -8273,7 +8304,10 @@ vte_terminal_determine_colors_internal(VteTerminal *terminal,
 
 	/* Reverse cell? */
 	if (cell->attr.reverse) {
-		swap (&fore, &back);
+                if (terminal->pvt->reverse_color_set)
+                        back = VTE_REV_BG;
+                else
+                        swap (&fore, &back);
 	}
 
 	/* Selection: use hightlight back, or inverse */
diff --git a/src/vtepalettedefs.h b/src/vtepalettedefs.h
index e1ac9bd..1d3e7f9 100644
--- a/src/vtepalettedefs.h
+++ b/src/vtepalettedefs.h
@@ -3146,3 +3146,15 @@ gtk_widget_class_install_style_property
                        GDK_TYPE_RGBA,
                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+/**
+ * VteTerminal: reverse-background-color
+ *
+ * Since: 0.30
+ */
+
+gtk_widget_class_install_style_property
+  (widget_class,
+   g_param_spec_boxed ("reverse-background-color", NULL, NULL,
+                       GDK_TYPE_RGBA,
+                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
diff --git a/src/vterowdata.h b/src/vterowdata.h
index 75f4b59..b2c9aaa 100644
--- a/src/vterowdata.h
+++ b/src/vterowdata.h
@@ -31,7 +31,8 @@ G_BEGIN_DECLS
 #define VTE_DIM_FG			259
 #define VTE_DEF_HL                      260
 #define VTE_CUR_BG			261
-#define VTE_PALETTE_SIZE		262
+#define VTE_REV_BG                      262
+#define VTE_PALETTE_SIZE		263
 
 
 /*



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