- Added dark mode mode constants, config storage as an integer, and a helper to resolve Auto/Dark/Light using system preferences where available.

- Replaced the dark mode checkbox with an Auto/Dark/Light color mode selector and ensured palette edits use the resolved mode.
- Applied the resolved color mode consistently across palette saving and GTK styling in the user list and channel tree/theme application paths.
This commit is contained in:
2026-01-17 22:52:32 -07:00
parent cf41615cb3
commit 8d275ddb31
7 changed files with 69 additions and 8 deletions

View File

@@ -437,7 +437,7 @@ const struct prefs vars[] =
{"gui_tab_dialogs", P_OFFINT (hex_gui_tab_dialogs), TYPE_BOOL},
{"gui_tab_dots", P_OFFINT (hex_gui_tab_dots), TYPE_BOOL},
{"gui_tab_icons", P_OFFINT (hex_gui_tab_icons), TYPE_BOOL},
{"gui_dark_mode", P_OFFINT (hex_gui_dark_mode), TYPE_BOOL},
{"gui_dark_mode", P_OFFINT (hex_gui_dark_mode), TYPE_INT},
{"gui_tab_layout", P_OFFINT (hex_gui_tab_layout), TYPE_INT},
{"gui_tab_middleclose", P_OFFINT (hex_gui_tab_middleclose), TYPE_BOOL},
{"gui_tab_newtofront", P_OFFINT (hex_gui_tab_newtofront), TYPE_INT},

View File

@@ -83,6 +83,10 @@ gboolean zoitechat_import_theme (const char *path, GError **error);
#define USERNAMELEN 10
#define HIDDEN_CHAR 8 /* invisible character for xtext */
#define ZOITECHAT_DARK_MODE_AUTO 0
#define ZOITECHAT_DARK_MODE_DARK 1
#define ZOITECHAT_DARK_MODE_LIGHT 2
struct nbexec
{
int myfd;

View File

@@ -122,7 +122,7 @@ chanview_apply_theme (chanview *cv)
return;
w = GTK_WIDGET (tv->tree);
if (prefs.hex_gui_dark_mode)
if (fe_dark_mode_is_enabled ())
{
gtk_widget_modify_base (w, GTK_STATE_NORMAL, &colors[COL_BG]);
gtk_widget_modify_text (w, GTK_STATE_NORMAL, &colors[COL_FG]);

View File

@@ -270,6 +270,59 @@ static const char adwaita_workaround_rc[] =
"}"
"widget \"*.zoitechat-inputbox\" style \"zoitechat-input-workaround\"";
static gboolean
fe_system_prefers_dark (void)
{
GtkSettings *settings = gtk_settings_get_default ();
gboolean prefer_dark = FALSE;
char *theme_name = NULL;
if (!settings)
return FALSE;
if (g_object_class_find_property (G_OBJECT_GET_CLASS (settings),
"gtk-application-prefer-dark-theme"))
{
g_object_get (settings, "gtk-application-prefer-dark-theme", &prefer_dark, NULL);
}
if (!prefer_dark)
{
g_object_get (settings, "gtk-theme-name", &theme_name, NULL);
if (theme_name)
{
char *lower = g_ascii_strdown (theme_name, -1);
if (g_str_has_suffix (lower, "-dark") || g_strrstr (lower, "dark"))
prefer_dark = TRUE;
g_free (lower);
g_free (theme_name);
}
}
return prefer_dark;
}
gboolean
fe_dark_mode_is_enabled_for (unsigned int mode)
{
switch (mode)
{
case ZOITECHAT_DARK_MODE_DARK:
return TRUE;
case ZOITECHAT_DARK_MODE_LIGHT:
return FALSE;
case ZOITECHAT_DARK_MODE_AUTO:
default:
return fe_system_prefers_dark ();
}
}
gboolean
fe_dark_mode_is_enabled (void)
{
return fe_dark_mode_is_enabled_for (prefs.hex_gui_dark_mode);
}
GtkStyle *
create_input_style (GtkStyle *style)
{
@@ -317,7 +370,7 @@ void
fe_init (void)
{
palette_load ();
palette_apply_dark_mode (prefs.hex_gui_dark_mode);
palette_apply_dark_mode (fe_dark_mode_is_enabled ());
key_init ();
pixmaps_init ();

View File

@@ -182,6 +182,9 @@ typedef struct session_gui
extern cairo_surface_t *channelwin_pix;
extern cairo_surface_t *dialogwin_pix;
gboolean fe_dark_mode_is_enabled (void);
gboolean fe_dark_mode_is_enabled_for (unsigned int mode);
#define SPELL_ENTRY_GET_TEXT(e) ((char *)(gtk_entry_get_text (GTK_ENTRY(e))))
#define SPELL_ENTRY_SET_TEXT(e,txt) gtk_entry_set_text(GTK_ENTRY(e),txt)
#define SPELL_ENTRY_SET_EDITABLE(e,v) gtk_editable_set_editable(GTK_EDITABLE(e),v)

View File

@@ -2650,7 +2650,7 @@ mg_create_userlist (session_gui *gui, GtkWidget *box)
* - When "Dark mode" is enabled, we also force the user list to use the
* palette colors so it doesn't stay blindingly white on GTK2 themes.
*/
if (prefs.hex_gui_ulist_style || prefs.hex_gui_dark_mode)
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]);

View File

@@ -311,20 +311,21 @@ palette_save (void)
char prefname[256];
const GdkColor *lightpal = colors;
const GdkColor *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. */
if (prefs.hex_gui_dark_mode && user_colors_valid)
if (dark_mode_active && user_colors_valid)
lightpal = user_colors;
/* If we're currently in light mode, ensure the snapshot stays in sync. */
if (!prefs.hex_gui_dark_mode)
if (!dark_mode_active)
{
memcpy (user_colors, colors, sizeof (user_colors));
user_colors_valid = TRUE;
}
/* If dark mode is enabled but we haven't snapshotted a custom dark palette yet, capture it now. */
if (prefs.hex_gui_dark_mode && !dark_user_colors_valid)
if (dark_mode_active && !dark_user_colors_valid)
{
memcpy (dark_user_colors, colors, sizeof (dark_user_colors));
dark_user_colors_valid = TRUE;
@@ -332,7 +333,7 @@ palette_save (void)
if (dark_user_colors_valid)
darkpal = dark_user_colors;
else if (prefs.hex_gui_dark_mode)
else if (dark_mode_active)
darkpal = colors; /* current dark palette (likely defaults) */
fh = zoitechat_open_file ("colors.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);