Updated fe_system_prefers_dark() to remove the old !has_theme_name gate and always read gtk-application-prefer-dark-theme whenever that property exists. Theme-name matching is still kept as an additional signal.

Added deterministic dark-mode precedence by combining explicit signals (theme_name_prefers_dark || property_prefers_dark), while preserving Windows system preference as another dark-enabling signal when available. This ensures “dark if any explicit dark signal is true.”
Re-checked the relevant callers (fe_auto_dark_mode_changed() and fe_apply_theme_for_mode()): they consume fe_system_prefers_dark() output and do not depend on the removed !has_theme_name conditional behavior.
This commit is contained in:
2026-02-25 22:42:43 -07:00
parent cbc474477b
commit 685989fa25

View File

@@ -541,11 +541,13 @@ static gboolean
fe_system_prefers_dark (void) fe_system_prefers_dark (void)
{ {
GtkSettings *settings = gtk_settings_get_default (); GtkSettings *settings = gtk_settings_get_default ();
gboolean theme_name_prefers_dark = FALSE;
gboolean property_prefers_dark = FALSE;
gboolean prefer_dark = FALSE; gboolean prefer_dark = FALSE;
gboolean has_theme_name = FALSE;
char *theme_name = NULL; char *theme_name = NULL;
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
gboolean have_win_pref = FALSE; gboolean have_win_pref = FALSE;
gboolean win_prefers_dark = FALSE;
if (fe_win32_high_contrast_is_enabled ()) if (fe_win32_high_contrast_is_enabled ())
return FALSE; return FALSE;
@@ -558,30 +560,29 @@ fe_system_prefers_dark (void)
if (theme_name) if (theme_name)
{ {
char *lower = g_ascii_strdown (theme_name, -1); char *lower = g_ascii_strdown (theme_name, -1);
has_theme_name = TRUE;
if (g_str_has_suffix (lower, "-dark") || g_strrstr (lower, "dark")) if (g_str_has_suffix (lower, "-dark") || g_strrstr (lower, "dark"))
prefer_dark = TRUE; theme_name_prefers_dark = TRUE;
g_free (lower); g_free (lower);
g_free (theme_name); g_free (theme_name);
}
if (prefer_dark) if (g_object_class_find_property (G_OBJECT_GET_CLASS (settings),
return TRUE; "gtk-application-prefer-dark-theme"))
{
/* Even if we last wrote this property, the toolkit or desktop can update
* it later, so AUTO mode should keep reading it as a signal. */
g_object_get (settings, "gtk-application-prefer-dark-theme", &property_prefers_dark, NULL);
} }
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
have_win_pref = fe_win32_try_get_system_dark (&prefer_dark); have_win_pref = fe_win32_try_get_system_dark (&win_prefers_dark);
if (have_win_pref)
return prefer_dark;
#endif #endif
if (!has_theme_name /* Deterministic precedence: any explicit dark signal wins. */
&& g_object_class_find_property (G_OBJECT_GET_CLASS (settings), prefer_dark = theme_name_prefers_dark || property_prefers_dark;
"gtk-application-prefer-dark-theme")) #ifdef G_OS_WIN32
{ prefer_dark = prefer_dark || (have_win_pref && win_prefers_dark);
/* Even if we last wrote this property, the toolkit or desktop can update #endif
* it later, so AUTO mode should keep reading it as a fallback signal. */
g_object_get (settings, "gtk-application-prefer-dark-theme", &prefer_dark, NULL);
}
return prefer_dark; return prefer_dark;
} }