From 51fd0fca9150eb6cde1ce384d2bbeda8e8536618 Mon Sep 17 00:00:00 2001 From: deepend Date: Thu, 22 Jan 2026 22:47:11 -0700 Subject: [PATCH] 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. --- src/fe-gtk/dccgui.c | 8 +------- src/fe-gtk/notifygui.c | 6 +----- src/fe-gtk/palette.c | 5 ++--- src/fe-gtk/setup.c | 5 ++--- src/fe-gtk/userlistgui.c | 8 +------- 5 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/fe-gtk/dccgui.c b/src/fe-gtk/dccgui.c index cbf4e697..59a77373 100644 --- a/src/fe-gtk/dccgui.c +++ b/src/fe-gtk/dccgui.c @@ -735,15 +735,9 @@ dcc_add_column (GtkWidget *tree, int textcol, int colorcol, char *title, gboolea renderer = gtk_cell_renderer_text_new (); if (right_justified) 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, - "text", textcol, "foreground-rgba", colorcol, + "text", textcol, PALETTE_FOREGROUND_PROPERTY, colorcol, 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); } diff --git a/src/fe-gtk/notifygui.c b/src/fe-gtk/notifygui.c index b7d8b86f..c036b210 100644 --- a/src/fe-gtk/notifygui.c +++ b/src/fe-gtk/notifygui.c @@ -79,11 +79,7 @@ notify_treecell_property_mapper (GtkTreeViewColumn *col, GtkCellRenderer *cell, COLOUR_COLUMN, &colour, model_column, &text, -1); g_object_set (G_OBJECT (cell), "text", text, NULL); -#if GTK_CHECK_VERSION(3,0,0) - g_object_set (G_OBJECT (cell), "foreground-rgba", colour, NULL); -#else - g_object_set (G_OBJECT (cell), "foreground-gdk", colour, NULL); -#endif + g_object_set (G_OBJECT (cell), PALETTE_FOREGROUND_PROPERTY, colour, NULL); g_free (text); } diff --git a/src/fe-gtk/palette.c b/src/fe-gtk/palette.c index f666a6a5..5557da3c 100644 --- a/src/fe-gtk/palette.c +++ b/src/fe-gtk/palette.c @@ -50,11 +50,10 @@ palette_color_set_rgb16 (PaletteColor *color, guint16 red, guint16 green, guint1 #if GTK_CHECK_VERSION(3,0,0) GdkRGBA parsed; 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); - g_free (color_string); if (!parsed_ok) { parsed.red = red / 65535.0; diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c index 9a98a7db..6ca52404 100644 --- a/src/fe-gtk/setup.c +++ b/src/fe-gtk/setup.c @@ -1596,15 +1596,14 @@ setup_color_cb (GtkWidget *button, gpointer userdata) PaletteColor *color; GdkRGBA rgba; gboolean parsed_ok; - char *color_string; + g_autofree char *color_string = NULL; setup_color_dialog_data *data; color = &colors[GPOINTER_TO_INT (userdata)]; dialog = gtk_color_chooser_dialog_new (_("Select color"), GTK_WINDOW (setup_window)); color_string = gdk_rgba_to_string (color); - parsed_ok = gdk_rgba_parse (&rgba, color_string); - g_free (color_string); + parsed_ok = color_string && gdk_rgba_parse (&rgba, color_string); if (!parsed_ok) rgba = *color; gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog), &rgba); diff --git a/src/fe-gtk/userlistgui.c b/src/fe-gtk/userlistgui.c index 76a9bef9..7676dc34 100644 --- a/src/fe-gtk/userlistgui.c +++ b/src/fe-gtk/userlistgui.c @@ -547,15 +547,9 @@ userlist_add_columns (GtkTreeView * treeview) if (prefs.hex_gui_compact) g_object_set (G_OBJECT (renderer), "ypad", 0, NULL); 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), -1, NULL, renderer, - "text", 1, "foreground-rgba", 4, NULL); -#else - gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), - -1, NULL, renderer, - "text", 1, "foreground-gdk", 4, NULL); -#endif + "text", 1, PALETTE_FOREGROUND_PROPERTY, 4, NULL); if (prefs.hex_gui_ulist_show_hosts) {