From 4993e2f36331299aba6a42df2896e49d4c98b111 Mon Sep 17 00:00:00 2001
From: rathnor <rathnor>
Date: Thu, 26 Jun 2003 12:22:43 +0000
Subject: speedups for having lots of stuck windows

---
 ChangeLog             |  3 +++
 src/Gnome.cc          |  7 +++++--
 src/IconBar.cc        | 46 ++++++++++++++++++++++++++++++++++------------
 src/IconBar.hh        |  9 +++++++--
 src/Toolbar.cc        | 16 +++++++++++++---
 src/Toolbar.hh        |  9 ++++++---
 src/ToolbarHandler.cc | 23 ++++++++++++++++++-----
 src/Window.cc         | 12 +++++++++---
 8 files changed, 95 insertions(+), 30 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a4206cf..badc7a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 (Format: Year/Month/Day)
 Changes for 0.9.4:
+*03/06/26:
+   * Speedups for having many (particularly stuck) windows (Simon)
+     Toolbar.hh/cc IconBar.hh/cc ToolbarHandler.cc Gnome.cc Window.cc
 *03/06/25:
    * Applied toggle max vertical/horizontal patch (Thanks MrChuoi mrchuoi<[aT]>yahoo.com)
      Window.hh/cc
diff --git a/src/Gnome.cc b/src/Gnome.cc
index 2b12b7f..240c691 100644
--- a/src/Gnome.cc
+++ b/src/Gnome.cc
@@ -19,7 +19,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Gnome.cc,v 1.27 2003/06/23 14:16:04 rathnor Exp $
+// $Id: Gnome.cc,v 1.28 2003/06/26 12:22:42 rathnor Exp $
 
 #include "Gnome.hh"
 
@@ -218,7 +218,10 @@ void Gnome::updateWorkspaceCount(BScreen &screen) {
 }
 
 void Gnome::updateWorkspace(FluxboxWindow &win) {
-    int val = win.workspaceNumber(); 
+    int val = win.workspaceNumber();
+    if (win.isStuck()) {
+        val = -1;
+    }
 #ifdef DEBUG
     cerr<<__FILE__<<"("<<__LINE__<<"): setting workspace("<<val<<
         ") for window("<<&win<<")"<<endl;
diff --git a/src/IconBar.cc b/src/IconBar.cc
index e24ba32..fa7478f 100644
--- a/src/IconBar.cc
+++ b/src/IconBar.cc
@@ -19,7 +19,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: IconBar.cc,v 1.37 2003/06/13 05:02:09 fluxgen Exp $
+// $Id: IconBar.cc,v 1.38 2003/06/26 12:22:42 rathnor Exp $
 
 #include "IconBar.hh"
 
@@ -84,7 +84,8 @@ IconBar::IconBar(BScreen &scrn, Window parent, FbTk::Font &font):
     m_parent(parent),
     m_focus_pm(None),
     m_vertical(false),
-    m_font(font)
+    m_font(font),
+    allow_updates(0)
 {
 
 }
@@ -103,9 +104,10 @@ Window IconBar::addIcon(FluxboxWindow *fluxboxwin) {
     decorate(iconwin);	
     //add window object to list	
     m_iconlist.push_back(new IconBarObj(fluxboxwin, iconwin));
+
     //reposition all icons to fit windowbar
     repositionIcons();
-	
+
     XMapSubwindows(m_display, iconwin);
     XMapWindow(m_display, iconwin);	
 	
@@ -139,16 +141,25 @@ Window IconBar::delIcon(FluxboxWindow *fluxboxwin) {
  * Removes all icons from list
  * Return X Windows of the removed iconobjs
  */
-IconBar::WindowList *IconBar::delAllIcons() {
+IconBar::WindowList *IconBar::delAllIcons(bool ignore_stuck) {
     Window retwin = None;
     WindowList *ret = new WindowList();
-    while (!m_iconlist.empty()) {
-            IconBarObj *obj = m_iconlist.back();
-            m_iconlist.pop_back();
-            retwin = obj->getIconWin();
-            ret->push_back(retwin);
-            delete obj;
-            XDestroyWindow(m_display, retwin);
+    IconList::iterator it = m_iconlist.begin();
+    IconList::iterator tmp = m_iconlist.end();
+    IconList::iterator it_end = m_iconlist.end();
+    while (it != it_end) {
+            IconBarObj *obj = *it;
+            if (!ignore_stuck || !obj->getFluxboxWin()->isStuck()) {
+                retwin = obj->getIconWin();
+                ret->push_back(retwin);
+                tmp = it;
+                ++it;
+                m_iconlist.erase(tmp);
+                delete obj;
+                XDestroyWindow(m_display, retwin);
+            } else {
+                ++it;
+            }
     }
     repositionIcons();
     return ret;
@@ -243,11 +254,22 @@ void IconBar::exposeEvent(XExposeEvent *ee) {
     }	
 }
 
+void IconBar::enableUpdates() {
+    --allow_updates;
+    if (allow_updates <= 0) 
+        repositionIcons();
+    
+}
+
+void IconBar::disableUpdates() {
+    ++allow_updates;
+}
+
 /**
  Calculates and moves/resizes the icons
 */
 void IconBar::repositionIcons() {
-    if (m_iconlist.size() == 0)
+    if (m_iconlist.size() == 0 || allow_updates > 0)
         return;
 		
     Window root;
diff --git a/src/IconBar.hh b/src/IconBar.hh
index ca2bd6d..7f58a12 100644
--- a/src/IconBar.hh
+++ b/src/IconBar.hh
@@ -19,7 +19,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: IconBar.hh,v 1.14 2003/04/15 12:06:11 fluxgen Exp $
+// $Id: IconBar.hh,v 1.15 2003/06/26 12:22:42 rathnor Exp $
 
 #ifndef ICONBAR_HH
 #define ICONBAR_HH
@@ -64,13 +64,16 @@ public:
     void reconfigure();
     Window addIcon(FluxboxWindow *fluxboxwin);
     Window delIcon(FluxboxWindow *fluxboxwin);
-    WindowList *delAllIcons();
+    WindowList *delAllIcons(bool ignore_stuck = false);
     void buttonPressEvent(XButtonEvent *be);	
     FluxboxWindow *findWindow(Window w);
     IconBarObj *findIcon(FluxboxWindow * const fluxboxwin);
     const IconBarObj *findIcon(const FluxboxWindow * const fluxboxwin) const;
     void exposeEvent(XExposeEvent *ee);
 
+    void enableUpdates();
+    void disableUpdates();    
+
     void draw(const IconBarObj * const obj, int width) const;
     void setVertical(bool value) { m_vertical = value; }
     BScreen &screen() { return m_screen; }
@@ -90,6 +93,8 @@ private:
     unsigned long m_focus_pixel;
     bool m_vertical;
     FbTk::Font &m_font;
+
+    int allow_updates;
 };
 
 #endif // ICONBAR_HH
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index a31fbaf..f97f2d2 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Toolbar.cc,v 1.95 2003/06/25 12:33:28 fluxgen Exp $
+// $Id: Toolbar.cc,v 1.96 2003/06/26 12:22:42 rathnor Exp $
 
 #include "Toolbar.hh"
 
@@ -404,11 +404,11 @@ void Toolbar::delIcon(FluxboxWindow *w) {
         FbTk::EventManager::instance()->remove(m_iconbar->delIcon(w));
 }
 
-void Toolbar::delAllIcons() {
+void Toolbar::delAllIcons(bool ignore_stuck) {
     if (m_iconbar.get() == 0)
         return;
 
-    IconBar::WindowList *deleted = m_iconbar->delAllIcons();
+    IconBar::WindowList *deleted = m_iconbar->delAllIcons(ignore_stuck);
     IconBar::WindowList::iterator it = deleted->begin();
     IconBar::WindowList::iterator it_end = deleted->end();
     for (; it != it_end; ++it) {
@@ -421,6 +421,16 @@ bool Toolbar::containsIcon(const FluxboxWindow &win) const {
     return (m_iconbar->findIcon(&win) != 0);
 }
 
+void Toolbar::enableUpdates() {
+    if (m_iconbar.get() != 0)
+        m_iconbar->enableUpdates();
+}
+
+void Toolbar::disableUpdates() {
+    if (m_iconbar.get() != 0)
+        m_iconbar->disableUpdates();
+}
+
 void Toolbar::enableIconBar() {
     if (m_iconbar.get() != 0) 
         return; // already on
diff --git a/src/Toolbar.hh b/src/Toolbar.hh
index 87cd223..7a62c8d 100644
--- a/src/Toolbar.hh
+++ b/src/Toolbar.hh
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Toolbar.hh,v 1.35 2003/06/23 13:16:50 fluxgen Exp $
+// $Id: Toolbar.hh,v 1.36 2003/06/26 12:22:42 rathnor Exp $
 
 #ifndef	 TOOLBAR_HH
 #define	 TOOLBAR_HH
@@ -71,13 +71,17 @@ public:
     void addIcon(FluxboxWindow *w);
     /// remove icon from iconbar
     void delIcon(FluxboxWindow *w);
+    bool containsIcon(const FluxboxWindow &win) const;
     /// remove all icons
-    void delAllIcons();
+    void delAllIcons(bool ignore_stuck = false);
     void enableIconBar();
     void disableIconBar();
     void raise();
     void lower();
 
+    void enableUpdates();
+    void disableUpdates();
+
     inline const FbTk::Menu &menu() const { return m_toolbarmenu; }
     inline FbTk::Menu &menu() { return m_toolbarmenu; }
     inline FbTk::Menu &placementMenu() { return m_placementmenu; }
@@ -111,7 +115,6 @@ public:
     inline const ToolbarTheme &theme() const { return m_theme; }
     inline ToolbarTheme &theme() { return m_theme; }
     bool isVertical() const;
-    bool containsIcon(const FluxboxWindow &win) const;
 
     /**
        @name eventhandlers
diff --git a/src/ToolbarHandler.cc b/src/ToolbarHandler.cc
index d7cf8f0..317890a 100644
--- a/src/ToolbarHandler.cc
+++ b/src/ToolbarHandler.cc
@@ -20,7 +20,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: ToolbarHandler.cc,v 1.17 2003/06/24 16:27:18 fluxgen Exp $
+// $Id: ToolbarHandler.cc,v 1.18 2003/06/26 12:22:42 rathnor Exp $
 
 /**
  * The ToolbarHandler class acts as a rough interface to the toolbar.
@@ -199,6 +199,10 @@ void ToolbarHandler::setMode(ToolbarMode newmode, bool initialise) {
 void ToolbarHandler::initForScreen(BScreen &screen) {
     if (&m_screen != &screen) 
         return;
+
+    if (m_toolbar.get() != 0)
+        m_toolbar->disableUpdates();
+
     switch (mode()) {
     case OFF:
         break;
@@ -212,6 +216,7 @@ void ToolbarHandler::initForScreen(BScreen &screen) {
             Workspace::Windows::iterator wit = wins.begin();
             Workspace::Windows::iterator wit_end = wins.end();
             for (; wit != wit_end; ++wit) {
+                if (!m_toolbar->containsIcon(**wit))
                     m_toolbar->addIcon(*wit);
 /*
                 FluxboxWindow::ClientList::iterator cit = (*wit)->clientList().begin();
@@ -238,7 +243,8 @@ void ToolbarHandler::initForScreen(BScreen &screen) {
         Workspace::Windows::iterator wit = wins.begin();
         Workspace::Windows::iterator wit_end = wins.end();
         for (; wit != wit_end; ++wit) {
-            m_toolbar->addIcon(*wit);
+            if (!m_toolbar->containsIcon(**wit))
+                m_toolbar->addIcon(*wit);
         }
     }
     // fall through and add icons for this workspace
@@ -255,6 +261,10 @@ void ToolbarHandler::initForScreen(BScreen &screen) {
     }
     break;
     }
+
+    if (m_toolbar.get() != 0)
+        m_toolbar->enableUpdates();
+
 }
 
 void ToolbarHandler::setupWindow(FluxboxWindow &win) {
@@ -305,7 +315,7 @@ void ToolbarHandler::updateWindowClose(FluxboxWindow &win) {
         }
         break;
     case WORKSPACE:
-        if (win.workspaceNumber() == m_current_workspace)
+        if (win.isStuck() || win.workspaceNumber() == m_current_workspace)
             m_toolbar->delIcon(&win);
         break;
     case ALLWINDOWS:
@@ -364,7 +374,8 @@ void ToolbarHandler::updateWorkspace(FluxboxWindow &win) {
             m_toolbar->addIcon(&win);
     } else {
         // relies on the fact that this runs but does nothing if window isn't contained.
-        m_toolbar->delIcon(&win);
+        if (!win.isStuck())
+            m_toolbar->delIcon(&win);
     }
 }
 
@@ -375,8 +386,10 @@ void ToolbarHandler::updateCurrentWorkspace(BScreen &screen) {
     // otherwise ignore it
     if (mode() != WORKSPACE && mode() != WORKSPACEICONS)
         return;
-    m_toolbar->delAllIcons();
+    m_toolbar->disableUpdates();
+    m_toolbar->delAllIcons(true);
     initForScreen(m_screen);
+    m_toolbar->enableUpdates();
     m_toolbar->redrawWorkspaceLabel(true);
 }
 
diff --git a/src/Window.cc b/src/Window.cc
index 464210c..380df19 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Window.cc,v 1.198 2003/06/25 13:37:06 fluxgen Exp $
+// $Id: Window.cc,v 1.199 2003/06/26 12:22:43 rathnor Exp $
 
 #include "Window.hh"
 
@@ -1286,6 +1286,7 @@ void FluxboxWindow::maximizeVertical() {
 
 
 void FluxboxWindow::setWorkspace(int n) {
+    unsigned int old_wkspc = m_workspace_number;
 
     m_workspace_number = n;
 
@@ -1293,10 +1294,12 @@ void FluxboxWindow::setWorkspace(int n) {
     m_blackbox_attrib.workspace = m_workspace_number;
 
     // notify workspace change
+    if (!stuck && old_wkspc != m_workspace_number) {
 #ifdef DEBUG
-    cerr<<this<<" notify workspace signal"<<endl;
+        cerr<<this<<" notify workspace signal"<<endl;
 #endif // DEBUG
-    m_workspacesig.notify();
+        m_workspacesig.notify();
+    }
 }
 
 void FluxboxWindow::setLayerNum(int layernum) {
@@ -1354,6 +1357,9 @@ void FluxboxWindow::stick() {
     }
  
     setState(m_current_state);
+    // notify since some things consider "stuck" to be a pseudo-workspace
+    m_workspacesig.notify();
+
 }
 
 
-- 
cgit v0.11.2