- if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
- XSync(blackbox->getXDisplay(), False);
- current_workspace->getLastFocusedWindow()->setInputFocus();
+ int x, y, rx, ry;
+ Window c, r;
+ unsigned int m;
+ BlackboxWindow *win = (BlackboxWindow *) 0;
+ bool f = False;
+
+ XSync(blackbox->getXDisplay(), False);
+
+ // If sloppy focus and we can find the client window under the pointer,
+ // try to focus it.
+ if (resource.sloppy_focus &&
+ XQueryPointer(blackbox->getXDisplay(), getRootWindow(), &r, &c,
+ &rx, &ry, &x, &y, &m) &&
+ c != None) {
+ if ( (win = blackbox->searchWindow(c)) )
+ f = win->setInputFocus();