From b87cd2c058b61968988f0a15d153e6e9cf3b2e08 Mon Sep 17 00:00:00 2001 From: auric <104602845+ihateamongus@users.noreply.github.com> Date: Sun, 7 Sep 2025 16:33:30 -0500 Subject: Enable dynamic accent color in dmenu --- dmenu/dmenu.c | 129 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 35 deletions(-) (limited to 'dmenu/dmenu.c') diff --git a/dmenu/dmenu.c b/dmenu/dmenu.c index fd49549..0eb6d45 100644 --- a/dmenu/dmenu.c +++ b/dmenu/dmenu.c @@ -7,6 +7,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include @@ -52,6 +57,17 @@ static XIC xic; static Drw *drw; static Clr *scheme[SchemeLast]; +#define SHMNAME "/breathing_color_shm" +typedef struct { +uint32_t seq; +char color[8]; +} ColorShm; +static ColorShm *accentshm; +static char accentcol[8] = "#005577"; + +static void initaccent(void); +static void updateaccent(void); + #include "config.h" static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; @@ -111,6 +127,34 @@ cleanup(void) XCloseDisplay(dpy); } +static void +updateaccent(void) +{ +uint32_t s1, s2; + +if (!accentshm) +return; +do { +s1 = accentshm->seq; +memcpy(accentcol, accentshm->color, 8); +s2 = accentshm->seq; +} while (s1 != s2); +drw_clr_create(drw, &scheme[SchemeSel][ColBg], accentcol); +} + +static void +initaccent(void) +{ +int fd = shm_open(SHMNAME, O_RDONLY, 0); +if (fd >= 0) { +accentshm = mmap(NULL, sizeof(ColorShm), PROT_READ, + MAP_SHARED, fd, 0); +if (accentshm == MAP_FAILED) +accentshm = NULL; +close(fd); +} +updateaccent(); +} static char * cistrstr(const char *h, const char *n) { @@ -575,39 +619,53 @@ readstdin(void) static void run(void) { - XEvent ev; - - while (!XNextEvent(dpy, &ev)) { - if (XFilterEvent(&ev, win)) - continue; - switch(ev.type) { - case DestroyNotify: - if (ev.xdestroywindow.window != win) - break; - cleanup(); - exit(1); - case Expose: - if (ev.xexpose.count == 0) - drw_map(drw, win, 0, 0, mw, mh); - break; - case FocusIn: - /* regrab focus from parent window */ - if (ev.xfocus.window != win) - grabfocus(); - break; - case KeyPress: - keypress(&ev.xkey); - break; - case SelectionNotify: - if (ev.xselection.property == utf8) - paste(); - break; - case VisibilityNotify: - if (ev.xvisibility.state != VisibilityUnobscured) - XRaiseWindow(dpy, win); - break; - } - } + XEvent ev; + int xfd; + fd_set fds; + struct timeval tv; + + xfd = ConnectionNumber(dpy); + for (;;) { + FD_ZERO(&fds); + FD_SET(xfd, &fds); + tv.tv_sec = 0; + tv.tv_usec = 50000; + if (select(xfd + 1, &fds, NULL, NULL, &tv) > 0) { + while (XPending(dpy)) { + XNextEvent(dpy, &ev); + if (XFilterEvent(&ev, win)) + continue; + switch (ev.type) { + case DestroyNotify: + if (ev.xdestroywindow.window != win) + break; + cleanup(); + exit(1); + case Expose: + if (ev.xexpose.count == 0) + drw_map(drw, win, 0, 0, mw, mh); + break; + case FocusIn: + if (ev.xfocus.window != win) + grabfocus(); + break; + case KeyPress: + keypress(&ev.xkey); + break; + case SelectionNotify: + if (ev.xselection.property == utf8) + paste(); + break; + case VisibilityNotify: + if (ev.xvisibility.state != VisibilityUnobscured) + XRaiseWindow(dpy, win); + break; + } + } + } + updateaccent(); + drawmenu(); + } } static void @@ -707,8 +765,9 @@ setup(void) } grabfocus(); } - drw_resize(drw, mw, mh); - drawmenu(); + drw_resize(drw, mw, mh); + initaccent(); + drawmenu(); } static void -- cgit v1.2.3