| 6 |
6 |
|
* events about window (dis-)appearance. Only one X connection at a time is |
| 7 |
7 |
|
* allowed to select for this event mask. |
| 8 |
8 |
|
* |
| 9 |
|
- |
* Calls to fetch an X event from the event queue are blocking. Due reading |
| 10 |
|
- |
* status text from standard input, a select()-driven main loop has been |
| 11 |
|
- |
* implemented which selects for reads on the X connection and STDIN_FILENO to |
| 12 |
|
- |
* handle all data smoothly. The event handlers of dwm are organized in an |
| 13 |
|
- |
* array which is accessed whenever a new event has been fetched. This allows |
| 14 |
|
- |
* event dispatching in O(1) time. |
|
9 |
+ |
* The event handlers of dwm are organized in an array which is accessed |
|
10 |
+ |
* whenever a new event has been fetched. This allows event dispatching |
|
11 |
+ |
* in O(1) time. |
| 15 |
12 |
|
* |
| 16 |
13 |
|
* Each child of the root window is called a client, except windows which have |
| 17 |
14 |
|
* set the override_redirect flag. Clients are organized in a global |
|
| 30 |
27 |
|
#include <stdlib.h> |
| 31 |
28 |
|
#include <string.h> |
| 32 |
29 |
|
#include <unistd.h> |
| 33 |
|
- |
#include <sys/select.h> |
| 34 |
30 |
|
#include <sys/types.h> |
| 35 |
31 |
|
#include <sys/wait.h> |
| 36 |
32 |
|
#include <X11/cursorfont.h> |
|
| 196 |
192 |
|
static void updategeom(void); |
| 197 |
193 |
|
static void updatenumlockmask(void); |
| 198 |
194 |
|
static void updatesizehints(Client *c); |
|
195 |
+ |
static void updatestatus(void); |
| 199 |
196 |
|
static void updatetitle(Client *c); |
| 200 |
197 |
|
static void updatewmhints(Client *c); |
| 201 |
198 |
|
static void view(const Arg *arg); |
|
| 998 |
995 |
|
Window trans; |
| 999 |
996 |
|
XPropertyEvent *ev = &e->xproperty; |
| 1000 |
997 |
|
|
| 1001 |
|
- |
if(ev->state == PropertyDelete) |
|
998 |
+ |
if((ev->window == root) && (ev->atom = XA_WM_NAME)) |
|
999 |
+ |
updatestatus(); |
|
1000 |
+ |
else if(ev->state == PropertyDelete) |
| 1002 |
1001 |
|
return; /* ignore */ |
| 1003 |
|
- |
if((c = getclient(ev->window))) { |
|
1002 |
+ |
else if((c = getclient(ev->window))) { |
| 1004 |
1003 |
|
switch (ev->atom) { |
| 1005 |
1004 |
|
default: break; |
| 1006 |
1005 |
|
case XA_WM_TRANSIENT_FOR: |
|
| 1026 |
1025 |
|
|
| 1027 |
1026 |
|
void |
| 1028 |
1027 |
|
quit(const Arg *arg) { |
| 1029 |
|
- |
readin = running = False; |
|
1028 |
+ |
running = False; |
| 1030 |
1029 |
|
} |
| 1031 |
1030 |
|
|
| 1032 |
1031 |
|
void |
|
| 1180 |
1179 |
|
|
| 1181 |
1180 |
|
void |
| 1182 |
1181 |
|
run(void) { |
| 1183 |
|
- |
char *p; |
| 1184 |
|
- |
char sbuf[sizeof stext]; |
| 1185 |
|
- |
fd_set rd; |
| 1186 |
|
- |
int r, xfd; |
| 1187 |
|
- |
unsigned int len, offset; |
| 1188 |
1182 |
|
XEvent ev; |
| 1189 |
1183 |
|
|
| 1190 |
|
- |
/* main event loop, also reads status text from stdin */ |
|
1184 |
+ |
/* main event loop */ |
| 1191 |
1185 |
|
XSync(dpy, False); |
| 1192 |
|
- |
xfd = ConnectionNumber(dpy); |
| 1193 |
|
- |
offset = 0; |
| 1194 |
|
- |
len = sizeof stext - 1; |
| 1195 |
|
- |
sbuf[len] = stext[len] = '\0'; /* 0-terminator is never touched */ |
| 1196 |
|
- |
while(running) { |
| 1197 |
|
- |
FD_ZERO(&rd); |
| 1198 |
|
- |
if(readin) |
| 1199 |
|
- |
FD_SET(STDIN_FILENO, &rd); |
| 1200 |
|
- |
FD_SET(xfd, &rd); |
| 1201 |
|
- |
if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) { |
| 1202 |
|
- |
if(errno == EINTR) |
| 1203 |
|
- |
continue; |
| 1204 |
|
- |
die("select failed\n"); |
| 1205 |
|
- |
} |
| 1206 |
|
- |
if(FD_ISSET(STDIN_FILENO, &rd)) { |
| 1207 |
|
- |
switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) { |
| 1208 |
|
- |
case -1: |
| 1209 |
|
- |
strncpy(stext, strerror(errno), len); |
| 1210 |
|
- |
readin = False; |
| 1211 |
|
- |
break; |
| 1212 |
|
- |
case 0: |
| 1213 |
|
- |
strncpy(stext, "EOF", 4); |
| 1214 |
|
- |
readin = False; |
| 1215 |
|
- |
break; |
| 1216 |
|
- |
default: |
| 1217 |
|
- |
for(p = sbuf + offset; r > 0; p++, r--, offset++) |
| 1218 |
|
- |
if(*p == '\n' || *p == '\0') { |
| 1219 |
|
- |
*p = '\0'; |
| 1220 |
|
- |
strncpy(stext, sbuf, len); |
| 1221 |
|
- |
p += r - 1; /* p is sbuf + offset + r - 1 */ |
| 1222 |
|
- |
for(r = 0; *(p - r) && *(p - r) != '\n'; r++); |
| 1223 |
|
- |
offset = r; |
| 1224 |
|
- |
if(r) |
| 1225 |
|
- |
memmove(sbuf, p - r + 1, r); |
| 1226 |
|
- |
break; |
| 1227 |
|
- |
} |
| 1228 |
|
- |
break; |
| 1229 |
|
- |
} |
| 1230 |
|
- |
drawbar(); |
| 1231 |
|
- |
} |
| 1232 |
|
- |
while(XPending(dpy)) { |
| 1233 |
|
- |
XNextEvent(dpy, &ev); |
| 1234 |
|
- |
if(handler[ev.type]) |
| 1235 |
|
- |
(handler[ev.type])(&ev); /* call handler */ |
| 1236 |
|
- |
} |
|
1186 |
+ |
while(running && !XNextEvent(dpy, &ev)) { |
|
1187 |
+ |
if(handler[ev.type]) |
|
1188 |
+ |
(handler[ev.type])(&ev); /* call handler */ |
| 1237 |
1189 |
|
} |
| 1238 |
1190 |
|
} |
| 1239 |
1191 |
|
|
|
| 1356 |
1308 |
|
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); |
| 1357 |
1309 |
|
XDefineCursor(dpy, barwin, cursor[CurNormal]); |
| 1358 |
1310 |
|
XMapRaised(dpy, barwin); |
| 1359 |
|
- |
strcpy(stext, "dwm-"VERSION); |
| 1360 |
|
- |
drawbar(); |
|
1311 |
+ |
updatestatus(); |
| 1361 |
1312 |
|
|
| 1362 |
1313 |
|
/* EWMH support per view */ |
| 1363 |
1314 |
|
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, |
|
| 1365 |
1316 |
|
|
| 1366 |
1317 |
|
/* select for events */ |
| 1367 |
1318 |
|
wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask |
| 1368 |
|
- |
|EnterWindowMask|LeaveWindowMask|StructureNotifyMask; |
|
1319 |
+ |
|EnterWindowMask|LeaveWindowMask|StructureNotifyMask |
|
1320 |
+ |
|PropertyChangeMask; |
| 1369 |
1321 |
|
XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); |
| 1370 |
1322 |
|
XSelectInput(dpy, root, wa.event_mask); |
| 1371 |
1323 |
|
|
|
| 1644 |
1596 |
|
updatetitle(Client *c) { |
| 1645 |
1597 |
|
if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) |
| 1646 |
1598 |
|
gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name); |
|
1599 |
+ |
} |
|
1600 |
+ |
|
|
1601 |
+ |
void |
|
1602 |
+ |
updatestatus() { |
|
1603 |
+ |
if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) |
|
1604 |
+ |
strcpy(stext, "dwm-"VERSION); |
|
1605 |
+ |
drawbar(); |
| 1647 |
1606 |
|
} |
| 1648 |
1607 |
|
|
| 1649 |
1608 |
|
void |