-
Notifications
You must be signed in to change notification settings - Fork 4
/
dwm-qubes.patch
282 lines (267 loc) · 10.9 KB
/
dwm-qubes.patch
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
diff --git a/config.mk b/config.mk
index 4eefb71..34ea872 100644
--- a/config.mk
+++ b/config.mk
@@ -22,7 +22,7 @@ FREETYPEINC = /usr/include/freetype2
# includes and libs
INCS = -I${X11INC} -I${FREETYPEINC}
-LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
+LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res
# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
diff --git a/config.def.h b/config.def.h
index 2d824d1..947facb 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,38 +1,42 @@
/* See LICENSE file for copyright and license details. */
/* appearance */
-static const unsigned int borderpx = 1; /* border pixel of windows */
+static const unsigned int borderpx = 2; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */
static const unsigned int systraypinning = 0; /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
static const unsigned int systrayspacing = 2; /* systray spacing */
static const int systraypinningfailfirst = 1; /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
-static const int showsystray = 1; /* 0 means no systray */
+static const int showsystray = 1; /* 0 means no systray */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
static const char *fonts[] = { "monospace:size=10" };
static const char dmenufont[] = "monospace:size=10";
+static const char col_dom0[] = "#3874D8";
+static const char col_white[] = "#FFFFFF";
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577";
-static const char *colors[][3] = {
- /* fg bg border */
- [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
- [SchemeSel] = { col_gray4, col_cyan, col_cyan },
+/* Dom0 Colors, tagbar and status bar */
+static const char *colors[][2] = {
+ /* fg bg */
+ [SchemeNorm] = { col_gray3, col_gray1 },
+ [SchemeSel] = { col_white, col_dom0 },
};
/* tagging */
-static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "Q" };
static const Rule rules[] = {
/* xprop(1):
* 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 monitor */
+ { "Qubes-qube-manager", NULL, NULL, NULL, 0, -1},
+ { "Pinentry-gtk-2", NULL, NULL, NULL, 1, -1}, // split-gpg
+ { "Zenity", NULL, NULL, NULL, 1, -1} // split-gpg
};
/* layout(s) */
@@ -59,13 +61,19 @@ /* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
/* commands */
-static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
-static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
-static const char *termcmd[] = { "st", NULL };
+static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
+static const char *dmenu_dom0[] = { "dmenu_run", "dom0", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_dom0, "-sf", col_white, NULL };
+static const char *dmenu_sensible[] = { "qubes-dmenu-sensible", "-a", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_dom0, "-sf", col_white, NULL };
+static const char *dmenu_vms[] = { "dmenu_run", "vms", "-a", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_dom0, "-sf", col_white, NULL };
+static const char *termcmd[] = { "qubes-run-sensible", "x-terminal-emulator", "urxvt", "rxvt", "termit", "terminator", "Eterm", "aterm", "gnome-terminal", "konsole", "roxterm", "xfce4-terminal", "termite", "lxterminal", "mate-terminal", "terminology", "st", "xterm", NULL};
+static const char *qubesmanagercmd[] = { "qubes-qube-manager", NULL };
static Key keys[] = {
/* modifier key function argument */
- { MODKEY, XK_p, spawn, {.v = dmenucmd } },
+ { MODKEY, XK_p, spawn, {.v = dmenu_sensible } },
+ { MODKEY|ShiftMask, XK_p, spawn, {.v = dmenu_vms} },
+ { MODKEY|ControlMask|ShiftMask, XK_p, spawn, {.v = dmenu_dom0} },
+ { MODKEY|ShiftMask, XK_m, spawn, {.v = qubesmanagercmd} },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
diff --git a/dwm.c b/dwm.c
index bb5929b..1943256 100644
--- a/dwm.c
+++ b/dwm.c
@@ -40,6 +40,8 @@
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
#include <X11/Xft/Xft.h>
+#include <X11/Xlib-xcb.h>
+#include <xcb/res.h>
#include "drw.h"
#include "util.h"
@@ -104,6 +104,8 @@ typedef struct Monitor Monitor;
typedef struct Client Client;
struct Client {
char name[256];
+ unsigned long vmcolor;
+ char *vmname;
float mina, maxa;
int x, y, w, h;
int oldx, oldy, oldw, oldh;
@@ -232,6 +234,8 @@ static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
static void seturgent(Client *c, int urg);
+static void setvmcolor(Client *c);
+static void setvmname(Client *c);
static void showhide(Client *c);
static void sigchld(int unused);
static void spawn(const Arg *arg);
@@ -267,6 +278,8 @@ static Drw *drw;
static Monitor *mons, *selmon;
static Window root, wmcheckwin;
+static xcb_connection_t *xcon;
+
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -824,8 +828,15 @@ drawbar(Monitor *m)
if ((w = m->ww - tw - stw - x) > bh) {
if (m->sel) {
+ unsigned long backPixel = scheme[SchemeSel][ColBg].pixel;
+ scheme[SchemeSel][ColBg].pixel = m->sel->vmcolor;
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
- drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
+ int size = strlen(m->sel->vmname) + strlen(m->sel->name) + 4;
+ char *content = ecalloc(size, 1);
+ snprintf(content, size, "[%s] %s", m->sel->vmname, m->sel->name);
+ drw_text(drw, x, 0, w, bh, lrpad / 2, content, 0);
+ scheme[SchemeSel][ColBg].pixel = backPixel;
+ free(content);
if (m->sel->isfloating)
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
} else {
@@ -892,7 +903,7 @@ focus(Client *c)
detachstack(c);
attachstack(c);
grabbuttons(c, 1);
- XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
+ XSetWindowBorder(dpy, c->win, c->vmcolor);
setfocus(c);
} else {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
@@ -1145,6 +1156,8 @@ manage(Window w, XWindowAttributes *wa)
c->h = c->oldh = wa->height;
c->oldbw = wa->border_width;
+ setvmname(c);
+ setvmcolor(c);
updatetitle(c);
if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
c->mon = t->mon;
@@ -1166,7 +1179,7 @@ manage(Window w, XWindowAttributes *wa)
wc.border_width = c->bw;
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
- XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
+ XSetWindowBorder(dpy, w, c->vmcolor);
configure(c); /* propagates border_width, if size doesn't change */
updatewindowtype(c);
updatesizehints(c);
@@ -1754,7 +1767,7 @@ setup(void)
/* init appearance */
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
for (i = 0; i < LENGTH(colors); i++)
- scheme[i] = drw_scm_create(drw, colors[i], 3);
+ scheme[i] = drw_scm_create(drw, colors[i], 2);
/* init system tray */
updatesystray();
/* init bars */
@@ -1797,6 +1810,67 @@ seturgent(Client *c, int urg)
XFree(wmh);
}
+void
+setvmcolor(Client *c)
+{
+ XftColor xft;
+ xcb_get_property_cookie_t qubes_label_cookie;
+
+ Atom id = XInternAtom(dpy, "_QUBES_LABEL_COLOR", True);
+ qubes_label_cookie = xcb_get_property(xcon, False, c->win, id, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT32_MAX);
+ xcb_get_property_reply_t *prop = xcb_get_property_reply(xcon, qubes_label_cookie, NULL);
+
+ if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
+ // dom0
+ drw_clr_create(drw, &xft, col_dom0);
+ } else {
+ // qube
+ const int len = xcb_get_property_value_length(prop);
+ unsigned char *qubes_label = (unsigned char*)xcb_get_property_value(prop);
+ if(len == 0) {
+ drw_clr_create(drw, &xft, col_dom0);
+ } else {
+ char color[8] = {0};
+ sprintf(color, "#%02x%02x%02x", (unsigned char)qubes_label[2], (unsigned char)qubes_label[1], (unsigned char)qubes_label[0]);
+ drw_clr_create(drw, &xft, color);
+ }
+ }
+
+ c->vmcolor = xft.pixel;
+ free(prop);
+}
+
+void
+setvmname(Client *c)
+{
+ Atom id = XInternAtom(dpy, "_QUBES_VMNAME", True);
+
+ if (id == None) {
+ c->vmname = ecalloc(5, 1);
+ strcpy(c->vmname, "Dom0");
+ } else {
+ Atom actual_type;
+ int actual_format;
+ unsigned long nitems;
+ unsigned long nbytes;
+ char *value = NULL;
+
+ XGetWindowProperty(dpy, c->win, id, 0, ~(0L), False, XA_STRING,
+ &actual_type, &actual_format, &nitems, &nbytes, (unsigned char **) &value);
+
+ if (nitems) {
+ c->vmname = ecalloc(nitems + 1, 1);
+ strncpy(c->vmname, value, nitems);
+ c->vmname[nitems] = '\0';
+ } else {
+ c->vmname = ecalloc(5, 1);
+ strcpy(c->vmname, "Dom0");
+ }
+
+ XFree(value);
+ }
+}
+
void
showhide(Client *c)
{
@@ -1826,7 +1900,7 @@ sigchld(int unused)
void
spawn(const Arg *arg)
{
- if (arg->v == dmenucmd)
+ if (arg->v == dmenu_dom0 || arg->v == dmenu_vms)
dmenumon[0] = '0' + selmon->num;
if (fork() == 0) {
if (dpy)
@@ -1950,7 +2024,7 @@ unfocus(Client *c, int setfocus)
if (!c)
return;
grabbuttons(c, 0);
- XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
+ XSetWindowBorder(dpy, c->win, c->vmcolor);
if (setfocus) {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
@@ -2131,6 +2313,8 @@ main(int argc, char *argv[])
fputs("warning: no locale support\n", stderr);
if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display");
+ if (!(xcon = XGetXCBConnection(dpy)))
+ die("dwm: cannot get xcb connection\n");
checkotherwm();
setup();
#ifdef __OpenBSD__