From 97c6f36b20ee64b307a1d707315d6de801b30dc1 Mon Sep 17 00:00:00 2001 From: deepend Date: Wed, 25 Feb 2026 19:43:19 -0700 Subject: [PATCH] =?UTF-8?q?Adjusted=20create=5Finput=5Fstyle=20so=20it=20n?= =?UTF-8?q?o=20longer=20globally=20forces=20color=20on=20#zoitechat-inputb?= =?UTF-8?q?ox,=20reducing=20over-constraining=20while=20still=20applying?= =?UTF-8?q?=20the=20user-selected=20background=20and=20caret=20color=20whe?= =?UTF-8?q?re=20intended.=20This=20keeps=20non-text-node=20state=20renderi?= =?UTF-8?q?ng=20more=20theme-driven.=20Kept=20user=20override=20support=20?= =?UTF-8?q?for=20baseline=20text=20color=20and=20caret=20color=20on=20the?= =?UTF-8?q?=20input=E2=80=99s=20text=20node=20(#zoitechat-inputbox=20text)?= =?UTF-8?q?.=20Added=20targeted=20state-aware=20text=20rules=20for=20:focu?= =?UTF-8?q?s=20and=20:backdrop=20(to=20preserve=20readability=20when=20the?= =?UTF-8?q?me=20state=20styling=20changes),=20plus=20a=20softened=20:disab?= =?UTF-8?q?led=20text=20rule=20instead=20of=20broad=20global=20color=20for?= =?UTF-8?q?cing.=20Added=20explicit=20selection-node=20handling=20(#zoitec?= =?UTF-8?q?hat-inputbox=20text=20selection)=20using=20theme=20selection=20?= =?UTF-8?q?tokens=20so=20selected=20text=20remains=20readable=20and=20alig?= =?UTF-8?q?ned=20with=20Adwaita/Yaru-style=20theme=20behavior.=20Preserved?= =?UTF-8?q?=20the=20existing=20Adwaita/Yaru=20background-image=20workaroun?= =?UTF-8?q?d=20logic,=20so=20fallback=20behavior=20remains=20compatible=20?= =?UTF-8?q?with=20those=20themes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fe-gtk/fe-gtk.c | 54 ++++++++++++++++++++++++----------- src/fe-gtk/setup.c | 69 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 90 insertions(+), 33 deletions(-) diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c index 7bb5e37d..6bc2a6a8 100644 --- a/src/fe-gtk/fe-gtk.c +++ b/src/fe-gtk/fe-gtk.c @@ -577,9 +577,8 @@ fe_system_prefers_dark (void) static gboolean auto_dark_mode_enabled = FALSE; -#ifdef G_OS_WIN32 static void -fe_apply_windows_theme (gboolean dark) +fe_set_gtk_prefer_dark_theme (gboolean dark) { GtkSettings *settings = gtk_settings_get_default (); @@ -588,6 +587,13 @@ fe_apply_windows_theme (gboolean dark) { g_object_set (settings, "gtk-application-prefer-dark-theme", dark, NULL); } +} + +#ifdef G_OS_WIN32 +static void +fe_apply_windows_theme (gboolean dark) +{ + fe_set_gtk_prefer_dark_theme (dark); { static GtkCssProvider *win_theme_provider = NULL; @@ -652,6 +658,10 @@ gboolean fe_apply_theme_for_mode (unsigned int mode, gboolean *palette_changed) { gboolean enabled = fe_dark_mode_is_enabled_for (mode); + + /* Apply the optional global GTK preference first, then reapply palette-driven + * chat/input colors so Preferences > Colors continues to take precedence. */ + fe_set_gtk_prefer_dark_theme (enabled); gboolean changed = palette_apply_dark_mode (enabled); #ifdef G_OS_WIN32 @@ -670,24 +680,23 @@ fe_apply_theme_for_mode (unsigned int mode, gboolean *palette_changed) void fe_apply_theme_to_toplevel (GtkWidget *window) { + GtkStyleContext *context; + gboolean dark; + if (!window) return; -#ifdef G_OS_WIN32 + context = gtk_widget_get_style_context (window); + dark = fe_dark_mode_is_enabled (); + + if (context) { - GtkStyleContext *context = gtk_widget_get_style_context (window); - gboolean dark = fe_dark_mode_is_enabled (); - - if (context) - { - gtk_style_context_remove_class (context, "zoitechat-dark"); - gtk_style_context_remove_class (context, "zoitechat-light"); - gtk_style_context_add_class (context, dark ? "zoitechat-dark" : "zoitechat-light"); - } + gtk_style_context_remove_class (context, "zoitechat-dark"); + gtk_style_context_remove_class (context, "zoitechat-light"); + gtk_style_context_add_class (context, dark ? "zoitechat-dark" : "zoitechat-light"); } -#endif - fe_win32_apply_native_titlebar (window, fe_dark_mode_is_enabled ()); + fe_win32_apply_native_titlebar (window, dark); } gboolean @@ -809,18 +818,31 @@ create_input_style (InputStyle *style) g_string_append_printf ( css, "background-color: #%02x%02x%02x;" - "color: #%02x%02x%02x;" "caret-color: %s;" "}" "#zoitechat-inputbox text {" "color: #%02x%02x%02x;" "caret-color: %s;" + "}" + "#zoitechat-inputbox:focus text," + "#zoitechat-inputbox:backdrop text {" + "color: #%02x%02x%02x;" + "caret-color: %s;" + "}" + "#zoitechat-inputbox:disabled text {" + "color: alpha(#%02x%02x%02x, 0.7);" + "}" + "#zoitechat-inputbox text selection {" + "color: @theme_selected_fg_color;" + "background-color: @theme_selected_bg_color;" "}", (bg_red >> 8), (bg_green >> 8), (bg_blue >> 8), + cursor_color, (fg_red >> 8), (fg_green >> 8), (fg_blue >> 8), cursor_color, (fg_red >> 8), (fg_green >> 8), (fg_blue >> 8), - cursor_color); + cursor_color, + (fg_red >> 8), (fg_green >> 8), (fg_blue >> 8)); gtk_css_provider_load_from_data (input_css_provider, css->str, -1, NULL); g_string_free (css, TRUE); } diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c index 36fc0822..0282358d 100644 --- a/src/fe-gtk/setup.c +++ b/src/fe-gtk/setup.c @@ -2412,6 +2412,47 @@ setup_apply_entry_style (GtkWidget *entry) input_style->font_desc); } +static void +setup_apply_input_caret_provider (GtkWidget *widget, const char *css) +{ + GtkCssProvider *provider; + GtkStyleContext *context; + + if (!widget) + return; + + context = gtk_widget_get_style_context (widget); + provider = g_object_get_data (G_OBJECT (widget), "zoitechat-input-caret-provider"); + if (!provider) + { + provider = gtk_css_provider_new (); + g_object_set_data_full (G_OBJECT (widget), "zoitechat-input-caret-provider", + provider, g_object_unref); + gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } + + gtk_css_provider_load_from_data (provider, css, -1, NULL); +} + +static void +setup_remove_input_caret_provider (GtkWidget *widget) +{ + GtkCssProvider *provider; + GtkStyleContext *context; + + if (!widget) + return; + + context = gtk_widget_get_style_context (widget); + provider = g_object_get_data (G_OBJECT (widget), "zoitechat-input-caret-provider"); + if (!provider) + return; + + gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (provider)); + g_object_set_data (G_OBJECT (widget), "zoitechat-input-caret-provider", NULL); +} + static void setup_apply_to_sess (session_gui *gui) { @@ -2437,35 +2478,29 @@ setup_apply_to_sess (session_gui *gui) if (prefs.hex_gui_input_style) { char buf[128]; - GtkCssProvider *provider = gtk_css_provider_new (); - GtkStyleContext *context; char *color_string = gdk_rgba_to_string (&colors[COL_FG]); g_snprintf (buf, sizeof (buf), ".zoitechat-inputbox { caret-color: %s; }", color_string); - gtk_css_provider_load_from_data (provider, buf, -1, NULL); g_free (color_string); - context = gtk_widget_get_style_context (gui->input_box); - gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - context = gtk_widget_get_style_context (gui->limit_entry); - gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - context = gtk_widget_get_style_context (gui->key_entry); - gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - context = gtk_widget_get_style_context (gui->topic_entry); - gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - - g_object_unref (provider); + setup_apply_input_caret_provider (gui->input_box, buf); + setup_apply_input_caret_provider (gui->limit_entry, buf); + setup_apply_input_caret_provider (gui->key_entry, buf); + setup_apply_input_caret_provider (gui->topic_entry, buf); setup_apply_entry_style (gui->input_box); setup_apply_entry_style (gui->limit_entry); setup_apply_entry_style (gui->key_entry); setup_apply_entry_style (gui->topic_entry); } + else + { + setup_remove_input_caret_provider (gui->input_box); + setup_remove_input_caret_provider (gui->limit_entry); + setup_remove_input_caret_provider (gui->key_entry); + setup_remove_input_caret_provider (gui->topic_entry); + } if (prefs.hex_gui_ulist_buttons) gtk_widget_show (gui->button_box);