From d74a90d1bf2f2a8c5a7a5a73ff7795612b6cb06a Mon Sep 17 00:00:00 2001 From: Ralf Hoffmann Date: Fri, 4 Dec 2009 15:01:14 +0100 Subject: [PATCH] changed behavior when focusing new windows with autofocus enabled New windows will only get focused if the mouse is on the same screen. The code doesn't handle multiple heads but since it's just one screen the function works as usual. Checking the head and assign the focus only if the window is on the same head might be a good idea. Making the whole stuff optional might be even better. --- src/window.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/window.c b/src/window.c index 616fd47d..6081036f 100644 --- a/src/window.c +++ b/src/window.c @@ -1366,8 +1366,28 @@ WWindow *wManageWindow(WScreen *scr, Window window) 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);