new focus code! working better than ever!
Dana Jansens danakj@orodu.net
5 files changed,
45 insertions(+),
47 deletions(-)
M
src/Screen.cc
→
src/Screen.cc
@@ -1979,8 +1979,7 @@
if (openbox.focusedWindow() && openbox.focusedWindow()->getScreen() == this && (! openbox.focusedWindow()->isStuck())) { - current_workspace->setLastFocusedWindow(openbox.focusedWindow()); - openbox.focusWindow((OpenboxWindow *) 0); + openbox.focusWindow(0); } current_workspace = getWorkspace(id);@@ -1991,9 +1990,9 @@ toolbar->redrawWorkspaceLabel(True);
current_workspace->showAll(); - if (resource.focus_last && current_workspace->getLastFocusedWindow()) { + if (resource.focus_last && current_workspace->lastFocusedWindow()) { XSync(openbox.getXDisplay(), False); - current_workspace->getLastFocusedWindow()->setInputFocus(); + current_workspace->lastFocusedWindow()->setInputFocus(); } }
M
src/Workspace.cc
→
src/Workspace.cc
@@ -63,12 +63,10 @@ typedef std::vector<Rect> rectList;
Workspace::Workspace(BScreen &scrn, int i) : screen(scrn) { cascade_x = cascade_y = 0; - _focused = (OpenboxWindow *) 0; + _focused = _last = (OpenboxWindow *) 0; id = i; clientmenu = new Clientmenu(*this); - - lastfocus = (OpenboxWindow *) 0; name = (char *) 0; setName(screen.getNameOfWorkspace(id));@@ -86,6 +84,8 @@
const int Workspace::addWindow(OpenboxWindow *w, Bool place) { if (! w) return -1; + if (place) placeWindow(*w); + w->setWorkspace(id); w->setWindowNumber(_windows.size());@@ -99,8 +99,6 @@ screen.updateNetizenWindowAdd(w->getClientWindow(), id);
raiseWindow(w); - if (place) placeWindow(*w); - return w->getWindowNumber(); }@@ -111,21 +109,22 @@
_zorder.remove(w); if (w->isFocused()) { + if (w == _last) + _last = (OpenboxWindow *) 0; + + OpenboxWindow *fw = (OpenboxWindow *) 0; if (w->isTransient() && w->getTransientFor() && - w->getTransientFor()->isVisible()) { - w->getTransientFor()->setInputFocus(); - } else { - if (screen.sloppyFocus() || // sloppy focus - _zorder.empty() || // click focus but no windows - !_zorder.front()->setInputFocus()) { // tried window, but wont focus - screen.getOpenbox().focusWindow((OpenboxWindow *) 0); - } - } + w->getTransientFor()->isVisible()) + fw = w->getTransientFor(); + else if (screen.sloppyFocus()) // sloppy focus + fw = (OpenboxWindow *) 0; + else if (!_zorder.empty()) // click focus + fw = _zorder.front(); + + if (!(fw != (OpenboxWindow *) 0 && fw->setInputFocus())) + screen.getOpenbox().focusWindow(0); } - if (lastfocus == w) - lastfocus = (OpenboxWindow *) 0; - _windows.erase(_windows.begin() + w->getWindowNumber()); clientmenu->remove(w->getWindowNumber()); clientmenu->update();@@ -146,6 +145,8 @@ clientmenu->setItemSelected(win->getWindowNumber(), true);
if (_focused != (OpenboxWindow *) 0) clientmenu->setItemSelected(_focused->getWindowNumber(), false); _focused = win; + if (win != (OpenboxWindow *) 0) + _last = win; }
M
src/Workspace.h
→
src/Workspace.h
@@ -38,7 +38,6 @@
class Workspace { private: BScreen &screen; - OpenboxWindow *lastfocus; Clientmenu *clientmenu; typedef std::vector<OpenboxWindow *> winVect;@@ -49,7 +48,10 @@
char *name; int id, cascade_x, cascade_y; - OpenboxWindow *_focused; + OpenboxWindow *_focused, *_last; // last is the same as focused except + // that when focus is removed from all + // windows on the workspace, last doesnt + // change to NULL protected: void placeWindow(OpenboxWindow &);@@ -64,12 +66,11 @@ Workspace(BScreen &, int = 0);
~Workspace(void); inline BScreen &getScreen(void) { return screen; } - inline OpenboxWindow *getLastFocusedWindow(void) { return lastfocus; } inline Clientmenu *getMenu(void) { return clientmenu; } inline const char *getName(void) const { return name; } inline const int &getWorkspaceID(void) const { return id; } - inline void setLastFocusedWindow(OpenboxWindow *w) { lastfocus = w; } inline OpenboxWindow *focusedWindow() { return _focused; } + inline OpenboxWindow *lastFocusedWindow() { return _last; } void focusWindow(OpenboxWindow *win); OpenboxWindow *getWindow(int); Bool isCurrent(void);
M
src/openbox.cc
→
src/openbox.cc
@@ -186,8 +186,8 @@ resource.menu_file = resource.style_file = NULL;
resource.titlebar_layout = NULL; resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec = 0; - focused_screen = (BScreen *) 0; - masked_window = NULL; + current_screen = (BScreen *) 0; + masked_window = (OpenboxWindow *) 0; masked = None; load();@@ -213,7 +213,7 @@ i18n->getMessage(openboxSet, openboxNoManagableScreens,
"Openbox::Openbox: no managable screens found, aborting.\n")); ::exit(3); } - focused_screen = screenList.front(); + current_screen = screenList.front(); // save current settings and default values save();@@ -229,7 +229,7 @@ timer->fireOnce(True);
ungrab(); - focusWindow((OpenboxWindow *) 0); + focusWindow(0); }@@ -868,11 +868,11 @@
void Openbox::shutdown() { BaseDisplay::shutdown(); - focusWindow((OpenboxWindow *) 0); - std::for_each(screenList.begin(), screenList.end(), std::mem_fun(&BScreen::shutdown)); + focusWindow(0); + XSync(getXDisplay(), False); }@@ -1063,12 +1063,11 @@ }
OpenboxWindow *Openbox::focusedWindow() { - if (focused_screen == (BScreen *) 0) - return (OpenboxWindow *) 0; - Workspace *w = focused_screen->getCurrentWorkspace(); - if (w == (Workspace *) 0) - return (OpenboxWindow *) 0; - return w->focusedWindow(); + Workspace *w; + if (current_screen) + if ((w = current_screen->getCurrentWorkspace())) + return w->focusedWindow(); + return (OpenboxWindow *) 0; }@@ -1083,28 +1082,26 @@ old_screen = old_win->getScreen();
old_wkspc = old_screen->getWorkspace(old_win->getWorkspaceNumber()); old_tbar = old_screen->getToolbar(); - old_win->setFocusFlag(False); + old_win->setFocusFlag(false); old_wkspc->focusWindow((OpenboxWindow *) 0); } if (win && !win->isIconic()) { - focused_screen = win->getScreen(); - tbar = focused_screen->getToolbar(); - wkspc = focused_screen->getWorkspace(win->getWorkspaceNumber()); + current_screen = win->getScreen(); + tbar = current_screen->getToolbar(); + wkspc = current_screen->getWorkspace(win->getWorkspaceNumber()); win->setFocusFlag(true); wkspc->focusWindow(win); if (tbar) tbar->redrawWindowLabel(true); - focused_screen->updateNetizenWindowFocus(); + current_screen->updateNetizenWindowFocus(); } else { - ASSERT(focused_screen != (BScreen *) 0); - XSetInputFocus(getXDisplay(), focused_screen->getRootWindow(), - None, CurrentTime); + XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime); } if (old_tbar && old_tbar != tbar) old_tbar->redrawWindowLabel(true); - if (old_screen && old_screen != focused_screen) + if (old_screen && old_screen != current_screen) old_screen->updateNetizenWindowFocus(); }
M
src/openbox.h
→
src/openbox.h
@@ -118,7 +118,7 @@
typedef std::list<BScreen*> ScreenList; ScreenList screenList; - BScreen *focused_screen; + BScreen *current_screen; OpenboxWindow *masked_window; BTimer *timer;