Added the GTK3 InputStyle abstraction and updated input style/chanview declarations to avoid direct GtkStyle usage in GTK3 builds.

Updated input style initialization and kept GTK2-only RC parsing while applying GTK3 palette styling for the channel tree via CSS-aware paths.
This commit is contained in:
2026-01-30 18:19:01 -07:00
parent d0d6a573a7
commit 6c17f4bc16
8 changed files with 43 additions and 11 deletions

View File

@@ -118,9 +118,14 @@ cv_tree_init (chanview *cv)
gtk_widget_set_name (view, "zoitechat-tree");
if (cv->style)
{
#if HAVE_GTK3
gtkutil_apply_palette (view, &colors[COL_BG], &colors[COL_FG],
cv->style->font_desc);
#else
gtkutil_apply_palette (view, &cv->style->base[GTK_STATE_NORMAL],
&cv->style->text[GTK_STATE_NORMAL],
cv->style->font_desc);
#endif
}
/*gtk_widget_modify_base (view, GTK_STATE_NORMAL, &colors[COL_BG]);*/
gtk_widget_set_can_focus (view, FALSE);

View File

@@ -45,7 +45,7 @@ struct _chanview
int size; /* number of channels in view */
GtkWidget *box; /* the box we destroy when changing implementations */
GtkStyle *style; /* style used for tree */
InputStyle *style; /* style used for tree */
chan *focused; /* currently focused channel */
int trunc_len;
@@ -292,7 +292,7 @@ chanview_box_destroy_cb (GtkWidget *box, chanview *cv)
chanview *
chanview_new (int type, int trunc_len, gboolean sort, gboolean use_icons,
GtkStyle *style)
InputStyle *style)
{
chanview *cv;

View File

@@ -20,10 +20,12 @@
#ifndef ZOITECHAT_CHANVIEW_H
#define ZOITECHAT_CHANVIEW_H
#include "fe-gtk.h"
typedef struct _chanview chanview;
typedef struct _chan chan;
chanview *chanview_new (int type, int trunc_len, gboolean sort, gboolean use_icons, GtkStyle *style);
chanview *chanview_new (int type, int trunc_len, gboolean sort, gboolean use_icons, InputStyle *style);
void chanview_set_callbacks (chanview *cv,
void (*cb_focus) (chanview *, chan *, int tag, void *userdata),
void (*cb_xbutton) (chanview *, chan *, int tag, void *userdata),

View File

@@ -250,6 +250,7 @@ fe_args (int argc, char *argv[])
return -1;
}
#if !HAVE_GTK3
const char cursor_color_rc[] =
"style \"xc-ib-st\""
"{"
@@ -272,6 +273,7 @@ static const char adwaita_workaround_rc[] =
"}"
"}"
"widget \"*.zoitechat-inputbox\" style \"zoitechat-input-workaround\"";
#endif
static gboolean
fe_system_prefers_dark (void)
@@ -397,13 +399,19 @@ fe_dark_mode_is_enabled (void)
return fe_dark_mode_is_enabled_for (prefs.hex_gui_dark_mode);
}
GtkStyle *
create_input_style (GtkStyle *style)
InputStyle *
create_input_style (InputStyle *style)
{
char buf[256];
static int done_rc = FALSE;
pango_font_description_free (style->font_desc);
#if HAVE_GTK3
if (!style)
style = g_new0 (InputStyle, 1);
#endif
if (style->font_desc)
pango_font_description_free (style->font_desc);
style->font_desc = pango_font_description_from_string (prefs.hex_text_font);
/* fall back */
@@ -417,6 +425,7 @@ create_input_style (GtkStyle *style)
if (prefs.hex_gui_input_style && !done_rc)
{
#if !HAVE_GTK3
GtkSettings *settings = gtk_settings_get_default ();
char *theme_name;
@@ -427,7 +436,6 @@ create_input_style (GtkStyle *style)
gtk_rc_parse_string (adwaita_workaround_rc);
g_free (theme_name);
done_rc = TRUE;
{
guint16 red;
guint16 green;
@@ -437,11 +445,15 @@ create_input_style (GtkStyle *style)
sprintf (buf, cursor_color_rc, (red >> 8), (green >> 8), (blue >> 8));
}
gtk_rc_parse_string (buf);
#endif
done_rc = TRUE;
}
#if !HAVE_GTK3
style->bg[GTK_STATE_NORMAL] = colors[COL_FG];
style->base[GTK_STATE_NORMAL] = colors[COL_BG];
style->text[GTK_STATE_NORMAL] = colors[COL_FG];
#endif
return style;
}
@@ -460,7 +472,11 @@ fe_init (void)
gtkosx_application_set_dock_icon_pixbuf (osx_app, pix_zoitechat);
#endif
channelwin_pix = pixmap_load_from_file (prefs.hex_text_background);
#if HAVE_GTK3
input_style = create_input_style (input_style);
#else
input_style = create_input_style (gtk_style_new ());
#endif
settings = gtk_settings_get_default ();
if (settings)

View File

@@ -48,6 +48,15 @@
#define flag_b flag_wid[7]
#define NUM_FLAG_WIDS 8
#if HAVE_GTK3
typedef struct _input_style
{
PangoFontDescription *font_desc;
} InputStyle;
#else
typedef GtkStyle InputStyle;
#endif
#ifdef HAVE_GTK_MAC
extern GtkosxApplication *osx_app;
#endif

View File

@@ -272,7 +272,7 @@ static const char chan_flags[] = { 'c', 'n', 't', 'i', 'm', 'l', 'k' };
static chan *active_tab = NULL; /* active tab */
GtkWidget *parent_window = NULL; /* the master window */
GtkStyle *input_style;
InputStyle *input_style;
static PangoAttrList *away_list;
static PangoAttrList *newdata_list;

View File

@@ -20,7 +20,7 @@
#ifndef ZOITECHAT_MAINGUI_H
#define ZOITECHAT_MAINGUI_H
extern GtkStyle *input_style;
extern InputStyle *input_style;
extern GtkWidget *parent_window;
void mg_changui_new (session *sess, restore_gui *res, int tab, int focus);

View File

@@ -48,7 +48,7 @@
#endif
#include "sexy-spell-entry.h"
GtkStyle *create_input_style (GtkStyle *);
InputStyle *create_input_style (InputStyle *);
#define LABEL_INDENT 12
@@ -2860,7 +2860,7 @@ setup_apply_to_sess (session_gui *gui)
if (prefs.hex_gui_input_style)
{
#if GTK_CHECK_VERSION(3,0,0)
#if HAVE_GTK3
char buf[128];
GtkCssProvider *provider = gtk_css_provider_new ();
GtkStyleContext *context;