Adjusted create_input_style so it no longer globally forces color on #zoitechat-inputbox, reducing over-constraining while still applying the user-selected background and caret color where intended. This keeps non-text-node state rendering more theme-driven.

Kept user override support for baseline text color and caret color on the input’s text node (#zoitechat-inputbox text).
Added targeted state-aware text rules for :focus and :backdrop (to preserve readability when theme state styling changes), plus a softened :disabled text rule instead of broad global color forcing.
Added explicit selection-node handling (#zoitechat-inputbox text selection) using theme selection tokens so selected text remains readable and aligned with Adwaita/Yaru-style theme behavior.
Preserved the existing Adwaita/Yaru background-image workaround logic, so fallback behavior remains compatible with those themes.
This commit is contained in:
2026-02-25 19:43:19 -07:00
parent 2bf32fc770
commit 97c6f36b20
2 changed files with 90 additions and 33 deletions

View File

@@ -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);
}

View File

@@ -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);