diff options
| author | auric <104602845+ihateamongus@users.noreply.github.com> | 2025-09-07 17:49:24 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-07 17:49:24 -0500 |
| commit | 055af7faa25e70b7f19bfdad8514ff684de6672d (patch) | |
| tree | 56962ec5459776bd69ffdb5019e9133d71b8baee /dmenu/dmenu.c | |
| parent | 417c5740bc4cd96e053b5725589fe3c4a835a231 (diff) | |
| parent | 2028ef39f0a65e44213acee2c2bda28006f462a1 (diff) | |
Merge pull request #5 from ihateamongus/codex/analyze-oldresources-folder-for-performance-ljz6ny
Add glass-style transparency and dynamic tags
Diffstat (limited to 'dmenu/dmenu.c')
| -rw-r--r-- | dmenu/dmenu.c | 50 |
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); |
