]> Dogcows Code - chaz/openbox/commitdiff
new focus code! working better than ever!
authorDana Jansens <danakj@orodu.net>
Tue, 14 May 2002 07:53:22 +0000 (07:53 +0000)
committerDana Jansens <danakj@orodu.net>
Tue, 14 May 2002 07:53:22 +0000 (07:53 +0000)
src/Screen.cc
src/Workspace.cc
src/Workspace.h
src/openbox.cc
src/openbox.h

index 75f8459af4adf49487dcf6dd9681bb6e959f9ada..50a0f1d125cc9f131d00c419264522e3e0ab5364 100644 (file)
@@ -1979,8 +1979,7 @@ void BScreen::changeWorkspaceID(int id) {
     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 @@ void BScreen::changeWorkspaceID(int id) {
 
     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();
     }
   }
 
index 5982f878a8bf2631394a043b73fd613ddeaa551d..41a09324ab4ab687d7971ab1f5668306e63278fa 100644 (file)
@@ -63,13 +63,11 @@ 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 @@ Workspace::~Workspace(void) {
 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 @@ const int Workspace::addWindow(OpenboxWindow *w, Bool place) {
 
   raiseWindow(w);
 
-  if (place) placeWindow(*w);
-
   return w->getWindowNumber();
 }
 
@@ -111,21 +109,22 @@ const int Workspace::removeWindow(OpenboxWindow *w) {
   _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 @@ void Workspace::focusWindow(OpenboxWindow *win) {
   if (_focused != (OpenboxWindow *) 0)
     clientmenu->setItemSelected(_focused->getWindowNumber(), false);
   _focused = win;
+  if (win != (OpenboxWindow *) 0)
+    _last = win;
 }
 
 
index 1f2483af499ea3903cd22d71190abfa2f19a39e3..21e65cec7d81cf715c6d84a0c427894a7f34db1c 100644 (file)
@@ -38,7 +38,6 @@ class Rect;
 class Workspace {
 private:
   BScreen &screen;
-  OpenboxWindow *lastfocus;
   Clientmenu *clientmenu;
 
   typedef std::vector<OpenboxWindow *> winVect;
@@ -49,7 +48,10 @@ private:
   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 @@ public:
   ~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);
index b603e56f3416e992520fac5ae7da3e93553c8b7e..8ef1e07c4249ce8d125f18314fbd75ec41fba6a9 100644 (file)
@@ -186,8 +186,8 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc)
   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 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc)
               "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 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc)
 
   ungrab();
 
-  focusWindow((OpenboxWindow *) 0);
+  focusWindow(0);
 }
 
 
@@ -868,11 +868,11 @@ void Openbox::restart(const char *prog) {
 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 @@ void Openbox::timeout() {
 
 
 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 @@ void Openbox::focusWindow(OpenboxWindow *win) {
     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();
 }
index c62dfa2ab6f542c6191b85fad66c1608bc025397..61d5fdb2a5a9d925974c3544ca66907b9a8a9794 100644 (file)
@@ -118,7 +118,7 @@ private:
   typedef std::list<BScreen*> ScreenList;
   ScreenList screenList;
 
-  BScreen *focused_screen;
+  BScreen *current_screen;
   OpenboxWindow *masked_window;
   BTimer *timer;
 
This page took 0.034607 seconds and 4 git commands to generate.