Skip to content

Commit aab01a2

Browse files
committed
Refactor theme-find functions
1 parent 9086850 commit aab01a2

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <sys/stat.h>
99
#include "state.h"
1010
#include "tab-appearance.h"
11-
#include "tweaks.h"
1211
#include "xml.h"
1312

1413
static void

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ executable(
1515
files(
1616
'main.c',
1717
'xml.c',
18-
'find-themes.c',
18+
'theme.c',
1919
'keyboard-layouts.c',
2020
'tab-appearance.c',
2121
'update.c',

tab-appearance.c

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,22 @@
22
#include "keyboard-layouts.h"
33
#include "state.h"
44
#include "tab-appearance.h"
5-
#include "tweaks.h"
5+
#include "theme.h"
66
#include "update.h"
77
#include "xml.h"
88

9-
static struct themes openbox_themes = { 0 };
10-
static struct themes gtk_themes = { 0 };
11-
static struct themes icon_themes = { 0 };
12-
static struct themes cursor_themes = { 0 };
13-
14-
static void
15-
free_theme_vector(struct themes *themes)
16-
{
17-
for (int i = 0; i < themes->nr; ++i) {
18-
struct theme *theme = themes->data + i;
19-
if (theme->name) {
20-
free(theme->name);
21-
}
22-
if (theme->path) {
23-
free(theme->path);
24-
}
25-
}
26-
free(themes->data);
27-
}
28-
299
void
3010
tab_appearance_init(struct state *state, GtkWidget *stack)
3111
{
3212
/* load themes */
33-
find_themes(&openbox_themes, "themes", "openbox-3/themerc");
34-
find_themes(&gtk_themes, "themes", "gtk-3.0/gtk.css");
35-
find_themes(&cursor_themes, "icons", "cursors");
36-
find_themes(&icon_themes, "icons", NULL);
13+
struct themes openbox_themes = { 0 };
14+
struct themes gtk_themes = { 0 };
15+
struct themes icon_themes = { 0 };
16+
struct themes cursor_themes = { 0 };
17+
theme_find(&openbox_themes, "themes", "openbox-3/themerc");
18+
theme_find(&gtk_themes, "themes", "gtk-3.0/gtk.css");
19+
theme_find(&cursor_themes, "icons", "cursors");
20+
theme_find(&icon_themes, "icons", NULL);
3721

3822
GtkWidget *vbox, *widget, *hbbox;
3923

@@ -186,9 +170,9 @@ tab_appearance_init(struct state *state, GtkWidget *stack)
186170
gtk_container_add(GTK_CONTAINER(hbbox), widget);
187171
gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_END);
188172

189-
free_theme_vector(&openbox_themes);
190-
free_theme_vector(&gtk_themes);
191-
free_theme_vector(&icon_themes);
192-
free_theme_vector(&cursor_themes);
173+
theme_free_vector(&openbox_themes);
174+
theme_free_vector(&gtk_themes);
175+
theme_free_vector(&icon_themes);
176+
theme_free_vector(&cursor_themes);
193177
}
194178

find-themes.c renamed to theme.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <strings.h>
1010
#include <sys/stat.h>
1111
#include <unistd.h>
12-
#include "tweaks.h"
12+
#include "theme.h"
1313

1414
static struct theme *
1515
grow_vector_by_one_theme(struct themes *themes)
@@ -180,7 +180,7 @@ static struct {
180180
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
181181

182182
void
183-
find_themes(struct themes *themes, const char *middle, const char *end)
183+
theme_find(struct themes *themes, const char *middle, const char *end)
184184
{
185185
char path[4096];
186186
for (uint32_t i = 0; i < ARRAY_SIZE(dirs); ++i) {
@@ -224,3 +224,19 @@ find_themes(struct themes *themes, const char *middle, const char *end)
224224

225225
qsort(themes->data, themes->nr, sizeof(struct theme), compare);
226226
}
227+
228+
void
229+
theme_free_vector(struct themes *themes)
230+
{
231+
for (int i = 0; i < themes->nr; ++i) {
232+
struct theme *theme = themes->data + i;
233+
if (theme->name) {
234+
free(theme->name);
235+
}
236+
if (theme->path) {
237+
free(theme->path);
238+
}
239+
}
240+
free(themes->data);
241+
}
242+

theme.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef THEME_H
3+
#define THEME_H
4+
#include <stdbool.h>
5+
6+
struct theme {
7+
char *name;
8+
char *path;
9+
};
10+
11+
struct themes {
12+
struct theme *data;
13+
int nr, alloc;
14+
};
15+
16+
void theme_find(struct themes *themes, const char *middle, const char *end);
17+
void theme_free_vector(struct themes *themes);
18+
19+
#endif /* THEME_H */

tweaks.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)