From 4f89009c9e6521910442eabc36d572367398c0bf Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavelo@centrum.sk>
Date: Fri, 6 May 2011 18:18:20 +0200
Subject: Convert FluxboxWindow::workspaceSig to FbTk::Signal

---
 src/FocusableList.cc | 36 +++++++++++++++++++++++-------------
 src/FocusableList.hh |  1 +
 src/Window.cc        | 11 +++++------
 src/Window.hh        |  7 +++----
 src/fluxbox.cc       | 10 ++++++----
 src/fluxbox.hh       |  2 ++
 6 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/src/FocusableList.cc b/src/FocusableList.cc
index 73d865e..ca73a22 100644
--- a/src/FocusableList.cc
+++ b/src/FocusableList.cc
@@ -114,16 +114,22 @@ void FocusableList::update(FbTk::Subject *subj) {
     if (typeid(*subj) == typeid(FluxboxWindow::WinSubject)) {
         FluxboxWindow::WinSubject *fsubj =
             static_cast<FluxboxWindow::WinSubject *>(subj);
-        // we only bind these for matching patterns, so skip finding out signal
-        FluxboxWindow &fbwin = fsubj->win();
-        if (m_parent->contains(fbwin))
-            checkUpdate(fbwin);
-        std::list<WinClient *> list = fbwin.clientList();
-        std::list<WinClient *>::iterator it = list.begin(), it_end = list.end();
-        for (; it != it_end; ++it) {
-            if (m_parent->contains(**it))
-                checkUpdate(**it);
-        }
+        windowUpdated(fsubj->win());
+    }
+}
+
+void FocusableList::windowUpdated(FluxboxWindow &fbwin) {
+    if (m_screen.isShuttingdown())
+        return;
+
+    // we only bind these for matching patterns, so skip finding out signal
+    if (m_parent->contains(fbwin))
+        checkUpdate(fbwin);
+    const std::list<WinClient *> &list = fbwin.clientList();
+    std::list<WinClient *>::const_iterator it = list.begin(), it_end = list.end();
+    for (; it != it_end; ++it) {
+        if (m_parent->contains(**it))
+            checkUpdate(**it);
     }
 }
 
@@ -252,6 +258,8 @@ void FocusableList::updateTitle(Focusable& win) {
 
 void FocusableList::attachSignals(Focusable &win) {
     if (m_parent) {
+        FluxboxWindow *fbwin = win.fbwindow();
+
         // attach various signals for matching
         FbTk::RefCount<FbTk::SignalTracker> &tracker = m_signal_map[&win];
         if (! tracker) {
@@ -259,12 +267,15 @@ void FocusableList::attachSignals(Focusable &win) {
             tracker = new SignalTracker;
             tracker->join(win.titleSig(), MemFunSelectArg1(*this, &FocusableList::updateTitle));
             tracker->join(win.dieSig(), MemFun(*this, &FocusableList::remove));
+            if(fbwin) {
+                tracker->join(fbwin->workspaceSig(),
+                            MemFun(*this, &FocusableList::windowUpdated)
+                        );
+            }
         }
 
-        FluxboxWindow *fbwin = win.fbwindow();
         if (!fbwin)
             return;
-        fbwin->workspaceSig().attach(this);
         fbwin->stateSig().attach(this);
         fbwin->layerSig().attach(this);
         // TODO: can't watch (head=...) yet
@@ -278,7 +289,6 @@ void FocusableList::detachSignals(Focusable &win) {
         FluxboxWindow *fbwin = win.fbwindow();
         if (!fbwin)
             return;
-        fbwin->workspaceSig().detach(this);
         fbwin->stateSig().detach(this);
         fbwin->layerSig().detach(this);
         // TODO: can't watch (head=...) yet
diff --git a/src/FocusableList.hh b/src/FocusableList.hh
index 29d536f..af73e3e 100644
--- a/src/FocusableList.hh
+++ b/src/FocusableList.hh
@@ -105,6 +105,7 @@ private:
     void parentOrderChanged(Focusable* win);
     void parentWindowAdded(Focusable* win);
     void parentWindowRemoved(Focusable* win);
+    void windowUpdated(FluxboxWindow &fbwin);
 
 
     std::auto_ptr<ClientPattern> m_pat;
diff --git a/src/Window.cc b/src/Window.cc
index ca63178..f91f741 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -262,7 +262,6 @@ FluxboxWindow::FluxboxWindow(WinClient &client):
     m_hintsig(*this),
     m_statesig(*this),
     m_layersig(*this),
-    m_workspacesig(*this),
     m_creation_time(0),
     moving(false), resizing(false),
     m_initialized(false),
@@ -536,7 +535,7 @@ void FluxboxWindow::init() {
         setMaximizedState(tmp);
     }
 
-    m_workspacesig.notify();
+    m_workspacesig.emit(*this);
 
     struct timeval now;
     gettimeofday(&now, NULL);
@@ -627,7 +626,7 @@ void FluxboxWindow::attachClient(WinClient &client, int x, int y) {
     // TODO: one day these should probably be neatened to only act on the
     // affected clients if possible
     m_statesig.notify();
-    m_workspacesig.notify();
+    m_workspacesig.emit(*this);
     m_layersig.notify();
 
     if (was_focused) {
@@ -1537,8 +1536,8 @@ void FluxboxWindow::setWorkspace(int n) {
 
     // notify workspace change
     if (m_initialized && old_wkspc != m_workspace_number) {
-        fbdbg<<this<<" notify workspace signal"<<endl;
-        m_workspacesig.notify();
+        fbdbg<<this<<" emit workspace signal"<<endl;
+        m_workspacesig.emit(*this);
     }
 }
 
@@ -1587,7 +1586,7 @@ void FluxboxWindow::stick() {
     if (m_initialized) {
         stateSig().notify();
         // notify since some things consider "stuck" to be a pseudo-workspace
-        m_workspacesig.notify();
+        m_workspacesig.emit(*this);
     }
 
     ClientList::iterator client_it = clientList().begin();
diff --git a/src/Window.hh b/src/Window.hh
index cbbb817..a394401 100644
--- a/src/Window.hh
+++ b/src/Window.hh
@@ -464,8 +464,7 @@ public:
     const FbTk::Subject &layerSig() const { return m_layersig; }
     FbTk::Subject &hintSig() { return m_hintsig; }
     const FbTk::Subject &hintSig() const { return m_hintsig; }
-    FbTk::Subject &workspaceSig() { return m_workspacesig; }
-    const FbTk::Subject &workspaceSig() const { return m_workspacesig; }
+    FbTk::Signal<FluxboxWindow &> &workspaceSig() { return m_workspacesig; }
     /** @} */ // end group signals
 
     //@}
@@ -543,8 +542,8 @@ private:
     // state and hint signals
     WinSubject m_hintsig,
         m_statesig,
-        m_layersig,
-        m_workspacesig;
+        m_layersig;
+    FbTk::Signal<FluxboxWindow &> m_workspacesig;
 
     time_t m_creation_time;
 
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 0263de7..e319a2f 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -978,9 +978,6 @@ void Fluxbox::update(FbTk::Subject *changedsub) {
     } else if (fbwin && &fbwin->layerSig() == changedsub) { // layer signal
         STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update),
             CallMemFunWithRefArg<AtomHandler, FluxboxWindow&, void>(&AtomHandler::updateLayer, *fbwin));
-    } else if (fbwin && &fbwin->workspaceSig() == changedsub) {  // workspace signal
-        STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update),
-            CallMemFunWithRefArg<AtomHandler, FluxboxWindow&, void>(&AtomHandler::updateWorkspace, *fbwin));
     }
 }
 
@@ -1023,10 +1020,15 @@ void Fluxbox::clientDied(Focusable &focusable) {
     screen.removeClient(client);
 }
 
+void Fluxbox::windowWorkspaceChanged(FluxboxWindow &win) {
+    STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update),
+        CallMemFunWithRefArg<AtomHandler, FluxboxWindow&, void>(&AtomHandler::updateWorkspace, win));
+}
+
 void Fluxbox::attachSignals(FluxboxWindow &win) {
     win.hintSig().attach(this);
     win.stateSig().attach(this);
-    win.workspaceSig().attach(this);
+    join(win.workspaceSig(), FbTk::MemFun(*this, &Fluxbox::windowWorkspaceChanged));
     win.layerSig().attach(this);
     join(win.dieSig(), FbTk::MemFun(*this, &Fluxbox::windowDied));
     STLUtil::forAll(m_atomhandler,
diff --git a/src/fluxbox.hh b/src/fluxbox.hh
index 082297f..4c8fcdf 100644
--- a/src/fluxbox.hh
+++ b/src/fluxbox.hh
@@ -221,6 +221,8 @@ private:
     void windowDied(Focusable &focusable);
     /// Called when a client (WinClient) dies
     void clientDied(Focusable &focusable);
+    /// Called when a window changes workspace
+    void windowWorkspaceChanged(FluxboxWindow &win);
 
     std::auto_ptr<FbAtoms> m_fbatoms;
 
-- 
cgit v0.11.2