Skip to content

Commit

Permalink
Provide and manage system configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
florentc committed Aug 25, 2018
1 parent be14e2e commit 5d266d4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ LDFLAGS += $(shell pkg-config --libs $(LIBS))

PROGRAM = xob
MANPAGE = doc/xob.1
SYSCONF = styles.cfg
SOURCES = $(wildcard src/*.c)
OBJECTS = $(SOURCES:.c=.o)

Expand All @@ -12,6 +13,7 @@ INSTALL_PROGRAM ?= $(INSTALL)
INSTALL_DATA ?= $(INSTALL) -m 644
prefix ?= /usr/local
bindir ?= $(prefix)/bin
sysconfdir ?= $(prefix)/etc
datarootdir ?= $(prefix)/share
mandir ?= $(datarootdir)/man
man1dir ?= $(mandir)/man1
Expand All @@ -22,17 +24,21 @@ $(PROGRAM): $(OBJECTS)
$(CC) -o $@ $(OBJECTS) $(LDFLAGS)

%.o: %.c %.h
$(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(CFLAGS) -DSYSCONFDIR='"$(sysconfdir)"' -c -o $@ $<

install: $(PROGRAM) $(MANPAGE)
install: $(PROGRAM) $(MANPAGE) $(SYSCONF)
mkdir --parents "$(DESTDIR)$(bindir)"
$(INSTALL_PROGRAM) "$(PROGRAM)" -t "$(DESTDIR)$(bindir)"
mkdir --parents "$(DESTDIR)$(man1dir)"
$(INSTALL_DATA) "$(MANPAGE)" -t "$(DESTDIR)$(man1dir)"
mkdir --parents "$(DESTDIR)$(sysconfdir)/$(PROGRAM)"
$(INSTALL_DATA) "$(SYSCONF)" -t "$(DESTDIR)$(sysconfdir)/$(PROGRAM)"

uninstall:
rm -f "$(DESTDIR)$(bindir)/$(PROGRAM)"
rm -f "$(DESTDIR)$(man1dir)/$(MANPAGE)"
rm -f "$(DESTDIR)$(sysconfdir)/$(PROGRAM)/$(SYSCONF)"
rmdir "$(DESTDIR)$(sysconfdir)/$(PROGRAM)"

clean:
rm -f $(OBJECTS)
Expand All @@ -43,4 +49,3 @@ src/display.o: src/display.h src/conf.h
src/main.o: src/main.h src/display.h src/conf.h

.PHONY: all install uninstall clean

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ When starting, xob looks for the configuration file in the following order:
1. The path specified as the **-c** argument.
2. `$XDG_CONFIG_HOME$/xob/styles.cfg` (if `$XDG_CONFIG_HOME$` is set)
3. `~/.config/xob/styles.cfg`
4. `/etc/xob/styles.cfg`
4. Under the system configuration directory (determined during build process): e.g. /etc/xob/styles.cfg or /usr/local/etc/xob/styles.cfg

Consult the man page for detailed information about the configuration file and the available options. The following `styles.cfg` defines a single style called "default" that showcases all the possible options set to the default values. The configration file may contain additional styles to choose among using the **-s** argument.

Expand Down
4 changes: 3 additions & 1 deletion doc/xob.1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ $XDG_CONFIG_HOME$/xob/styles.cfg (if $XDG_CONFIG_HOME$ is set)
.IP "3." 3
~/.config/xob/styles.cfg
.IP "4." 3
/etc/xob/styles.cfg
Under the system configuration directory (determined during build
process): e.g.
/etc/xob/styles.cfg or /usr/local/etc/xob/styles.cfg
.SS SYNTAX
.PP
The configuration file adheres to the libconfig syntax.
Expand Down
2 changes: 1 addition & 1 deletion doc/xob.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The configuration file only specifies styles (appearances) for the bar. The maxi
1. The path specified as the **-c** argument.
2. \$XDG\_CONFIG\_HOME\$/xob/styles.cfg (if \$XDG\_CONFIG\_HOME\$ is set)
3. ~/.config/xob/styles.cfg
4. /etc/xob/styles.cfg
4. Under the system configuration directory (determined during build process): e.g. /etc/xob/styles.cfg or /usr/local/etc/xob/styles.cfg

## SYNTAX

Expand Down
11 changes: 4 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,11 @@ int main(int argc, char *argv[])
/* Case #4: system wide configuration */
if (config_file == NULL)
{
if (snprintf(xdg_config_file_path, PATH_MAX, "/etc/%s/%s",
DEFAULT_CONFIG_APPNAME,
DEFAULT_CONFIG_FILENAME) < PATH_MAX)
if (realpath(SYSCONFDIR "/" DEFAULT_CONFIG_APPNAME
"/" DEFAULT_CONFIG_FILENAME,
real_config_file_path) != NULL)
{
if (realpath(xdg_config_file_path, real_config_file_path) != NULL)
{
config_file = fopen(real_config_file_path, "r");
}
config_file = fopen(real_config_file_path, "r");
}
}

Expand Down
34 changes: 34 additions & 0 deletions styles.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
default = {
x = {relative = 0.0; offset = 0;};
y = {relative = 0.9; offset = 0;};
length = {relative = 0.2; offset = 0;};
thickness = 24;
outline = 3;
border = 4;
padding = 3;

overflow = "proportional";

color = {
normal = {
fg = "#ffffff";
bg = "#000000";
border = "#ffffff";
};
alt = {
fg = "#555555";
bg = "#000000";
border = "#555555";
};
overflow = {
fg = "#ff0000";
bg = "#000000";
border = "#ff0000";
};
altoverflow = {
fg = "#550000";
bg = "#000000";
border = "#550000";
};
};
};

0 comments on commit 5d266d4

Please sign in to comment.