summaryrefslogtreecommitdiff
path: root/dmenu/dmenu.c
diff options
context:
space:
mode:
Diffstat (limited to 'dmenu/dmenu.c')
-rw-r--r--dmenu/dmenu.c50
1 files changed, 36 insertions, 14 deletions
diff --git a/dmenu/dmenu.c b/dmenu/dmenu.c
index 40153dc..066d20f 100644
--- a/dmenu/dmenu.c
+++ b/dmenu/dmenu.c
@@ -64,9 +64,12 @@ char color[8];
} ColorShm;
static ColorShm *accentshm;
static char accentcol[8] = "#005577";
+static const double opacity = 0.85;
static void initaccent(void);
static void updateaccent(void);
+static int openaccent(void);
+static void setopacity(Window w, double opacity);
#include "config.h"
@@ -127,13 +130,30 @@ cleanup(void)
XCloseDisplay(dpy);
}
+static int
+openaccent(void)
+{
+ int fd;
+ if (accentshm)
+ return 1;
+ if ((fd = shm_open(SHMNAME, O_RDONLY, 0)) < 0)
+ return 0;
+ accentshm = mmap(NULL, sizeof(ColorShm), PROT_READ, MAP_SHARED, fd, 0);
+ close(fd);
+ if (accentshm == MAP_FAILED) {
+ accentshm = NULL;
+ return 0;
+ }
+ return 1;
+}
+
static void
updateaccent(void)
{
uint32_t s1, s2;
char tmp[8];
- if (!accentshm)
+ if (!accentshm && !openaccent())
return;
do {
s1 = accentshm->seq;
@@ -149,15 +169,7 @@ updateaccent(void)
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();
+ updateaccent();
}
static char *
cistrstr(const char *h, const char *n)
@@ -240,6 +252,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 };
@@ -758,10 +779,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);