refactor configuration infrastructure

This patch reworks how `hikari` gets configured and provides a default
configuration as well as means to incorporate this into the binary.

This deprecated the `ETC_PREFIX` configuration during make and makes it reuse
`PREFIX`.

A default terminal is now specified via the `TERMINAL` environment variable.
This commit is contained in:
raichoo 2020-05-02 14:34:45 +00:00
parent 02a9f4c24c
commit 401b900323
7 changed files with 96 additions and 168 deletions

View File

@ -1,24 +1,7 @@
.ifmake doc || dist
.ifndef VERSION
.error please specify VERSION
.endif
.endif
VERSION ?= "darcs"
.ifmake install || uninstall
.ifndef PREFIX
.error please specify PREFIX
.endif
OS != uname
VERSION ?= "CURRENT"
INSTALL_GROUP != id -gn
.endif
.ifmake install || uninstall
.ifndef ETC_PREFIX
.error please specify ETC_PREFIX
.endif
.endif
PREFIX ?= /usr/local
OBJS = \
action.o \
@ -103,7 +86,7 @@ CFLAGS += -DHAVE_SCREENCOPY=1
CFLAGS += -DHAVE_LAYERSHELL=1
.endif
CFLAGS += -Wall -I. -Iinclude
CFLAGS += -Wall -I. -Iinclude -DHIKARI_PREFIX=${PREFIX}
WLROOTS_CFLAGS != pkg-config --cflags wlroots
WLROOTS_LIBS != pkg-config --libs wlroots
@ -208,8 +191,8 @@ hikari-${VERSION}.tar.gz: version.h share/man/man1/hikari.1
README.md \
share/man/man1/hikari.md \
share/man/man1/hikari.1 \
share/examples/hikari/hikari.conf \
pam.d/hikari-unlocker.*
etc/hikari/hikari.conf \
etc/pam.d/hikari-unlocker.*
distclean: clean-doc
@test -e _darcs && echo "cleaning version.h" ||:
@ -220,17 +203,17 @@ dist: distclean hikari-${VERSION}.tar.gz
install: hikari hikari-unlocker share/man/man1/hikari.1
mkdir -p ${PREFIX}/bin
mkdir -p ${PREFIX}/share/man/man1
mkdir -p ${PREFIX}/share/examples/hikari
mkdir -p ${ETC_PREFIX}/pam.d
mkdir -p ${PREFIX}/etc/hikari
mkdir -p ${PREFIX}/etc/pam.d
install -m 4555 -g ${INSTALL_GROUP} hikari hikari-unlocker ${PREFIX}/bin
install -m 644 -g ${INSTALL_GROUP} share/man/man1/hikari.1 ${PREFIX}/share/man/man1
install -m 644 -g ${INSTALL_GROUP} share/examples/hikari/hikari.conf ${PREFIX}/share/examples/hikari
install -m 644 -g ${INSTALL_GROUP} pam.d/hikari-unlocker.${OS} ${ETC_PREFIX}/pam.d/hikari-unlocker
install -m 644 -g ${INSTALL_GROUP} etc/hikari/hikari.conf ${PREFIX}/etc/hikari
install -m 644 -g ${INSTALL_GROUP} etc/pam.d/hikari-unlocker.${OS} ${PREFIX}/etc/pam.d/hikari-unlocker
uninstall:
-rm ${PREFIX}/bin/hikari
-rm ${PREFIX}/bin/hikari-unlocker
-rm ${PREFIX}/share/examples/hikari/hikari.conf
-rmdir ${PREFIX}/share/examples/hikari
-rm ${PREFIX}/share/man/man1/hikari.1
-rm ${ETC_PREFIX}/pam.d/hikari-unlocker
-rm ${PREFIX}/etc/pam.d/hikari-unlocker
-rm ${PREFIX}/etc/hikari/hikari.conf
-rmdir ${PREFIX}/etc/hikari

View File

@ -90,19 +90,31 @@ The build process will produce two binaries `hikari` and `hikari-unlocker`. The
latter one is used to check credentials for unlocking the screen. Both need to
be installed with root setuid in your `PATH`.
`hikari` can be configured via `$HOME/.config/hikari/hikari.conf`, an example
can be found under `share/exampes/hikari/hikari.conf`.
`hikari` can be configured via `$HOME/.config/hikari/hikari.conf`, the default
configuration can be found under `$PREFIX/etc/hikari/hikari.conf` (depending
on the value of `PREFIX` that was specified during the installation).
The default configuration expects your default terminal emulator to be specified
in the `$TERMINAL` environment variable.
The installation destination can be configured by setting`PREFIX` (default is
`/usr/local` and does not need to be given explicitly). If you want to install
`hikari` into a directory other than `/usr/local` you always should state the
`PREFIX` when issuing `make`, since this information is also used to specify
where `hikari` can find the default configuration on your system and is needed
during the compilation process.
#### Building on FreeBSD
Simply run `make`. Installation needs `PREFIX` and `ETC_PREFIX` to be defined.
To install everything in `/usr/local` run
Simply run `make`. The installation destination can be configured by
setting`PREFIX` (default is `/usr/local` and does not need to be given
explicitly).
```
make PREFIX=/usr/local ETC_PREFIX=/usr/local/etc install
make
```
`uninstall` requires the same values for `PREFIX` and `ETC_PREFIX`.
`uninstall` requires the same value for `PREFIX`.
#### Building on Linux
@ -112,17 +124,15 @@ On Linux `bmake` is required which needs to be run like so:
bmake WITH_POSIX_C_SOURCE=YES
```
Installation needs `PREFIX` and `ETC_PREFIX` to be defined. To install
everything in `/usr/local` run.
The installation destination can be configured by
setting`PREFIX` (default is `/usr/local` and does not need to be given
explicitly).
```
bmake PREFIX=/usr/local ETC_PREFIX=/etc install
bmake PREFIX=/usr/local install
```
`pam.d` files should be installed in `/etc` or `/usr/lib/pam.d` depending on
your distribution.
`uninstall` requires the same values for `PREFIX` and `ETC_PREFIX`.
`uninstall` requires the same value for `PREFIX`.
#### Building with XWayland support

View File

@ -1,8 +1,7 @@
border = 1
gap = 5
step = 100
font = "DejaVu Sans Mono 10"
font = "monospace 10"
colorscheme {
background = 0x282C34
@ -16,121 +15,13 @@ colorscheme {
inactive = 0x465457
}
inputs {
pointers {
"System mouse" = {
accel = 1.0
scroll-method = on-button-down
scroll-button = middle
}
}
}
outputs {
eDP-1 = {
background = "/path/to/wallpaper"
position = {
x = 1680
y = 0
}
}
"HDMI-A-1" = {
position = {
x = 0
y = 0
}
}
WL-1 = {
background = {
path = "/path/to/wallpaper"
fit = center
}
}
}
marks {
c = "sakura --name cmus -c 150 -r 50 -e cmus"
f = "firefox"
m = "sakura -t mutt --name mutt -c 125 -r 37 -e mutt"
i = "sakura --name irssi -r 65 -c 227 -e irssi"
r = "sakura --name rootshell -e su - root -c fish"
}
views {
rootshell = {
mark = r
}
jabber = {
group = communication
sheet = 1
mark = j
position = {
x = 30
y = 20
}
focus = true
}
irssi = {
group = communication
sheet = 1
mark = i
position = {
x = 940
y = 20
}
focus = true
}
mutt = {
group = communication
sheet = 1
mark = m
position = {
x = 30
y = 860
}
focus = true
}
cmus = {
group = music
mark = c
}
top = {
group = monitor
sheet = 0
position = {
x = 1997 # 2560 - 1 - 562
y = 1077 # 1440 - 1 - 362
}
}
systat = {
group = monitor
sheet = 0
position = {
x = 1429 # 2560 - 2 - 2 * 562 - 5
y = 1077 # 1440 - 1 - 362
}
focus = true
}
firefox = {
group = web
sheet = 2
mark = f
}
}
layouts {
# main stack
s = {
scale = 0.75
scale = {
min = 0.5
max = 0.75
}
left = single
right = stack
}
@ -164,10 +55,7 @@ layouts {
}
actions {
shell = "sakura --name shell"
rootshell = "sakura --name rootshell -e su - root -c fish"
volup = "mixer -s vol +5"
voldown = "mixer -s vol -5"
terminal = "$TERMINAL"
}
bindings {
@ -273,10 +161,7 @@ bindings {
"LCA+q" = quit
"LCA+r" = reload
"L+Return" = action-shell
"LS+Return" = action-rootshell
"0-122" = action-voldown
"0-123" = action-volup
"L+Return" = action-terminal
"A+F1" = vt-switch-to-1
"A+F2" = vt-switch-to-2

48
main.c
View File

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wlr/util/log.h>
@ -29,11 +30,50 @@ get_default_autostart(void)
return get_default_path("/.config/hikari/autostart");
}
static char *
get_path(const char *path)
{
char *ret = NULL;
size_t len = strlen(path) + 1;
struct stat s;
if (stat(path, &s) == 0 && S_ISREG(s.st_mode)) {
ret = malloc(len + 1);
strcpy(ret, path);
return ret;
}
return NULL;
}
#define STR(s) #s
#define DEFAULT_CONFIG(s) STR(s) "/etc/hikari/hikari.conf"
#define DEFAULT_CONFIG_FILE DEFAULT_CONFIG(HIKARI_PREFIX)
static const char *default_config_file = DEFAULT_CONFIG_FILE;
static char *
get_default_config_path(void)
{
return get_default_path("/.config/hikari/hikari.conf");
char *ret = get_default_path("/.config/hikari/hikari.conf");
struct stat s;
if (stat(ret, &s) == 0 && S_ISREG(s.st_mode)) {
return ret;
} else {
free(ret);
if ((ret = get_path(default_config_file)) != NULL) {
return ret;
}
}
return NULL;
}
#undef STR
#undef DEFAULT_CONFIG
#undef DEFAULT_CONFIG_FILE
const char *usage = "Usage: hikari [options]\n"
"\n"
@ -92,6 +132,12 @@ main(int argc, char **argv)
if (config_path == NULL) {
config_path = get_default_config_path();
if (config_path == NULL) {
free(autostart);
fprintf(stderr, "could not load default configuration \"%s\"\n", default_config_file);
exit(EXIT_FAILURE);
}
}
if (autostart == NULL) {

View File

@ -140,10 +140,14 @@ CONFIGURATION
=============
**hikari** is configured using libucl(3) as a configuration file format. The
configuration is located under _$HOME/.config/hikari/hikari.conf_. An example
can be found under _share/examples/hikari/hikari.conf_.
configuration is located under _~/.config/hikari/hikari.conf_. If this file is
not found **hikari** is going to try _hikari.conf_ from the install _etc_
directory.
On startup **hikari** attempts to execute _$HOME/.config/hikari/autostart_ to
The default configuration is going to use **$TERMINAL** as your standard
terminal application.
On startup **hikari** attempts to execute _~/.config/hikari/autostart_ to
autostart applications.
ACTIONS