[vte/vte-next] Add extra style properties to control the cursor color etc



commit 7cc734493f37e32a11a20dacc59536eff672dbd4
Author: Christian Persch <chpe gnome org>
Date:   Fri May 27 23:08:29 2011 +0200

    Add extra style properties to control the cursor color etc
    
    Instead of making the effect dependent on whether a colour has been set
    for cursor, selection or reverse, add style properties that control
    which effect is used.

 src/palette.c       |    7 +-
 src/vte-private.h   |    9 +-
 src/vte.c           |  221 +++++++++++++++++++++++++++------------------------
 src/vte.h           |   12 +++
 src/vteapp.c        |    6 +-
 src/vtepalettecss.h |    3 +
 src/vteseq.c        |    3 +-
 7 files changed, 146 insertions(+), 115 deletions(-)
---
diff --git a/src/palette.c b/src/palette.c
index 0c317e3..3bc7fe4 100644
--- a/src/palette.c
+++ b/src/palette.c
@@ -121,11 +121,8 @@ write_css_property (const char *property_name,
 {
         char *color_string;
 
-        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, "reverse-background-color") == 0)
+        if (strcmp (property_name, "bold-foreground-color") == 0 ||
+            strcmp (property_name, "dim-foreground-color") == 0)
                 return;
 
         color_string = gdk_rgba_to_string (color);
diff --git a/src/vte-private.h b/src/vte-private.h
index f1522cb..100f4c6 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -451,10 +451,11 @@ gboolean _vte_terminal_size_to_grid_size(VteTerminal *terminal,
                                          long *cols,
                                          long *rows);
 
-
-void _vte_terminal_set_color_cursor_rgba(VteTerminal *terminal,
-                                         const GdkRGBA *rgba,
-                                         gboolean override);
+void _vte_terminal_set_effect_color(VteTerminal *terminal,
+                                    int entry,
+                                    const GdkRGBA *rgba,
+                                    VteTerminalEffect effect,
+                                    gboolean override);
 
 G_END_DECLS
 
diff --git a/src/vte.c b/src/vte.c
index b1ddf16..5ddd6a4 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -2346,102 +2346,6 @@ _vte_terminal_set_color_background_rgba(VteTerminal *terminal,
         vte_terminal_set_color_internal(terminal, VTE_DEF_BG, rgba, FALSE);
 }
 
-/*
- * _vte_terminal_set_color_cursor_rgba:
- * @terminal: a #VteTerminal
- * @cursor_background: (allow-none): the new color to use for the text cursor, or %NULL
- * @override: whether to override the style
- *
- * Sets the background color for text which is under the cursor.  If %NULL, the color
- * will be taken from the style, or, if unset there, text under the cursor will be drawn
- * with foreground and background colors reversed.
- *
- * Since: 0.28
- */
-void
-_vte_terminal_set_color_cursor_rgba(VteTerminal *terminal,
-                                    const GdkRGBA *rgba,
-                                    gboolean override)
-{
-        VteTerminalPrivate *pvt = terminal->pvt;
-
-        if (!override && VTE_PALETTE_HAS_OVERRIDE(pvt->palette_set, VTE_CUR_BG)) {
-                _vte_debug_print(VTE_DEBUG_STYLE,
-                                 "Have cursor color override; not setting new color.\n");
-                return;
-        }
-
-        if (rgba != NULL) {
-                _vte_debug_print(VTE_DEBUG_MISC | VTE_DEBUG_STYLE,
-                                 "Set cursor color to rgba(%.3f,%.3f,%.3f,%.3f).\n",
-                                 rgba->red, rgba->green, rgba->blue, rgba->alpha);
-                vte_terminal_set_color_internal(terminal, VTE_CUR_BG, rgba, override);
-                terminal->pvt->cursor_color_set = TRUE;
-        } else {
-                _vte_debug_print(VTE_DEBUG_MISC | VTE_DEBUG_STYLE,
-                                "Cleared cursor color.\n");
-                _vte_invalidate_cursor_once(terminal, FALSE);
-                terminal->pvt->cursor_color_set = FALSE;
-        }
-}
-
-/*
- * _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
- *
- * Sets the background color for text which is highlighted.  If %NULL,
- * highlighted text (which is usually highlighted because it is selected) will
- * be drawn with foreground and background colors reversed.
- *
- * Since: 0.28
- */
-static void
-_vte_terminal_set_color_highlight_rgba(VteTerminal *terminal,
-                                       const GdkRGBA *rgba)
-{
-        if (rgba != NULL) {
-                _vte_debug_print(VTE_DEBUG_MISC | VTE_DEBUG_STYLE,
-                                "Set highlight color to rgba(%.3f,%.3f,%.3f,%.3f).\n",
-                                rgba->red, rgba->green, rgba->blue, rgba->alpha);
-                vte_terminal_set_color_internal(terminal, VTE_DEF_HL, rgba, FALSE);
-                terminal->pvt->highlight_color_set = TRUE;
-        } else {
-                _vte_debug_print(VTE_DEBUG_MISC | VTE_DEBUG_STYLE,
-                                "Cleared highlight color.\n");
-                _vte_invalidate_all(terminal);
-                terminal->pvt->highlight_color_set = FALSE;
-        }
-}
-
 /* Cleanup smart-tabs.  See vte_sequence_handler_ta() */
 void
 _vte_terminal_cleanup_tab_fragments_at_cursor (VteTerminal *terminal)
@@ -4115,7 +4019,57 @@ vte_terminal_set_padding(VteTerminal *terminal)
         gtk_widget_queue_resize(widget);
 }
 
-/**
+/*
+ * _vte_terminal_set_effect_color:
+ * @terminal: a #VteTerminal
+ * @entry: the entry in the colour palette
+ * @rgba:
+ * @effect:
+ * @override: whether to override an application-set colour
+ *
+ * Sets the entry for @entry in the terminal colour palette
+ * to the given colour.
+ *
+ * If the colour was previously set by the terminal application
+ * and @override is %FALSE, does nothing.
+ */
+void
+_vte_terminal_set_effect_color(VteTerminal *terminal,
+                               int entry,
+                               const GdkRGBA *rgba,
+                               VteTerminalEffect effect,
+                               gboolean override)
+{
+        VteTerminalPrivate *pvt = terminal->pvt;
+        gboolean has_override, color_set;
+
+        has_override = VTE_PALETTE_HAS_OVERRIDE(pvt->palette_set, entry);
+        if (has_override && !override) {
+                _vte_debug_print(VTE_DEBUG_STYLE,
+                                 "Have color override for %d; not setting new color.\n",
+                                 entry);
+                return;
+        }
+
+        g_assert (rgba != NULL);
+
+        vte_terminal_set_color_internal(terminal, entry, rgba, override);
+
+        color_set = (effect == VTE_TERMINAL_EFFECT_COLOR);
+        switch (entry) {
+        case VTE_CUR_BG:
+                pvt->cursor_color_set = color_set;
+                break;
+        case VTE_DEF_HL:
+                pvt->highlight_color_set = color_set;
+                break;
+        case VTE_REV_BG:
+                pvt->reverse_color_set = color_set;
+                break;
+        }
+}
+
+/*
  * _vte_gtk_style_context_lookup_color:
  * @context:
  * @color_name:
@@ -4169,6 +4123,7 @@ vte_terminal_update_style_colors(VteTerminal *terminal,
         const GdkRGBA *color;
         int i;
         char name[64];
+        int cursor_effect, reverse_effect, selection_effect;
 
         context = gtk_widget_get_style_context(&terminal->widget);
 
@@ -4214,20 +4169,26 @@ vte_terminal_update_style_colors(VteTerminal *terminal,
 
         /* Now the extra colours */
 
-        color = _vte_style_context_get_color(context, "cursor-background-color", &rgba);
-        _vte_terminal_set_color_cursor_rgba(terminal, color, override);
-
         color = _vte_style_context_get_color(context, "bold-foreground-color", &rgba);
         _vte_terminal_set_color_bold_rgba(terminal, color);
 
           color = _vte_style_context_get_color(context, "dim-foreground-color", &rgba);
         _vte_terminal_set_color_dim_rgba(terminal, color);
 
-        color = _vte_style_context_get_color(context, "selection-background-color", &rgba);
-        _vte_terminal_set_color_highlight_rgba(terminal, color);
+        gtk_widget_style_get(&terminal->widget,
+                             "cursor-effect", &cursor_effect,
+                             "reverse-effect", &reverse_effect,
+                             "selection-effect", &selection_effect,
+                             NULL);
+
+        color = _vte_style_context_get_color(context, "cursor-background-color", &rgba);
+        _vte_terminal_set_effect_color(terminal, VTE_CUR_BG, color, cursor_effect, override);
 
           color = _vte_style_context_get_color(context, "reverse-background-color", &rgba);
-        vte_terminal_set_color_reverse_rgba(terminal, color);
+        _vte_terminal_set_effect_color(terminal, VTE_REV_BG, color, reverse_effect, override);
+
+        color = _vte_style_context_get_color(context, "selection-background-color", &rgba);
+        _vte_terminal_set_effect_color(terminal, VTE_DEF_HL, color, selection_effect, override);
 }
 
 static void
@@ -11603,6 +11564,60 @@ vte_terminal_class_init(VteTerminalClass *klass)
 
 #include "vtepalettedefs.h"
 
+        /**
+         * VteTerminal:cursor-effect:
+         *
+         * Controls how the terminal will draw the cursor.
+         *
+         * If set to $VTE_TERMINAL_EFFECT_COLOR, the cursor is drawn
+         * with the background color from the #VteTerminal:cursor-background-color
+         * style property.
+         *
+         * Since: 0.30
+         */
+        gtk_widget_class_install_style_property
+                (widget_class,
+                 g_param_spec_enum ("cursor-effect", NULL, NULL,
+                                    VTE_TYPE_TERMINAL_EFFECT,
+                                    VTE_TERMINAL_EFFECT_REVERSE,
+                                    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+        /**
+         * VteTerminal:reverse-effect:
+         *
+         * Controls how the terminal will draw reversed text.
+         *
+         * If set to $VTE_TERMINAL_EFFECT_COLOR, reversed text is drawn
+         * with the background color from the #VteTerminal:reverse-background-color
+         * style property.
+         *
+         * Since: 0.30
+         */
+        gtk_widget_class_install_style_property
+                (widget_class,
+                 g_param_spec_enum ("reverse-effect", NULL, NULL,
+                                    VTE_TYPE_TERMINAL_EFFECT,
+                                    VTE_TERMINAL_EFFECT_REVERSE,
+                                    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+        /**
+         * VteTerminal:selection-effect:
+         *
+         * Controls how the terminal will draw selected text.
+         *
+         * If set to $VTE_TERMINAL_EFFECT_COLOR, selected text is drawn
+         * with the background color from the #VteTerminal:selection-background-color
+         * style property.
+         *
+         * Since: 0.30
+         */
+        gtk_widget_class_install_style_property
+                (widget_class,
+                 g_param_spec_enum ("selection-effect", NULL, NULL,
+                                    VTE_TYPE_TERMINAL_EFFECT,
+                                    VTE_TERMINAL_EFFECT_REVERSE,
+                                    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
         /* Keybindings */
 	binding_set = gtk_binding_set_by_class(klass);
 
diff --git a/src/vte.h b/src/vte.h
index 3d91d0b..f8d4175 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -159,6 +159,18 @@ typedef enum {
         VTE_CURSOR_SHAPE_UNDERLINE
 } VteTerminalCursorShape;
 
+/**
+ * VteTerminalEffect:
+ * @VTE_TERMINAL_EFFECT_REVERSE: Text is draw with foreground and background color reversed.
+ * @VTE_TERMINAL_EFFECT_COLOR: Text is drawn with the background color from the corresponding style property.
+ *
+ * Since: 0.30
+ */
+typedef enum {
+        VTE_TERMINAL_EFFECT_REVERSE,
+        VTE_TERMINAL_EFFECT_COLOR
+} VteTerminalEffect;
+
 /* The structure we return as the supplemental attributes for strings. */
 typedef struct _VteCharAttributes VteCharAttributes;
 struct _VteCharAttributes {
diff --git a/src/vteapp.c b/src/vteapp.c
index 376d1af..edc362b 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -793,12 +793,14 @@ main(int argc, char **argv)
                 g_free(background);
         }
         if (cursor_color_string) {
-                g_string_append_printf (css_string, "-VteTerminal-cursor-background-color: %s;\n",
+                g_string_append_printf (css_string, "-VteTerminal-cursor-background-color: %s;\n"
+                                                    "-VteTerminal-cursor-effect: color;\n",
                                         cursor_color_string);
                 g_free(cursor_color_string);
         }
         if (selection_background_color_string) {
-                g_string_append_printf (css_string, "-VteTerminal-selection-background-color: %s;\n",
+                g_string_append_printf (css_string, "-VteTerminal-selection-background-color: %s;\n"
+                                                    "-VteTerminal-selection-effect: color;\n",
                                         selection_background_color_string);
                 g_free(selection_background_color_string);
         }
diff --git a/src/vtepalettecss.h b/src/vtepalettecss.h
index 666fc62..a56ea53 100644
--- a/src/vtepalettecss.h
+++ b/src/vtepalettecss.h
@@ -260,3 +260,6 @@
 "-VteTerminal-shade-24-shades-24-color: rgb(238,238,238);\n"
 "-VteTerminal-foreground-color: rgb(191,191,191);\n"
 "-VteTerminal-background-color: rgb(0,0,0);\n"
+"-VteTerminal-selection-background-color: rgb(255,255,255);\n"
+"-VteTerminal-cursor-background-color: rgb(191,191,191);\n"
+"-VteTerminal-reverse-background-color: rgb(255,255,255);\n"
diff --git a/src/vteseq.c b/src/vteseq.c
index cc72ff4..07d96be 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -3274,7 +3274,8 @@ vte_sequence_handler_change_cursor_color (VteTerminal *terminal, GValueArray *pa
 			return;
 
 		if (vte_parse_color (name, &color))
-			_vte_terminal_set_color_cursor_rgba (terminal, &color, TRUE);
+			_vte_terminal_set_effect_color(terminal, VTE_CUR_BG, &color,
+                                                       VTE_TERMINAL_EFFECT_COLOR, TRUE);
 		else if (strcmp (name, "?") == 0) {
 			gchar buf[128];
 			g_snprintf (buf, sizeof (buf),



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