summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dwm.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/dwm.c b/dwm.c
index 1297b2b..0a1b30e 100644
--- a/dwm.c
+++ b/dwm.c
@@ -59,7 +59,7 @@ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
59enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ 59enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
60enum { NetSupported, NetWMName, NetWMState, 60enum { NetSupported, NetWMName, NetWMState,
61 NetWMFullscreen, NetLast }; /* EWMH atoms */ 61 NetWMFullscreen, NetLast }; /* EWMH atoms */
62enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */ 62enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
63enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, 63enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
64 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ 64 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
65 65
@@ -88,7 +88,7 @@ struct Client {
88 int basew, baseh, incw, inch, maxw, maxh, minw, minh; 88 int basew, baseh, incw, inch, maxw, maxh, minw, minh;
89 int bw, oldbw; 89 int bw, oldbw;
90 unsigned int tags; 90 unsigned int tags;
91 Bool isfixed, isfloating, isurgent, oldstate; 91 Bool isfixed, isfloating, isurgent, neverfocus, oldstate;
92 Client *next; 92 Client *next;
93 Client *snext; 93 Client *snext;
94 Monitor *mon; 94 Monitor *mon;
@@ -190,7 +190,6 @@ static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
190static void grabbuttons(Client *c, Bool focused); 190static void grabbuttons(Client *c, Bool focused);
191static void grabkeys(void); 191static void grabkeys(void);
192static void initfont(const char *fontstr); 192static void initfont(const char *fontstr);
193static Bool isprotodel(Client *c);
194static void keypress(XEvent *e); 193static void keypress(XEvent *e);
195static void killclient(const Arg *arg); 194static void killclient(const Arg *arg);
196static void manage(Window w, XWindowAttributes *wa); 195static void manage(Window w, XWindowAttributes *wa);
@@ -208,8 +207,10 @@ static void resizemouse(const Arg *arg);
208static void restack(Monitor *m); 207static void restack(Monitor *m);
209static void run(void); 208static void run(void);
210static void scan(void); 209static void scan(void);
210static Bool sendevent(Client *c, Atom proto);
211static void sendmon(Client *c, Monitor *m); 211static void sendmon(Client *c, Monitor *m);
212static void setclientstate(Client *c, long state); 212static void setclientstate(Client *c, long state);
213static void setfocus(Client *c);
213static void setlayout(const Arg *arg); 214static void setlayout(const Arg *arg);
214static void setmfact(const Arg *arg); 215static void setmfact(const Arg *arg);
215static void setup(void); 216static void setup(void);
@@ -821,7 +822,7 @@ focus(Client *c) {
821 attachstack(c); 822 attachstack(c);
822 grabbuttons(c, True); 823 grabbuttons(c, True);
823 XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); 824 XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
824 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); 825 setfocus(c);
825 } 826 }
826 else 827 else
827 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 828 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
@@ -834,7 +835,7 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */
834 XFocusChangeEvent *ev = &e->xfocus; 835 XFocusChangeEvent *ev = &e->xfocus;
835 836
836 if(selmon->sel && ev->window != selmon->sel->win) 837 if(selmon->sel && ev->window != selmon->sel->win)
837 XSetInputFocus(dpy, selmon->sel->win, RevertToPointerRoot, CurrentTime); 838 setfocus(selmon->sel);
838} 839}
839 840
840void 841void
@@ -1012,20 +1013,6 @@ initfont(const char *fontstr) {
1012 dc.font.height = dc.font.ascent + dc.font.descent; 1013 dc.font.height = dc.font.ascent + dc.font.descent;
1013} 1014}
1014 1015
1015Bool
1016isprotodel(Client *c) {
1017 int n;
1018 Atom *protocols;
1019 Bool ret = False;
1020
1021 if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
1022 while(!ret && n--)
1023 ret = protocols[n] == wmatom[WMDelete];
1024 XFree(protocols);
1025 }
1026 return ret;
1027}
1028
1029#ifdef XINERAMA 1016#ifdef XINERAMA
1030static Bool 1017static Bool
1031isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) { 1018isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) {
@@ -1054,20 +1041,9 @@ keypress(XEvent *e) {
1054 1041
1055void 1042void
1056killclient(const Arg *arg) { 1043killclient(const Arg *arg) {
1057 XEvent ev;
1058
1059 if(!selmon->sel) 1044 if(!selmon->sel)
1060 return; 1045 return;
1061 if(isprotodel(selmon->sel)) { 1046 if(!sendevent(selmon->sel, wmatom[WMDelete])) {
1062 ev.type = ClientMessage;
1063 ev.xclient.window = selmon->sel->win;
1064 ev.xclient.message_type = wmatom[WMProtocols];
1065 ev.xclient.format = 32;
1066 ev.xclient.data.l[0] = wmatom[WMDelete];
1067 ev.xclient.data.l[1] = CurrentTime;
1068 XSendEvent(dpy, selmon->sel->win, False, NoEventMask, &ev);
1069 }
1070 else {
1071 XGrabServer(dpy); 1047 XGrabServer(dpy);
1072 XSetErrorHandler(xerrordummy); 1048 XSetErrorHandler(xerrordummy);
1073 XSetCloseDownMode(dpy, DestroyAll); 1049 XSetCloseDownMode(dpy, DestroyAll);
@@ -1124,6 +1100,7 @@ manage(Window w, XWindowAttributes *wa) {
1124 XSetWindowBorder(dpy, w, dc.norm[ColBorder]); 1100 XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
1125 configure(c); /* propagates border_width, if size doesn't change */ 1101 configure(c); /* propagates border_width, if size doesn't change */
1126 updatesizehints(c); 1102 updatesizehints(c);
1103 updatewmhints(c);
1127 XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); 1104 XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
1128 grabbuttons(c, False); 1105 grabbuttons(c, False);
1129 if(!c->isfloating) 1106 if(!c->isfloating)
@@ -1471,6 +1448,37 @@ setclientstate(Client *c, long state) {
1471 PropModeReplace, (unsigned char *)data, 2); 1448 PropModeReplace, (unsigned char *)data, 2);
1472} 1449}
1473 1450
1451Bool
1452sendevent(Client *c, Atom proto) {
1453 int n;
1454 Atom *protocols;
1455 Bool exists = False;
1456 XEvent ev;
1457
1458 if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
1459 while(!exists && n--)
1460 exists = protocols[n] == proto;
1461 XFree(protocols);
1462 }
1463 if (exists) {
1464 ev.type = ClientMessage;
1465 ev.xclient.window = c->win;
1466 ev.xclient.message_type = wmatom[WMProtocols];
1467 ev.xclient.format = 32;
1468 ev.xclient.data.l[0] = proto;
1469 ev.xclient.data.l[1] = CurrentTime;
1470 XSendEvent(dpy, c->win, False, NoEventMask, &ev);
1471 }
1472 return exists;
1473}
1474
1475void
1476setfocus(Client *c) {
1477 if (!c->neverfocus)
1478 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
1479 sendevent(c, wmatom[WMTakeFocus]);
1480}
1481
1474void 1482void
1475setlayout(const Arg *arg) { 1483setlayout(const Arg *arg) {
1476 if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) 1484 if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
@@ -1517,6 +1525,7 @@ setup(void) {
1517 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 1525 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
1518 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); 1526 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
1519 wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False); 1527 wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
1528 wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
1520 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); 1529 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
1521 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); 1530 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
1522 netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False); 1531 netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
@@ -1933,6 +1942,8 @@ updatewmhints(Client *c) {
1933 } 1942 }
1934 else 1943 else
1935 c->isurgent = (wmh->flags & XUrgencyHint) ? True : False; 1944 c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
1945 if (wmh->flags & InputHint) c->neverfocus = !wmh->input;
1946 else c->neverfocus = False;
1936 XFree(wmh); 1947 XFree(wmh);
1937 } 1948 }
1938} 1949}