mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-10 07:50:19 +00:00
Added gtkutil_apply_palette declaration and implementation to apply palette colors/fonts via GTK3 CSS providers with GTK2 fallbacks preserved.
Switched channel tree and theme application logic to use the new palette helper. Updated entry and user list styling to route palette/font application through the helper.
This commit is contained in:
@@ -118,9 +118,9 @@ cv_tree_init (chanview *cv)
|
||||
gtk_widget_set_name (view, "zoitechat-tree");
|
||||
if (cv->style)
|
||||
{
|
||||
gtk_widget_modify_base (view, GTK_STATE_NORMAL, &cv->style->base[GTK_STATE_NORMAL]);
|
||||
gtk_widget_modify_text (view, GTK_STATE_NORMAL, &cv->style->text[GTK_STATE_NORMAL]);
|
||||
gtk_widget_modify_font (view, cv->style->font_desc);
|
||||
gtkutil_apply_palette (view, &cv->style->base[GTK_STATE_NORMAL],
|
||||
&cv->style->text[GTK_STATE_NORMAL],
|
||||
cv->style->font_desc);
|
||||
}
|
||||
/*gtk_widget_modify_base (view, GTK_STATE_NORMAL, &colors[COL_BG]);*/
|
||||
gtk_widget_set_can_focus (view, FALSE);
|
||||
|
||||
@@ -124,14 +124,12 @@ chanview_apply_theme (chanview *cv)
|
||||
w = GTK_WIDGET (tv->tree);
|
||||
if (fe_dark_mode_is_enabled () || prefs.hex_gui_dark_mode == ZOITECHAT_DARK_MODE_LIGHT)
|
||||
{
|
||||
gtk_widget_modify_base (w, GTK_STATE_NORMAL, &colors[COL_BG]);
|
||||
gtk_widget_modify_text (w, GTK_STATE_NORMAL, &colors[COL_FG]);
|
||||
gtkutil_apply_palette (w, &colors[COL_BG], &colors[COL_FG], NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Revert back to theme defaults. */
|
||||
gtk_widget_modify_base (w, GTK_STATE_NORMAL, NULL);
|
||||
gtk_widget_modify_text (w, GTK_STATE_NORMAL, NULL);
|
||||
gtkutil_apply_palette (w, NULL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,79 @@ gtkutil_image_new_from_stock (const char *stock, GtkIconSize size)
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
gtkutil_apply_palette (GtkWidget *widget, const PaletteColor *bg, const PaletteColor *fg,
|
||||
const PangoFontDescription *font_desc)
|
||||
{
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
#if HAVE_GTK3
|
||||
{
|
||||
static const char *class_name = "zoitechat-palette";
|
||||
GtkStyleContext *context = gtk_widget_get_style_context (widget);
|
||||
GtkCssProvider *provider = g_object_get_data (G_OBJECT (widget),
|
||||
"zoitechat-palette-provider");
|
||||
GString *css;
|
||||
gchar *bg_color = NULL;
|
||||
gchar *fg_color = NULL;
|
||||
gchar *font_str = NULL;
|
||||
|
||||
if (!bg && !fg && !font_desc)
|
||||
{
|
||||
gtk_style_context_remove_class (context, class_name);
|
||||
if (provider)
|
||||
{
|
||||
gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (provider));
|
||||
g_object_set_data (G_OBJECT (widget), "zoitechat-palette-provider", NULL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!provider)
|
||||
{
|
||||
provider = gtk_css_provider_new ();
|
||||
g_object_set_data_full (G_OBJECT (widget), "zoitechat-palette-provider",
|
||||
provider, g_object_unref);
|
||||
}
|
||||
|
||||
css = g_string_new (".");
|
||||
g_string_append (css, class_name);
|
||||
g_string_append (css, " {");
|
||||
if (bg)
|
||||
{
|
||||
bg_color = gdk_rgba_to_string (bg);
|
||||
g_string_append_printf (css, " background-color: %s;", bg_color);
|
||||
}
|
||||
if (fg)
|
||||
{
|
||||
fg_color = gdk_rgba_to_string (fg);
|
||||
g_string_append_printf (css, " color: %s;", fg_color);
|
||||
}
|
||||
if (font_desc)
|
||||
{
|
||||
font_str = pango_font_description_to_string (font_desc);
|
||||
g_string_append_printf (css, " font: %s;", font_str);
|
||||
}
|
||||
g_string_append (css, " }");
|
||||
|
||||
gtk_css_provider_load_from_data (provider, css->str, -1, NULL);
|
||||
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
gtk_style_context_add_class (context, class_name);
|
||||
|
||||
g_string_free (css, TRUE);
|
||||
g_free (bg_color);
|
||||
g_free (fg_color);
|
||||
g_free (font_str);
|
||||
}
|
||||
#else
|
||||
gtk_widget_modify_base (widget, GTK_STATE_NORMAL, bg);
|
||||
gtk_widget_modify_text (widget, GTK_STATE_NORMAL, fg);
|
||||
gtk_widget_modify_font (widget, (PangoFontDescription *) font_desc);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
gtkutil_file_req_destroy (GtkWidget * wid, struct file_req *freq)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "../common/fe.h"
|
||||
#include "palette.h"
|
||||
|
||||
typedef void (*filereqcallback) (void *, char *file);
|
||||
|
||||
@@ -47,6 +48,8 @@ gboolean gtkutil_treemodel_string_to_iter (GtkTreeModel *model, gchar *pathstr,
|
||||
gboolean gtkutil_treeview_get_selected_iter (GtkTreeView *view, GtkTreeIter *iter_ret);
|
||||
gboolean gtkutil_treeview_get_selected (GtkTreeView *view, GtkTreeIter *iter_ret, ...);
|
||||
gboolean gtkutil_tray_icon_supported (GtkWindow *window);
|
||||
void gtkutil_apply_palette (GtkWidget *widget, const PaletteColor *bg, const PaletteColor *fg,
|
||||
const PangoFontDescription *font_desc);
|
||||
|
||||
#if defined (WIN32) || defined (__APPLE__)
|
||||
gboolean gtkutil_find_font (const char *fontname);
|
||||
|
||||
@@ -2284,9 +2284,8 @@ mg_limit_entry_cb (GtkWidget * igad, gpointer userdata)
|
||||
static void
|
||||
mg_apply_entry_style (GtkWidget *entry)
|
||||
{
|
||||
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);
|
||||
gtkutil_apply_palette (entry, &colors[COL_BG], &colors[COL_FG],
|
||||
input_style->font_desc);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2712,11 +2711,6 @@ mg_create_userlist (session_gui *gui, GtkWidget *box)
|
||||
|
||||
gui->user_tree = ulist = userlist_create (vbox);
|
||||
|
||||
if (prefs.hex_gui_ulist_style)
|
||||
{
|
||||
gtk_widget_modify_font (ulist, input_style->font_desc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Keep the user list in sync with the chat palette.
|
||||
*
|
||||
@@ -2727,8 +2721,8 @@ mg_create_userlist (session_gui *gui, GtkWidget *box)
|
||||
*/
|
||||
if (prefs.hex_gui_ulist_style || fe_dark_mode_is_enabled ())
|
||||
{
|
||||
gtk_widget_modify_base (ulist, GTK_STATE_NORMAL, &colors[COL_BG]);
|
||||
gtk_widget_modify_text (ulist, GTK_STATE_NORMAL, &colors[COL_FG]);
|
||||
gtkutil_apply_palette (ulist, &colors[COL_BG], &colors[COL_FG],
|
||||
prefs.hex_gui_ulist_style ? input_style->font_desc : NULL);
|
||||
}
|
||||
|
||||
mg_create_meters (gui, vbox);
|
||||
|
||||
Reference in New Issue
Block a user