Skip to content

Commit 5d266d4

Browse files
committed
Provide and manage system configuration file
1 parent be14e2e commit 5d266d4

File tree

6 files changed

+51
-13
lines changed

6 files changed

+51
-13
lines changed

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ LDFLAGS += $(shell pkg-config --libs $(LIBS))
44

55
PROGRAM = xob
66
MANPAGE = doc/xob.1
7+
SYSCONF = styles.cfg
78
SOURCES = $(wildcard src/*.c)
89
OBJECTS = $(SOURCES:.c=.o)
910

@@ -12,6 +13,7 @@ INSTALL_PROGRAM ?= $(INSTALL)
1213
INSTALL_DATA ?= $(INSTALL) -m 644
1314
prefix ?= /usr/local
1415
bindir ?= $(prefix)/bin
16+
sysconfdir ?= $(prefix)/etc
1517
datarootdir ?= $(prefix)/share
1618
mandir ?= $(datarootdir)/man
1719
man1dir ?= $(mandir)/man1
@@ -22,17 +24,21 @@ $(PROGRAM): $(OBJECTS)
2224
$(CC) -o $@ $(OBJECTS) $(LDFLAGS)
2325

2426
%.o: %.c %.h
25-
$(CC) $(CFLAGS) -c -o $@ $<
27+
$(CC) $(CFLAGS) -DSYSCONFDIR='"$(sysconfdir)"' -c -o $@ $<
2628

27-
install: $(PROGRAM) $(MANPAGE)
29+
install: $(PROGRAM) $(MANPAGE) $(SYSCONF)
2830
mkdir --parents "$(DESTDIR)$(bindir)"
2931
$(INSTALL_PROGRAM) "$(PROGRAM)" -t "$(DESTDIR)$(bindir)"
3032
mkdir --parents "$(DESTDIR)$(man1dir)"
3133
$(INSTALL_DATA) "$(MANPAGE)" -t "$(DESTDIR)$(man1dir)"
34+
mkdir --parents "$(DESTDIR)$(sysconfdir)/$(PROGRAM)"
35+
$(INSTALL_DATA) "$(SYSCONF)" -t "$(DESTDIR)$(sysconfdir)/$(PROGRAM)"
3236

3337
uninstall:
3438
rm -f "$(DESTDIR)$(bindir)/$(PROGRAM)"
3539
rm -f "$(DESTDIR)$(man1dir)/$(MANPAGE)"
40+
rm -f "$(DESTDIR)$(sysconfdir)/$(PROGRAM)/$(SYSCONF)"
41+
rmdir "$(DESTDIR)$(sysconfdir)/$(PROGRAM)"
3642

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

4551
.PHONY: all install uninstall clean
46-

README.md

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

9595
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.
9696

doc/xob.1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ $XDG_CONFIG_HOME$/xob/styles.cfg (if $XDG_CONFIG_HOME$ is set)
6767
.IP "3." 3
6868
~/.config/xob/styles.cfg
6969
.IP "4." 3
70-
/etc/xob/styles.cfg
70+
Under the system configuration directory (determined during build
71+
process): e.g.
72+
/etc/xob/styles.cfg or /usr/local/etc/xob/styles.cfg
7173
.SS SYNTAX
7274
.PP
7375
The configuration file adheres to the libconfig syntax.

doc/xob.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The configuration file only specifies styles (appearances) for the bar. The maxi
3535
1. The path specified as the **-c** argument.
3636
2. \$XDG\_CONFIG\_HOME\$/xob/styles.cfg (if \$XDG\_CONFIG\_HOME\$ is set)
3737
3. ~/.config/xob/styles.cfg
38-
4. /etc/xob/styles.cfg
38+
4. Under the system configuration directory (determined during build process): e.g. /etc/xob/styles.cfg or /usr/local/etc/xob/styles.cfg
3939

4040
## SYNTAX
4141

src/main.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,11 @@ int main(int argc, char *argv[])
142142
/* Case #4: system wide configuration */
143143
if (config_file == NULL)
144144
{
145-
if (snprintf(xdg_config_file_path, PATH_MAX, "/etc/%s/%s",
146-
DEFAULT_CONFIG_APPNAME,
147-
DEFAULT_CONFIG_FILENAME) < PATH_MAX)
145+
if (realpath(SYSCONFDIR "/" DEFAULT_CONFIG_APPNAME
146+
"/" DEFAULT_CONFIG_FILENAME,
147+
real_config_file_path) != NULL)
148148
{
149-
if (realpath(xdg_config_file_path, real_config_file_path) != NULL)
150-
{
151-
config_file = fopen(real_config_file_path, "r");
152-
}
149+
config_file = fopen(real_config_file_path, "r");
153150
}
154151
}
155152

styles.cfg

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
default = {
2+
x = {relative = 0.0; offset = 0;};
3+
y = {relative = 0.9; offset = 0;};
4+
length = {relative = 0.2; offset = 0;};
5+
thickness = 24;
6+
outline = 3;
7+
border = 4;
8+
padding = 3;
9+
10+
overflow = "proportional";
11+
12+
color = {
13+
normal = {
14+
fg = "#ffffff";
15+
bg = "#000000";
16+
border = "#ffffff";
17+
};
18+
alt = {
19+
fg = "#555555";
20+
bg = "#000000";
21+
border = "#555555";
22+
};
23+
overflow = {
24+
fg = "#ff0000";
25+
bg = "#000000";
26+
border = "#ff0000";
27+
};
28+
altoverflow = {
29+
fg = "#550000";
30+
bg = "#000000";
31+
border = "#550000";
32+
};
33+
};
34+
};

0 commit comments

Comments
 (0)