Skip to content

Commit 17ba688

Browse files
committed
find-themes.c: improve search for icons themes
/usr/share/icons (and equivalent) contain both icons used by applications/menus/etc and cursors. We search for cursor themes by looking for /usr/share/icons/<theme>/cursors With this commit we verify icon themes by the existance of any /usr/share/icons/<theme>/ subdirectories other than 'cursors' Fixes: PR #7
1 parent 35ba7bd commit 17ba688

File tree

2 files changed

+82
-8
lines changed

2 files changed

+82
-8
lines changed

find-themes.c

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,70 @@ grow_vector_by_one_theme(struct themes *themes)
2323
return theme;
2424
}
2525

26+
/**
27+
* add_theme_if_icon_theme - add theme iff it is a proper icon theme
28+
* @themes: vector
29+
* @path: path to directory to search in
30+
* The criteria for deciding if a icon theme is a "proper icon theme" is to
31+
* verify the existance of a subdirectory other than "cursors"
32+
*/
33+
static void
34+
add_theme_if_icon_theme(struct themes *themes, const char *path)
35+
{
36+
struct dirent *entry;
37+
DIR *dp;
38+
struct stat st;
39+
40+
dp = opendir(path);
41+
if (!dp) {
42+
return;
43+
}
44+
while ((entry = readdir(dp))) {
45+
if (entry->d_type != DT_DIR || entry->d_name[0] == '.') {
46+
continue;
47+
}
48+
49+
char buf[4096];
50+
snprintf(buf, sizeof(buf), "%s/%s", path, entry->d_name);
51+
/* filter 'hicolor' as it is not a complete icon set */
52+
if (strstr(buf, "hicolor") != NULL) {
53+
continue;
54+
}
55+
56+
/* process subdirectories within the theme directory */
57+
struct dirent *sub_entry;
58+
DIR *sub_dp;
59+
sub_dp = opendir(buf);
60+
if (!sub_dp) {
61+
return;
62+
}
63+
64+
/*
65+
* Add theme if directory other than 'cursors' exists.
66+
* This could be "scalable", "22x22", or whatever...
67+
*/
68+
while ((sub_entry = readdir(sub_dp))) {
69+
if (sub_entry->d_type != DT_DIR || sub_entry->d_name[0] == '.') {
70+
continue;
71+
}
72+
if (!strcmp(sub_entry->d_name, "cursors")) {
73+
continue;
74+
}
75+
76+
/* We've found a directory other than "cursors"! */
77+
struct theme *theme = NULL;
78+
if (!stat(buf, &st)) {
79+
theme = grow_vector_by_one_theme(themes);
80+
theme->name = strdup(entry->d_name);
81+
theme->path = strdup(buf);
82+
}
83+
break;
84+
}
85+
closedir(sub_dp);
86+
}
87+
closedir(dp);
88+
}
89+
2690
/**
2791
* process_dir - find themes and store them in vector
2892
* @themes: vector
@@ -120,12 +184,22 @@ find_themes(struct themes *themes, const char *middle, const char *end)
120184
snprintf(path, sizeof(path), "%s/%s", dirs[i].path, middle);
121185
}
122186

123-
/*
124-
* Find themes by recursively reading directories at
125-
* "$DATA_DIR/@middle" and then checking for
126-
* "$DATA_DIR/@middle/<themename>/@end"
127-
*/
128-
process_dir(themes, path, end);
187+
if (end) {
188+
/*
189+
* Add theme <themename> if
190+
* "$DATA_DIR/@middle/<themename>/@end" exists
191+
*/
192+
process_dir(themes, path, end);
193+
} else {
194+
/*
195+
* Add icon theme iff "$DATA_DIR/@middle/<themename>/"
196+
* contains a subdirectory other than "cursors".
197+
* Note: searching for index.theme only is not good
198+
* enough because some cursor themes contain the same
199+
* file and some themes contain both cursors and icons.
200+
*/
201+
add_theme_if_icon_theme(themes, path);
202+
}
129203
}
130204

131205
/*

main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ main(int argc, char **argv)
248248
/* load themes */
249249
find_themes(&openbox_themes, "themes", "openbox-3/themerc");
250250
find_themes(&gtk_themes, "themes", "gtk-3.0/gtk.css");
251-
find_themes(&icon_themes, "icons", "index.theme");
252-
find_themes(&cursor_themes, "icons", "cursors/xterm");
251+
find_themes(&cursor_themes, "icons", "cursors");
252+
find_themes(&icon_themes, "icons", NULL);
253253

254254
/* connect to gsettings */
255255
settings = g_settings_new("org.gnome.desktop.interface");

0 commit comments

Comments
 (0)