This patch adds a small feature. New windows will only get focus if the mouse
is on the same screen. This is only useful for multihead environments.
Currently it doesn't handle a xinerama mode.

(C) 2007-11-10 Ralf Hoffmann
License: GPL V2 or later

diff -purN WindowMaker-0.92.0-rh2/src/window.c WindowMaker-0.92.0-rh3/src/window.c
--- WindowMaker-0.92.0-rh2/src/window.c	2007-11-10 13:19:35.000000000 +0100
+++ WindowMaker-0.92.0-rh3/src/window.c	2007-11-10 13:21:25.000000000 +0100
@@ -92,7 +92,7 @@ extern Time LastTimestamp;
 /* superfluous... */
 extern void DoWindowBirth(WWindow*);
 
-
+extern int wScreenCount;
 
 /***** Local Stuff *****/
 
@@ -1523,8 +1523,28 @@ wManageWindow(WScreen *scr, Window windo
     if (!wwin->flags.miniaturized && workspace == scr->current_workspace
         && !wwin->flags.hidden) {
         if (((transientOwner && transientOwner->flags.focused)
-             || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
-            wSetFocusTo(scr, wwin);
+             || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable)) {
+
+            /* only auto_focus if on same screen as mouse
+             * (and same head for xinerama mode)
+             * TODO: make it an option */
+
+            /*TODO add checking the head of the window, is it available? */
+            short same_screen = 0, same_head = 1;
+            
+            int foo;
+            unsigned int bar;
+            Window dummy;
+
+            if ( XQueryPointer( dpy, scr->root_win,
+                                &dummy, &dummy, &foo, &foo, &foo, &foo, &bar ) != False ) {
+                same_screen = 1;
+            }
+            
+            if ( same_screen == 1 && same_head == 1 ) {
+                wSetFocusTo(scr, wwin);
+            }
+        }
     }
     wWindowResetMouseGrabs(wwin);
 
