tint2conf: force refresh fix

This commit is contained in:
o9000 2017-03-04 22:36:51 +01:00
parent e833b27533
commit 3c9642c5fc
3 changed files with 41 additions and 5 deletions

View file

@ -167,6 +167,7 @@ static void viewRowActivated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeV
static void select_first_theme(); static void select_first_theme();
static void load_all_themes(); static void load_all_themes();
static void reload_all_themes();
// ====== Globals ====== // ====== Globals ======
@ -256,7 +257,7 @@ int main(int argc, char **argv)
{"ThemeEdit", GTK_STOCK_PROPERTIES, _("_Edit theme..."), NULL, _("Edit the selected theme"), G_CALLBACK(edit_theme)}, {"ThemeEdit", GTK_STOCK_PROPERTIES, _("_Edit theme..."), NULL, _("Edit the selected theme"), G_CALLBACK(edit_theme)},
{"ThemeMakeDefault", GTK_STOCK_APPLY, _("_Make default"), NULL, _("Replace the default theme with the selected one"), G_CALLBACK(make_selected_theme_default)}, {"ThemeMakeDefault", GTK_STOCK_APPLY, _("_Make default"), NULL, _("Replace the default theme with the selected one"), G_CALLBACK(make_selected_theme_default)},
{"ThemeRefresh", GTK_STOCK_REFRESH, _("Refresh"), NULL, _("Redraw the selected theme"), G_CALLBACK(refresh_current_theme)}, {"ThemeRefresh", GTK_STOCK_REFRESH, _("Refresh"), NULL, _("Redraw the selected theme"), G_CALLBACK(refresh_current_theme)},
{"RefreshAll", GTK_STOCK_REFRESH, _("Refresh all"), NULL, _("Redraw all themes"), G_CALLBACK(load_all_themes)}, {"RefreshAll", GTK_STOCK_REFRESH, _("Refresh all"), NULL, _("Redraw all themes"), G_CALLBACK(reload_all_themes)},
{"Quit", GTK_STOCK_QUIT, _("_Quit"), "<control>Q", _("Quit"), G_CALLBACK(gtk_main_quit)}, {"Quit", GTK_STOCK_QUIT, _("_Quit"), "<control>Q", _("Quit"), G_CALLBACK(gtk_main_quit)},
{"HelpMenu", NULL, _("_Help"), NULL, NULL, NULL}, {"HelpMenu", NULL, _("_Help"), NULL, NULL, NULL},
{"HelpAbout", GTK_STOCK_ABOUT, _("_About"), "<Control>A", _("About"), G_CALLBACK(menuAbout)}}; {"HelpAbout", GTK_STOCK_ABOUT, _("_About"), "<Control>A", _("About"), G_CALLBACK(menuAbout)}};
@ -837,6 +838,37 @@ static void load_all_themes()
} }
} }
static void reload_all_themes()
{
ensure_default_theme_exists();
gtk_list_store_clear(GTK_LIST_STORE(theme_list_store));
theme_selection_changed(NULL, NULL);
gboolean found_themes = FALSE;
if (load_user_themes())
found_themes = TRUE;
if (load_system_themes())
found_themes = TRUE;
if (found_themes) {
select_first_theme();
GtkTreeIter iter;
GtkTreeModel *model;
gboolean have_iter;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
have_iter = gtk_tree_model_get_iter_first(model, &iter);
while (have_iter) {
gtk_list_store_set(theme_list_store, &iter, COL_SNAPSHOT, NULL, COL_FORCE_REFRESH, TRUE, -1);
have_iter = gtk_tree_model_iter_next(model, &iter);
}
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
}
}
static void load_specific_themes(char **paths, int count) static void load_specific_themes(char **paths, int count)
{ {
ensure_default_theme_exists(); ensure_default_theme_exists();

View file

@ -38,7 +38,7 @@ GtkWidget *create_view()
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
theme_list_store = theme_list_store =
gtk_list_store_new(NB_COL, G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_INT, G_TYPE_INT); gtk_list_store_new(NB_COL, G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_INT, G_TYPE_INT, G_TYPE_BOOLEAN);
GtkWidget *view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(theme_list_store)); GtkWidget *view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(theme_list_store));
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view), TRUE); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view), TRUE);
@ -148,7 +148,7 @@ void theme_list_append(const gchar *path)
g_free(dir); g_free(dir);
gchar *display_name = g_strdup_printf("%s\n(%s)", name, suffix); gchar *display_name = g_strdup_printf("%s\n(%s)", name, suffix);
gtk_list_store_set(theme_list_store, &iter, COL_THEME_FILE, path, COL_THEME_NAME, display_name, -1); gtk_list_store_set(theme_list_store, &iter, COL_THEME_FILE, path, COL_THEME_NAME, display_name, COL_FORCE_REFRESH, FALSE, -1);
g_free(display_name); g_free(display_name);
g_free(suffix); g_free(suffix);
} }
@ -183,14 +183,15 @@ gboolean update_snapshot()
} }
gchar *path; gchar *path;
gtk_tree_model_get(model, &iter, COL_THEME_FILE, &path, -1); gboolean force_refresh;
gtk_tree_model_get(model, &iter, COL_THEME_FILE, &path, COL_FORCE_REFRESH, &force_refresh, -1);
char hash[MD4_HEX_SIZE + 4]; char hash[MD4_HEX_SIZE + 4];
md4hexf(path, hash); md4hexf(path, hash);
strcat(hash, ".png"); strcat(hash, ".png");
gchar *snap = g_build_filename(g_get_user_cache_dir(), "tint2", hash, NULL); gchar *snap = g_build_filename(g_get_user_cache_dir(), "tint2", hash, NULL);
pixbuf = gdk_pixbuf_new_from_file(snap, NULL); pixbuf = force_refresh ? NULL : gdk_pixbuf_new_from_file(snap, NULL);
if (!pixbuf) { if (!pixbuf) {
gchar *cmd = g_strdup_printf("tint2 -c \'%s\' -s \'%s\' 1>/dev/null 2>/dev/null", path, snap); gchar *cmd = g_strdup_printf("tint2 -c \'%s\' -s \'%s\' 1>/dev/null 2>/dev/null", path, snap);
num_updates++; num_updates++;
@ -216,6 +217,8 @@ gboolean update_snapshot()
gdk_pixbuf_get_width(pixbuf) + PADDING, gdk_pixbuf_get_width(pixbuf) + PADDING,
COL_HEIGHT, COL_HEIGHT,
gdk_pixbuf_get_height(pixbuf) + PADDING, gdk_pixbuf_get_height(pixbuf) + PADDING,
COL_FORCE_REFRESH,
FALSE,
-1); -1);
if (pixbuf) if (pixbuf)
g_object_unref(pixbuf); g_object_unref(pixbuf);

View file

@ -10,6 +10,7 @@ enum { COL_THEME_FILE = 0,
COL_SNAPSHOT, COL_SNAPSHOT,
COL_WIDTH, COL_WIDTH,
COL_HEIGHT, COL_HEIGHT,
COL_FORCE_REFRESH,
NB_COL, }; NB_COL, };
GtkWidget *create_view(); GtkWidget *create_view();