mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
Simplify and merge {config,theme}-dir.c
This commit is contained in:
parent
fc6fca6945
commit
f003abf608
20 changed files with 181 additions and 163 deletions
|
|
@ -1,6 +1,5 @@
|
|||
labwc_sources += files(
|
||||
'theme.c',
|
||||
'theme-dir.c',
|
||||
)
|
||||
|
||||
subdir('xbm')
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Find the openbox theme directory
|
||||
*
|
||||
* Copyright Johan Malm 2020
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdbool.h>
|
||||
#include <glib.h>
|
||||
|
||||
struct dir {
|
||||
const char *prefix;
|
||||
const char *path;
|
||||
};
|
||||
|
||||
/* clang-format off */
|
||||
static struct dir theme_dirs[] = {
|
||||
{ "XDG_DATA_HOME", "themes" },
|
||||
{ "HOME", ".local/share/themes" },
|
||||
{ "HOME", ".themes" },
|
||||
{ "XDG_DATA_DIRS", "themes" },
|
||||
{ NULL, "/usr/share/themes" },
|
||||
{ NULL, "/usr/local/share/themes" },
|
||||
{ NULL, "opt/share/themes" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static bool isdir(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
return (!stat(path, &st) && S_ISDIR(st.st_mode));
|
||||
}
|
||||
|
||||
char *theme_dir(const char *theme_name)
|
||||
{
|
||||
static char buf[4096] = { 0 };
|
||||
if (buf[0] != '\0')
|
||||
return buf;
|
||||
|
||||
for (int i = 0; theme_dirs[i].path; i++) {
|
||||
struct dir d = theme_dirs[i];
|
||||
if (!d.prefix) {
|
||||
snprintf(buf, sizeof(buf), "%s/%s/openbox-3", d.path,
|
||||
theme_name);
|
||||
if (isdir(buf))
|
||||
return buf;
|
||||
} else {
|
||||
char *prefix = getenv(d.prefix);
|
||||
if (!prefix)
|
||||
continue;
|
||||
gchar **prefixes = g_strsplit(prefix, ":", -1);
|
||||
for (gchar **p = prefixes; *p; p++) {
|
||||
snprintf(buf, sizeof(buf),
|
||||
"%s/%s/%s/openbox-3", *p, d.path,
|
||||
theme_name);
|
||||
if (isdir(buf))
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* no config directory was found */
|
||||
buf[0] = '.';
|
||||
buf[1] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
#include <glib.h>
|
||||
|
||||
#include "theme/theme.h"
|
||||
#include "theme/theme-dir.h"
|
||||
#include "common/dir.h"
|
||||
|
||||
static int hex_to_dec(char c)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
#include "theme/theme.h"
|
||||
#include "theme/xbm/xbm.h"
|
||||
#include "theme/xbm/parse.h"
|
||||
#include "theme/theme-dir.h"
|
||||
#include "config/rcxml.h"
|
||||
#include "common/dir.h"
|
||||
#include "common/grab-file.h"
|
||||
|
||||
/* built-in 6x6 buttons */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue