dwm-r1507-focusatom.diff (2057B)
1 diff -r 72e52c5333ef dwm.c 2 --- a/dwm.c Wed Nov 25 13:56:17 2009 +0000 3 +++ b/dwm.c Thu Feb 25 23:41:45 2010 +0100 4 @@ -177,6 +177,7 @@ 5 static void enternotify(XEvent *e); 6 static void expose(XEvent *e); 7 static void focus(Client *c); 8 +static void focusatomchange(void); 9 static void focusin(XEvent *e); 10 static void focusmon(const Arg *arg); 11 static void focusstack(const Arg *arg); 12 @@ -262,6 +263,7 @@ 13 [UnmapNotify] = unmapnotify 14 }; 15 static Atom wmatom[WMLast], netatom[NetLast]; 16 +static Atom focusatom; 17 static Bool otherwm; 18 static Bool running = True; 19 static Cursor cursor[CurLast]; 20 @@ -834,6 +836,33 @@ 21 } 22 23 void 24 +focusatomchange() { 25 + int format, status; 26 + unsigned long n, extra; 27 + unsigned char *p = NULL; 28 + Atom real; 29 + Client *c; 30 + Monitor *m; 31 + Window *w; 32 + 33 + status = XGetWindowProperty(dpy, root, focusatom, 0L, 32L, True, XA_CARDINAL, &real, &format, &n, &extra, &p); 34 + if(status!=Success || n==0) return; 35 + if((w = (Window*)p) && (m = wintomon(*w)) && m != selmon) { 36 + unfocus(selmon->sel); 37 + selmon = m; 38 + } 39 + if((c = wintoclient(*w))) { 40 + if (!ISVISIBLE(c)) { 41 + c->mon->seltags ^= 1; /* toggle sel tagset */ 42 + c->mon->tagset[c->mon->seltags] = c->tags & TAGMASK; 43 + } 44 + focus(c); 45 + arrange(c->mon); 46 + } 47 + XFree(p); 48 +} 49 + 50 +void 51 focusin(XEvent *e) { /* there are some broken focus acquiring clients */ 52 XFocusChangeEvent *ev = &e->xfocus; 53 54 @@ -1264,6 +1293,8 @@ 55 56 if((ev->window == root) && (ev->atom == XA_WM_NAME)) 57 updatestatus(); 58 + else if((ev->window == root) && (ev->atom == focusatom)) 59 + focusatomchange(); 60 else if(ev->state == PropertyDelete) 61 return; /* ignore */ 62 else if((c = wintoclient(ev->window))) { 63 @@ -1493,6 +1524,7 @@ 64 wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False); 65 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); 66 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); 67 + focusatom = XInternAtom(dpy, "_DWM_FOCUS", False); 68 /* init cursors */ 69 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); 70 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);