diff --git a/Makefile b/Makefile index 5482dc8..2c61bb7 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ .POSIX: +VERSION =0 + PREFIX = /usr/local PKG_CONFIG = pkg-config @@ -8,7 +10,7 @@ PKGS = wayland-client fcft pixman-1 INCS = `$(PKG_CONFIG) --cflags $(PKGS)` LIBS = `$(PKG_CONFIG) --libs $(PKGS)` -DAMCPPFLAGS = -D_GNU_SOURCE +DAMCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_GNU_SOURCE DAMCFLAGS = -pedantic -Wall $(INCS) $(DAMCPPFLAGS) $(CPPFLAGS) $(CFLAGS) LDLIBS = $(LIBS) diff --git a/config.h b/config.h index 9aeb527..71bb4ec 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,6 @@ /* appearance */ -static const int showbar = 1; /* 0 means no bar */ -static const int topbar = 1; /* 0 means bottom bar */ +static int showbar = 1; /* 0 means no bar */ +static int topbar = 1; /* 0 means bottom bar */ static const char *fonts[] = { "monospace:size=10" }; static uint32_t colors[][3] = { /* fg bg */ diff --git a/dam.c b/dam.c index 937322f..2d414ab 100644 --- a/dam.c +++ b/dam.c @@ -1,15 +1,13 @@ /* See LICENSE file for copyright and license details. */ -#define _POSIX_C_SOURCE 200809L #include #include +#include #include #include #include -#include #include #include #include -#include #include #include #include @@ -106,6 +104,21 @@ die(const char *fmt, ...) exit(1); } +static void +parse_color(uint32_t *dest, const char *src) +{ + int len; + + if (src[0] == '#') + src++; + len = strlen(src); + if (len != 6 && len != 8) + die("bad color: %s", src); + + *dest = strtoul(src, NULL, 16); + if (len == 6) + *dest = (*dest << 8) | 0xFF; +} static void bar_deinit_surface(Bar *bar) @@ -696,9 +709,42 @@ cleanup(void) wl_display_disconnect(display); } +static void +usage(void) +{ + die("usage: dam [-st] [-f font] [-nb color] [-nf color] [-sb color] [-sf color]\n"); +} + int main(int argc, char *argv[]) { + int i; + + for (i = 1; i < argc; i++) { + /* these options take no arguments */ + if (!strcmp(argv[i], "-v")) { + puts("dam-"VERSION); + return EXIT_SUCCESS; + } else if (!strcmp(argv[i], "-s")) + showbar = !showbar; + else if (!strcmp(argv[i], "-t")) + topbar = !showbar; + else if (i + 1 == argc) + usage(); + else if (!strcmp(argv[i], "-f")) + fonts[0] = argv[++i]; + else if (!strcmp(argv[i], "-nb")) + parse_color(&colors[SchemeNorm][ColBg], argv[++i]); + else if (!strcmp(argv[i], "-nf")) + parse_color(&colors[SchemeNorm][ColFg], argv[++i]); + else if (!strcmp(argv[i], "-sb")) + parse_color(&colors[SchemeSel][ColBg], argv[++i]); + else if (!strcmp(argv[i], "-sf")) + parse_color(&colors[SchemeSel][ColFg], argv[++i]); + else + usage(); + } + setup(); run(); cleanup();