summaryrefslogtreecommitdiff
path: root/dmenu
diff options
context:
space:
mode:
Diffstat (limited to 'dmenu')
-rw-r--r--dmenu/dmenu.c129
1 files changed, 94 insertions, 35 deletions
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 <strings.h>
#include <time.h>
#include <unistd.h>
+#include <stdint.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/select.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
@@ -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