Merge pull request #211 from ZoiteChat/gtk-state-mismatch

Fix palette color reads to preserve base GTK state
This commit is contained in:
deepend-tildeclub
2026-04-27 13:40:28 -06:00
committed by GitHub

View File

@@ -82,6 +82,36 @@ theme_token_to_rgb16 (ThemeSemanticToken token, guint16 *red, guint16 *green, gu
return TRUE; return TRUE;
} }
static GtkStateFlags
theme_access_state_with_base (GtkStyleContext *context, GtkStateFlags state)
{
GtkStateFlags base_state;
base_state = gtk_style_context_get_state (context);
base_state &= (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL | GTK_STATE_FLAG_BACKDROP | GTK_STATE_FLAG_FOCUSED);
return base_state | state;
}
static void
theme_access_context_get_color (GtkStyleContext *context, GtkStateFlags state, GdkRGBA *out_color)
{
gtk_style_context_save (context);
gtk_style_context_set_state (context, theme_access_state_with_base (context, state));
gtk_style_context_get_color (context, gtk_style_context_get_state (context), out_color);
gtk_style_context_restore (context);
}
static void
theme_access_context_get_background_color (GtkStyleContext *context, GtkStateFlags state, GdkRGBA *out_color)
{
gtk_style_context_save (context);
gtk_style_context_set_state (context, theme_access_state_with_base (context, state));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_style_context_get_background_color (context, gtk_style_context_get_state (context), out_color);
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_style_context_restore (context);
}
static gboolean static gboolean
theme_access_get_gtk_palette_map (GtkWidget *widget, ThemeGtkPaletteMap *out_map) theme_access_get_gtk_palette_map (GtkWidget *widget, ThemeGtkPaletteMap *out_map)
{ {
@@ -96,13 +126,11 @@ theme_access_get_gtk_palette_map (GtkWidget *widget, ThemeGtkPaletteMap *out_map
if (context == NULL) if (context == NULL)
return FALSE; return FALSE;
gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &out_map->text_foreground); theme_access_context_get_color (context, GTK_STATE_FLAG_NORMAL, &out_map->text_foreground);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS theme_access_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &out_map->text_background);
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &out_map->text_background); theme_access_context_get_color (context, GTK_STATE_FLAG_SELECTED, &out_map->selection_foreground);
gtk_style_context_get_color (context, GTK_STATE_FLAG_SELECTED, &out_map->selection_foreground); theme_access_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &out_map->selection_background);
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &out_map->selection_background); theme_access_context_get_color (context, GTK_STATE_FLAG_LINK, &accent);
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_style_context_get_color (context, GTK_STATE_FLAG_LINK, &accent);
if (accent.alpha <= 0.0) if (accent.alpha <= 0.0)
accent = out_map->selection_background; accent = out_map->selection_background;
out_map->accent = accent; out_map->accent = accent;