diff options
| author | auric <104602845+ihateamongus@users.noreply.github.com> | 2025-09-07 17:44:04 -0500 |
|---|---|---|
| committer | auric <104602845+ihateamongus@users.noreply.github.com> | 2025-09-07 17:44:04 -0500 |
| commit | 1a4ac1fea3f629a08481a9b8b43ea1fc38461445 (patch) | |
| tree | 56962ec5459776bd69ffdb5019e9133d71b8baee /dwm/dwm.c | |
| parent | b59b8b8e5d16af7f0daccb280a4991e3fe428e41 (diff) | |
Add Aero transparency and dynamic tags
Diffstat (limited to 'dwm/dwm.c')
| -rw-r--r-- | dwm/dwm.c | 196 |
1 files changed, 162 insertions, 34 deletions
@@ -30,6 +30,11 @@ #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> +#include <stdint.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/select.h> #include <X11/cursorfont.h> #include <X11/keysym.h> #include <X11/Xatom.h> @@ -118,6 +123,7 @@ struct Monitor { int by; /* bar geometry */ int mx, my, mw, mh; /* screen size */ int wx, wy, ww, wh; /* window area */ + int gappx; /* gaps between windows */ unsigned int seltags; unsigned int sellt; unsigned int tagset[2]; @@ -199,9 +205,13 @@ static void sendmon(Client *c, Monitor *m); static void setclientstate(Client *c, long state); static void setfocus(Client *c); static void setfullscreen(Client *c, int fullscreen); +static void setgaps(const Arg *arg); static void setlayout(const Arg *arg); static void setmfact(const Arg *arg); +static void setopacity(Window w, double opacity); static void setup(void); +static void initaccent(void); +static void updateaccent(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); static void spawn(const Arg *arg); @@ -210,6 +220,7 @@ static void tagmon(const Arg *arg); static void tile(Monitor *m); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); +static void togglescratch(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c, int setfocus); @@ -270,6 +281,19 @@ static Window root, wmcheckwin; /* configuration, allows nested code to access above variables */ #include "config.h" +static unsigned int scratchtag = 1 << LENGTH(tags); + +#define SHMNAME "/breathing_color_shm" +typedef struct { + uint32_t magic; + uint32_t version; + volatile uint32_t seq; + char color[8]; +} ColorShm; + +static ColorShm *accentshm; +static char accentcol[8] = "#005577"; + /* compile-time check if all tags fit into an unsigned int bit array. */ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; @@ -640,12 +664,46 @@ createmon(void) m->nmaster = nmaster; m->showbar = showbar; m->topbar = topbar; + m->gappx = gappx; m->lt[0] = &layouts[0]; m->lt[1] = &layouts[1 % LENGTH(layouts)]; strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); return m; } +static void +updateaccent(void) { + if (!accentshm) + return; + uint32_t s1, s2; + char tmp[8]; + do { + s1 = accentshm->seq; + memcpy(tmp, accentshm->color, 8); + s2 = accentshm->seq; + } while (s1 != s2); + if (tmp[0] != '#') + return; + memcpy(accentcol, tmp, 8); + drw_clr_create(drw, &scheme[SchemeSel][ColBg], accentcol); + drw_clr_create(drw, &scheme[SchemeSel][ColBorder], accentcol); + for (Monitor *m = mons; m; m = m->next) + if (m->sel) + XSetWindowBorder(dpy, m->sel->win, scheme[SchemeSel][ColBorder].pixel); +} + +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); + close(fd); + if (accentshm == MAP_FAILED) + accentshm = NULL; + } + updateaccent(); +} + void destroynotify(XEvent *e) { @@ -697,7 +755,7 @@ dirtomon(int dir) void drawbar(Monitor *m) { - int x, w, tw = 0; + int x, w, tw = 0; int boxs = drw->fonts->h / 9; int boxw = drw->fonts->h / 6 + 2; unsigned int i, occ = 0, urg = 0; @@ -719,16 +777,18 @@ drawbar(Monitor *m) urg |= c->tags; } x = 0; - for (i = 0; i < LENGTH(tags); i++) { - w = TEXTW(tags[i]); - drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); - if (occ & 1 << i) - drw_rect(drw, x + boxs, boxs, boxw, boxw, - m == selmon && selmon->sel && selmon->sel->tags & 1 << i, - urg & 1 << i); - x += w; - } + for (i = 0; i < LENGTH(tags); i++) { + if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) + continue; + w = TEXTW(tags[i]); + drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); + drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); + if (occ & 1 << i) + drw_rect(drw, x + boxs, boxs, boxw, boxw, + m == selmon && selmon->sel && selmon->sel->tags & 1 << i, + urg & 1 << i); + x += w; + } w = TEXTW(m->ltsymbol); drw_setscheme(drw, scheme[SchemeNorm]); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); @@ -750,10 +810,11 @@ drawbar(Monitor *m) void drawbars(void) { - Monitor *m; + Monitor *m; - for (m = mons; m; m = m->next) - drawbar(m); + updateaccent(); + for (m = mons; m; m = m->next) + drawbar(m); } void @@ -1060,6 +1121,14 @@ manage(Window w, XWindowAttributes *wa) c->y = MAX(c->y, c->mon->wy); c->bw = borderpx; + selmon->tagset[selmon->seltags] &= ~scratchtag; + if (!strcmp(c->name, scratchpadname)) { + c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag; + c->isfloating = True; + c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); + c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); + } + wc.border_width = c->bw; XConfigureWindow(dpy, w, CWBorderWidth, &wc); XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); @@ -1381,12 +1450,27 @@ restack(Monitor *m) void run(void) { - XEvent ev; - /* main event loop */ - XSync(dpy, False); - while (running && !XNextEvent(dpy, &ev)) - if (handler[ev.type]) - handler[ev.type](&ev); /* call handler */ + XEvent ev; + int xfd; + fd_set fds; + struct timeval tv; + + XSync(dpy, False); + xfd = ConnectionNumber(dpy); + while (running) { + 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 (handler[ev.type]) + handler[ev.type](&ev); /* call handler */ + } + } + drawbars(); + } } void @@ -1507,6 +1591,16 @@ setfullscreen(Client *c, int fullscreen) } void +setgaps(const Arg *arg) +{ + if ((arg->i == 0) || (selmon->gappx + arg->i < 0)) + selmon->gappx = 0; + else + selmon->gappx += arg->i; + arrange(selmon); +} + +void setlayout(const Arg *arg) { if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) @@ -1535,6 +1629,15 @@ setmfact(const Arg *arg) arrange(selmon); } +static void +setopacity(Window w, double opacity) +{ + unsigned long val = opacity * 0xffffffff; + XChangeProperty(dpy, w, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False), + XA_CARDINAL, 32, PropModeReplace, + (unsigned char *)&val, 1); +} + void setup(void) { @@ -1586,6 +1689,7 @@ setup(void) scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); for (i = 0; i < LENGTH(colors); i++) scheme[i] = drw_scm_create(drw, colors[i], 3); + initaccent(); /* init bars */ updatebars(); updatestatus(); @@ -1650,6 +1754,7 @@ spawn(const Arg *arg) if (arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; + selmon->tagset[selmon->seltags] &= ~scratchtag; if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); @@ -1696,18 +1801,18 @@ tile(Monitor *m) if (n > m->nmaster) mw = m->nmaster ? m->ww * m->mfact : 0; else - mw = m->ww; - for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) - if (i < m->nmaster) { - h = (m->wh - my) / (MIN(n, m->nmaster) - i); - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); - if (my + HEIGHT(c) < m->wh) - my += HEIGHT(c); + mw = m->ww - m->gappx; + for (i = 0, my = ty = m->gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + if (i < m->nmaster) { + h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gappx; + resize(c, m->wx + m->gappx, m->wy + my, mw - (2*c->bw) - m->gappx, h - (2*c->bw), 0); + if (my + HEIGHT(c) + m->gappx < m->wh) + my += HEIGHT(c) + m->gappx; } else { - h = (m->wh - ty) / (n - i); - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); - if (ty + HEIGHT(c) < m->wh) - ty += HEIGHT(c); + h = (m->wh - ty) / (n - i) - m->gappx; + resize(c, m->wx + mw + m->gappx, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gappx, h - (2*c->bw), 0); + if (ty + HEIGHT(c) + m->gappx < m->wh) + ty += HEIGHT(c) + m->gappx; } } @@ -1735,6 +1840,28 @@ togglefloating(const Arg *arg) } void +togglescratch(const Arg *arg) +{ + Client *c; + unsigned int found = 0; + + for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); + if (found) { + unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; + if (newtagset) { + selmon->tagset[selmon->seltags] = newtagset; + focus(NULL); + arrange(selmon); + } + if (ISVISIBLE(c)) { + focus(c); + restack(selmon); + } + } else + spawn(arg); +} + +void toggletag(const Arg *arg) { unsigned int newtags; @@ -1831,9 +1958,10 @@ updatebars(void) CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); - XMapRaised(dpy, m->barwin); - XSetClassHint(dpy, m->barwin, &ch); - } + XMapRaised(dpy, m->barwin); + setopacity(m->barwin, baropacity); + XSetClassHint(dpy, m->barwin, &ch); + } } void |
