Enclosed is a patch that gives focus back to the last focused window on a
workspace when a workspace change occurs.  Has not been tested too long, but
seems safe and functional.  One problem, bbpager accepts focus when it is
clicked, so if you change workspaces with bbpager, it becomes the last
focused window.  Not sure how to solve this.

Will start looking into my second request, which is to have a "All Workspaces"
window list.
diff -c -r /tmp/blackbox-0.60.0/src/Screen.cc blackbox-0.60.0/src/Screen.cc
*** /tmp/blackbox-0.60.0/src/Screen.cc  Thu Mar 30 15:37:21 2000
--- blackbox-0.60.0/src/Screen.cc       Sun May  7 01:03:35 2000
***************
*** 1079,1095 ****
  
      workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
                                   False);
!     
!     if (blackbox->getFocusedWindow() &&
!       blackbox->getFocusedWindow()->getScreen() == this &&
!         (! blackbox->getFocusedWindow()->isStuck()))
        blackbox->setFocusedWindow((BlackboxWindow *) 0);
!     current_workspace = getWorkspace(id);
      
      workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
                                   True);
      toolbar->redrawWorkspaceLabel(True);
!     
      current_workspace->showAll();
    }
  
--- 1079,1100 ----
  
      workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
                                   False);
! 
!     BlackboxWindow *w = blackbox->getFocusedWindow();
!     if (w && w->getScreen() == this && ! w->isStuck()) {
!       current_workspace->setLastFocusedWindow(w);
        blackbox->setFocusedWindow((BlackboxWindow *) 0);
!     }
      
+     current_workspace = getWorkspace(id);
+ 
      workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
                                   True);
      toolbar->redrawWorkspaceLabel(True);
! 
!     if (current_workspace->getLastFocusedWindow())
!       blackbox->setFocusedWindow(current_workspace->getLastFocusedWindow());
! 
      current_workspace->showAll();
    }
  
diff -c -r /tmp/blackbox-0.60.0/src/Workspace.cc blackbox-0.60.0/src/Workspace.cc
*** /tmp/blackbox-0.60.0/src/Workspace.cc       Sun Mar 19 17:11:07 2000
--- blackbox-0.60.0/src/Workspace.cc    Sun May  7 00:32:45 2000
***************
*** 65,70 ****
--- 65,72 ----
  
    cascade_x = cascade_y = 32;
  
+   last_focused_window = (BlackboxWindow *) 0;
+ 
    id = i;
  
    windowList = new LinkedList<BlackboxWindow>;
***************
*** 131,138 ****
  
    windowList->remove((const int) w->getWindowNumber());
    
!   if (w->isFocused())
      screen->getBlackbox()->setFocusedWindow((BlackboxWindow *) 0);
    
    clientmenu->remove(w->getWindowNumber());
    clientmenu->update();
--- 133,143 ----
  
    windowList->remove((const int) w->getWindowNumber());
    
!   if (w->isFocused()) {
      screen->getBlackbox()->setFocusedWindow((BlackboxWindow *) 0);
+     if (last_focused_window == w)
+       last_focused_window = (BlackboxWindow *) 0;
+   }
    
    clientmenu->remove(w->getWindowNumber());
    clientmenu->update();
***************
*** 338,343 ****
--- 343,353 ----
    
    clientmenu->setLabel(name);
    clientmenu->update();
+ }
+ 
+ 
+ void Workspace::setLastFocusedWindow(BlackboxWindow *w) {
+   last_focused_window = w;
  }
  
  
diff -c -r /tmp/blackbox-0.60.0/src/Workspace.hh blackbox-0.60.0/src/Workspace.hh
*** /tmp/blackbox-0.60.0/src/Workspace.hh       Sat Mar 18 15:24:27 2000
--- blackbox-0.60.0/src/Workspace.hh    Sun May  7 00:40:26 2000
***************
*** 41,47 ****
  
    char *name;
    int id, cascade_x, cascade_y;
! 
  
  protected:
    void placeWindow(BlackboxWindow *);
--- 41,47 ----
  
    char *name;
    int id, cascade_x, cascade_y;
!   BlackboxWindow *last_focused_window;
  
  protected:
    void placeWindow(BlackboxWindow *);
***************
*** 59,64 ****
--- 59,66 ----
  
    inline const int &getWorkspaceID(void) const { return id; }
  
+   inline BlackboxWindow *getLastFocusedWindow(void) { return last_focused_window; }
+ 
    BlackboxWindow *getWindow(int);
  
    Bool isCurrent(void);
***************
*** 77,82 ****
--- 79,85 ----
    void update();
    void setCurrent(void);
    void setName(char *);
+   void setLastFocusedWindow(BlackboxWindow *);
    void shutdown(void);
  };
  

Reply via email to