From b333822f244fde91226eb505e70869779e11dd15 Mon Sep 17 00:00:00 2001 From: podit Date: Tue, 14 Feb 2023 00:16:13 +0000 Subject: [PATCH 1/5] moved all configurable defaults to separate header --- .gitignore | 1 + Makefile | 5 ++++- config.def.h | 17 +++++++++++++++++ dwlb.c | 13 ++----------- 4 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 config.def.h diff --git a/.gitignore b/.gitignore index 4bc8107..9d5528d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ dwlb +config.h *.o wlr-layer-shell-unstable-v1-protocol.c wlr-layer-shell-unstable-v1-protocol.h diff --git a/Makefile b/Makefile index a4aca0b..06bafc1 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-format-truncation -g all: $(BINS) +config.h: + cp config.def.h $@ + clean: $(RM) $(BINS) $(addsuffix .o,$(BINS)) @@ -44,7 +47,7 @@ wlr-layer-shell-unstable-v1-protocol.c: wlr-layer-shell-unstable-v1-protocol.o: wlr-layer-shell-unstable-v1-protocol.h -dwlb.o: utf8.h xdg-shell-protocol.h xdg-output-unstable-v1-protocol.h wlr-layer-shell-unstable-v1-protocol.h +dwlb.o: utf8.h config.h xdg-shell-protocol.h xdg-output-unstable-v1-protocol.h wlr-layer-shell-unstable-v1-protocol.h # Protocol dependencies dwlb: xdg-shell-protocol.o xdg-output-unstable-v1-protocol.o wlr-layer-shell-unstable-v1-protocol.o diff --git a/config.def.h b/config.def.h new file mode 100644 index 0000000..53119b4 --- /dev/null +++ b/config.def.h @@ -0,0 +1,17 @@ +// bar properties +static bool hidden = false; +static bool bottom = false; +static bool hide_vacant = false; + +// define the number of tags and the tag names, if the number of tags is +// greater than TAGSLEN they will not be displayed, each tag also needs a name +#define TAGSLEN 9 +static char *tags[TAGSLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; + +// set colors for bar +// TODO: explain the formatting? or at least how a hex color code would be translated +static pixman_color_t activecolor = { .red = 0x0000, .green = 0x5555, .blue = 0x7777, .alpha = 0xffff, }; +static pixman_color_t inactivecolor = { .red = 0x2222, .green = 0x2222, .blue = 0x2222, .alpha = 0xffff, }; +static pixman_color_t textcolor = { .red = 0xeeee, .green = 0xeeee, .blue = 0xeeee, .alpha = 0xffff, }; +static pixman_color_t urgbgcolor = { .red = 0xeeee, .green = 0xeeee, .blue = 0xeeee, .alpha = 0xffff, }; +static pixman_color_t urgtextcolor = { .red = 2222, .green = 0x2222, .blue = 0x2222, .alpha = 0xffff, }; diff --git a/dwlb.c b/dwlb.c index 091fcb9..5d21c1f 100644 --- a/dwlb.c +++ b/dwlb.c @@ -23,6 +23,8 @@ #include "xdg-output-unstable-v1-protocol.h" #include "wlr-layer-shell-unstable-v1-protocol.h" +#include "config.h" + #define DIE(fmt, ...) \ do { \ fprintf(stderr, fmt "\n", ##__VA_ARGS__); \ @@ -124,22 +126,11 @@ static Bar *bars = NULL; static uint32_t height; static uint32_t textpadding; -static bool hidden = false; -static bool bottom = false; static bool run_display = true; static bool ready = false; -static bool hide_vacant = false; - -#define TAGSLEN 9 -static char *tags[TAGSLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; static struct fcft_font *font; -static pixman_color_t activecolor = { .red = 0x0000, .green = 0x5555, .blue = 0x7777, .alpha = 0xffff, }; -static pixman_color_t inactivecolor = { .red = 0x2222, .green = 0x2222, .blue = 0x2222, .alpha = 0xffff, }; -static pixman_color_t textcolor = { .red = 0xeeee, .green = 0xeeee, .blue = 0xeeee, .alpha = 0xffff, }; -static pixman_color_t urgbgcolor = { .red = 0xeeee, .green = 0xeeee, .blue = 0xeeee, .alpha = 0xffff, }; -static pixman_color_t urgtextcolor = { .red = 2222, .green = 0x2222, .blue = 0x2222, .alpha = 0xffff, }; static void From a72b8228b428588db111c71c99d91ef8542c88ea Mon Sep 17 00:00:00 2001 From: podit Date: Tue, 14 Feb 2023 01:00:22 +0000 Subject: [PATCH 2/5] added todos to not yet configurable settings --- dwlb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dwlb.c b/dwlb.c index 5d21c1f..4eafc3f 100644 --- a/dwlb.c +++ b/dwlb.c @@ -124,12 +124,15 @@ static struct zxdg_output_manager_v1 *output_manager; static Bar *bars = NULL; +// TODO: it would be nice to have these be configurable, they seem to be set by the font currently? static uint32_t height; static uint32_t textpadding; +// TODO: these seem to be operational, unless i have misunderstood their use? static bool run_display = true; static bool ready = false; +// TODO: ideally there would be a default font, if there is i can't see where it is set static struct fcft_font *font; From de0569da9dfdace48fc504f9ad6c9ba0eba16aad Mon Sep 17 00:00:00 2001 From: ktyl Date: Tue, 14 Feb 2023 22:55:53 +0000 Subject: [PATCH 3/5] disambiguate 16bit color formatting --- config.def.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.def.h b/config.def.h index 53119b4..8a27b30 100644 --- a/config.def.h +++ b/config.def.h @@ -8,8 +8,9 @@ static bool hide_vacant = false; #define TAGSLEN 9 static char *tags[TAGSLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; -// set colors for bar -// TODO: explain the formatting? or at least how a hex color code would be translated +// set 16-bit colors for bar +// 8-bit color can be converted to 16-bit color by simply duplicating values e.g +// 0x55 -> 0x5555, 0xf1 -> 0xf1f1 static pixman_color_t activecolor = { .red = 0x0000, .green = 0x5555, .blue = 0x7777, .alpha = 0xffff, }; static pixman_color_t inactivecolor = { .red = 0x2222, .green = 0x2222, .blue = 0x2222, .alpha = 0xffff, }; static pixman_color_t textcolor = { .red = 0xeeee, .green = 0xeeee, .blue = 0xeeee, .alpha = 0xffff, }; From 5c5948aaf9d665989713a31d6ab6015d10e2338d Mon Sep 17 00:00:00 2001 From: podit Date: Tue, 14 Feb 2023 23:09:43 +0000 Subject: [PATCH 4/5] fix typo in urgtextcolor --- config.def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 8a27b30..d554597 100644 --- a/config.def.h +++ b/config.def.h @@ -15,4 +15,4 @@ static pixman_color_t activecolor = { .red = 0x0000, .green = 0x5555, .blue = 0x static pixman_color_t inactivecolor = { .red = 0x2222, .green = 0x2222, .blue = 0x2222, .alpha = 0xffff, }; static pixman_color_t textcolor = { .red = 0xeeee, .green = 0xeeee, .blue = 0xeeee, .alpha = 0xffff, }; static pixman_color_t urgbgcolor = { .red = 0xeeee, .green = 0xeeee, .blue = 0xeeee, .alpha = 0xffff, }; -static pixman_color_t urgtextcolor = { .red = 2222, .green = 0x2222, .blue = 0x2222, .alpha = 0xffff, }; +static pixman_color_t urgtextcolor = { .red = 0x2222, .green = 0x2222, .blue = 0x2222, .alpha = 0xffff, }; From 4a7a99fc5c5e128d83447efa1d4d5924b3c3d02f Mon Sep 17 00:00:00 2001 From: kolunmi Date: Tue, 14 Feb 2023 16:29:56 -0700 Subject: [PATCH 5/5] add default font, remove requirement for TAGSLEN with LENGTH macro --- config.def.h | 9 +++++---- dwlb.c | 26 ++++++++++++-------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/config.def.h b/config.def.h index d554597..683adf0 100644 --- a/config.def.h +++ b/config.def.h @@ -3,10 +3,11 @@ static bool hidden = false; static bool bottom = false; static bool hide_vacant = false; -// define the number of tags and the tag names, if the number of tags is -// greater than TAGSLEN they will not be displayed, each tag also needs a name -#define TAGSLEN 9 -static char *tags[TAGSLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; +// font +static char *fontstr = "monospace:size=10"; + +// tag names +static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; // set 16-bit colors for bar // 8-bit color can be converted to 16-bit color by simply duplicating values e.g diff --git a/dwlb.c b/dwlb.c index 4eafc3f..8e946a3 100644 --- a/dwlb.c +++ b/dwlb.c @@ -23,8 +23,6 @@ #include "xdg-output-unstable-v1-protocol.h" #include "wlr-layer-shell-unstable-v1-protocol.h" -#include "config.h" - #define DIE(fmt, ...) \ do { \ fprintf(stderr, fmt "\n", ##__VA_ARGS__); \ @@ -50,6 +48,8 @@ ((a) < (b) ? (a) : (b)) #define MAX(a, b) \ ((a) > (b) ? (a) : (b)) +#define LENGTH(X) \ + (sizeof X / sizeof X[0]) #define PROGRAM "dwlb" #define VERSION "0.1" @@ -65,7 +65,7 @@ " -inactive-color [COLOR] specify color to indicate inactive tags or monitors\n" \ " -urg-text-color [COLOR] specify text color on urgent tags\n" \ " -urg-bg-color [COLOR] specify color of urgent tags\n" \ - " -tags [TAG 1]...[TAG 9] specify custom tag names\n" \ + " -tags [FIRST TAG]...[LAST TAG] specify custom tag names\n" \ "Commands\n" \ " -status [OUTPUT] [TEXT] set status text\n" \ " -show [OUTPUT] show bar\n" \ @@ -122,19 +122,18 @@ static struct wl_shm *shm; static struct zwlr_layer_shell_v1 *layer_shell; static struct zxdg_output_manager_v1 *output_manager; +static struct fcft_font *font; + static Bar *bars = NULL; -// TODO: it would be nice to have these be configurable, they seem to be set by the font currently? +// TODO: it would be nice to have these be configurable, currently set by font static uint32_t height; static uint32_t textpadding; -// TODO: these seem to be operational, unless i have misunderstood their use? static bool run_display = true; static bool ready = false; -// TODO: ideally there would be a default font, if there is i can't see where it is set -static struct fcft_font *font; - +#include "config.h" static void wl_buffer_release(void *data, struct wl_buffer *wl_buffer) @@ -393,7 +392,7 @@ draw_frame(Bar *b) uint32_t boxs = font->height / 9; uint32_t boxw = font->height / 6 + 2; - for (uint32_t i = 0; i < TAGSLEN; i++) { + for (uint32_t i = 0; i < LENGTH(tags); i++) { bool active = b->mtags & 1 << i; bool occupied = b->ctags & 1 << i; bool urgent = b->urg & 1 << i; @@ -979,7 +978,6 @@ sig_handler(int sig) int main(int argc, char **argv) { - char *fontstr = ""; char *xdgruntimedir; struct sockaddr_un sock_address; Bar *b, *t; @@ -1066,11 +1064,11 @@ main(int argc, char **argv) if (parse_color(argv[i], &urgbgcolor) == -1) DIE("malformed color string"); } else if (!strcmp(argv[i], "-tags")) { - if (i + TAGSLEN >= argc) - DIE("Option -tags requires %i arguments", TAGSLEN); - for (int j = 0; j < TAGSLEN; j++) + if (i + (int)LENGTH(tags) >= argc) + DIE("Option -tags requires %lu arguments", LENGTH(tags)); + for (int j = 0; j < (int)LENGTH(tags); j++) tags[j] = argv[i + 1 + j]; - i += TAGSLEN; + i += LENGTH(tags); } else if (!strcmp(argv[i], "-v")) { fprintf(stderr, PROGRAM " " VERSION "\n"); return 0;