From c8d0c2af35d27c03efa22d0de8b5a65fcd773b18 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Thu, 15 Oct 2020 20:13:18 +0530 Subject: [PATCH] Enable default transparency --- config.def.h | 4 ++++ dwm.c | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index ee97cf1..0d9e747 100644 --- a/config.def.h +++ b/config.def.h @@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ +static const double defaultopacity = 0.75; static const char *fonts[] = { "monospace:size=10" }; static const char dmenufont[] = "monospace:size=10"; static const char col_gray1[] = "#222222"; @@ -69,6 +70,9 @@ static Key keys[] = { /* modifier key function argument */ { MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, + { MODKEY|ShiftMask, XK_s, spawn, SHCMD("transset-df -a --dec .1") }, + { MODKEY|ShiftMask, XK_d, spawn, SHCMD("transset-df -a --inc .1") }, + { MODKEY|ShiftMask, XK_f, spawn, SHCMD("transset-df -a .75") }, { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, diff --git a/dwm.c b/dwm.c index 9f1b668..512d63b 100644 --- a/dwm.c +++ b/dwm.c @@ -69,7 +69,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 */ @@ -174,6 +174,7 @@ static void drawbar(Monitor *m); static void drawbars(void); static void enternotify(XEvent *e); static void expose(XEvent *e); +static void opacity(Client *c, double opacity); static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); @@ -849,6 +850,18 @@ expose(XEvent *e) drawbar(m); } +void +opacity(Client *c, double opacity) +{ + if(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 focus(Client *c) { @@ -1100,6 +1113,7 @@ manage(Window w, XWindowAttributes *wa) c->oldbw = wa->border_width; updatetitle(c); + opacity(c, defaultopacity); if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { c->mon = t->mon; c->tags = t->tags; @@ -1641,6 +1655,7 @@ setup(void) netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False); netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); + netatom[NetWMWindowsOpacity] = XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False); 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);