diff options
| author | Milan Crha <mcrha@redhat.com> | 2020-11-13 12:15:19 +0100 |
|---|---|---|
| committer | Milan Crha <mcrha@redhat.com> | 2020-11-13 12:15:19 +0100 |
| commit | a51e13c6c24eb489c62b34c74fae56f65bb36d40 (patch) | |
| tree | 74c916a7516f9f519b4dd5647daebe0f6f71cdf0 /src/libedataserverui | |
| parent | 6b34dd3ad1c077af011dbce65d1aa4e9047fa78d (diff) | |
| download | evolution-data-server-a51e13c6c24eb489c62b34c74fae56f65bb36d40.tar.gz | |
EBufferTagger: Derive link color from the theme
There had been used the 'blue' color, which doesn't look correctly
in dark themes and can be totally wrong for any theme.
Related to https://gitlab.gnome.org/GNOME/gtk/-/issues/3344
Diffstat (limited to 'src/libedataserverui')
| -rw-r--r-- | src/libedataserverui/e-buffer-tagger.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libedataserverui/e-buffer-tagger.c b/src/libedataserverui/e-buffer-tagger.c index 12fc50b13..468c9d3c4 100644 --- a/src/libedataserverui/e-buffer-tagger.c +++ b/src/libedataserverui/e-buffer-tagger.c @@ -467,6 +467,47 @@ update_mouse_cursor (GtkTextView *text_view, } } +static void +textview_style_updated_cb (GtkWidget *textview, + gpointer user_data) +{ + GtkStyleContext *context; + GtkStateFlags state; + GtkTextBuffer *buffer; + GtkTextTagTable *tag_table; + GtkTextTag *tag; + GdkRGBA rgba; + + g_return_if_fail (GTK_IS_WIDGET (textview)); + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)); + tag_table = gtk_text_buffer_get_tag_table (buffer); + tag = gtk_text_tag_table_lookup (tag_table, E_BUFFER_TAGGER_LINK_TAG); + + if (!tag) + return; + + context = gtk_widget_get_style_context (textview); + + rgba.red = 0; + rgba.green = 0; + rgba.blue = 1; + rgba.alpha = 1; + + state = gtk_style_context_get_state (context); + state = state & (~(GTK_STATE_FLAG_VISITED | GTK_STATE_FLAG_LINK)); + state = state | GTK_STATE_FLAG_LINK; + + gtk_style_context_save (context); + /* Remove the 'view' style, because it can "confuse" some themes */ + gtk_style_context_remove_class (context, GTK_STYLE_CLASS_VIEW); + gtk_style_context_set_state (context, state); + gtk_style_context_get_color (context, state, &rgba); + gtk_style_context_restore (context); + + g_object_set (G_OBJECT (tag), "foreground-rgba", &rgba, NULL); +} + static gboolean textview_query_tooltip (GtkTextView *text_view, gint x, @@ -824,6 +865,9 @@ e_buffer_tagger_connect (GtkTextView *textview) gtk_widget_set_has_tooltip (GTK_WIDGET (textview), TRUE); g_signal_connect ( + textview, "style-updated", + G_CALLBACK (textview_style_updated_cb), NULL); + g_signal_connect ( textview, "query-tooltip", G_CALLBACK (textview_query_tooltip), NULL); g_signal_connect ( @@ -870,6 +914,7 @@ e_buffer_tagger_disconnect (GtkTextView *textview) gtk_widget_set_has_tooltip (GTK_WIDGET (textview), FALSE); + g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_style_updated_cb), NULL); g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_query_tooltip), NULL); g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_key_press_event), NULL); g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_event_after), NULL); |
