[vte/vte-next: 80/114] Make 'cursor-background-color' a style property
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-next: 80/114] Make 'cursor-background-color' a style property
- Date: Mon, 30 May 2011 17:13:28 +0000 (UTC)
commit 2991b59689193681b35fc8977f5e6ca060c9da96
Author: Christian Persch <chpe gnome org>
Date: Wed May 18 19:31:14 2011 +0200
Make 'cursor-background-color' a style property
doc/reference/vte-sections.txt | 1 -
src/vte-private.h | 5 ++
src/vte.c | 99 +++++++++++++++++++++++++++++++++++-----
src/vte.h | 2 -
src/vteapp.c | 17 ++++---
src/vteseq.c | 2 +-
6 files changed, 103 insertions(+), 23 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index c3ffd5c..15f08c1 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -29,7 +29,6 @@ vte_terminal_set_color_bold_rgba
vte_terminal_set_color_foreground_rgba
vte_terminal_set_color_background_rgba
vte_terminal_set_color_dim_rgba
-vte_terminal_set_color_cursor_rgba
vte_terminal_set_color_highlight_rgba
vte_terminal_set_colors_rgba
vte_terminal_set_default_colors
diff --git a/src/vte-private.h b/src/vte-private.h
index 8197369..24b231e 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -449,6 +449,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);
+
G_END_DECLS
#endif
diff --git a/src/vte.c b/src/vte.c
index 22e64df..6d302bd 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -2495,34 +2495,44 @@ vte_terminal_set_color_background_rgba(VteTerminal *terminal,
vte_terminal_set_color_internal(terminal, VTE_DEF_BG, rgba, TRUE);
}
-/**
- * vte_terminal_set_color_cursor_rgba:
+/*
+ * _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, text
- * under the cursor will be drawn with foreground and background colors
- * reversed.
+ * 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)
+_vte_terminal_set_color_cursor_rgba(VteTerminal *terminal,
+ const GdkRGBA *rgba,
+ gboolean override)
{
- g_return_if_fail(VTE_IS_TERMINAL(terminal));
+ 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,
- "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, TRUE);
+ _vte_debug_print(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,
"Cleared cursor color.\n");
terminal->pvt->cursor_color_set = FALSE;
}
+
+ _vte_invalidate_cursor_once(terminal, FALSE);
}
/**
@@ -4239,6 +4249,53 @@ vte_terminal_set_padding(VteTerminal *terminal)
gtk_widget_queue_resize(widget);
}
+/**
+ * _vte_gtk_style_context_lookup_color:
+ * @context:
+ * @color_name:
+ * @color: a location to store the color
+ *
+ * Like gtk_style_context_lookup_color(), but returns the color
+ * instead of boolean.
+ *
+ * Returns: (transfer none): @color if lookup succeeded, else %NULL
+ */
+static const GdkRGBA *
+_vte_style_context_get_color(GtkStyleContext *context,
+ const char *color_name,
+ GdkRGBA *color)
+{
+ GdkRGBA *copy;
+
+ gtk_style_context_get_style(context, color_name, ©, NULL);
+ if (copy == NULL)
+ {
+#if 0
+ /* Put in a nice shade of magenta, to indicate something's wrong */
+ color->red = color->blue = color->alpha = 1.; color->green = 0.;
+ return color;
+#endif
+ return NULL;
+ }
+
+ *color = *copy;
+ gdk_rgba_free (copy);
+ return color;
+}
+
+static void
+vte_terminal_update_style_colors(VteTerminal *terminal)
+{
+ GtkStyleContext *context;
+ GdkRGBA rgba;
+ const GdkRGBA *color;
+
+ context = gtk_widget_get_style_context(&terminal->widget);
+
+ color = _vte_style_context_get_color(context, "cursor-background-color", &rgba);
+ _vte_terminal_set_color_cursor_rgba(terminal, color, FALSE);
+}
+
static void
vte_terminal_update_style(VteTerminal *terminal)
{
@@ -4250,6 +4307,7 @@ vte_terminal_update_style(VteTerminal *terminal)
vte_terminal_set_font(terminal, pvt->fontdesc);
vte_terminal_set_padding(terminal);
+ vte_terminal_update_style_colors(terminal);
gtk_widget_style_get(widget,
"allow-bold", &allow_bold,
@@ -11639,6 +11697,23 @@ vte_terminal_class_init(VteTerminalClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ /* Colours */
+
+ /**
+ * VteTerminal:cursor-background-color:
+ *
+ * The background color for text which is under the cursor. If not set,
+ * text under the cursor will be drawn with foreground and background
+ * colors reversed.
+ *
+ * Since: 0.30
+ */
+ gtk_widget_class_install_style_property
+ (widget_class,
+ g_param_spec_boxed ("cursor-background-color", NULL, NULL,
+ GDK_TYPE_RGBA,
+ 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 e92ef67..abf39ac 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -236,8 +236,6 @@ void vte_terminal_set_color_foreground_rgba(VteTerminal *terminal,
const GdkRGBA *rgba);
void vte_terminal_set_color_background_rgba(VteTerminal *terminal,
const GdkRGBA *rgba);
-void vte_terminal_set_color_cursor_rgba(VteTerminal *terminal,
- const GdkRGBA *rgba);
void vte_terminal_set_color_highlight_rgba(VteTerminal *terminal,
const GdkRGBA *rgba);
void vte_terminal_set_colors_rgba(VteTerminal *terminal,
diff --git a/src/vteapp.c b/src/vteapp.c
index 596d228..457013d 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -550,7 +550,7 @@ main(int argc, char **argv)
debug = FALSE, dingus = FALSE, dbuffer = TRUE,
console = FALSE, scroll = FALSE, keep = FALSE,
icon_title = FALSE, shell = TRUE, highlight_set = FALSE,
- cursor_set = FALSE, reverse = FALSE, use_geometry_hints = TRUE,
+ reverse = FALSE, use_geometry_hints = TRUE,
use_scrolled_window = FALSE,
show_object_notifications = FALSE;
char *geometry = NULL;
@@ -563,6 +563,7 @@ main(int argc, char **argv)
const char *output_file = NULL;
char *tint_color_string = NULL;
char *pty_flags_string = NULL;
+ char *cursor_color_string = NULL;
char *cursor_blink_mode_string = NULL;
char *cursor_shape_string = NULL;
char *scrollbar_policy_string = NULL;
@@ -648,9 +649,9 @@ main(int argc, char **argv)
"Cursor blink mode (system|on|off)", "MODE"
},
{
- "color-cursor", 'r', 0,
- G_OPTION_ARG_NONE, &cursor_set,
- "Enable a colored cursor", NULL
+ "cursor-color", 'r', 0,
+ G_OPTION_ARG_STRING, &cursor_color_string,
+ "Enable a colored cursor", "COLOR"
},
{
"cursor-shape", 0, 0,
@@ -797,6 +798,11 @@ main(int argc, char **argv)
g_string_append_c (css_string, '\n');
}
+ if (cursor_color_string) {
+ g_string_append_printf (css_string, "VteTerminal { -VteTerminal-cursor-background-color: %s; }\n",
+ cursor_color_string);
+ g_free(cursor_color_string);
+ }
if (cursor_shape_string) {
g_string_append_printf (css_string, "VteTerminal { -VteTerminal-cursor-shape: %s; }\n",
cursor_shape_string);
@@ -964,9 +970,6 @@ main(int argc, char **argv)
if (highlight_set) {
vte_terminal_set_color_highlight_rgba(terminal, &highlight);
}
- if (cursor_set) {
- vte_terminal_set_color_cursor_rgba(terminal, &cursor);
- }
if (termcap != NULL) {
vte_terminal_set_emulation(terminal, termcap);
}
diff --git a/src/vteseq.c b/src/vteseq.c
index 9e6851d..cc72ff4 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -3274,7 +3274,7 @@ 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);
+ _vte_terminal_set_color_cursor_rgba (terminal, &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]