From 71674739ec6de376273cb3c5b938da132e7035c5 Mon Sep 17 00:00:00 2001
From: Henrik Kinnunen <fluxgen@fluxbox.org>
Date: Sun, 21 Sep 2008 15:25:47 +0200
Subject: Changed workspace names signal in BScreen to use the new signal
 system

---
 ChangeLog                |  3 +++
 src/Screen.cc            |  5 ++---
 src/Screen.hh            |  6 ++++--
 src/SendToMenu.cc        | 15 +++++++--------
 src/SendToMenu.hh        |  2 --
 src/WorkspaceMenu.cc     | 17 ++---------------
 src/WorkspaceMenu.hh     |  3 +--
 src/WorkspaceNameTool.cc |  4 ++--
 src/fluxbox.cc           | 19 +++++++++++--------
 src/fluxbox.hh           |  2 ++
 10 files changed, 34 insertions(+), 42 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0bd3700..37fc0c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
  (Format: Year/Month/Day)
 Changes for 1.1.2
 *08/09/21:
+   * Changed workspace names signal in BScreen to use the new signal
+     system (Henrik)
+     Screen.hh/cc, SendToMenu.hh/cc, WorkspaceMenu.hh/cc, WorkspaceNameTool.hh/cc
    * Changed current workspace signal in Bscreen to use the new signal
      system (Henrik)
      FocusableList.hh/cc, Screen.hh/cc, SendToMenu.hh/cc,
diff --git a/src/Screen.cc b/src/Screen.cc
index 06f3146..7c372bc 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -341,7 +341,6 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
                  int scrn, int num_layers) :
     m_clientlist_sig(*this),  // client signal
     m_iconlist_sig(*this), // icon list signal
-    m_workspacenames_sig(*this), // workspace names signal
     m_workspace_area_sig(*this), // workspace area signal
     m_focusedwindow_sig(*this), // focused window signal
     m_reconfigure_sig(*this), // reconfigure signal
@@ -1017,7 +1016,7 @@ void BScreen::updateWorkspaceName(unsigned int w) {
     Workspace *space = getWorkspace(w);
     if (space) {
         m_workspace_names[w] = space->name();
-        m_workspacenames_sig.notify();
+        m_workspacenames_sig.emit(*this);
         Fluxbox::instance()->save_rc();
     }
 }
@@ -1104,7 +1103,7 @@ int BScreen::addWorkspace() {
 
     if (save_name) {
         addWorkspaceName(wkspc->name().c_str()); //update names
-        m_workspacenames_sig.notify();
+        m_workspacenames_sig.emit(*this);
     }
 
     saveWorkspaces(m_workspaces_list.size());
diff --git a/src/Screen.hh b/src/Screen.hh
index bbfe70b..7bafead 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -216,7 +216,7 @@ public:
     /// workspace count signal
     FbTk::Signal<void, BScreen&> &workspaceCountSig() { return m_workspacecount_sig; }
     /// workspace names signal
-    FbTk::Subject &workspaceNamesSig() { return m_workspacenames_sig; }
+    FbTk::Signal<void, BScreen&> &workspaceNamesSig() { return m_workspacenames_sig; }
     /// workspace area signal
     FbTk::Subject &workspaceAreaSig() { return m_workspace_area_sig; }
     /// current workspace signal
@@ -494,7 +494,7 @@ private:
     ScreenSubject
     m_clientlist_sig,  ///< client signal
         m_iconlist_sig, ///< notify if a window gets iconified/deiconified
-        m_workspacenames_sig, ///< workspace names signal
+
         m_workspace_area_sig, ///< workspace area changed signal
         m_focusedwindow_sig, ///< focused window signal
         m_reconfigure_sig, ///< reconfigure signal
@@ -503,6 +503,8 @@ private:
 
     FbTk::Signal<void, BScreen&> m_workspacecount_sig; ///< workspace count signal
     FbTk::Signal<void, BScreen&> m_currentworkspace_sig; ///< current workspace signal
+    FbTk::Signal<void, BScreen&> m_workspacenames_sig; ///< workspace names signal
+
     FbTk::MultLayers m_layermanager;
 
     bool root_colormap_installed, managed;
diff --git a/src/SendToMenu.cc b/src/SendToMenu.cc
index ac7612b..0aa1c31 100644
--- a/src/SendToMenu.cc
+++ b/src/SendToMenu.cc
@@ -55,17 +55,16 @@ SendToMenu::SendToMenu(BScreen &screen):
     // workspace count signal
     // workspace names signal
     // current workspace signal
-    m_rebuildObs = makeObserver(*this, &SendToMenu::rebuildMenu);
 
-    screen.workspaceNamesSig().attach(m_rebuildObs);
+    join(screen.workspaceNamesSig(),
+         FbTk::MemFun(*this, &SendToMenu::rebuildMenuForScreen));
 
-    // setup new signal system
-    join( screen.currentWorkspaceSig(),
-          FbTk::MemFun(*this, &SendToMenu::rebuildMenuForScreen));
+    join(screen.currentWorkspaceSig(),
+         FbTk::MemFun(*this, &SendToMenu::rebuildMenuForScreen));
 
     // setup new signal system
-    join( screen.workspaceCountSig(),
-          FbTk::MemFun(*this, &SendToMenu::rebuildMenuForScreen));
+    join(screen.workspaceCountSig(),
+         FbTk::MemFun(*this, &SendToMenu::rebuildMenuForScreen));
 
     // no title for this menu, it should be a submenu in the window menu.
     disableTitle();
@@ -74,7 +73,7 @@ SendToMenu::SendToMenu(BScreen &screen):
 }
 
 SendToMenu::~SendToMenu() {
-    delete m_rebuildObs;
+
 }
 
 void SendToMenu::rebuildMenu() {
diff --git a/src/SendToMenu.hh b/src/SendToMenu.hh
index a217b5f..37f45fc 100644
--- a/src/SendToMenu.hh
+++ b/src/SendToMenu.hh
@@ -52,8 +52,6 @@ private:
 
     /// Rebuild the menu from scratch.
     void rebuildMenu();
-    /// listens to signals that makes this instance need to rebuild menu
-    FbTk::Observer *m_rebuildObs;
 };
 
 #endif // SENDTOMENU_HH
diff --git a/src/WorkspaceMenu.cc b/src/WorkspaceMenu.cc
index dd7b96e..c343920 100644
--- a/src/WorkspaceMenu.cc
+++ b/src/WorkspaceMenu.cc
@@ -97,27 +97,14 @@ void WorkspaceMenu::workspaceChanged(BScreen& screen) {
     updateMenu(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS);
 }
 
-void WorkspaceMenu::update(FbTk::Subject *subj) {
-
-    if (subj != 0 && typeid(*subj) == typeid(BScreen::ScreenSubject)) {
-        BScreen::ScreenSubject &screen_subj = *static_cast<BScreen::ScreenSubject *>(subj);
-        BScreen &screen = screen_subj.screen();
-        if ( subj == &screen.workspaceNamesSig() ) {
-            workspaceInfoChanged( screen );
-        }
-    } else {
-        FbTk::Menu::update(subj);
-    }
-}
-
 void WorkspaceMenu::init(BScreen &screen) {
 
-    screen.workspaceNamesSig().attach(this);
-
     join(screen.currentWorkspaceSig(),
          FbTk::MemFun(*this, &WorkspaceMenu::workspaceChanged));
     join(screen.workspaceCountSig(),
          FbTk::MemFun(*this, &WorkspaceMenu::workspaceInfoChanged));
+    join(screen.workspaceNamesSig(),
+         FbTk::MemFun(*this, &WorkspaceMenu::workspaceInfoChanged));
 
     using namespace FbTk;
     _FB_USES_NLS;
diff --git a/src/WorkspaceMenu.hh b/src/WorkspaceMenu.hh
index 19cf0f8..fef576c 100644
--- a/src/WorkspaceMenu.hh
+++ b/src/WorkspaceMenu.hh
@@ -38,8 +38,7 @@ class WorkspaceMenu: public FbMenu, private FbTk::SignalTracker {
 public:
     explicit WorkspaceMenu(BScreen &screen);
     virtual ~WorkspaceMenu() { }
-    /// called when a subject is sending a signal
-    void update(FbTk::Subject *subj);
+
 private:
     /// initialize menu for the screen
     void init(BScreen &screen);
diff --git a/src/WorkspaceNameTool.cc b/src/WorkspaceNameTool.cc
index b6afad8..579592f 100644
--- a/src/WorkspaceNameTool.cc
+++ b/src/WorkspaceNameTool.cc
@@ -43,10 +43,10 @@ WorkspaceNameTool::WorkspaceNameTool(const FbTk::FbWindow &parent,
     m_button.setText(m_screen.currentWorkspace()->name());
 
     // setup signals
-    screen.workspaceNamesSig().attach(this);
-
     join(screen.currentWorkspaceSig(),
          FbTk::MemFun(*this, &WorkspaceNameTool::updateForScreen));
+    join(screen.workspaceNamesSig(),
+         FbTk::MemFun(*this, &WorkspaceNameTool::updateForScreen));
 
     theme.reconfigSig().attach(this);
 }
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index acbb55d..e9c548c 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -454,10 +454,11 @@ void Fluxbox::initScreen(BScreen *screen) {
 
     // attach screen signals to this
     screen->focusedWindowSig().attach(this);
-    screen->workspaceNamesSig().attach(this);
     screen->workspaceAreaSig().attach(this);
     screen->clientListSig().attach(this);
 
+    join(screen->workspaceNamesSig(), 
+         FbTk::MemFun(*this, &Fluxbox::workspaceNamesChanged));
     join(screen->currentWorkspaceSig(), 
          FbTk::MemFun(*this, &Fluxbox::workspaceChanged));
 
@@ -1102,13 +1103,7 @@ void Fluxbox::update(FbTk::Subject *changedsub) {
     } else if (typeid(*changedsub) == typeid(BScreen::ScreenSubject)) {
         BScreen::ScreenSubject *subj = dynamic_cast<BScreen::ScreenSubject *>(changedsub);
         BScreen &screen = subj->screen();
-        if ((&(screen.workspaceNamesSig())) == changedsub) {
-            for (AtomHandlerContainerIt it= m_atomhandler.begin();
-                 it != m_atomhandler.end(); ++it) {
-                if ((*it).first->update())
-                    (*it).first->updateWorkspaceNames(screen);
-            }
-        } else if ((&(screen.focusedWindowSig())) == changedsub) {
+        if ((&(screen.focusedWindowSig())) == changedsub) {
             for (AtomHandlerContainerIt it= m_atomhandler.begin();
                  it != m_atomhandler.end(); it++) {
                 (*it).first->updateFocusedWindow(screen,
@@ -1530,3 +1525,11 @@ void Fluxbox::workspaceChanged( BScreen& screen ) {
             (*it).first->updateCurrentWorkspace(screen);
     }
 }
+
+void Fluxbox::workspaceNamesChanged(BScreen &screen) {
+    for (AtomHandlerContainerIt it= m_atomhandler.begin();
+         it != m_atomhandler.end(); ++it) {
+        if ((*it).first->update())
+            (*it).first->updateWorkspaceNames(screen);
+    }
+}
diff --git a/src/fluxbox.hh b/src/fluxbox.hh
index 36208b6..82740d4 100644
--- a/src/fluxbox.hh
+++ b/src/fluxbox.hh
@@ -205,6 +205,8 @@ private:
     void workspaceCountChanged( BScreen& screen );
     /// Called when workspace was switched
     void workspaceChanged(BScreen& screen);
+    /// Called when workspace names changed
+    void workspaceNamesChanged(BScreen &screen);
 
     std::auto_ptr<FbAtoms> m_fbatoms;
 
-- 
cgit v0.11.2