From 33e91e39690fee930c61166edd5423d3853d362a Mon Sep 17 00:00:00 2001 From: piotrruss Date: Sun, 7 Apr 2024 19:51:16 +0200 Subject: active opacity patch applied --- dwm.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'dwm.c') diff --git a/dwm.c b/dwm.c index 17fd55b..9f5d481 100644 --- a/dwm.c +++ b/dwm.c @@ -62,7 +62,7 @@ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { SchemeNorm, SchemeSel }; /* color schemes */ enum { NetSupported, NetWMName, NetWMState, NetWMCheck, NetWMFullscreen, NetActiveWindow, NetWMWindowType, - NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ + NetWMWindowTypeDialog, NetClientList, NetWMWindowsOpacity, NetLast }; /* EWMH atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ @@ -186,6 +186,7 @@ static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); static Client *nexttiled(Client *c); +static void opacity(Client *c, double opacity); static void pop(Client *c); static void propertynotify(XEvent *e); static void quit(const Arg *arg); @@ -213,6 +214,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 toggleopacity(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c, int setfocus); @@ -813,6 +815,7 @@ focus(Client *c) grabbuttons(c, 1); XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel); setfocus(c); + opacity(c, activeopacity); } else { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); XDeleteProperty(dpy, root, netatom[NetActiveWindow]); @@ -1219,6 +1222,18 @@ nexttiled(Client *c) return c; } +void +opacity(Client *c, double opacity) +{ + if(bUseOpacity && opacity > 0 && opacity < 1) { + unsigned long real_opacity[] = { opacity * 0xffffffff }; + XChangeProperty(dpy, c->win, netatom[NetWMWindowsOpacity], XA_CARDINAL, + 32, PropModeReplace, (unsigned char *)real_opacity, + 1); + } else + XDeleteProperty(dpy, c->win, netatom[NetWMWindowsOpacity]); +} + void pop(Client *c) { @@ -1599,6 +1614,7 @@ setup(void) netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); + netatom[NetWMWindowsOpacity] = XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False); /* init cursors */ cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); cursor[CurResize] = drw_cur_create(drw, XC_sizing); @@ -1755,6 +1771,14 @@ togglefloating(const Arg *arg) arrange(selmon); } +void +toggleopacity(const Arg *arg) { + bUseOpacity = !bUseOpacity; + for (Monitor* m = mons; m; m = m->next) + for (Client* c = m->clients; c; c = c->next) + opacity(c, (bUseOpacity && c != selmon->sel) ? inactiveopacity : activeopacity); +} + void toggletag(const Arg *arg) { @@ -1788,6 +1812,7 @@ unfocus(Client *c, int setfocus) if (!c) return; grabbuttons(c, 0); + opacity(c, inactiveopacity); XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); if (setfocus) { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); -- cgit v1.2.3