From 2f4db57898920a3f17eaaa2586a39dad76d5c7e8 Mon Sep 17 00:00:00 2001 From: Henrik Kinnunen Date: Thu, 18 Sep 2008 22:27:16 +0200 Subject: Changed workspace count signal in BScreen to use the new signal system. --- ChangeLog | 3 +++ src/Screen.cc | 5 ++--- src/Screen.hh | 5 +++-- src/SendToMenu.cc | 8 +++++++- src/SendToMenu.hh | 9 ++++++++- src/WorkspaceMenu.cc | 50 +++++++++++++++++++++++++++++--------------------- src/WorkspaceMenu.hh | 6 +++++- src/fluxbox.cc | 21 +++++++++++++-------- src/fluxbox.hh | 8 +++++++- 9 files changed, 77 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index da15ff6..998ead4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ (Format: Year/Month/Day) Changes for 1.1.2: *08/09/18: + * Changed workspace count signal in BScreen to use the new signal + system. (Henrik) + Screen.cc/hh, SendToMenu.cc/hh, fluxbox.hh/cc, WorkspaceMenu.cc/hh * Added new Signal/Slot system to FbTk (Henrik) This is suppose to replace the obsolete Subject/Observer classes. FbTk/Signal.hh, FbTk/Slot.hh, FbTk/MemFun.hh, tests/testSignals.cc diff --git a/src/Screen.cc b/src/Screen.cc index 23bc417..83bc92e 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_workspacecount_sig(*this), // workspace count signal m_workspacenames_sig(*this), // workspace names signal m_workspace_area_sig(*this), // workspace area signal m_currentworkspace_sig(*this), // current workspace signal @@ -1110,7 +1109,7 @@ int BScreen::addWorkspace() { } saveWorkspaces(m_workspaces_list.size()); - workspaceCountSig().notify(); + workspaceCountSig().emit( *this ); return m_workspaces_list.size(); @@ -1140,7 +1139,7 @@ int BScreen::removeLastWorkspace() { m_workspaces_list.pop_back(); saveWorkspaces(m_workspaces_list.size()); - workspaceCountSig().notify(); + workspaceCountSig().emit( *this ); // must be deleted after we send notify!! // so we dont get bad pointers somewhere // while processing the notify signal diff --git a/src/Screen.hh b/src/Screen.hh index 038570e..3f57c22 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -39,6 +39,7 @@ #include "FbTk/MultLayers.hh" #include "FbTk/NotCopyable.hh" #include "FbTk/Observer.hh" +#include "FbTk/Signal.hh" #include @@ -213,7 +214,7 @@ public: /// icon list sig FbTk::Subject &iconListSig() { return m_iconlist_sig; } /// workspace count signal - FbTk::Subject &workspaceCountSig() { return m_workspacecount_sig; } + FbTk::Signal &workspaceCountSig() { return m_workspacecount_sig; } /// workspace names signal FbTk::Subject &workspaceNamesSig() { return m_workspacenames_sig; } /// workspace area signal @@ -493,7 +494,6 @@ private: ScreenSubject m_clientlist_sig, ///< client signal m_iconlist_sig, ///< notify if a window gets iconified/deiconified - m_workspacecount_sig, ///< workspace count signal m_workspacenames_sig, ///< workspace names signal m_workspace_area_sig, ///< workspace area changed signal m_currentworkspace_sig, ///< current workspace signal @@ -502,6 +502,7 @@ private: m_resize_sig, ///< resize signal m_bg_change_sig; ///< background change signal + FbTk::Signal m_workspacecount_sig; ///< workspace count signal FbTk::MultLayers m_layermanager; bool root_colormap_installed, managed; diff --git a/src/SendToMenu.cc b/src/SendToMenu.cc index 2362eb2..397ec81 100644 --- a/src/SendToMenu.cc +++ b/src/SendToMenu.cc @@ -31,6 +31,7 @@ #include "FbTk/MultiButtonMenuItem.hh" #include "FbTk/Command.hh" #include "FbTk/SimpleObserver.hh" +#include "FbTk/MemFun.hh" class SendToCmd: public FbTk::Command { public: @@ -55,9 +56,14 @@ SendToMenu::SendToMenu(BScreen &screen): // workspace names signal // current workspace signal m_rebuildObs = makeObserver(*this, &SendToMenu::rebuildMenu); - screen.workspaceCountSig().attach(m_rebuildObs); + screen.workspaceNamesSig().attach(m_rebuildObs); screen.currentWorkspaceSig().attach(m_rebuildObs); + + // setup new signal system + join( screen.workspaceCountSig(), + FbTk::MemFun(*this, &SendToMenu::workspaceCountChange) ); + // no title for this menu, it should be a submenu in the window menu. disableTitle(); // setup menu items diff --git a/src/SendToMenu.hh b/src/SendToMenu.hh index 0f668a9..1582dd5 100644 --- a/src/SendToMenu.hh +++ b/src/SendToMenu.hh @@ -25,6 +25,8 @@ #include "FbMenu.hh" +#include "FbTk/Signal.hh" + namespace FbTk { class Observer; } @@ -35,7 +37,7 @@ class BScreen; * Creates the "send to menu". * Displays all the workspaces for which the current window can be sent to. */ -class SendToMenu:public FbMenu { +class SendToMenu:public FbMenu, private FbTk::SignalTracker { public: /// @param screen the screen on which this menu should be created on. explicit SendToMenu(BScreen &screen); @@ -43,6 +45,11 @@ public: /// @see FbTk::Menu void show(); private: + /// workspace count changed on screen + void workspaceCountChange( BScreen& screen ) { + rebuildMenu(); + } + /// Rebuild the menu from scratch. void rebuildMenu(); /// listens to signals that makes this instance need to rebuild menu diff --git a/src/WorkspaceMenu.cc b/src/WorkspaceMenu.cc index 3bef2b6..33cfb7f 100644 --- a/src/WorkspaceMenu.cc +++ b/src/WorkspaceMenu.cc @@ -36,6 +36,7 @@ #include "FbTk/MenuItem.hh" #include "FbTk/MenuSeparator.hh" #include "FbTk/MultiButtonMenuItem.hh" +#include "FbTk/MemFun.hh" #include @@ -61,6 +62,27 @@ WorkspaceMenu::WorkspaceMenu(BScreen &screen): init(screen); } +void WorkspaceMenu::workspaceInfoChanged( BScreen& screen ) { + while (numberOfItems() > NR_STATIC_ITEMS) { + remove(IDX_AFTER_ICONS); + } + // for each workspace add workspace name and it's menu + // to our workspace menu + for (size_t workspace = 0; workspace < screen.numberOfWorkspaces(); + ++workspace) { + Workspace *wkspc = screen.getWorkspace(workspace); + wkspc->menu().setInternalMenu(); + FbTk::MultiButtonMenuItem* mb_menu = new FbTk::MultiButtonMenuItem(5, + wkspc->name().c_str(), + &wkspc->menu()); + FbTk::RefCount > jump_cmd(new JumpToWorkspaceCmd(wkspc->workspaceID())); + mb_menu->setCommand(3, jump_cmd); + insert(mb_menu, workspace + IDX_AFTER_ICONS); + } + + updateMenu(-1); +} + void WorkspaceMenu::update(FbTk::Subject *subj) { if (subj != 0 && typeid(*subj) == typeid(BScreen::ScreenSubject)) { @@ -78,26 +100,8 @@ void WorkspaceMenu::update(FbTk::Subject *subj) { } setItemSelected(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS, true); updateMenu(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS); - } else if (subj == &screen.workspaceCountSig() || - subj == &screen.workspaceNamesSig()) { - while (numberOfItems() > NR_STATIC_ITEMS) { - remove(IDX_AFTER_ICONS); - } - // for each workspace add workspace name and it's menu - // to our workspace menu - for (size_t workspace = 0; workspace < screen.numberOfWorkspaces(); - ++workspace) { - Workspace *wkspc = screen.getWorkspace(workspace); - wkspc->menu().setInternalMenu(); - FbTk::MultiButtonMenuItem* mb_menu = new FbTk::MultiButtonMenuItem(5, - wkspc->name().c_str(), - &wkspc->menu()); - FbTk::RefCount > jump_cmd(new JumpToWorkspaceCmd(wkspc->workspaceID())); - mb_menu->setCommand(3, jump_cmd); - insert(mb_menu, workspace + IDX_AFTER_ICONS); - } - - updateMenu(-1); + } else if ( subj == &screen.workspaceNamesSig() ) { + workspaceInfoChanged( screen ); } } else { FbTk::Menu::update(subj); @@ -106,8 +110,12 @@ void WorkspaceMenu::update(FbTk::Subject *subj) { void WorkspaceMenu::init(BScreen &screen) { screen.currentWorkspaceSig().attach(this); - screen.workspaceCountSig().attach(this); + screen.workspaceNamesSig().attach(this); + + join( screen.workspaceCountSig(), + FbTk::MemFun( *this, &WorkspaceMenu::workspaceInfoChanged ) ); + using namespace FbTk; _FB_USES_NLS; diff --git a/src/WorkspaceMenu.hh b/src/WorkspaceMenu.hh index 8591a65..e8a671d 100644 --- a/src/WorkspaceMenu.hh +++ b/src/WorkspaceMenu.hh @@ -23,6 +23,7 @@ #define WORKSPACEMENU_HH #include "FbMenu.hh" +#include "FbTk/Signal.hh" class BScreen; @@ -33,7 +34,7 @@ class BScreen; * workspace name. * It also contains client menus for all clients. */ -class WorkspaceMenu: public FbMenu { +class WorkspaceMenu: public FbMenu, private FbTk::SignalTracker { public: explicit WorkspaceMenu(BScreen &screen); virtual ~WorkspaceMenu() { } @@ -42,6 +43,9 @@ public: private: /// initialize menu for the screen void init(BScreen &screen); + /// Called when workspace info was changed + /// ( number of workspace, workspace names etc ) + void workspaceInfoChanged( BScreen& screen ); }; #endif // WORKSPACEMENU_HH diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 4a223f9..4a7c68d 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -53,6 +53,7 @@ #include "FbTk/Select2nd.hh" #include "FbTk/Compose.hh" #include "FbTk/KeyUtil.hh" +#include "FbTk/MemFun.hh" //Use GNU extensions #ifndef _GNU_SOURCE @@ -452,11 +453,13 @@ void Fluxbox::initScreen(BScreen *screen) { // attach screen signals to this screen->currentWorkspaceSig().attach(this); screen->focusedWindowSig().attach(this); - screen->workspaceCountSig().attach(this); screen->workspaceNamesSig().attach(this); screen->workspaceAreaSig().attach(this); screen->clientListSig().attach(this); + join( screen->workspaceCountSig(), + FbTk::MemFun( *this, &Fluxbox::workspaceCountChanged ) ); + // initiate atomhandler for screen specific stuff for (AtomHandlerContainerIt it= m_atomhandler.begin(); it != m_atomhandler.end(); @@ -1095,13 +1098,7 @@ void Fluxbox::update(FbTk::Subject *changedsub) { } else if (typeid(*changedsub) == typeid(BScreen::ScreenSubject)) { BScreen::ScreenSubject *subj = dynamic_cast(changedsub); BScreen &screen = subj->screen(); - if ((&(screen.workspaceCountSig())) == changedsub) { - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it).first->update()) - (*it).first->updateWorkspaceCount(screen); - } - } else if ((&(screen.workspaceNamesSig())) == changedsub) { + if ((&(screen.workspaceNamesSig())) == changedsub) { for (AtomHandlerContainerIt it= m_atomhandler.begin(); it != m_atomhandler.end(); ++it) { if ((*it).first->update()) @@ -1519,3 +1516,11 @@ void Fluxbox::updateFrameExtents(FluxboxWindow &win) { (*it).first->updateFrameExtents(win); } } + +void Fluxbox::workspaceCountChanged( BScreen& screen ) { + for (AtomHandlerContainerIt it= m_atomhandler.begin(); + it != m_atomhandler.end(); ++it) { + if ((*it).first->update()) + (*it).first->updateWorkspaceCount(screen); + } +} diff --git a/src/fluxbox.hh b/src/fluxbox.hh index a6c0b2f..8478833 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -30,6 +30,8 @@ #include "FbTk/Timer.hh" #include "FbTk/Observer.hh" #include "FbTk/SignalHandler.hh" +#include "FbTk/Signal.hh" + #include "AttentionNoticeHandler.hh" #include @@ -74,7 +76,8 @@ class FbAtoms; */ class Fluxbox : public FbTk::App, public FbTk::SignalEventHandler, - public FbTk::Observer { + public FbTk::Observer, + private FbTk::SignalTracker { public: Fluxbox(int argc, char **argv, const char * dpy_name= 0, const char *rcfilename = 0, bool xsync = false); @@ -198,6 +201,9 @@ private: void handleUnmapNotify(XUnmapEvent &ue); void handleClientMessage(XClientMessageEvent &ce); + /// Called when workspace count on a specific screen changed. + void workspaceCountChanged( BScreen& screen ); + std::auto_ptr m_fbatoms; FbTk::ResourceManager m_resourcemanager, &m_screen_rm; -- cgit v0.11.2