summaryrefslogtreecommitdiff
path: root/dmenu
diff options
context:
space:
mode:
Diffstat (limited to 'dmenu')
-rw-r--r--dmenu/config.def.h8
-rw-r--r--dmenu/dmenu.c129
2 files changed, 94 insertions, 43 deletions
diff --git a/dmenu/config.def.h b/dmenu/config.def.h
index 1edb647..bc17068 100644
--- a/dmenu/config.def.h
+++ b/dmenu/config.def.h
@@ -8,10 +8,10 @@ static const char *fonts[] = {
};
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
static const char *colors[SchemeLast][2] = {
- /* fg bg */
- [SchemeNorm] = { "#bbbbbb", "#222222" },
- [SchemeSel] = { "#eeeeee", "#005577" },
- [SchemeOut] = { "#000000", "#00ffff" },
+ /* fg bg */
+ [SchemeNorm] = { "#dddddd", "#000000" },
+ [SchemeSel] = { "#ffffff", "#66ccff" },
+ [SchemeOut] = { "#000000", "#66ccff" },
};
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0;
diff --git a/dmenu/dmenu.c b/dmenu/dmenu.c
index fd49549..54a14e2 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,15 @@ static XIC xic;
static Drw *drw;
static Clr *scheme[SchemeLast];
+#include "../accent.h"
+static ColorShm *accentshm;
+static char accentcol[8] = "#005577";
+static const double opacity = 0.85;
+
+static void initaccent(void);
+static void updateaccent(void);
+static void setopacity(Window w, double opacity);
+
#include "config.h"
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
@@ -111,6 +125,18 @@ cleanup(void)
XCloseDisplay(dpy);
}
+static void
+updateaccent(void)
+{
+ if (readaccent(&accentshm, accentcol))
+ drw_clr_create(drw, &scheme[SchemeSel][ColBg], accentcol);
+}
+
+static void
+initaccent(void)
+{
+ updateaccent();
+}
static char *
cistrstr(const char *h, const char *n)
{
@@ -192,6 +218,15 @@ drawmenu(void)
}
static void
+setopacity(Window w, double op)
+{
+ unsigned long val = op * 0xffffffff;
+ XChangeProperty(dpy, w, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False),
+ XA_CARDINAL, 32, PropModeReplace,
+ (unsigned char *)&val, 1);
+}
+
+static void
grabfocus(void)
{
struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
@@ -575,39 +610,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
@@ -696,10 +745,11 @@ setup(void)
xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, win, XNFocusWindow, win, NULL);
- XMapRaised(dpy, win);
- if (embed) {
- XReparentWindow(dpy, win, parentwin, x, y);
- XSelectInput(dpy, parentwin, FocusChangeMask | SubstructureNotifyMask);
+ XMapRaised(dpy, win);
+ setopacity(win, opacity);
+ if (embed) {
+ XReparentWindow(dpy, win, parentwin, x, y);
+ XSelectInput(dpy, parentwin, FocusChangeMask | SubstructureNotifyMask);
if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) {
for (i = 0; i < du && dws[i] != win; ++i)
XSelectInput(dpy, dws[i], FocusChangeMask);
@@ -707,8 +757,9 @@ setup(void)
}
grabfocus();
}
- drw_resize(drw, mw, mh);
- drawmenu();
+ drw_resize(drw, mw, mh);
+ initaccent();
+ drawmenu();
}
static void