JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fixed focus steeling bug done by clients like opera
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index c11d7d2..53e5cb2 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -53,7 +53,7 @@
 enum { BarTop, BarBot, BarOff };                       /* bar position */
 enum { CurNormal, CurResize, CurMove, CurLast };       /* cursor */
 enum { ColBorder, ColFG, ColBG, ColLast };             /* color */
-enum { NetSupported, NetWMCheck, NetWMName, NetLast }; /* EWMH atoms */
+enum { NetSupported, NetWMName, NetLast };             /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
 
 /* typedefs */
@@ -137,6 +137,7 @@ void eprint(const char *errstr, ...);
 void expose(XEvent *e);
 void floating(void); /* default floating layout */
 void focus(Client *c);
+void focusin(XEvent *e);
 void focusnext(const char *arg);
 void focusprev(const char *arg);
 Client *getclient(Window w);
@@ -206,9 +207,10 @@ void (*handler[LASTEvent]) (XEvent *) = {
        [ConfigureNotify] = configurenotify,
        [DestroyNotify] = destroynotify,
        [EnterNotify] = enternotify,
-       [LeaveNotify] = leavenotify,
        [Expose] = expose,
+       [FocusIn] = focusin,
        [KeyPress] = keypress,
+       [LeaveNotify] = leavenotify,
        [MappingNotify] = mappingnotify,
        [MapRequest] = maprequest,
        [PropertyNotify] = propertynotify,
@@ -710,6 +712,14 @@ focus(Client *c) {
 }
 
 void
+focusin(XEvent *e) { /* there are some broken focus acquiring clients */
+       XFocusChangeEvent *ev = &e->xfocus;
+
+       if(sel && ev->window != sel->win)
+               XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
+}
+
+void
 focusnext(const char *arg) {
        Client *c;
 
@@ -1026,8 +1036,7 @@ manage(Window w, XWindowAttributes *wa) {
        XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
        configure(c); /* propagates border_width, if size doesn't change */
        updatesizehints(c);
-       XSelectInput(dpy, w,
-               StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
+       XSelectInput(dpy, w, EnterWindowMask | FocusChangeMask | PropertyChangeMask | StructureNotifyMask);
        grabbuttons(c, False);
        updatetitle(c);
        if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
@@ -1427,20 +1436,19 @@ void
 setup(void) {
        int d;
        unsigned int i, j, mask;
-       Atom utf8string;
        Window w;
        XModifierKeymap *modmap;
        XSetWindowAttributes wa;
 
        /* init atoms */
-       utf8string = XInternAtom(dpy, "UTF8_STRING", False);
        wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
        wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
        wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
        wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
        netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
-       netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
        netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
+       XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
+                       PropModeReplace, (unsigned char *) netatom, NetLast);
 
        /* init cursors */
        cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
@@ -1516,16 +1524,6 @@ setup(void) {
        /* multihead support */
        selscreen = XQueryPointer(dpy, root, &w, &w, &d, &d, &d, &d, &mask);
 
-       /* EWMH properties */
-       XChangeProperty(dpy, barwin, netatom[NetWMCheck], XA_WINDOW, 32,
-                       PropModeReplace, (unsigned char *) &barwin, 1);
-       /* HACK: dwm identifies itself as LookingGlass to workaround the XToolkit bug of Sun JDK */
-       XChangeProperty(dpy, barwin, netatom[NetWMName], utf8string, 8,
-                       PropModeReplace, (unsigned char *) "LG3D", 4);
-       XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32,
-                       PropModeReplace, (unsigned char *) &barwin, 1);
-       XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
-                       PropModeReplace, (unsigned char *) netatom, NetLast);
 }
 
 void