-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwm-clientopacity-20220612-d3f93c7.diff
166 lines (158 loc) · 5.91 KB
/
dwm-clientopacity-20220612-d3f93c7.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
From d59a5a5409e4078c2c1b5ead786e1312d431c9a8 Mon Sep 17 00:00:00 2001
From: blatzfab <fabian.blatz@hansgrohe.com>
Date: Sun, 12 Jun 2022 18:42:28 +0200
Subject: [PATCH] [PATCH] adds opacity on a per client basis
---
config.def.h | 10 +++++++---
dwm.c | 37 ++++++++++++++++++++++++++++++++++++-
2 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/config.def.h b/config.def.h
index a2ac963..4b6903c 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";
@@ -26,9 +27,10 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
- /* class instance title tags mask isfloating monitor */
- { "Gimp", NULL, NULL, 0, 1, -1 },
- { "Firefox", NULL, NULL, 1 << 8, 0, -1 },
+ /* class instance title tags mask isfloating opacity monitor */
+ { "Gimp", NULL, NULL, 0, 1, 1.0, -1 },
+ { "Firefox", NULL, NULL, 1 << 8, 0, 1.0, -1 },
+ { "St", NULL, NULL, 0, 0, defaultopacity, -1},
};
/* layout(s) */
@@ -85,6 +87,8 @@ static Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_KP_Add, changeopacity, {.f = +0.1}},
+ { MODKEY|ShiftMask, XK_KP_Subtract, changeopacity, {.f = -0.1}},
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
diff --git a/dwm.c b/dwm.c
index 5646a5c..591dff9 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 */
@@ -95,6 +95,7 @@ struct Client {
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
Client *next;
Client *snext;
+ double opacity;
Monitor *mon;
Window win;
};
@@ -138,6 +139,7 @@ typedef struct {
const char *title;
unsigned int tags;
int isfloating;
+ double opacity;
int monitor;
} Rule;
@@ -149,6 +151,7 @@ static void arrangemon(Monitor *m);
static void attach(Client *c);
static void attachstack(Client *c);
static void buttonpress(XEvent *e);
+static void changeopacity(const Arg *arg);
static void checkotherwm(void);
static void cleanup(void);
static void cleanupmon(Monitor *mon);
@@ -185,6 +188,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 *);
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
@@ -288,6 +292,7 @@ applyrules(Client *c)
/* rule matching */
c->isfloating = 0;
c->tags = 0;
+ c->opacity = defaultopacity;
XGetClassHint(dpy, c->win, &ch);
class = ch.res_class ? ch.res_class : broken;
instance = ch.res_name ? ch.res_name : broken;
@@ -300,6 +305,7 @@ applyrules(Client *c)
{
c->isfloating = r->isfloating;
c->tags |= r->tags;
+ c->opacity = r->opacity;
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
c->mon = m;
@@ -458,6 +464,21 @@ buttonpress(XEvent *e)
buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
}
+void
+changeopacity(const Arg *arg)
+{
+ if (!selmon->sel)
+ return;
+ selmon->sel->opacity+=arg->f;
+ if(selmon->sel->opacity > 1.0)
+ selmon->sel->opacity = 1.0;
+
+ if(selmon->sel->opacity < 0)
+ selmon->sel->opacity = 0;
+
+ opacity(selmon->sel, selmon->sel->opacity);
+}
+
void
checkotherwm(void)
{
@@ -1045,6 +1066,7 @@ manage(Window w, XWindowAttributes *wa)
c->mon = selmon;
applyrules(c);
}
+ opacity(c, c->opacity);
if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw)
c->x = c->mon->mx + c->mon->mw - WIDTH(c);
@@ -1206,6 +1228,18 @@ nexttiled(Client *c)
return c;
}
+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
pop(Client *c)
{
@@ -1569,6 +1603,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);
--
2.36.1