@@ -23,6 +23,70 @@ grow_vector_by_one_theme(struct themes *themes)
23
23
return theme ;
24
24
}
25
25
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
+
26
90
/**
27
91
* process_dir - find themes and store them in vector
28
92
* @themes: vector
@@ -120,12 +184,22 @@ find_themes(struct themes *themes, const char *middle, const char *end)
120
184
snprintf (path , sizeof (path ), "%s/%s" , dirs [i ].path , middle );
121
185
}
122
186
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
+ }
129
203
}
130
204
131
205
/*
0 commit comments