all repos — tint2 @ 38ef80637fba5c8d24a0d08e53980fd4ea5ebd14

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

tint2conf: Support for loading themes from /usr/share/tint2
o9000 mrovi9000@gmail.com
commit

38ef80637fba5c8d24a0d08e53980fd4ea5ebd14

parent

7f9ac5c584750173618fc5a03487fad69743348f

4 files changed, 155 insertions(+), 90 deletions(-)

jump to
M src/tint2conf/main.csrc/tint2conf/main.c

@@ -62,6 +62,7 @@ }

static void menuAddWidget(GtkUIManager *, GtkWidget *, GtkContainer *); static void menuImport(); +static void menuImportSelected(); static void menuImportDefault(); static void menuSaveAs(); static void menuDelete();

@@ -87,6 +88,8 @@

GtkWidget *g_window; static GtkUIManager *globalUIManager = NULL; GtkWidget *tint_cmd; + +GtkActionGroup *actionGroup = NULL; static const char *global_ui = "<ui>"

@@ -113,10 +116,12 @@ " </menubar>"

" <toolbar name='ToolBar'>" " <toolitem action='ThemeProperties'/>" " <toolitem action='ThemeSelect'/>" + " <toolitem action='ThemeAddIt'/>" " </toolbar>" " <popup name='ThemePopup'>" " <menuitem action='ThemeProperties'/>" " <menuitem action='EditRefresh'/>" + " <menuitem action='ThemeAddIt'/>" " <separator/>" " <menuitem action='ThemeDelete'/>" " </popup>"

@@ -130,8 +135,6 @@ bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");

textdomain(GETTEXT_PACKAGE); GtkWidget *vBox = NULL, *scrollbar = NULL; - GtkActionGroup *actionGroup; - gtk_init(&argc, &argv); #if !GLIB_CHECK_VERSION(2, 31, 0)

@@ -154,7 +157,7 @@

// define main layout : container, menubar, toolbar g_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(g_window), _("Panel theming")); - gtk_window_resize(GTK_WINDOW(g_window), 800, 600); + gtk_window_resize(GTK_WINDOW(g_window), 920, 600); g_signal_connect(G_OBJECT(g_window), "destroy", G_CALLBACK(gtk_main_quit), NULL); vBox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(g_window), vBox);

@@ -165,6 +168,7 @@ // Menubar and toolbar entries

GtkActionEntry entries[] = { {"ThemeMenu", NULL, _("Theme"), NULL, NULL, NULL}, {"ThemeAdd", GTK_STOCK_ADD, _("_Import theme..."), "<Control>N", _("Import theme"), G_CALLBACK(menuImport)}, + {"ThemeAddIt", GTK_STOCK_ADD, _("_Import theme"), NULL, _("Import theme"), G_CALLBACK(menuImportSelected)}, {"ThemeDefault", GTK_STOCK_NEW, _("_Import default theme..."), NULL, _("Import default theme"), G_CALLBACK(menuImportDefault)}, {"ThemeSaveAs", GTK_STOCK_SAVE_AS, _("_Save as..."), NULL, _("Save theme as"), G_CALLBACK(menuSaveAs)}, {"ThemeDelete", GTK_STOCK_DELETE, _("_Delete"), NULL, _("Delete theme"), G_CALLBACK(menuDelete)},

@@ -288,6 +292,37 @@ gtk_widget_destroy(dialog);

load_all_themes(); } +static void menuImportSelected() +{ + GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view)); + GtkTreeModel *model; + GtkTreeIter iter; + if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) { + char *file; + gtk_tree_model_get(model, &iter, COL_THEME_FILE, &file, -1); + + if (strstr(file, g_get_user_config_dir()) == file) + return; + gchar *pt1 = strrchr(file, '/'); + if (!pt1) + return; + pt1++; + if (!*pt1) + return; + + gchar *name = pt1; + gchar *path = g_build_filename(g_get_user_config_dir(), "tint2", name, NULL); + if (g_file_test(path, G_FILE_TEST_EXISTS)) { + g_free(path); + return; + } + copy_file(file, path); + theme_list_append(path, NULL); + } + + g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL); +} + static void menuImportDefault() { GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Save default theme as"), GTK_WINDOW(g_window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);

@@ -419,10 +454,10 @@

// ====== Theme selection ====== gboolean theme_selected(GtkTreeSelection *selection, - GtkTreeModel *model, - GtkTreePath *path, - gboolean path_currently_selected, - gpointer userdata) + GtkTreeModel *model, + GtkTreePath *path, + gboolean path_currently_selected, + gpointer userdata) { GtkTreeIter iter; if (gtk_tree_model_get_iter(model, &iter, path)) {

@@ -432,6 +467,10 @@ if (!path_currently_selected) {

gchar *text = g_strdup_printf("tint2 -c %s", current_theme); gtk_entry_set_text(GTK_ENTRY(tint_cmd), text); g_free(text); + gboolean editable = strstr(current_theme, g_get_user_config_dir()) == current_theme; + gtk_action_set_sensitive(gtk_action_group_get_action(actionGroup, "ThemeProperties"), editable); + gtk_action_set_sensitive(gtk_action_group_get_action(actionGroup, "ThemeDelete"), editable); + gtk_action_set_sensitive(gtk_action_group_get_action(actionGroup, "ThemeAddIt"), !editable); } else { gtk_entry_set_text(GTK_ENTRY(tint_cmd), ""); }

@@ -529,28 +568,62 @@ }

// ====== Theme load/reload ====== -#if 0 -static void copy_default_themes() +static void ensure_default_theme_exists() { + // Without a user tint2rc file, copy the default gchar *path_home = g_build_filename(g_get_user_config_dir(), "tint2", "tint2rc", NULL); if (!g_file_test(path_home, G_FILE_TEST_EXISTS)) { const gchar * const * system_dirs = g_get_system_config_dirs(); - int i; - for (i = 0; system_dirs[i]; i++) { + for (int i = 0; system_dirs[i]; i++) { gchar *path = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL); if (g_file_test(path, G_FILE_TEST_EXISTS)) { copy_file(path, path_home); + break; } g_free(path); } } g_free(path_home); +} +static gboolean load_user_themes() +{ + // Load configs from home directory + gchar *tint2_config_dir = g_build_filename(g_get_user_config_dir(), "tint2", NULL); + GDir *dir = g_dir_open(tint2_config_dir, 0, NULL); + if (dir == NULL) { + g_free(tint2_config_dir); + return FALSE; + } + gboolean found_theme = FALSE; + + const gchar *file_name; + while ((file_name = g_dir_read_name(dir))) { + if (!g_file_test(file_name, G_FILE_TEST_IS_DIR) && + !strstr(file_name, "backup") && + !strstr(file_name, "copy") && + !strstr(file_name, "~") && + (endswith(file_name, "tint2rc") || + endswith(file_name, ".conf"))) { + found_theme = TRUE; + gchar *path = g_build_filename(tint2_config_dir, file_name, NULL); + theme_list_append(path, NULL); + g_free(path); + } + } + g_dir_close(dir); + g_free(tint2_config_dir); + + return found_theme; +} + +static gboolean load_system_themes() +{ + gboolean found_theme = FALSE; + // Load configs from /usr etc const gchar * const * data_dirs = g_get_system_data_dirs(); - int i; - for (i = 0; data_dirs[i]; i++) { + for (int i = 0; data_dirs[i]; i++) { gchar *path_tint2 = g_build_filename(data_dirs[i], "tint2", NULL); - fprintf(stderr, "%s\n", path_tint2); GDir *dir = g_dir_open(path_tint2, 0, NULL); if (dir) { const gchar *file_name;

@@ -561,55 +634,32 @@ !strstr(file_name, "copy") &&

!strstr(file_name, "~") && (endswith(file_name, "tint2rc") || endswith(file_name, ".conf"))) { - gchar *path_home = g_build_filename(g_get_user_config_dir(), "tint2", file_name, NULL); - if (!g_file_test(path_home, G_FILE_TEST_EXISTS)) { - gchar *path_usr = g_build_filename(path_tint2, file_name, NULL); - copy_file(path_usr, path_home); - g_free(path_usr); - } - g_free(path_home); + found_theme = TRUE; + gchar *path = g_build_filename(path_tint2, file_name, NULL); + theme_list_append(path, data_dirs[i]); + g_free(path); } } g_dir_close(dir); } g_free(path_tint2); } + return found_theme; } -#endif static void load_all_themes() { - // We don't do this anymore since it has proven unpopular... -#if 0 - copy_default_themes(); -#endif + ensure_default_theme_exists(); - gtk_list_store_clear(GTK_LIST_STORE(g_store)); + gtk_list_store_clear(GTK_LIST_STORE(theme_list_store)); - gchar *tint2_config_dir = g_build_filename(g_get_user_config_dir(), "tint2", NULL); - GDir *dir = g_dir_open(tint2_config_dir, 0, NULL); - if (dir == NULL) { - g_free(tint2_config_dir); - return; - } - gboolean found_theme = FALSE; + gboolean found_themes = FALSE; + if (load_user_themes()) + found_themes = TRUE; + if (load_system_themes()) + found_themes = TRUE; - const gchar *file_name; - while ((file_name = g_dir_read_name(dir))) { - if (!g_file_test(file_name, G_FILE_TEST_IS_DIR) && - !strstr(file_name, "backup") && - !strstr(file_name, "copy") && - !strstr(file_name, "~") && - (endswith(file_name, "tint2rc") || - endswith(file_name, ".conf"))) { - found_theme = TRUE; - gchar *name = g_build_filename(tint2_config_dir, file_name, NULL); - custom_list_append(name); - g_free(name); - } - } - - if (found_theme) { + if (found_themes) { select_first_theme(); GtkTreeIter iter;

@@ -619,15 +669,12 @@

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(g_store, &iter, COL_SNAPSHOT, NULL, -1); + gtk_list_store_set(theme_list_store, &iter, COL_SNAPSHOT, NULL, -1); have_iter = gtk_tree_model_iter_next(model, &iter); } g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL); } - - g_dir_close(dir); - g_free(tint2_config_dir); } static void refresh_current_theme()

@@ -638,7 +685,7 @@ GtkTreeModel *model;

sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view)); if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) { - gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, NULL, -1); + gtk_list_store_set(theme_list_store, &iter, COL_SNAPSHOT, NULL, -1); } g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
M src/tint2conf/main.hsrc/tint2conf/main.h

@@ -16,4 +16,4 @@ #endif

#define SNAPSHOT_TICK 190 gboolean update_snapshot(); -void menuApply();+void menuApply();
M src/tint2conf/theme_view.csrc/tint2conf/theme_view.c

@@ -24,7 +24,7 @@ #include "theme_view.h"

// The data columns that we export via the tree model interface GtkWidget *g_theme_view; -GtkListStore *g_store; +GtkListStore *theme_list_store; int g_width_list, g_height_list; GtkCellRenderer *g_renderer;

@@ -39,13 +39,13 @@ GtkTreeViewColumn *col;

GtkCellRenderer *renderer; GtkWidget *view; - g_store = gtk_list_store_new(NB_COL, G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF); + theme_list_store = gtk_list_store_new(NB_COL, G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF); - view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(g_store)); + 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_headers_visible(GTK_TREE_VIEW(view), FALSE); - g_object_unref(g_store); // destroy store automatically with view + g_object_unref(theme_list_store); // destroy store automatically with view renderer = gtk_cell_renderer_text_new(); col = gtk_tree_view_column_new();

@@ -73,7 +73,7 @@ gtk_tree_view_column_add_attribute(col, g_renderer, "pixbuf", COL_SNAPSHOT);

gtk_tree_view_append_column(GTK_TREE_VIEW(view),col); GtkTreeSortable *sortable; - sortable = GTK_TREE_SORTABLE(g_store); + sortable = GTK_TREE_SORTABLE(theme_list_store); gtk_tree_sortable_set_sort_column_id(sortable, COL_THEME_FILE, GTK_SORT_ASCENDING); gtk_tree_sortable_set_sort_func(sortable, COL_THEME_FILE, theme_name_compare, NULL, NULL); return view;

@@ -87,6 +87,15 @@ {

gchar *path_a, *path_b; gtk_tree_model_get(model, a, COL_THEME_FILE, &path_a, -1); gtk_tree_model_get(model, b, COL_THEME_FILE, &path_b, -1); + + gboolean home_a = strstr(path_a, g_get_user_config_dir()) == path_a; + gboolean home_b = strstr(path_b, g_get_user_config_dir()) == path_b; + + if (home_a && !home_b) + return -1; + if (!home_a && home_b) + return 1; + gchar *name_a = path_a; gchar *p; for (p = name_a; *p; p++) {

@@ -110,15 +119,23 @@ g_free(path_b);

return result; } -void custom_list_append(const gchar *path) +void theme_list_append(const gchar *path, const gchar *suffix) { - GtkTreeIter iter; + GtkTreeIter iter; - gtk_list_store_append(g_store, &iter); - gtk_list_store_set(g_store, &iter, COL_THEME_FILE, path, -1); + gtk_list_store_append(theme_list_store, &iter); + gtk_list_store_set(theme_list_store, &iter, COL_THEME_FILE, path, -1); + + gchar *name = strrchr(path, '/') + 1; - gchar *name = g_strdup(strrchr(path, '/') + 1); - gtk_list_store_set(g_store, &iter, COL_THEME_NAME, name, -1); + gchar *full_name; + if (suffix) { + full_name = g_strdup_printf("%s\n(%s)", name, suffix); + } else { + full_name = g_strdup(name); + } + gtk_list_store_set(theme_list_store, &iter, COL_THEME_NAME, full_name, -1); + g_free(full_name); }

@@ -126,7 +143,6 @@ gboolean update_snapshot()

{ GtkTreeModel *model; GtkTreeIter iter; - GdkPixbuf *icon; gboolean have_iter; gint pixWidth = 200, pixHeight = 30;

@@ -134,20 +150,27 @@

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_tree_model_get(model, &iter, COL_SNAPSHOT, &icon, -1); - if (icon != NULL) { - g_object_unref(icon); + GdkPixbuf *pixbuf; + gtk_tree_model_get(model, &iter, COL_SNAPSHOT, &pixbuf, -1); + if (pixbuf) { + pixWidth = MAX(pixWidth, gdk_pixbuf_get_width(pixbuf)); + pixHeight = MAX(pixHeight, gdk_pixbuf_get_height(pixbuf)); + g_object_unref(pixbuf); + have_iter = gtk_tree_model_iter_next(model, &iter); + continue; } // build panel's snapshot - GdkPixbuf *pixbuf = NULL; - gchar *name, *snap, *cmd; + gchar *path; + gtk_tree_model_get(model, &iter, + COL_THEME_FILE, &path, + -1); - snap = g_build_filename(g_get_user_config_dir(), "tint2", "snap.jpg", NULL); + + gchar *snap = g_build_filename(g_get_user_config_dir(), "tint2", "snap.jpg", NULL); g_remove(snap); - gtk_tree_model_get(model, &iter, COL_THEME_FILE, &name, -1); - cmd = g_strdup_printf("tint2 -c \'%s\' -s \'%s\'", name, snap); + gchar *cmd = g_strdup_printf("tint2 -c \'%s\' -s \'%s\' 1>/dev/null 2>/dev/null", path, snap); if (system(cmd) == 0) { // load pixbuf = gdk_pixbuf_new_from_file(snap, NULL);

@@ -155,18 +178,16 @@ if (pixbuf == NULL) {

printf("snapshot NULL : %s\n", cmd); } } - g_free(snap); g_free(cmd); - g_free(name); - - gint w, h; - w = gdk_pixbuf_get_width(pixbuf); - h = gdk_pixbuf_get_height(pixbuf); - pixWidth = w > pixWidth ? w : pixWidth; - pixHeight = h > pixHeight ? h : pixHeight; + g_free(snap); + g_free(path); - gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, pixbuf, -1); + pixWidth = MAX(pixWidth, gdk_pixbuf_get_width(pixbuf)); + pixHeight = MAX(pixHeight, gdk_pixbuf_get_height(pixbuf)); + gtk_list_store_set(theme_list_store, &iter, COL_SNAPSHOT, pixbuf, -1); + if (pixbuf) + g_object_unref(pixbuf); have_iter = gtk_tree_model_iter_next(model, &iter); }

@@ -174,6 +195,3 @@ gtk_cell_renderer_set_fixed_size(g_renderer, pixWidth + 30, pixHeight + 30);

return FALSE; } - - -
M src/tint2conf/theme_view.hsrc/tint2conf/theme_view.h

@@ -5,12 +5,12 @@

#include <gtk/gtk.h> extern GtkWidget *g_theme_view; -extern GtkListStore *g_store; +extern GtkListStore *theme_list_store; enum { COL_THEME_FILE = 0, COL_THEME_NAME, COL_SNAPSHOT, NB_COL, }; GtkWidget *create_view(); -void custom_list_append(const gchar *path); +void theme_list_append(const gchar *path, const gchar *suffix); #endif