s2dblocks

statusbar blocks for dwm
Log | Files | Refs

commit 08dff375521b915f8c11c948e3c0393ee370ca2f
parent f9c4388924a9c3d1bd113e7e2fa0db3c92a3543e
Author: hhvn <dev@hhvn.uk>
Date:   Thu, 14 Apr 2022 11:29:06 +0100

Date handler

Diffstat:
Mdwmbar.h | 4++++
Ahandlers/date.c | 32++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/dwmbar.h b/dwmbar.h @@ -5,6 +5,10 @@ #define ORANGE "#AA7700" #define GREEN "#00AA00" #define BRBG "#1A413A" +#define BLACK "#000000" +#define GREY "#888888" +#define YELLOW "#AAAA00" +#define WHITE "#CCCCCC" /* misc.c */ void bar_assert_(const char *aval, const char *file, int line, const char *func); diff --git a/handlers/date.c b/handlers/date.c @@ -0,0 +1,32 @@ +#include <stdio.h> +#include <ctype.h> +#include <time.h> +#include "../dwmbar.h" + +int +main(void) { + char buf[BUFSIZ], *p; + time_t t = time(NULL); + struct tm *tm = localtime(&t); + + strftime(buf, sizeof(buf), "%a", tm); + for (p = buf; *p; p++) + *p = toupper(*p); + if (tm->tm_wday == 0 || tm->tm_wday == 1) /* weekend */ + s2d_fg(GREEN); + else + s2d_fg(GREY); + s2d_print("%s", buf); + + strftime(buf, sizeof(buf), "%d/%m", tm); + if (tm->tm_mon >= 3 && tm->tm_mon <= 5) + s2d_fg(YELLOW); /* spring */ + else if (tm->tm_mon >= 6 && tm->tm_mon <= 7) + s2d_fg(GREEN); /* summer */ + else if (tm->tm_mon >= 8 && tm->tm_mon <= 11) + s2d_fg(ORANGE); /* autumn */ + else + s2d_fg(WHITE); /* winter */ + s2d_print("%s", buf); + s2d_finish(); +}