Standardized GtkCellRendererText foreground bindings to use the palette foreground property macro across user list, notify list, and DCC views (GTK2/GTK3 aware).

Generated GTK3 caret-color CSS using GdkRGBA string conversion instead of manual RGB math for input styling.
Simplified palette RGB16 parsing by building a GdkRGBA-compatible color string before parsing.
This commit is contained in:
2026-01-22 22:25:26 -07:00
parent 61669f6b98
commit 9959cf1f24
5 changed files with 11 additions and 27 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 ();
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);
}

View File

@@ -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);
}

View File

@@ -48,12 +48,13 @@ static void
palette_color_set_rgb16 (PaletteColor *color, guint16 red, guint16 green, guint16 blue)
{
#if GTK_CHECK_VERSION(3,0,0)
char buf[8];
GdkRGBA parsed;
gboolean parsed_ok;
char *color_string;
g_snprintf (buf, sizeof (buf), "#%02x%02x%02x", red >> 8, green >> 8, blue >> 8);
parsed_ok = gdk_rgba_parse (&parsed, buf);
color_string = g_strdup_printf ("#%02x%02x%02x", red >> 8, green >> 8, blue >> 8);
parsed_ok = gdk_rgba_parse (&parsed, color_string);
g_free (color_string);
if (!parsed_ok)
{
parsed.red = red / 65535.0;

View File

@@ -2543,16 +2543,15 @@ setup_apply_to_sess (session_gui *gui)
if (prefs.hex_gui_input_style)
{
#if GTK_CHECK_VERSION(3,0,0)
guint8 red = (guint8) CLAMP (colors[COL_FG].red * 255.0 + 0.5, 0.0, 255.0);
guint8 green = (guint8) CLAMP (colors[COL_FG].green * 255.0 + 0.5, 0.0, 255.0);
guint8 blue = (guint8) CLAMP (colors[COL_FG].blue * 255.0 + 0.5, 0.0, 255.0);
char buf[128];
GtkCssProvider *provider = gtk_css_provider_new ();
GtkStyleContext *context;
char *color_string = gdk_rgba_to_string (&colors[COL_FG]);
g_snprintf (buf, sizeof (buf), ".zoitechat-inputbox { caret-color: #%02x%02x%02x; }",
red, green, blue);
g_snprintf (buf, sizeof (buf), ".zoitechat-inputbox { caret-color: %s; }",
color_string);
gtk_css_provider_load_from_data (provider, buf, -1, NULL);
g_free (color_string);
context = gtk_widget_get_style_context (gui->input_box);
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider),

View File

@@ -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)
{