Add /etc/swindle/config.lua as fallback

This commit is contained in:
Tsukasa 2026-09-13 14:33:28 +08:00
parent a49666431a
commit 59c1e07f4b

View file

@ -13,6 +13,7 @@
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/stat.h>
#include <sys/inotify.h> #include <sys/inotify.h>
#include <linux/input-event-codes.h> #include <linux/input-event-codes.h>
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
@ -503,17 +504,28 @@ parse_autostart(lua_State *L, Config *cfg)
/* Public API */ /* Public API */
#define SWINDLE_SYSTEM_CONFIG "/etc/swindle/config.lua"
char * char *
config_get_path(char *buf, size_t bufsz) config_get_path(char *buf, size_t bufsz)
{ {
struct stat sb;
const char *xdg = getenv("XDG_CONFIG_HOME"); const char *xdg = getenv("XDG_CONFIG_HOME");
if (xdg && *xdg) if (xdg && *xdg)
snprintf(buf, bufsz, "%s/swindle/config.lua", xdg); snprintf(buf, bufsz, "%s/swindle/config.lua", xdg);
else { else {
const char *home = getenv("HOME"); const char *home = getenv("HOME");
if (!home) home = "/root"; /* you're probably root, aren't you */ if (!home) home = "/root";
snprintf(buf, bufsz, "%s/.config/swindle/config.lua", home); snprintf(buf, bufsz, "%s/.config/swindle/config.lua", home);
} }
if (stat(buf, &sb) != 0 || !S_ISREG(sb.st_mode)) {
fprintf(stderr, "swindle config: '%s' not found, falling back to '%s'\n",
buf, SWINDLE_SYSTEM_CONFIG);
snprintf(buf, bufsz, "%s", SWINDLE_SYSTEM_CONFIG);
}
return buf; return buf;
} }