Updated GTK3 color parsing in the palette/setup helpers to use RGBA-friendly hex strings with gdk_rgba_parse fallbacks while preserving GTK2 behavior.

Switched GtkCellRendererText foreground property selection to foreground-rgba on GTK3 paths (with GTK2 guarded), covering userlist, notify, and DCC views.
This commit is contained in:
2026-01-23 00:13:14 -07:00
parent 131691156a
commit ea4ef5be90
5 changed files with 29 additions and 9 deletions

View File

@@ -731,7 +731,12 @@ static void
dcc_add_column (GtkWidget *tree, int textcol, int colorcol, char *title, gboolean right_justified) dcc_add_column (GtkWidget *tree, int textcol, int colorcol, char *title, gboolean right_justified)
{ {
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
const char *foreground_property = PALETTE_FOREGROUND_PROPERTY; const char *foreground_property =
#if GTK_CHECK_VERSION(3,0,0)
"foreground-rgba";
#else
"foreground-gdk";
#endif
renderer = gtk_cell_renderer_text_new (); renderer = gtk_cell_renderer_text_new ();
if (right_justified) if (right_justified)

View File

@@ -74,18 +74,24 @@ notify_treecell_property_mapper (GtkTreeViewColumn *col, GtkCellRenderer *cell,
gchar *text; gchar *text;
PaletteColor *colour; PaletteColor *colour;
int model_column = GPOINTER_TO_INT (data); int model_column = GPOINTER_TO_INT (data);
const char *foreground_property =
#if GTK_CHECK_VERSION(3,0,0)
"foreground-rgba";
#else
"foreground-gdk";
#endif
gtk_tree_model_get (GTK_TREE_MODEL (model), iter, gtk_tree_model_get (GTK_TREE_MODEL (model), iter,
COLOUR_COLUMN, &colour, COLOUR_COLUMN, &colour,
model_column, &text, -1); model_column, &text, -1);
#if GTK_CHECK_VERSION(3,0,0) #if GTK_CHECK_VERSION(3,0,0)
g_object_set (G_OBJECT (cell), "text", text, g_object_set (G_OBJECT (cell), "text", text,
PALETTE_FOREGROUND_PROPERTY, colour, NULL); foreground_property, colour, NULL);
if (colour) if (colour)
gdk_rgba_free (colour); gdk_rgba_free (colour);
#else #else
g_object_set (G_OBJECT (cell), "text", text, g_object_set (G_OBJECT (cell), "text", text,
PALETTE_FOREGROUND_PROPERTY, colour, NULL); foreground_property, colour, NULL);
if (colour) if (colour)
gdk_color_free (colour); gdk_color_free (colour);
#endif #endif

View File

@@ -47,13 +47,13 @@
static void static void
palette_color_set_rgb16 (PaletteColor *color, guint16 red, guint16 green, guint16 blue) palette_color_set_rgb16 (PaletteColor *color, guint16 red, guint16 green, guint16 blue)
{ {
char color_string[16];
g_snprintf (color_string, sizeof (color_string), "#%04x%04x%04x", red, green, blue);
#if GTK_CHECK_VERSION(3,0,0) #if GTK_CHECK_VERSION(3,0,0)
char color_string[8];
GdkRGBA parsed = { 0 }; GdkRGBA parsed = { 0 };
gboolean parsed_ok; gboolean parsed_ok;
g_snprintf (color_string, sizeof (color_string), "#%02x%02x%02x",
red >> 8, green >> 8, blue >> 8);
parsed_ok = gdk_rgba_parse (&parsed, color_string); parsed_ok = gdk_rgba_parse (&parsed, color_string);
if (!parsed_ok) if (!parsed_ok)
{ {
@@ -64,6 +64,9 @@ palette_color_set_rgb16 (PaletteColor *color, guint16 red, guint16 green, guint1
} }
*color = parsed; *color = parsed;
#else #else
char color_string[16];
g_snprintf (color_string, sizeof (color_string), "#%04x%04x%04x", red, green, blue);
if (!gdk_color_parse (color_string, color)) if (!gdk_color_parse (color_string, color))
{ {
color->red = red; color->red = red;

View File

@@ -1537,10 +1537,11 @@ static void
setup_rgba_from_palette (const PaletteColor *color, GdkRGBA *rgba) setup_rgba_from_palette (const PaletteColor *color, GdkRGBA *rgba)
{ {
guint16 red, green, blue; guint16 red, green, blue;
char color_string[16]; char color_string[8];
palette_color_get_rgb16 (color, &red, &green, &blue); palette_color_get_rgb16 (color, &red, &green, &blue);
g_snprintf (color_string, sizeof (color_string), "#%04x%04x%04x", red, green, blue); g_snprintf (color_string, sizeof (color_string), "#%02x%02x%02x",
red >> 8, green >> 8, blue >> 8);
if (!gdk_rgba_parse (rgba, color_string)) if (!gdk_rgba_parse (rgba, color_string))
{ {
rgba->red = red / 65535.0; rgba->red = red / 65535.0;

View File

@@ -533,7 +533,12 @@ static void
userlist_add_columns (GtkTreeView * treeview) userlist_add_columns (GtkTreeView * treeview)
{ {
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
const char *foreground_property = PALETTE_FOREGROUND_PROPERTY; const char *foreground_property =
#if GTK_CHECK_VERSION(3,0,0)
"foreground-rgba";
#else
"foreground-gdk";
#endif
/* icon column */ /* icon column */
renderer = gtk_cell_renderer_pixbuf_new (); renderer = gtk_cell_renderer_pixbuf_new ();