Added a reload-capable GTK3 theme apply API (fe_apply_gtk3_theme_with_reload) and kept fe_apply_gtk3_theme as the default fast-path wrapper (force_reload = FALSE).

Updated the same-theme early return so it is bypassed when reload is requested, while preserving the existing provider reset/replacement flow, gtk_style_context_reset_widgets, and top-level reapply behavior.

Wired setup import/apply flow to force a reload on the next apply after successful archive import, ensuring same-name imported themes are reloaded from disk; the flag is cleared after apply and when switching back to system theme.
This commit is contained in:
2026-02-26 02:38:12 -07:00
parent c9682d98f3
commit 4a996c9135
3 changed files with 19 additions and 3 deletions

View File

@@ -596,7 +596,7 @@ static char *gtk3_theme_provider_name = NULL;
static gboolean gtk3_theme_provider_dark = FALSE;
gboolean
fe_apply_gtk3_theme (const char *theme_name, GError **error)
fe_apply_gtk3_theme_with_reload (const char *theme_name, gboolean force_reload, GError **error)
{
GdkScreen *screen = gdk_screen_get_default ();
char *theme_dir = NULL;
@@ -628,7 +628,8 @@ fe_apply_gtk3_theme (const char *theme_name, GError **error)
return TRUE;
}
if (gtk3_theme_provider_name
if (!force_reload
&& gtk3_theme_provider_name
&& g_strcmp0 (gtk3_theme_provider_name, theme_name) == 0
&& gtk3_theme_provider_dark == dark)
{
@@ -694,6 +695,14 @@ fe_apply_gtk3_theme (const char *theme_name, GError **error)
}
gboolean
fe_apply_gtk3_theme (const char *theme_name, GError **error)
{
return fe_apply_gtk3_theme_with_reload (theme_name, FALSE, error);
}
static void
fe_set_gtk_prefer_dark_theme (gboolean dark)
{

View File

@@ -194,6 +194,8 @@ void fe_set_auto_dark_mode_state (gboolean enabled);
void fe_refresh_auto_dark_mode (void);
gboolean fe_apply_theme_for_mode (unsigned int mode, gboolean *palette_changed);
gboolean fe_apply_gtk3_theme (const char *theme_name, GError **error);
gboolean fe_apply_gtk3_theme_with_reload (const char *theme_name, gboolean force_reload,
GError **error);
void fe_apply_theme_to_toplevel (GtkWidget *window);
#define SPELL_ENTRY_GET_TEXT(e) ((char *)(gtk_entry_get_text (GTK_ENTRY(e))))

View File

@@ -72,6 +72,7 @@ typedef struct
GtkWidget *gtk3_use_system_button;
GtkWidget *gtk3_status_label;
GPtrArray *gtk3_theme_paths;
gboolean gtk3_force_reload_next_apply;
} setup_theme_ui;
@@ -2049,6 +2050,7 @@ setup_theme_gtk3_import_cb (GtkWidget *button, gpointer user_data)
}
else
{
ui->gtk3_force_reload_next_apply = TRUE;
setup_gtk3_theme_populate (ui);
gtk_label_set_text (GTK_LABEL (ui->gtk3_status_label), _("GTK3 theme archive imported successfully."));
setup_theme_show_message (GTK_MESSAGE_INFO, _("GTK3 theme archive imported successfully."));
@@ -2079,7 +2081,7 @@ setup_theme_apply_gtk3_cb (GtkWidget *button, gpointer user_data)
return;
}
if (!fe_apply_gtk3_theme (theme, &error))
if (!fe_apply_gtk3_theme_with_reload (theme, ui->gtk3_force_reload_next_apply, &error))
{
setup_theme_show_message (GTK_MESSAGE_ERROR,
error ? error->message : _("Failed to apply GTK3 theme."));
@@ -2088,6 +2090,8 @@ setup_theme_apply_gtk3_cb (GtkWidget *button, gpointer user_data)
return;
}
ui->gtk3_force_reload_next_apply = FALSE;
safe_strcpy (prefs.hex_gui_gtk3_theme_name, theme, sizeof (prefs.hex_gui_gtk3_theme_name));
/* Keep the Preferences working copy in sync so pressing OK does not
* overwrite the just-selected theme with stale setup_prefs data. */
@@ -2106,6 +2110,7 @@ setup_theme_gtk3_use_system_cb (GtkWidget *button, gpointer user_data)
setup_theme_ui *ui = user_data;
fe_apply_gtk3_theme (NULL, NULL);
ui->gtk3_force_reload_next_apply = FALSE;
prefs.hex_gui_gtk3_theme_name[0] = '\0';
setup_prefs.hex_gui_gtk3_theme_name[0] = '\0';
save_config ();