[vte/wip/rishi/css-theme-background-color] widget: Improve legibility by tweaking the system theme's base colour
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/wip/rishi/css-theme-background-color] widget: Improve legibility by tweaking the system theme's base colour
- Date: Fri, 3 Apr 2020 13:28:08 +0000 (UTC)
commit e881b64c89ee3cd004dfb53b3ef984687d767613
Author: Jakub Steiner <jimmac gmail com>
Date: Tue Mar 31 20:55:23 2020 +0200
widget: Improve legibility by tweaking the system theme's base colour
Some changes by Debarshi Ray.
https://gitlab.gnome.org/GNOME/vte/-/issues/226
src/vtegtk.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 58 insertions(+), 9 deletions(-)
---
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 0838b6bc..9d8189d4 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -73,7 +73,8 @@
#define VTE_TERMINAL_CSS_NAME "vte-terminal"
struct _VteTerminalClassPrivate {
- GtkStyleProvider *style_provider;
+ GtkStyleProvider *style_provider_dark;
+ GtkStyleProvider *style_provider_light;
};
#ifdef VTE_DEBUG
@@ -127,6 +128,41 @@ valid_color(GdkRGBA const* color)
color->alpha >= 0. && color->alpha <= 1.;
}
+static void
+vte_terminal_theme_update (VteTerminal *terminal)
+{
+ GtkSettings *settings;
+ GtkStyleContext *context;
+ gboolean application_prefer_dark_theme;
+
+ settings = gtk_settings_get_default ();
+ g_object_get (settings, "gtk-application-prefer-dark-theme", &application_prefer_dark_theme,
nullptr);
+
+ context = gtk_widget_get_style_context (&terminal->widget);
+
+ if (application_prefer_dark_theme) {
+ gtk_style_context_remove_provider (context,
+ VTE_TERMINAL_GET_CLASS
(terminal)->priv->style_provider_light);
+
+ gtk_style_context_add_provider (context,
+ VTE_TERMINAL_GET_CLASS (terminal)->priv->style_provider_dark,
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ } else {
+ gtk_style_context_remove_provider (context,
+ VTE_TERMINAL_GET_CLASS
(terminal)->priv->style_provider_dark);
+
+ gtk_style_context_add_provider (context,
+ VTE_TERMINAL_GET_CLASS
(terminal)->priv->style_provider_light,
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
+}
+
+static void
+vte_terminal_theme_changed (VteTerminal *terminal)
+{
+ vte_terminal_theme_update (terminal);
+}
+
static void
vte_terminal_set_hadjustment(VteTerminal *terminal,
GtkAdjustment *adjustment)
@@ -392,14 +428,18 @@ static void
vte_terminal_init(VteTerminal *terminal)
{
void *place;
- GtkStyleContext *context;
+ GtkSettings *settings;
_vte_debug_print(VTE_DEBUG_LIFECYCLE, "vte_terminal_init()\n");
- context = gtk_widget_get_style_context(&terminal->widget);
- gtk_style_context_add_provider (context,
- VTE_TERMINAL_GET_CLASS (terminal)->priv->style_provider,
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ vte_terminal_theme_update (terminal);
+
+ settings = gtk_settings_get_default ();
+ g_signal_connect_object (settings,
+ "notify::gtk-application-prefer-dark-theme",
+ G_CALLBACK (vte_terminal_theme_changed),
+ terminal,
+ G_CONNECT_SWAPPED);
/* Initialize private data. NOTE: place is zeroed */
place = vte_terminal_get_instance_private(terminal);
@@ -1812,11 +1852,20 @@ vte_terminal_class_init(VteTerminalClass *klass)
klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, VTE_TYPE_TERMINAL, VteTerminalClassPrivate);
- klass->priv->style_provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
- gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (klass->priv->style_provider),
+ klass->priv->style_provider_dark = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
+ gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (klass->priv->style_provider_dark),
+ "VteTerminal, " VTE_TERMINAL_CSS_NAME " {\n"
+ "padding: 1px 1px 1px 1px;\n"
+ "background-color: shade(@theme_base_color, 0.67);\n"
+ "color: @theme_text_color;\n"
+ "}\n",
+ -1, NULL);
+
+ klass->priv->style_provider_light = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
+ gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (klass->priv->style_provider_light),
"VteTerminal, " VTE_TERMINAL_CSS_NAME " {\n"
"padding: 1px 1px 1px 1px;\n"
- "background-color: @theme_base_color;\n"
+ "background-color: shade(@theme_base_color, 1.1);\n"
"color: @theme_text_color;\n"
"}\n",
-1, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]