add default font, remove requirement for TAGSLEN with LENGTH macro

This commit is contained in:
kolunmi 2023-02-14 16:29:56 -07:00
parent 5c5948aaf9
commit 4a7a99fc5c
2 changed files with 17 additions and 18 deletions

View File

@ -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

26
dwlb.c
View File

@ -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;