mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-05-16 21:50:20 +00:00
Merge pull request #211 from ZoiteChat/gtk-state-mismatch
Fix palette color reads to preserve base GTK state
This commit is contained in:
@@ -82,6 +82,36 @@ theme_token_to_rgb16 (ThemeSemanticToken token, guint16 *red, guint16 *green, gu
|
||||
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
|
||||
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)
|
||||
return FALSE;
|
||||
|
||||
gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &out_map->text_foreground);
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &out_map->text_background);
|
||||
gtk_style_context_get_color (context, GTK_STATE_FLAG_SELECTED, &out_map->selection_foreground);
|
||||
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &out_map->selection_background);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
gtk_style_context_get_color (context, GTK_STATE_FLAG_LINK, &accent);
|
||||
theme_access_context_get_color (context, GTK_STATE_FLAG_NORMAL, &out_map->text_foreground);
|
||||
theme_access_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);
|
||||
theme_access_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &out_map->selection_background);
|
||||
theme_access_context_get_color (context, GTK_STATE_FLAG_LINK, &accent);
|
||||
if (accent.alpha <= 0.0)
|
||||
accent = out_map->selection_background;
|
||||
out_map->accent = accent;
|
||||
|
||||
Reference in New Issue
Block a user