Routed GTK cell renderer foreground bindings through PALETTE_FOREGROUND_PROPERTY for user list, notify, and DCC views to ensure GTK3 uses RGBA while preserving GTK2 behavior.

Tightened GTK3 RGBA parsing by using stack buffers in palette color conversion and guarded parsing in the setup color chooser dialog.
This commit is contained in:
2026-01-22 22:47:11 -07:00
parent 3c0a4e4995
commit 51fd0fca91
5 changed files with 7 additions and 25 deletions

View File

@@ -735,15 +735,9 @@ dcc_add_column (GtkWidget *tree, int textcol, int colorcol, char *title, gboolea
renderer = gtk_cell_renderer_text_new (); renderer = gtk_cell_renderer_text_new ();
if (right_justified) if (right_justified)
g_object_set (G_OBJECT (renderer), "xalign", (float) 1.0, NULL); g_object_set (G_OBJECT (renderer), "xalign", (float) 1.0, NULL);
#if GTK_CHECK_VERSION(3,0,0)
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, title, renderer, gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, title, renderer,
"text", textcol, "foreground-rgba", colorcol, "text", textcol, PALETTE_FOREGROUND_PROPERTY, colorcol,
NULL); NULL);
#else
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, title, renderer,
"text", textcol, "foreground-gdk", colorcol,
NULL);
#endif
gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer), 1); gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer), 1);
} }

View File

@@ -79,11 +79,7 @@ notify_treecell_property_mapper (GtkTreeViewColumn *col, GtkCellRenderer *cell,
COLOUR_COLUMN, &colour, COLOUR_COLUMN, &colour,
model_column, &text, -1); model_column, &text, -1);
g_object_set (G_OBJECT (cell), "text", text, NULL); g_object_set (G_OBJECT (cell), "text", text, NULL);
#if GTK_CHECK_VERSION(3,0,0) g_object_set (G_OBJECT (cell), PALETTE_FOREGROUND_PROPERTY, colour, NULL);
g_object_set (G_OBJECT (cell), "foreground-rgba", colour, NULL);
#else
g_object_set (G_OBJECT (cell), "foreground-gdk", colour, NULL);
#endif
g_free (text); g_free (text);
} }

View File

@@ -50,11 +50,10 @@ palette_color_set_rgb16 (PaletteColor *color, guint16 red, guint16 green, guint1
#if GTK_CHECK_VERSION(3,0,0) #if GTK_CHECK_VERSION(3,0,0)
GdkRGBA parsed; GdkRGBA parsed;
gboolean parsed_ok; gboolean parsed_ok;
char *color_string; char color_string[16];
color_string = g_strdup_printf ("#%04x%04x%04x", red, green, blue); g_snprintf (color_string, sizeof (color_string), "#%04x%04x%04x", red, green, blue);
parsed_ok = gdk_rgba_parse (&parsed, color_string); parsed_ok = gdk_rgba_parse (&parsed, color_string);
g_free (color_string);
if (!parsed_ok) if (!parsed_ok)
{ {
parsed.red = red / 65535.0; parsed.red = red / 65535.0;

View File

@@ -1596,15 +1596,14 @@ setup_color_cb (GtkWidget *button, gpointer userdata)
PaletteColor *color; PaletteColor *color;
GdkRGBA rgba; GdkRGBA rgba;
gboolean parsed_ok; gboolean parsed_ok;
char *color_string; g_autofree char *color_string = NULL;
setup_color_dialog_data *data; setup_color_dialog_data *data;
color = &colors[GPOINTER_TO_INT (userdata)]; color = &colors[GPOINTER_TO_INT (userdata)];
dialog = gtk_color_chooser_dialog_new (_("Select color"), GTK_WINDOW (setup_window)); dialog = gtk_color_chooser_dialog_new (_("Select color"), GTK_WINDOW (setup_window));
color_string = gdk_rgba_to_string (color); color_string = gdk_rgba_to_string (color);
parsed_ok = gdk_rgba_parse (&rgba, color_string); parsed_ok = color_string && gdk_rgba_parse (&rgba, color_string);
g_free (color_string);
if (!parsed_ok) if (!parsed_ok)
rgba = *color; rgba = *color;
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog), &rgba); gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog), &rgba);

View File

@@ -547,15 +547,9 @@ userlist_add_columns (GtkTreeView * treeview)
if (prefs.hex_gui_compact) if (prefs.hex_gui_compact)
g_object_set (G_OBJECT (renderer), "ypad", 0, NULL); g_object_set (G_OBJECT (renderer), "ypad", 0, NULL);
gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer), 1); gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer), 1);
#if GTK_CHECK_VERSION(3,0,0)
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, NULL, renderer, -1, NULL, renderer,
"text", 1, "foreground-rgba", 4, NULL); "text", 1, PALETTE_FOREGROUND_PROPERTY, 4, NULL);
#else
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, NULL, renderer,
"text", 1, "foreground-gdk", 4, NULL);
#endif
if (prefs.hex_gui_ulist_show_hosts) if (prefs.hex_gui_ulist_show_hosts)
{ {