Skip to content

Commit 67adbed

Browse files
committed
theme.c: deduplicate openbox themes
If a theme exists in a user-override location (for example ~/.local/share/themes/), then do not add the same theme if it also exists in a system-wide location (for example /usr/share/themes/). Reported-by: @stefonarch
1 parent aa4221a commit 67adbed

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

theme.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ grow_vector_by_one_theme(struct themes *themes)
2424
return theme;
2525
}
2626

27+
static bool
28+
vector_contains(struct themes *themes, const char *needle)
29+
{
30+
assert(needle);
31+
for (int i = 0; i < themes->nr; ++i) {
32+
struct theme *theme = themes->data + i;
33+
if (!theme || !theme->name) {
34+
continue;
35+
}
36+
if ((!strcmp(theme->name, needle))) {
37+
return true;
38+
}
39+
}
40+
return false;
41+
}
42+
2743
static bool
2844
isdir(const char *path, const char *dirname)
2945
{
@@ -130,7 +146,7 @@ process_dir(struct themes *themes, const char *path, const char *filename)
130146
if (strstr(buf, "hicolor") != NULL) {
131147
continue;
132148
}
133-
if (!stat(buf, &st)) {
149+
if (!stat(buf, &st) && !vector_contains(themes, entry->d_name)) {
134150
theme = grow_vector_by_one_theme(themes);
135151
theme->name = strdup(entry->d_name);
136152
theme->path = strdup(buf);
@@ -140,22 +156,6 @@ process_dir(struct themes *themes, const char *path, const char *filename)
140156
closedir(dp);
141157
}
142158

143-
static bool
144-
vector_contains(struct themes *themes, const char *needle)
145-
{
146-
assert(needle);
147-
for (int i = 0; i < themes->nr; ++i) {
148-
struct theme *theme = themes->data + i;
149-
if (!theme || !theme->name) {
150-
continue;
151-
}
152-
if ((!strcmp(theme->name, needle))) {
153-
return true;
154-
}
155-
}
156-
return false;
157-
}
158-
159159
/* Sort system themes in alphabetical order */
160160
static int
161161
compare(const void *a, const void *b)

0 commit comments

Comments
 (0)