[vte] widget: Allow setting the cursor foreground colour



commit 86f206b3ec01033c07a76cf949276058489b53ee
Author: Christian Persch <chpe gnome org>
Date:   Tue Nov 24 23:10:00 2015 +0100

    widget: Allow setting the cursor foreground colour
    
    Based on a patch by James Reed <supplantr archlinux info>.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695011

 doc/reference/vte-sections.txt |    1 +
 src/app.vala                   |   21 +++++++++++----
 src/caps.cc                    |    6 ++--
 src/vte.cc                     |   51 +++++++++++++++++++++++++++++++++------
 src/vte/vteterminal.h          |    2 +
 src/vteapp.c                   |   26 +++++++++++++++-----
 src/vtegtk.cc                  |   22 +++++++++++++++++
 src/vteinternal.hh             |    2 +
 src/vterowdata.h               |    3 +-
 src/vteseq-n.gperf             |    6 ++--
 src/vteseq.cc                  |   10 ++++----
 11 files changed, 117 insertions(+), 33 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index dff9bc9..bc5a8e0 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -32,6 +32,7 @@ vte_terminal_set_color_bold
 vte_terminal_set_color_foreground
 vte_terminal_set_color_background
 vte_terminal_set_color_cursor
+vte_terminal_set_color_cursor_foreground
 vte_terminal_set_color_highlight
 vte_terminal_set_color_highlight_foreground
 vte_terminal_set_colors
diff --git a/src/app.vala b/src/app.vala
index f706ae1..d60e891 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -352,7 +352,8 @@ class Window : Gtk.ApplicationWindow
     terminal.set_colors(App.Options.get_color_fg(),
                         App.Options.get_color_bg(),
                         null);
-    terminal.set_color_cursor(App.Options.get_color_cursor());
+    terminal.set_color_cursor(App.Options.get_color_cursor_background());
+    terminal.set_color_cursor_foreground(App.Options.get_color_cursor_foreground());
     terminal.set_color_highlight(App.Options.get_color_hl_bg());
     terminal.set_color_highlight_foreground(App.Options.get_color_hl_fg());
 
@@ -786,7 +787,8 @@ class App : Gtk.Application
     public static string? command = null;
     private static string? cjk_ambiguous_width_string = null;
     private static string? cursor_blink_mode_string = null;
-    private static string? cursor_color_string = null;
+    private static string? cursor_background_color_string = null;
+    private static string? cursor_foreground_color_string = null;
     private static string? cursor_shape_string = null;
     public static string[]? dingus = null;
     public static bool debug = false;
@@ -897,9 +899,14 @@ class App : Gtk.Application
       return color;
     }
 
-    public static Gdk.RGBA? get_color_cursor()
+    public static Gdk.RGBA? get_color_cursor_background()
     {
-      return get_color(cursor_color_string);
+      return get_color(cursor_background_color_string);
+    }
+
+    public static Gdk.RGBA? get_color_cursor_foreground()
+    {
+      return get_color(cursor_foreground_color_string);
     }
 
     public static Gdk.RGBA? get_color_hl_bg()
@@ -954,8 +961,10 @@ class App : Gtk.Application
         "Specify the cjk ambiguous width to use for UTF-8 encoding", "NARROW|WIDE" },
       { "cursor-blink", 0, 0, OptionArg.STRING, ref cursor_blink_mode_string,
         "Cursor blink mode (system|on|off)", "MODE" },
-      { "cursor-color", 0, 0, OptionArg.STRING, ref cursor_color_string,
-        "Enable a colored cursor", null },
+      { "cursor-background-color", 0, 0, OptionArg.STRING, ref cursor_background_color_string,
+        "Enable a colored cursor background", null },
+      { "cursor-foreground-color", 0, 0, OptionArg.STRING, ref cursor_foreground_color_string,
+        "Enable a colored cursor foreground", null },
       { "cursor-shape", 0, 0, OptionArg.STRING, ref cursor_shape_string,
         "Set cursor shape (block|underline|ibeam)", null },
       { "dingu", 'D', 0, OptionArg.STRING_ARRAY, ref dingus,
diff --git a/src/caps.cc b/src/caps.cc
index 82078af..d4ac3d8 100644
--- a/src/caps.cc
+++ b/src/caps.cc
@@ -231,7 +231,7 @@ const char _vte_xterm_capability_strings[] =
         ENTRY(OSC "7;%s" BEL, "set-current-directory-uri")
         ENTRY(OSC "10;%s" BEL, "change-foreground-color-bel")
         ENTRY(OSC "11;%s" BEL, "change-background-color-bel")
-        ENTRY(OSC "12;%s" BEL, "change-cursor-color-bel")
+        ENTRY(OSC "12;%s" BEL, "change-cursor-background-color-bel")
         ENTRY(OSC "13;%s" BEL, "change-mouse-cursor-foreground-color-bel")
         ENTRY(OSC "14;%s" BEL, "change-mouse-cursor-background-color-bel")
         ENTRY(OSC "15;%s" BEL, "change-tek-foreground-color-bel")
@@ -246,7 +246,7 @@ const char _vte_xterm_capability_strings[] =
         ENTRY(OSC "104;%m" BEL, "reset-color")
         ENTRY(OSC "110" BEL, "reset-foreground-color")
         ENTRY(OSC "111" BEL, "reset-background-color")
-        ENTRY(OSC "112" BEL, "reset-cursor-color")
+        ENTRY(OSC "112" BEL, "reset-cursor-background-color")
         ENTRY(OSC "113" BEL, "reset-mouse-cursor-foreground-color")
         ENTRY(OSC "114" BEL, "reset-mouse-cursor-background-color")
         ENTRY(OSC "115" BEL, "reset-tek-foreground-color")
@@ -266,7 +266,7 @@ const char _vte_xterm_capability_strings[] =
         ENTRY(OSC "7;%s" ST, "set-current-directory-uri")
         ENTRY(OSC "10;%s" ST, "change-foreground-color-st")
         ENTRY(OSC "11;%s" ST, "change-background-color-st")
-        ENTRY(OSC "12;%s" ST, "change-cursor-color-st")
+        ENTRY(OSC "12;%s" ST, "change-cursor-background-color-st")
         ENTRY(OSC "13;%s" ST, "change-mouse-cursor-foreground-color-st")
         ENTRY(OSC "14;%s" ST, "change-mouse-cursor-background-color-st")
         ENTRY(OSC "15;%s" ST, "change-tek-foreground-color-st")
diff --git a/src/vte.cc b/src/vte.cc
index 0863ec4..39f9567 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -2470,7 +2470,7 @@ VteTerminalPrivate::set_pointer_visible(bool visible)
 /*
  * Get the actually used color from the palette.
  * The return value can be NULL only if entry is one of VTE_CURSOR_BG,
- * VTE_HIGHLIGHT_BG or VTE_HIGHLIGHT_FG.
+ * VTE_CURSOR_FG, VTE_HIGHLIGHT_BG or VTE_HIGHLIGHT_FG.
  */
 vte::color::rgb const*
 VteTerminalPrivate::get_color(int entry) const
@@ -2516,7 +2516,7 @@ VteTerminalPrivate::set_color(int entry,
        }
 
        /* and redraw */
-       if (entry == VTE_CURSOR_BG)
+       if (entry == VTE_CURSOR_BG || entry == VTE_CURSOR_FG)
                invalidate_cursor_once();
        else
                invalidate_all();
@@ -2551,7 +2551,7 @@ VteTerminalPrivate::reset_color(int entry,
        }
 
        /* and redraw */
-       if (entry == VTE_CURSOR_BG)
+       if (entry == VTE_CURSOR_BG || entry == VTE_CURSOR_FG)
                invalidate_cursor_once();
        else
                invalidate_all();
@@ -2677,6 +2677,9 @@ _vte_terminal_set_colors(VteTerminal *terminal,
                        case VTE_CURSOR_BG:
                                unset = TRUE;
                                break;
+                       case VTE_CURSOR_FG:
+                               unset = TRUE;
+                               break;
                        }
 
                /* Override from the supplied palette if there is one. */
@@ -2766,7 +2769,7 @@ VteTerminalPrivate::set_color_background(vte::color::rgb const& color)
 }
 
 /*
- * VteTerminalPrivate::set_color_cursor:
+ * VteTerminalPrivate::set_color_cursor_background:
  * @cursor_background: (allow-none): the new color to use for the text cursor, or %NULL
  *
  * Sets the background color for text which is under the cursor.  If %NULL, text
@@ -2791,6 +2794,31 @@ VteTerminalPrivate::reset_color_cursor_background()
 }
 
 /*
+ * VteTerminalPrivate::set_color_cursor_foreground:
+ * @cursor_foreground: (allow-none): the new color to use for the text cursor, or %NULL
+ *
+ * Sets the foreground color for text which is under the cursor.  If %NULL, text
+ * under the cursor will be drawn with foreground and background colors
+ * reversed.
+ */
+void
+VteTerminalPrivate::set_color_cursor_foreground(vte::color::rgb const& color)
+{
+        _vte_debug_print(VTE_DEBUG_MISC,
+                         "Set %s color to (%04x,%04x,%04x).\n", "cursor foreground",
+                         color.red, color.green, color.blue);
+       set_color(VTE_CURSOR_FG, VTE_COLOR_SOURCE_API, color);
+}
+
+void
+VteTerminalPrivate::reset_color_cursor_foreground()
+{
+        _vte_debug_print(VTE_DEBUG_MISC,
+                         "Reset %s color.\n", "cursor foreground");
+        reset_color(VTE_CURSOR_FG, VTE_COLOR_SOURCE_API);
+}
+
+/*
  * VteTerminalPrivate::set_color_highlight_background:
  * @highlight_background: (allow-none): the new color to use for highlighted text, or %NULL
  *
@@ -8664,10 +8692,17 @@ vte_terminal_determine_colors_internal(VteTerminal *terminal,
        /* Cursor: use cursor back, or inverse */
        if (cursor) {
                /* XXX what if cursor back is same color as current back? */
-               if (terminal->pvt->get_color(VTE_CURSOR_BG) != NULL)
-                       back = VTE_CURSOR_BG;
-               else
-                       swap (&fore, &back);
+                gboolean do_swap = TRUE;
+                if (terminal->pvt->get_color(VTE_CURSOR_BG) != NULL) {
+                        back = VTE_CURSOR_BG;
+                        do_swap = FALSE;
+                }
+                if (terminal->pvt->get_color(VTE_CURSOR_FG) != NULL) {
+                        fore = VTE_CURSOR_FG;
+                        do_swap = FALSE;
+                }
+                if (do_swap)
+                        swap (&fore, &back);
        }
 
        /* Invisible? */
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index 857819f..19f83ed 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -211,6 +211,8 @@ void vte_terminal_set_color_background(VteTerminal *terminal,
                                        const GdkRGBA *background) _VTE_GNUC_NONNULL(1) _VTE_GNUC_NONNULL(2);
 void vte_terminal_set_color_cursor(VteTerminal *terminal,
                                    const GdkRGBA *cursor_background) _VTE_GNUC_NONNULL(1);
+void vte_terminal_set_color_cursor_foreground(VteTerminal *terminal,
+                                              const GdkRGBA *cursor_foreground) _VTE_GNUC_NONNULL(1);
 void vte_terminal_set_color_highlight(VteTerminal *terminal,
                                       const GdkRGBA *highlight_background) _VTE_GNUC_NONNULL(1);
 void vte_terminal_set_color_highlight_foreground(VteTerminal *terminal,
diff --git a/src/vteapp.c b/src/vteapp.c
index f1ecbda..ff67f8a 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -636,7 +636,8 @@ main(int argc, char **argv)
        char *cursor_shape_string = NULL;
        char *scrollbar_policy_string = NULL;
         char *border_width_string = NULL;
-        char *cursor_color_string = NULL;
+        char *cursor_foreground_color_string = NULL;
+        char *cursor_background_color_string = NULL;
         char *highlight_foreground_color_string = NULL;
         char *highlight_background_color_string = NULL;
         char **dingus = NULL;
@@ -741,9 +742,14 @@ main(int argc, char **argv)
                        "Cursor blink mode (system|on|off)", "MODE"
                },
                {
-                       "cursor-color", 0, 0,
-                       G_OPTION_ARG_STRING, &cursor_color_string,
-                       "Enable a colored cursor", NULL
+                       "cursor-background-color", 0, 0,
+                       G_OPTION_ARG_STRING, &cursor_background_color_string,
+                       "Enable a colored cursor background", NULL
+               },
+               {
+                       "cursor-foreground-color", 0, 0,
+                       G_OPTION_ARG_STRING, &cursor_foreground_color_string,
+                       "Enable a colored cursor foreground", NULL
                },
                {
                        "cursor-shape", 0, 0,
@@ -989,11 +995,17 @@ main(int argc, char **argv)
 
        vte_terminal_set_colors(terminal, &fore, &back, NULL, 0);
 
-       if (cursor_color_string) {
+       if (cursor_foreground_color_string) {
+                GdkRGBA rgba;
+                if (parse_color (cursor_foreground_color_string, &rgba))
+                        vte_terminal_set_color_cursor_foreground(terminal, &rgba);
+                g_free(cursor_foreground_color_string);
+       }
+       if (cursor_background_color_string) {
                 GdkRGBA rgba;
-                if (parse_color (cursor_color_string, &rgba))
+                if (parse_color (cursor_background_color_string, &rgba))
                         vte_terminal_set_color_cursor(terminal, &rgba);
-                g_free(cursor_color_string);
+                g_free(cursor_background_color_string);
        }
        if (highlight_foreground_color_string) {
                 GdkRGBA rgba;
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 097778b..64e31f2 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -2643,6 +2643,28 @@ vte_terminal_set_color_cursor(VteTerminal *terminal,
 }
 
 /**
+ * vte_terminal_set_color_cursor_foreground:
+ * @terminal: a #VteTerminal
+ * @cursor_foreground: (allow-none): the new color to use for the text cursor, or %NULL
+ *
+ * Sets the foreground color for text which is under the cursor.  If %NULL, text
+ * under the cursor will be drawn with foreground and background colors
+ * reversed.
+ *
+ * Since: 0.44
+ */
+void
+vte_terminal_set_color_cursor_foreground(VteTerminal *terminal,
+                                         const GdkRGBA *cursor_foreground)
+{
+        g_return_if_fail(VTE_IS_TERMINAL(terminal));
+        if (cursor_foreground)
+                terminal->pvt->set_color_cursor_foreground(vte::color::rgb(cursor_foreground));
+        else
+                terminal->pvt->reset_color_cursor_foreground();
+}
+
+/**
  * vte_terminal_set_color_foreground:
  * @terminal: a #VteTerminal
  * @foreground: the new foreground color
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index fe6e450..ca268b1 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -753,6 +753,8 @@ public:
         void reset_color_bold();
         void set_color_cursor_background(vte::color::rgb const& color);
         void reset_color_cursor_background();
+        void set_color_cursor_foreground(vte::color::rgb const& color);
+        void reset_color_cursor_foreground();
         void set_color_foreground(vte::color::rgb const& color);
         void set_color_highlight_background(vte::color::rgb const& color);
         void reset_color_highlight_background();
diff --git a/src/vterowdata.h b/src/vterowdata.h
index 7c58066..447410f 100644
--- a/src/vterowdata.h
+++ b/src/vterowdata.h
@@ -35,7 +35,8 @@ G_BEGIN_DECLS
 #define VTE_HIGHLIGHT_FG               259
 #define VTE_HIGHLIGHT_BG               260
 #define VTE_CURSOR_BG                  261
-#define VTE_PALETTE_SIZE               262
+#define VTE_CURSOR_FG                   262
+#define VTE_PALETTE_SIZE               263
 
 /*
  * VteCellAttr: A single cell style attributes
diff --git a/src/vteseq-n.gperf b/src/vteseq-n.gperf
index ad5b6d9..4e2f337 100644
--- a/src/vteseq-n.gperf
+++ b/src/vteseq-n.gperf
@@ -85,9 +85,9 @@ struct vteseq_n_struct {
 #"end-of-guarded-area", VTE_SEQUENCE_HANDLER_NULL
 #"utf-8-character-set", VTE_SEQUENCE_HANDLER_NULL
 "window-manipulation", VTE_SEQUENCE_HANDLER(vte_sequence_handler_window_manipulation)
-"change-cursor-color-bel", VTE_SEQUENCE_HANDLER(vte_sequence_handler_change_cursor_color_bel)
-"change-cursor-color-st", VTE_SEQUENCE_HANDLER(vte_sequence_handler_change_cursor_color_st)
-"reset-cursor-color", VTE_SEQUENCE_HANDLER(vte_sequence_handler_reset_cursor_color)
+"change-cursor-background-color-bel", 
VTE_SEQUENCE_HANDLER(vte_sequence_handler_change_cursor_background_color_bel)
+"change-cursor-background-color-st", 
VTE_SEQUENCE_HANDLER(vte_sequence_handler_change_cursor_background_color_st)
+"reset-cursor-background_color", VTE_SEQUENCE_HANDLER(vte_sequence_handler_reset_cursor_background_color)
 "character-attributes", VTE_SEQUENCE_HANDLER(vte_sequence_handler_character_attributes)
 "device-status-report", VTE_SEQUENCE_HANDLER(vte_sequence_handler_device_status_report)
 "set-scrolling-region", VTE_SEQUENCE_HANDLER(vte_sequence_handler_set_scrolling_region)
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 2f04308..7383e13 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -3145,17 +3145,17 @@ vte_sequence_handler_reset_background_color (VteTerminal *terminal, GValueArray
        terminal->pvt->reset_color(VTE_DEFAULT_BG, VTE_COLOR_SOURCE_ESCAPE);
 }
 
-/* Change the color of the cursor, BEL terminated */
+/* Change the color of the cursor background, BEL terminated */
 static void
-vte_sequence_handler_change_cursor_color_bel (VteTerminal *terminal, GValueArray *params)
+vte_sequence_handler_change_cursor_background_color_bel (VteTerminal *terminal, GValueArray *params)
 {
        vte_sequence_handler_change_special_color_internal (terminal, params,
                                                            VTE_CURSOR_BG, VTE_DEFAULT_FG, 12, BEL);
 }
 
-/* Change the color of the cursor, ST terminated */
+/* Change the color of the cursor background, ST terminated */
 static void
-vte_sequence_handler_change_cursor_color_st (VteTerminal *terminal, GValueArray *params)
+vte_sequence_handler_change_cursor_background_color_st (VteTerminal *terminal, GValueArray *params)
 {
        vte_sequence_handler_change_special_color_internal (terminal, params,
                                                            VTE_CURSOR_BG, VTE_DEFAULT_FG, 12, ST);
@@ -3163,7 +3163,7 @@ vte_sequence_handler_change_cursor_color_st (VteTerminal *terminal, GValueArray
 
 /* Reset the color of the cursor */
 static void
-vte_sequence_handler_reset_cursor_color (VteTerminal *terminal, GValueArray *params)
+vte_sequence_handler_reset_cursor_background_color (VteTerminal *terminal, GValueArray *params)
 {
        terminal->pvt->reset_color(VTE_CURSOR_BG, VTE_COLOR_SOURCE_ESCAPE);
 }


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