mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-21 20:05:42 +02:00
Merge branch 'master' into i3-expose-window-title
This commit is contained in:
commit
6f021b62de
1 changed files with 36 additions and 7 deletions
43
main.c
43
main.c
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/eventfd.h>
|
#include <sys/eventfd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
#include "bar/bar.h"
|
#include "bar/bar.h"
|
||||||
|
@ -30,7 +31,7 @@ signal_handler(int signo)
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
get_config_path(void)
|
get_config_path_user_config(void)
|
||||||
{
|
{
|
||||||
struct passwd *passwd = getpwuid(getuid());
|
struct passwd *passwd = getpwuid(getuid());
|
||||||
if (passwd == NULL) {
|
if (passwd == NULL) {
|
||||||
|
@ -41,15 +42,43 @@ get_config_path(void)
|
||||||
const char *home_dir = passwd->pw_dir;
|
const char *home_dir = passwd->pw_dir;
|
||||||
LOG_DBG("user's home directory: %s", home_dir);
|
LOG_DBG("user's home directory: %s", home_dir);
|
||||||
|
|
||||||
long path_max = sysconf(_PC_PATH_MAX);
|
int len = snprintf(NULL, 0, "%s/.config/f00bar/config.yml", home_dir);
|
||||||
if (path_max == -1)
|
char *path = malloc(len + 1);
|
||||||
path_max = 1024;
|
snprintf(path, len + 1, "%s/.config/f00bar/config.yml", home_dir);
|
||||||
|
|
||||||
char *path = malloc(path_max + 1);
|
|
||||||
snprintf(path, path_max + 1, "%s/.config/f00bar/config.yml", home_dir);
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
get_config_path_xdg(void)
|
||||||
|
{
|
||||||
|
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||||
|
if (xdg_config_home == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
int len = snprintf(NULL, 0, "%s/f00bar/config.yml", xdg_config_home);
|
||||||
|
char *path = malloc(len + 1);
|
||||||
|
snprintf(path, len + 1, "%s/f00bar/config.yml", xdg_config_home);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
get_config_path(void)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
char *config = get_config_path_user_config();
|
||||||
|
if (config != NULL && stat(config, &st) == 0 && S_ISREG(st.st_mode))
|
||||||
|
return config;
|
||||||
|
free(config);
|
||||||
|
|
||||||
|
config = get_config_path_xdg();
|
||||||
|
if (config != NULL && stat(config, &st) == 0 && S_ISREG(st.st_mode))
|
||||||
|
return config;
|
||||||
|
free(config);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static struct bar *
|
static struct bar *
|
||||||
load_bar(const char *config_path)
|
load_bar(const char *config_path)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue