diff --git a/src/fe-gtk/dccgui.c b/src/fe-gtk/dccgui.c index fc199d7d..98ad2e1f 100644 --- a/src/fe-gtk/dccgui.c +++ b/src/fe-gtk/dccgui.c @@ -50,7 +50,7 @@ enum /* DCC SEND/RECV */ COL_ETA, COL_NICK, COL_DCC, /* struct DCC * */ - COL_COLOR, /* GdkColor */ + COL_COLOR, /* PaletteColor */ N_COLUMNS }; @@ -62,7 +62,7 @@ enum /* DCC CHAT */ CCOL_SENT, CCOL_START, CCOL_DCC, /* struct DCC * */ - CCOL_COLOR, /* GdkColor * */ + CCOL_COLOR, /* PaletteColor * */ CN_COLUMNS }; @@ -730,7 +730,11 @@ dcc_add_column (GtkWidget *tree, int textcol, int colorcol, char *title, gboolea if (right_justified) g_object_set (G_OBJECT (renderer), "xalign", (float) 1.0, NULL); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, title, renderer, +#if GTK_CHECK_VERSION(3,0,0) + "text", textcol, "foreground-rgba", colorcol, +#else "text", textcol, "foreground-gdk", colorcol, +#endif NULL); gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer), 1); } @@ -810,7 +814,7 @@ fe_dcc_open_recv_win (int passive) store = gtk_list_store_new (N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_POINTER, GDK_TYPE_COLOR); + G_TYPE_STRING, G_TYPE_POINTER, PALETTE_GDK_TYPE); view = gtkutil_treeview_new (vbox, GTK_TREE_MODEL (store), NULL, -1); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE); /* Up/Down Icon column */ @@ -1057,7 +1061,7 @@ fe_dcc_open_chat_win (int passive) store = gtk_list_store_new (CN_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_POINTER, GDK_TYPE_COLOR); + G_TYPE_POINTER, PALETTE_GDK_TYPE); view = gtkutil_treeview_new (vbox, GTK_TREE_MODEL (store), NULL, -1); dcc_add_column (view, CCOL_STATUS, CCOL_COLOR, _("Status"), FALSE); diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c index a6d00991..1b2944ed 100644 --- a/src/fe-gtk/fe-gtk.c +++ b/src/fe-gtk/fe-gtk.c @@ -425,8 +425,14 @@ create_input_style (GtkStyle *style) g_free (theme_name); done_rc = TRUE; - sprintf (buf, cursor_color_rc, (colors[COL_FG].red >> 8), - (colors[COL_FG].green >> 8), (colors[COL_FG].blue >> 8)); + { + guint16 red; + guint16 green; + guint16 blue; + + palette_color_get_rgb16 (&colors[COL_FG], &red, &green, &blue); + sprintf (buf, cursor_color_rc, (red >> 8), (green >> 8), (blue >> 8)); + } gtk_rc_parse_string (buf); } diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c index 87c6b08c..486dcee4 100644 --- a/src/fe-gtk/maingui.c +++ b/src/fe-gtk/maingui.c @@ -1661,9 +1661,14 @@ mg_create_color_menu (GtkWidget *menu, session *sess) for (i = 0; i < 8; i++) { + guint16 red; + guint16 green; + guint16 blue; + + palette_color_get_rgb16 (&colors[i], &red, &green, &blue); sprintf (buf, "%02d " " ", - i, colors[i].red >> 8, colors[i].green >> 8, colors[i].blue >> 8); + i, red >> 8, green >> 8, blue >> 8); mg_markup_item (subsubmenu, buf, i); } @@ -1671,9 +1676,14 @@ mg_create_color_menu (GtkWidget *menu, session *sess) for (i = 8; i < 16; i++) { + guint16 red; + guint16 green; + guint16 blue; + + palette_color_get_rgb16 (&colors[i], &red, &green, &blue); sprintf (buf, "%02d " " ", - i, colors[i].red >> 8, colors[i].green >> 8, colors[i].blue >> 8); + i, red >> 8, green >> 8, blue >> 8); mg_markup_item (subsubmenu, buf, i); } } diff --git a/src/fe-gtk/notifygui.c b/src/fe-gtk/notifygui.c index 42d61fdb..8c021217 100644 --- a/src/fe-gtk/notifygui.c +++ b/src/fe-gtk/notifygui.c @@ -64,7 +64,7 @@ notify_closegui (void) } /* Need this to be able to set the foreground colour property of a row - * from a GdkColor * in the model -Vince + * from a PaletteColor * in the model -Vince */ static void notify_treecell_property_mapper (GtkTreeViewColumn *col, GtkCellRenderer *cell, @@ -72,14 +72,18 @@ notify_treecell_property_mapper (GtkTreeViewColumn *col, GtkCellRenderer *cell, gpointer data) { gchar *text; - GdkColor *colour; + PaletteColor *colour; int model_column = GPOINTER_TO_INT (data); gtk_tree_model_get (GTK_TREE_MODEL (model), iter, 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_free (text); } @@ -113,7 +117,7 @@ notify_treeview_new (GtkWidget *box) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_POINTER, /* can't specify colour! */ + PALETTE_GDK_TYPE, G_TYPE_POINTER ); g_return_val_if_fail (store != NULL, NULL); diff --git a/src/fe-gtk/palette.c b/src/fe-gtk/palette.c index f2af5bd1..e1b188ec 100644 --- a/src/fe-gtk/palette.c +++ b/src/fe-gtk/palette.c @@ -38,121 +38,150 @@ #include "../common/cfgfiles.h" #include "../common/typedef.h" +#if GTK_CHECK_VERSION(3,0,0) +#define PALETTE_COLOR_INIT(r, g, b) { (r) / 65535.0, (g) / 65535.0, (b) / 65535.0, 1.0 } +#else +#define PALETTE_COLOR_INIT(r, g, b) { 0, (r), (g), (b) } +#endif + +static void +palette_color_set_rgb16 (PaletteColor *color, guint16 red, guint16 green, guint16 blue) +{ +#if GTK_CHECK_VERSION(3,0,0) + char buf[8]; + + g_snprintf (buf, sizeof (buf), "#%02x%02x%02x", red >> 8, green >> 8, blue >> 8); + gdk_rgba_parse (color, buf); +#else + color->red = red; + color->green = green; + color->blue = blue; + color->pixel = 0; +#endif +} + static XTextColor -palette_color_from_gdk (const GdkColor *color) +palette_color_from_gdk (const PaletteColor *color) { XTextColor result; +#if GTK_CHECK_VERSION(3,0,0) + result.red = color->red; + result.green = color->green; + result.blue = color->blue; + result.alpha = color->alpha; +#else result.red = color->red / 65535.0; result.green = color->green / 65535.0; result.blue = color->blue / 65535.0; result.alpha = 1.0; +#endif return result; } -GdkColor colors[] = { +PaletteColor colors[] = { /* colors for xtext */ - {0, 0xd3d3, 0xd7d7, 0xcfcf}, /* 0 white */ - {0, 0x2e2e, 0x3434, 0x3636}, /* 1 black */ - {0, 0x3434, 0x6565, 0xa4a4}, /* 2 blue */ - {0, 0x4e4e, 0x9a9a, 0x0606}, /* 3 green */ - {0, 0xcccc, 0x0000, 0x0000}, /* 4 red */ - {0, 0x8f8f, 0x3939, 0x0202}, /* 5 light red */ - {0, 0x5c5c, 0x3535, 0x6666}, /* 6 purple */ - {0, 0xcece, 0x5c5c, 0x0000}, /* 7 orange */ - {0, 0xc4c4, 0xa0a0, 0x0000}, /* 8 yellow */ - {0, 0x7373, 0xd2d2, 0x1616}, /* 9 green */ - {0, 0x1111, 0xa8a8, 0x7979}, /* 10 aqua */ - {0, 0x5858, 0xa1a1, 0x9d9d}, /* 11 light aqua */ - {0, 0x5757, 0x7979, 0x9e9e}, /* 12 blue */ - {0, 0xa0d0, 0x42d4, 0x6562}, /* 13 light purple */ - {0, 0x5555, 0x5757, 0x5353}, /* 14 grey */ - {0, 0x8888, 0x8a8a, 0x8585}, /* 15 light grey */ + PALETTE_COLOR_INIT (0xd3d3, 0xd7d7, 0xcfcf), /* 0 white */ + PALETTE_COLOR_INIT (0x2e2e, 0x3434, 0x3636), /* 1 black */ + PALETTE_COLOR_INIT (0x3434, 0x6565, 0xa4a4), /* 2 blue */ + PALETTE_COLOR_INIT (0x4e4e, 0x9a9a, 0x0606), /* 3 green */ + PALETTE_COLOR_INIT (0xcccc, 0x0000, 0x0000), /* 4 red */ + PALETTE_COLOR_INIT (0x8f8f, 0x3939, 0x0202), /* 5 light red */ + PALETTE_COLOR_INIT (0x5c5c, 0x3535, 0x6666), /* 6 purple */ + PALETTE_COLOR_INIT (0xcece, 0x5c5c, 0x0000), /* 7 orange */ + PALETTE_COLOR_INIT (0xc4c4, 0xa0a0, 0x0000), /* 8 yellow */ + PALETTE_COLOR_INIT (0x7373, 0xd2d2, 0x1616), /* 9 green */ + PALETTE_COLOR_INIT (0x1111, 0xa8a8, 0x7979), /* 10 aqua */ + PALETTE_COLOR_INIT (0x5858, 0xa1a1, 0x9d9d), /* 11 light aqua */ + PALETTE_COLOR_INIT (0x5757, 0x7979, 0x9e9e), /* 12 blue */ + PALETTE_COLOR_INIT (0xa0d0, 0x42d4, 0x6562), /* 13 light purple */ + PALETTE_COLOR_INIT (0x5555, 0x5757, 0x5353), /* 14 grey */ + PALETTE_COLOR_INIT (0x8888, 0x8a8a, 0x8585), /* 15 light grey */ - {0, 0xd3d3, 0xd7d7, 0xcfcf}, /* 16 white */ - {0, 0x2e2e, 0x3434, 0x3636}, /* 17 black */ - {0, 0x3434, 0x6565, 0xa4a4}, /* 18 blue */ - {0, 0x4e4e, 0x9a9a, 0x0606}, /* 19 green */ - {0, 0xcccc, 0x0000, 0x0000}, /* 20 red */ - {0, 0x8f8f, 0x3939, 0x0202}, /* 21 light red */ - {0, 0x5c5c, 0x3535, 0x6666}, /* 22 purple */ - {0, 0xcece, 0x5c5c, 0x0000}, /* 23 orange */ - {0, 0xc4c4, 0xa0a0, 0x0000}, /* 24 yellow */ - {0, 0x7373, 0xd2d2, 0x1616}, /* 25 green */ - {0, 0x1111, 0xa8a8, 0x7979}, /* 26 aqua */ - {0, 0x5858, 0xa1a1, 0x9d9d}, /* 27 light aqua */ - {0, 0x5757, 0x7979, 0x9e9e}, /* 28 blue */ - {0, 0xa0d0, 0x42d4, 0x6562}, /* 29 light purple */ - {0, 0x5555, 0x5757, 0x5353}, /* 30 grey */ - {0, 0x8888, 0x8a8a, 0x8585}, /* 31 light grey */ + PALETTE_COLOR_INIT (0xd3d3, 0xd7d7, 0xcfcf), /* 16 white */ + PALETTE_COLOR_INIT (0x2e2e, 0x3434, 0x3636), /* 17 black */ + PALETTE_COLOR_INIT (0x3434, 0x6565, 0xa4a4), /* 18 blue */ + PALETTE_COLOR_INIT (0x4e4e, 0x9a9a, 0x0606), /* 19 green */ + PALETTE_COLOR_INIT (0xcccc, 0x0000, 0x0000), /* 20 red */ + PALETTE_COLOR_INIT (0x8f8f, 0x3939, 0x0202), /* 21 light red */ + PALETTE_COLOR_INIT (0x5c5c, 0x3535, 0x6666), /* 22 purple */ + PALETTE_COLOR_INIT (0xcece, 0x5c5c, 0x0000), /* 23 orange */ + PALETTE_COLOR_INIT (0xc4c4, 0xa0a0, 0x0000), /* 24 yellow */ + PALETTE_COLOR_INIT (0x7373, 0xd2d2, 0x1616), /* 25 green */ + PALETTE_COLOR_INIT (0x1111, 0xa8a8, 0x7979), /* 26 aqua */ + PALETTE_COLOR_INIT (0x5858, 0xa1a1, 0x9d9d), /* 27 light aqua */ + PALETTE_COLOR_INIT (0x5757, 0x7979, 0x9e9e), /* 28 blue */ + PALETTE_COLOR_INIT (0xa0d0, 0x42d4, 0x6562), /* 29 light purple */ + PALETTE_COLOR_INIT (0x5555, 0x5757, 0x5353), /* 30 grey */ + PALETTE_COLOR_INIT (0x8888, 0x8a8a, 0x8585), /* 31 light grey */ - {0, 0xd3d3, 0xd7d7, 0xcfcf}, /* 32 marktext Fore (white) */ - {0, 0x2020, 0x4a4a, 0x8787}, /* 33 marktext Back (blue) */ - {0, 0x2512, 0x29e8, 0x2b85}, /* 34 foreground (black) */ - {0, 0xfae0, 0xfae0, 0xf8c4}, /* 35 background (white) */ - {0, 0x8f8f, 0x3939, 0x0202}, /* 36 marker line (red) */ + PALETTE_COLOR_INIT (0xd3d3, 0xd7d7, 0xcfcf), /* 32 marktext Fore (white) */ + PALETTE_COLOR_INIT (0x2020, 0x4a4a, 0x8787), /* 33 marktext Back (blue) */ + PALETTE_COLOR_INIT (0x2512, 0x29e8, 0x2b85), /* 34 foreground (black) */ + PALETTE_COLOR_INIT (0xfae0, 0xfae0, 0xf8c4), /* 35 background (white) */ + PALETTE_COLOR_INIT (0x8f8f, 0x3939, 0x0202), /* 36 marker line (red) */ /* colors for GUI */ - {0, 0x3434, 0x6565, 0xa4a4}, /* 37 tab New Data (dark red) */ - {0, 0x4e4e, 0x9a9a, 0x0606}, /* 38 tab Nick Mentioned (blue) */ - {0, 0xcece, 0x5c5c, 0x0000}, /* 39 tab New Message (red) */ - {0, 0x8888, 0x8a8a, 0x8585}, /* 40 away user (grey) */ - {0, 0xa4a4, 0x0000, 0x0000}, /* 41 spell checker color (red) */ + PALETTE_COLOR_INIT (0x3434, 0x6565, 0xa4a4), /* 37 tab New Data (dark red) */ + PALETTE_COLOR_INIT (0x4e4e, 0x9a9a, 0x0606), /* 38 tab Nick Mentioned (blue) */ + PALETTE_COLOR_INIT (0xcece, 0x5c5c, 0x0000), /* 39 tab New Message (red) */ + PALETTE_COLOR_INIT (0x8888, 0x8a8a, 0x8585), /* 40 away user (grey) */ + PALETTE_COLOR_INIT (0xa4a4, 0x0000, 0x0000), /* 41 spell checker color (red) */ }; /* User palette snapshot (what we write to colors.conf) */ -static GdkColor user_colors[MAX_COL + 1]; +static PaletteColor user_colors[MAX_COL + 1]; static gboolean user_colors_valid = FALSE; /* Dark palette snapshot (saved separately so dark mode can have its own custom palette). */ -static GdkColor dark_user_colors[MAX_COL + 1]; +static PaletteColor dark_user_colors[MAX_COL + 1]; static gboolean dark_user_colors_valid = FALSE; /* ZoiteChat's curated dark palette (applies when prefs.hex_gui_dark_mode is enabled). */ -static const GdkColor dark_colors[MAX_COL + 1] = { +static const PaletteColor dark_colors[MAX_COL + 1] = { /* mIRC colors 0-15 */ - {0, 0xe5e5, 0xe5e5, 0xe5e5}, /* 0 white */ - {0, 0x3c3c, 0x3c3c, 0x3c3c}, /* 1 black (dark gray for contrast) */ - {0, 0x5656, 0x9c9c, 0xd6d6}, /* 2 blue */ - {0, 0x0d0d, 0xbcbc, 0x7979}, /* 3 green */ - {0, 0xf4f4, 0x4747, 0x4747}, /* 4 red */ - {0, 0xcece, 0x9191, 0x7878}, /* 5 light red / brown */ - {0, 0xc5c5, 0x8686, 0xc0c0}, /* 6 purple */ - {0, 0xd7d7, 0xbaba, 0x7d7d}, /* 7 orange */ - {0, 0xdcdc, 0xdcdc, 0xaaaa}, /* 8 yellow */ - {0, 0xb5b5, 0xcece, 0xa8a8}, /* 9 light green */ - {0, 0x4e4e, 0xc9c9, 0xb0b0}, /* 10 aqua */ - {0, 0x9c9c, 0xdcdc, 0xfefe}, /* 11 light aqua */ - {0, 0x3737, 0x9494, 0xffff}, /* 12 light blue */ - {0, 0xd6d6, 0x7070, 0xd6d6}, /* 13 pink */ - {0, 0x8080, 0x8080, 0x8080}, /* 14 gray */ - {0, 0xc0c0, 0xc0c0, 0xc0c0}, /* 15 light gray */ + PALETTE_COLOR_INIT (0xe5e5, 0xe5e5, 0xe5e5), /* 0 white */ + PALETTE_COLOR_INIT (0x3c3c, 0x3c3c, 0x3c3c), /* 1 black (dark gray for contrast) */ + PALETTE_COLOR_INIT (0x5656, 0x9c9c, 0xd6d6), /* 2 blue */ + PALETTE_COLOR_INIT (0x0d0d, 0xbcbc, 0x7979), /* 3 green */ + PALETTE_COLOR_INIT (0xf4f4, 0x4747, 0x4747), /* 4 red */ + PALETTE_COLOR_INIT (0xcece, 0x9191, 0x7878), /* 5 light red / brown */ + PALETTE_COLOR_INIT (0xc5c5, 0x8686, 0xc0c0), /* 6 purple */ + PALETTE_COLOR_INIT (0xd7d7, 0xbaba, 0x7d7d), /* 7 orange */ + PALETTE_COLOR_INIT (0xdcdc, 0xdcdc, 0xaaaa), /* 8 yellow */ + PALETTE_COLOR_INIT (0xb5b5, 0xcece, 0xa8a8), /* 9 light green */ + PALETTE_COLOR_INIT (0x4e4e, 0xc9c9, 0xb0b0), /* 10 aqua */ + PALETTE_COLOR_INIT (0x9c9c, 0xdcdc, 0xfefe), /* 11 light aqua */ + PALETTE_COLOR_INIT (0x3737, 0x9494, 0xffff), /* 12 light blue */ + PALETTE_COLOR_INIT (0xd6d6, 0x7070, 0xd6d6), /* 13 pink */ + PALETTE_COLOR_INIT (0x8080, 0x8080, 0x8080), /* 14 gray */ + PALETTE_COLOR_INIT (0xc0c0, 0xc0c0, 0xc0c0), /* 15 light gray */ /* mIRC colors 16-31 (repeat) */ - {0, 0xe5e5, 0xe5e5, 0xe5e5}, {0, 0x3c3c, 0x3c3c, 0x3c3c}, - {0, 0x5656, 0x9c9c, 0xd6d6}, {0, 0x0d0d, 0xbcbc, 0x7979}, - {0, 0xf4f4, 0x4747, 0x4747}, {0, 0xcece, 0x9191, 0x7878}, - {0, 0xc5c5, 0x8686, 0xc0c0}, {0, 0xd7d7, 0xbaba, 0x7d7d}, - {0, 0xdcdc, 0xdcdc, 0xaaaa}, {0, 0xb5b5, 0xcece, 0xa8a8}, - {0, 0x4e4e, 0xc9c9, 0xb0b0}, {0, 0x9c9c, 0xdcdc, 0xfefe}, - {0, 0x3737, 0x9494, 0xffff}, {0, 0xd6d6, 0x7070, 0xd6d6}, - {0, 0x8080, 0x8080, 0x8080}, {0, 0xc0c0, 0xc0c0, 0xc0c0}, + PALETTE_COLOR_INIT (0xe5e5, 0xe5e5, 0xe5e5), PALETTE_COLOR_INIT (0x3c3c, 0x3c3c, 0x3c3c), + PALETTE_COLOR_INIT (0x5656, 0x9c9c, 0xd6d6), PALETTE_COLOR_INIT (0x0d0d, 0xbcbc, 0x7979), + PALETTE_COLOR_INIT (0xf4f4, 0x4747, 0x4747), PALETTE_COLOR_INIT (0xcece, 0x9191, 0x7878), + PALETTE_COLOR_INIT (0xc5c5, 0x8686, 0xc0c0), PALETTE_COLOR_INIT (0xd7d7, 0xbaba, 0x7d7d), + PALETTE_COLOR_INIT (0xdcdc, 0xdcdc, 0xaaaa), PALETTE_COLOR_INIT (0xb5b5, 0xcece, 0xa8a8), + PALETTE_COLOR_INIT (0x4e4e, 0xc9c9, 0xb0b0), PALETTE_COLOR_INIT (0x9c9c, 0xdcdc, 0xfefe), + PALETTE_COLOR_INIT (0x3737, 0x9494, 0xffff), PALETTE_COLOR_INIT (0xd6d6, 0x7070, 0xd6d6), + PALETTE_COLOR_INIT (0x8080, 0x8080, 0x8080), PALETTE_COLOR_INIT (0xc0c0, 0xc0c0, 0xc0c0), /* selection colors */ - {0, 0xffff, 0xffff, 0xffff}, /* 32 COL_MARK_FG */ - {0, 0x2626, 0x4f4f, 0x7878}, /* 33 COL_MARK_BG */ + PALETTE_COLOR_INIT (0xffff, 0xffff, 0xffff), /* 32 COL_MARK_FG */ + PALETTE_COLOR_INIT (0x2626, 0x4f4f, 0x7878), /* 33 COL_MARK_BG */ /* foreground/background */ - {0, 0xd4d4, 0xd4d4, 0xd4d4}, /* 34 COL_FG */ - {0, 0x1e1e, 0x1e1e, 0x1e1e}, /* 35 COL_BG */ + PALETTE_COLOR_INIT (0xd4d4, 0xd4d4, 0xd4d4), /* 34 COL_FG */ + PALETTE_COLOR_INIT (0x1e1e, 0x1e1e, 0x1e1e), /* 35 COL_BG */ /* interface colors */ - {0, 0x4040, 0x4040, 0x4040}, /* 36 COL_MARKER (marker line) */ - {0, 0x3737, 0x9494, 0xffff}, /* 37 COL_NEW_DATA (tab: new data) */ - {0, 0xd7d7, 0xbaba, 0x7d7d}, /* 38 COL_HILIGHT (tab: nick mentioned) */ - {0, 0xf4f4, 0x4747, 0x4747}, /* 39 COL_NEW_MSG (tab: new message) */ - {0, 0x8080, 0x8080, 0x8080}, /* 40 COL_AWAY (tab: away) */ - {0, 0xf4f4, 0x4747, 0x4747}, /* 41 COL_SPELL (spellcheck underline) */ + PALETTE_COLOR_INIT (0x4040, 0x4040, 0x4040), /* 36 COL_MARKER (marker line) */ + PALETTE_COLOR_INIT (0x3737, 0x9494, 0xffff), /* 37 COL_NEW_DATA (tab: new data) */ + PALETTE_COLOR_INIT (0xd7d7, 0xbaba, 0x7d7d), /* 38 COL_HILIGHT (tab: nick mentioned) */ + PALETTE_COLOR_INIT (0xf4f4, 0x4747, 0x4747), /* 39 COL_NEW_MSG (tab: new message) */ + PALETTE_COLOR_INIT (0x8080, 0x8080, 0x8080), /* 40 COL_AWAY (tab: away) */ + PALETTE_COLOR_INIT (0xf4f4, 0x4747, 0x4747), /* 41 COL_SPELL (spellcheck underline) */ }; void @@ -168,7 +197,7 @@ palette_get_xtext_colors (XTextColor *palette, size_t palette_len) } void -palette_user_set_color (int idx, const GdkColor *col) +palette_user_set_color (int idx, const PaletteColor *col) { if (!col) return; @@ -181,14 +210,18 @@ palette_user_set_color (int idx, const GdkColor *col) user_colors_valid = TRUE; } +#if GTK_CHECK_VERSION(3,0,0) + user_colors[idx] = *col; +#else user_colors[idx].red = col->red; user_colors[idx].green = col->green; user_colors[idx].blue = col->blue; user_colors[idx].pixel = 0; +#endif } void -palette_dark_set_color (int idx, const GdkColor *col) +palette_dark_set_color (int idx, const PaletteColor *col) { if (!col) return; @@ -202,15 +235,22 @@ palette_dark_set_color (int idx, const GdkColor *col) dark_user_colors_valid = TRUE; } +#if GTK_CHECK_VERSION(3,0,0) + dark_user_colors[idx] = *col; +#else dark_user_colors[idx].red = col->red; dark_user_colors[idx].green = col->green; dark_user_colors[idx].blue = col->blue; dark_user_colors[idx].pixel = 0; +#endif } void palette_alloc (GtkWidget * widget) { +#if GTK_CHECK_VERSION(3,0,0) + (void) widget; +#else int i; static int done_alloc = FALSE; GdkColormap *cmap; @@ -222,6 +262,7 @@ palette_alloc (GtkWidget * widget) for (i = MAX_COL; i >= 0; i--) gdk_colormap_alloc_color (cmap, &colors[i], FALSE, TRUE); } +#endif } void @@ -247,9 +288,7 @@ palette_load (void) g_snprintf (prefname, sizeof prefname, "color_%d", i); if (cfg_get_color (cfg, prefname, &red, &green, &blue)) { - colors[i].red = red; - colors[i].green = green; - colors[i].blue = blue; + palette_color_set_rgb16 (&colors[i], red, green, blue); } } @@ -259,9 +298,7 @@ palette_load (void) g_snprintf (prefname, sizeof prefname, "color_%d", i); if (cfg_get_color (cfg, prefname, &red, &green, &blue)) { - colors[j].red = red; - colors[j].green = green; - colors[j].blue = blue; + palette_color_set_rgb16 (&colors[j], red, green, blue); } } @@ -273,9 +310,7 @@ palette_load (void) g_snprintf (prefname, sizeof prefname, "dark_color_%d", i); if (cfg_get_color (cfg, prefname, &red, &green, &blue)) { - dark_user_colors[i].red = red; - dark_user_colors[i].green = green; - dark_user_colors[i].blue = blue; + palette_color_set_rgb16 (&dark_user_colors[i], red, green, blue); dark_found = TRUE; } } @@ -285,9 +320,7 @@ palette_load (void) g_snprintf (prefname, sizeof prefname, "dark_color_%d", i); if (cfg_get_color (cfg, prefname, &red, &green, &blue)) { - dark_user_colors[j].red = red; - dark_user_colors[j].green = green; - dark_user_colors[j].blue = blue; + palette_color_set_rgb16 (&dark_user_colors[j], red, green, blue); dark_found = TRUE; } } @@ -309,8 +342,8 @@ palette_save (void) { int i, j, fh; char prefname[256]; - const GdkColor *lightpal = colors; - const GdkColor *darkpal = NULL; + const PaletteColor *lightpal = colors; + const PaletteColor *darkpal = NULL; gboolean dark_mode_active = fe_dark_mode_is_enabled (); /* If we're currently in dark mode, keep colors.conf's legacy keys as the user's light palette. */ @@ -343,13 +376,25 @@ palette_save (void) for (i = 0; i < 32; i++) { g_snprintf (prefname, sizeof prefname, "color_%d", i); - cfg_put_color (fh, lightpal[i].red, lightpal[i].green, lightpal[i].blue, prefname); + guint16 red; + guint16 green; + guint16 blue; + + palette_color_get_rgb16 (&lightpal[i], &red, &green, &blue); + cfg_put_color (fh, red, green, blue, prefname); } for (i = 256, j = 32; j < MAX_COL + 1; i++, j++) { g_snprintf (prefname, sizeof prefname, "color_%d", i); - cfg_put_color (fh, lightpal[j].red, lightpal[j].green, lightpal[j].blue, prefname); + { + guint16 red; + guint16 green; + guint16 blue; + + palette_color_get_rgb16 (&lightpal[j], &red, &green, &blue); + cfg_put_color (fh, red, green, blue, prefname); + } } /* Dark palette (new keys) */ @@ -358,13 +403,25 @@ palette_save (void) for (i = 0; i < 32; i++) { g_snprintf (prefname, sizeof prefname, "dark_color_%d", i); - cfg_put_color (fh, darkpal[i].red, darkpal[i].green, darkpal[i].blue, prefname); + guint16 red; + guint16 green; + guint16 blue; + + palette_color_get_rgb16 (&darkpal[i], &red, &green, &blue); + cfg_put_color (fh, red, green, blue, prefname); } for (i = 256, j = 32; j < MAX_COL + 1; i++, j++) { g_snprintf (prefname, sizeof prefname, "dark_color_%d", i); - cfg_put_color (fh, darkpal[j].red, darkpal[j].green, darkpal[j].blue, prefname); + { + guint16 red; + guint16 green; + guint16 blue; + + palette_color_get_rgb16 (&darkpal[j], &red, &green, &blue); + cfg_put_color (fh, red, green, blue, prefname); + } } } @@ -374,16 +431,25 @@ palette_save (void) static gboolean -palette_color_eq (const GdkColor *a, const GdkColor *b) +palette_color_eq (const PaletteColor *a, const PaletteColor *b) { - return a->red == b->red && a->green == b->green && a->blue == b->blue; + guint16 red_a; + guint16 green_a; + guint16 blue_a; + guint16 red_b; + guint16 green_b; + guint16 blue_b; + + palette_color_get_rgb16 (a, &red_a, &green_a, &blue_a); + palette_color_get_rgb16 (b, &red_b, &green_b, &blue_b); + + return red_a == red_b && green_a == green_b && blue_a == blue_b; } gboolean palette_apply_dark_mode (gboolean enable) { - GdkColor old_colors[MAX_COL + 1]; - GdkColormap *cmap; + PaletteColor old_colors[MAX_COL + 1]; int i; gboolean changed = FALSE; @@ -407,15 +473,19 @@ palette_apply_dark_mode (gboolean enable) memcpy (colors, user_colors, sizeof (colors)); /* Allocate the new colors for GTK's colormap. */ - cmap = gdk_colormap_get_system (); - for (i = 0; i <= MAX_COL; i++) - gdk_colormap_alloc_color (cmap, &colors[i], FALSE, TRUE); +#if !GTK_CHECK_VERSION(3,0,0) + { + GdkColormap *cmap; + + cmap = gdk_colormap_get_system (); + for (i = 0; i <= MAX_COL; i++) + gdk_colormap_alloc_color (cmap, &colors[i], FALSE, TRUE); + } +#endif for (i = 0; i <= MAX_COL; i++) { - if (old_colors[i].red != colors[i].red || - old_colors[i].green != colors[i].green || - old_colors[i].blue != colors[i].blue) + if (!palette_color_eq (&old_colors[i], &colors[i])) { changed = TRUE; break; diff --git a/src/fe-gtk/palette.h b/src/fe-gtk/palette.h index 3c09e957..1dbb66cf 100644 --- a/src/fe-gtk/palette.h +++ b/src/fe-gtk/palette.h @@ -24,7 +24,29 @@ #include "xtext-color.h" -extern GdkColor colors[]; +#if GTK_CHECK_VERSION(3,0,0) +typedef GdkRGBA PaletteColor; +#define PALETTE_GDK_TYPE GDK_TYPE_RGBA +#else +typedef GdkColor PaletteColor; +#define PALETTE_GDK_TYPE GDK_TYPE_COLOR +#endif + +extern PaletteColor colors[]; + +static inline void +palette_color_get_rgb16 (const PaletteColor *color, guint16 *red, guint16 *green, guint16 *blue) +{ +#if GTK_CHECK_VERSION(3,0,0) + *red = (guint16) CLAMP (color->red * 65535.0 + 0.5, 0.0, 65535.0); + *green = (guint16) CLAMP (color->green * 65535.0 + 0.5, 0.0, 65535.0); + *blue = (guint16) CLAMP (color->blue * 65535.0 + 0.5, 0.0, 65535.0); +#else + *red = color->red; + *green = color->green; + *blue = color->blue; +#endif +} #define COL_MARK_FG 32 #define COL_MARK_BG 33 @@ -43,8 +65,8 @@ void palette_load (void); void palette_save (void); /* Keep a copy of the user's palette so dark mode can be toggled without losing it. */ -void palette_user_set_color (int idx, const GdkColor *col); -void palette_dark_set_color (int idx, const GdkColor *col); +void palette_user_set_color (int idx, const PaletteColor *col); +void palette_dark_set_color (int idx, const PaletteColor *col); /* * Apply ZoiteChat's built-in "dark mode" palette. diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c index a4d028b9..439615c0 100644 --- a/src/fe-gtk/setup.c +++ b/src/fe-gtk/setup.c @@ -1485,9 +1485,19 @@ setup_create_dark_mode_menu (GtkWidget *table, int row, const setting *set) } static void -setup_color_button_apply (GtkWidget *button, const GdkColor *color) +setup_color_button_apply (GtkWidget *button, const PaletteColor *color) { GtkWidget *target = g_object_get_data (G_OBJECT (button), "zoitechat-color-box"); + GtkWidget *apply_widget = GTK_IS_WIDGET (target) ? target : button; +#if GTK_CHECK_VERSION(3,0,0) + GtkStateFlags states[] = { + GTK_STATE_FLAG_NORMAL, + GTK_STATE_FLAG_PRELIGHT, + GTK_STATE_FLAG_ACTIVE, + GTK_STATE_FLAG_SELECTED, + GTK_STATE_FLAG_INSENSITIVE + }; +#else GtkStateType states[] = { GTK_STATE_NORMAL, GTK_STATE_PRELIGHT, @@ -1495,19 +1505,55 @@ setup_color_button_apply (GtkWidget *button, const GdkColor *color) GTK_STATE_SELECTED, GTK_STATE_INSENSITIVE }; +#endif guint i; - GtkWidget *apply_widget = GTK_IS_WIDGET (target) ? target : button; for (i = 0; i < G_N_ELEMENTS (states); i++) +#if GTK_CHECK_VERSION(3,0,0) + gtk_widget_override_background_color (apply_widget, states[i], color); +#else gtk_widget_modify_bg (apply_widget, states[i], color); +#endif if (apply_widget != button) for (i = 0; i < G_N_ELEMENTS (states); i++) +#if GTK_CHECK_VERSION(3,0,0) + gtk_widget_override_background_color (button, states[i], color); +#else gtk_widget_modify_bg (button, states[i], color); +#endif gtk_widget_queue_draw (button); } +#if GTK_CHECK_VERSION(3,0,0) +typedef struct +{ + GtkWidget *button; + PaletteColor *color; +} setup_color_dialog_data; + +static void +setup_color_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data) +{ + setup_color_dialog_data *data = user_data; + + if (response_id == GTK_RESPONSE_OK) + { + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), data->color); + color_change = TRUE; + setup_color_button_apply (data->button, data->color); + + if (fe_dark_mode_is_enabled_for (setup_prefs.hex_gui_dark_mode)) + palette_dark_set_color ((int)(data->color - colors), data->color); + else + palette_user_set_color ((int)(data->color - colors), data->color); + } + + gtk_widget_destroy (GTK_WIDGET (dialog)); + g_free (data); +} +#else static void setup_color_ok_cb (GtkWidget *button, GtkWidget *dialog) { @@ -1529,12 +1575,16 @@ setup_color_ok_cb (GtkWidget *button, GtkWidget *dialog) gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (cdialog)), col); +#if !GTK_CHECK_VERSION(3,0,0) gdk_colormap_alloc_color (gtk_widget_get_colormap (button), col, TRUE, TRUE); +#endif setup_color_button_apply (button, col); /* is this line correct?? */ +#if !GTK_CHECK_VERSION(3,0,0) gdk_colormap_free_colors (gtk_widget_get_colormap (button), &old_color, 1); +#endif /* Persist custom colors for the palette the user is editing. */ if (fe_dark_mode_is_enabled_for (setup_prefs.hex_gui_dark_mode)) @@ -1544,10 +1594,28 @@ setup_color_ok_cb (GtkWidget *button, GtkWidget *dialog) gtk_widget_destroy (dialog); } +#endif static void setup_color_cb (GtkWidget *button, gpointer userdata) { +#if GTK_CHECK_VERSION(3,0,0) + GtkWidget *dialog; + PaletteColor *color; + setup_color_dialog_data *data; + + color = &colors[GPOINTER_TO_INT (userdata)]; + + dialog = gtk_color_chooser_dialog_new (_("Select color"), GTK_WINDOW (setup_window)); + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog), color); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + + data = g_new0 (setup_color_dialog_data, 1); + data->button = button; + data->color = color; + g_signal_connect (dialog, "response", G_CALLBACK (setup_color_response_cb), data); + gtk_widget_show (dialog); +#else GtkWidget *dialog, *cancel_button, *ok_button, *help_button; GtkColorSelectionDialog *cdialog; GdkColor *color; @@ -1577,6 +1645,7 @@ setup_color_cb (GtkWidget *button, gpointer userdata) g_object_unref (cancel_button); g_object_unref (ok_button); g_object_unref (help_button); +#endif } static void @@ -2427,9 +2496,15 @@ setup_create_tree (GtkWidget *box, GtkWidget *book) static void setup_apply_entry_style (GtkWidget *entry) { +#if GTK_CHECK_VERSION(3,0,0) + gtk_widget_override_background_color (entry, GTK_STATE_FLAG_NORMAL, &colors[COL_BG]); + gtk_widget_override_color (entry, GTK_STATE_FLAG_NORMAL, &colors[COL_FG]); + gtk_widget_override_font (entry, input_style->font_desc); +#else gtk_widget_modify_base (entry, GTK_STATE_NORMAL, &colors[COL_BG]); gtk_widget_modify_text (entry, GTK_STATE_NORMAL, &colors[COL_FG]); gtk_widget_modify_font (entry, input_style->font_desc); +#endif } static void @@ -2441,7 +2516,22 @@ setup_apply_to_sess (session_gui *gui) if (prefs.hex_gui_ulist_style) gtk_widget_modify_font (gui->user_tree, input_style->font_desc); - if (prefs.hex_gui_ulist_style || fe_dark_mode_is_enabled ()) +#if GTK_CHECK_VERSION(3,0,0) + if (prefs.hex_gui_ulist_style || fe_dark_mode_is_enabled ()) + { + gtk_widget_override_background_color (gui->user_tree, GTK_STATE_FLAG_NORMAL, &colors[COL_BG]); + if (fe_dark_mode_is_enabled ()) + gtk_widget_override_color (gui->user_tree, GTK_STATE_FLAG_NORMAL, &colors[COL_FG]); + else + gtk_widget_override_color (gui->user_tree, GTK_STATE_FLAG_NORMAL, NULL); + } + else + { + gtk_widget_override_background_color (gui->user_tree, GTK_STATE_FLAG_NORMAL, NULL); + gtk_widget_override_color (gui->user_tree, GTK_STATE_FLAG_NORMAL, NULL); + } +#else + if (prefs.hex_gui_ulist_style || fe_dark_mode_is_enabled ()) { gtk_widget_modify_base (gui->user_tree, GTK_STATE_NORMAL, &colors[COL_BG]); if (fe_dark_mode_is_enabled ()) @@ -2454,9 +2544,37 @@ setup_apply_to_sess (session_gui *gui) gtk_widget_modify_base (gui->user_tree, GTK_STATE_NORMAL, NULL); gtk_widget_modify_text (gui->user_tree, GTK_STATE_NORMAL, NULL); } +#endif 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; + + g_snprintf (buf, sizeof (buf), ".zoitechat-inputbox { caret-color: #%02x%02x%02x; }", + red, green, blue); + gtk_css_provider_load_from_data (provider, buf, -1, NULL); + + context = gtk_widget_get_style_context (gui->input_box); + gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + context = gtk_widget_get_style_context (gui->limit_entry); + gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + context = gtk_widget_get_style_context (gui->key_entry); + gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + context = gtk_widget_get_style_context (gui->topic_entry); + gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + + g_object_unref (provider); +#else extern char cursor_color_rc[]; char buf[256]; sprintf (buf, cursor_color_rc, @@ -2464,6 +2582,7 @@ setup_apply_to_sess (session_gui *gui) (colors[COL_FG].green >> 8), (colors[COL_FG].blue >> 8)); gtk_rc_parse_string (buf); +#endif setup_apply_entry_style (gui->input_box); setup_apply_entry_style (gui->limit_entry); diff --git a/src/fe-gtk/sexy-spell-entry.c b/src/fe-gtk/sexy-spell-entry.c index 1c97837d..8acb16d4 100644 --- a/src/fe-gtk/sexy-spell-entry.c +++ b/src/fe-gtk/sexy-spell-entry.c @@ -342,8 +342,12 @@ insert_underline_error (SexySpellEntry *entry, guint start, guint end) { PangoAttribute *ucolor; PangoAttribute *unline; + guint16 red; + guint16 green; + guint16 blue; - ucolor = pango_attr_underline_color_new (colors[COL_SPELL].red, colors[COL_SPELL].green, colors[COL_SPELL].blue); + palette_color_get_rgb16 (&colors[COL_SPELL], &red, &green, &blue); + ucolor = pango_attr_underline_color_new (red, green, blue); unline = pango_attr_underline_new (PANGO_UNDERLINE_ERROR); ucolor->start_index = start; @@ -406,22 +410,33 @@ insert_color (SexySpellEntry *entry, guint start, int fgcolor, int bgcolor) PangoAttribute *fgattr; PangoAttribute *ulattr; PangoAttribute *bgattr; + guint16 red; + guint16 green; + guint16 blue; if (fgcolor < 0 || fgcolor > MAX_COL) { - fgattr = pango_attr_foreground_new (colors[COL_FG].red, colors[COL_FG].green, colors[COL_FG].blue); - ulattr = pango_attr_underline_color_new (colors[COL_FG].red, colors[COL_FG].green, colors[COL_FG].blue); + palette_color_get_rgb16 (&colors[COL_FG], &red, &green, &blue); + fgattr = pango_attr_foreground_new (red, green, blue); + ulattr = pango_attr_underline_color_new (red, green, blue); } else { - fgattr = pango_attr_foreground_new (colors[fgcolor].red, colors[fgcolor].green, colors[fgcolor].blue); - ulattr = pango_attr_underline_color_new (colors[fgcolor].red, colors[fgcolor].green, colors[fgcolor].blue); + palette_color_get_rgb16 (&colors[fgcolor], &red, &green, &blue); + fgattr = pango_attr_foreground_new (red, green, blue); + ulattr = pango_attr_underline_color_new (red, green, blue); } if (bgcolor < 0 || bgcolor > MAX_COL) - bgattr = pango_attr_background_new (colors[COL_BG].red, colors[COL_BG].green, colors[COL_BG].blue); + { + palette_color_get_rgb16 (&colors[COL_BG], &red, &green, &blue); + bgattr = pango_attr_background_new (red, green, blue); + } else - bgattr = pango_attr_background_new (colors[bgcolor].red, colors[bgcolor].green, colors[bgcolor].blue); + { + palette_color_get_rgb16 (&colors[bgcolor], &red, &green, &blue); + bgattr = pango_attr_background_new (red, green, blue); + } fgattr->start_index = start; fgattr->end_index = PANGO_ATTR_INDEX_TO_TEXT_END; diff --git a/src/fe-gtk/userlistgui.c b/src/fe-gtk/userlistgui.c index 77d9235c..b34fc3bb 100644 --- a/src/fe-gtk/userlistgui.c +++ b/src/fe-gtk/userlistgui.c @@ -46,7 +46,7 @@ enum COL_NICK=1, /* char * */ COL_HOST=2, /* char * */ COL_USER=3, /* struct User * */ - COL_GDKCOLOR=4 /* GdkColor * */ + COL_GDKCOLOR=4 /* PaletteColor * */ }; @@ -475,7 +475,7 @@ userlist_create_model (session *sess) GtkSortType sort_type; store = gtk_list_store_new (5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_POINTER, GDK_TYPE_COLOR); + G_TYPE_POINTER, PALETTE_GDK_TYPE); switch (prefs.hex_gui_ulist_sort) { @@ -528,7 +528,11 @@ userlist_add_columns (GtkTreeView * treeview) gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer), 1); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, NULL, renderer, +#if GTK_CHECK_VERSION(3,0,0) + "text", 1, "foreground-rgba", 4, NULL); +#else "text", 1, "foreground-gdk", 4, NULL); +#endif if (prefs.hex_gui_ulist_show_hosts) {