all repos — fluxbox @ ae68b7f7cd47c91e776fadee7aecb93d5b3ee3df

custom fork of the fluxbox windowmanager

Convert Focusable::orderSig,addSig,removeSig,resetSig to FbTk::Signal
Pavel Labath pavelo@centrum.sk
commit

ae68b7f7cd47c91e776fadee7aecb93d5b3ee3df

parent

19ac8e40d85235328e0e2c7c428a2d3e1e86872c

4 files changed, 72 insertions(+), 79 deletions(-)

jump to
M src/FocusableList.ccsrc/FocusableList.cc

@@ -125,40 +125,41 @@ if (m_parent->contains(**it))

checkUpdate(**it); } } - if (typeid(*subj) == typeid(FocusableListSubject)) { - FocusableListSubject *fsubj = - static_cast<FocusableListSubject *>(subj); - if (subj == &m_parent->addSig()) { - attachSignals(*fsubj->win()); - if (m_pat->match(*fsubj->win())) { - insertFromParent(*fsubj->win()); - m_addsig.notify(fsubj->win()); - } - } else if (subj == &m_parent->removeSig()) - remove(*fsubj->win()); - else if (subj == &m_parent->resetSig()) - reset(); - else if (subj == &m_parent->orderSig()) { - Focusable *win = fsubj->win(); - if (!win || !contains(*win)) - return; - if (insertFromParent(*win)) - m_ordersig.notify(win); +} + +void FocusableList::parentOrderChanged(Focusable *win) { + if(!m_screen.isShuttingdown() && contains(*win)) { + if(insertFromParent(*win)) + m_ordersig.emit(win); + } +} + +void FocusableList::parentWindowAdded(Focusable *win) { + if(!m_screen.isShuttingdown()) { + attachSignals(*win); + if (m_pat->match(*win)) { + insertFromParent(*win); + m_addsig.emit(win); } } } +void FocusableList::parentWindowRemoved(Focusable *win) { + if(!m_screen.isShuttingdown()) + remove(*win); +} + void FocusableList::checkUpdate(Focusable &win) { if (contains(win)) { if (!m_pat->match(win)) { m_list.remove(&win); m_pat->removeMatch(); - m_removesig.notify(&win); + m_removesig.emit(&win); } } else if (m_pat->match(win)) { insertFromParent(win); m_pat->addMatch(); - m_addsig.notify(&win); + m_addsig.emit(&win); } }

@@ -203,13 +204,13 @@

void FocusableList::pushFront(Focusable &win) { m_list.push_front(&win); attachSignals(win); - m_addsig.notify(&win); + m_addsig.emit(&win); } void FocusableList::pushBack(Focusable &win) { m_list.push_back(&win); attachSignals(win); - m_addsig.notify(&win); + m_addsig.emit(&win); } void FocusableList::moveToFront(Focusable &win) {

@@ -219,7 +220,7 @@ return;

m_list.remove(&win); m_list.push_front(&win); - m_ordersig.notify(&win); + m_ordersig.emit(&win); } void FocusableList::moveToBack(Focusable &win) {

@@ -229,7 +230,7 @@ return;

m_list.remove(&win); m_list.push_back(&win); - m_ordersig.notify(&win); + m_ordersig.emit(&win); } void FocusableList::remove(Focusable &win) {

@@ -241,7 +242,7 @@ if (!contained) {

return; } m_list.remove(&win); - m_removesig.notify(&win); + m_removesig.emit(&win); } void FocusableList::updateTitle(Focusable& win) {

@@ -292,7 +293,7 @@ }

m_pat->resetMatches(); if (m_parent) addMatching(); - m_resetsig.notify(0); + m_resetsig.emit(); } bool FocusableList::contains(const Focusable &win) const {

@@ -311,10 +312,10 @@ return 0;

} void FocusableList::attachChild(FocusableList &child) const { - m_addsig.attach(&child); - m_removesig.attach(&child); - m_resetsig.attach(&child); - m_ordersig.attach(&child); + m_addsig.connect(FbTk::MemFun(child, &FocusableList::parentWindowAdded)); + m_ordersig.connect(FbTk::MemFun(child, &FocusableList::parentOrderChanged)); + m_removesig.connect(FbTk::MemFun(child, &FocusableList::parentWindowRemoved)); + m_resetsig.connect(FbTk::MemFun(child, &FocusableList::reset)); } void FocusableList::workspaceChanged(BScreen &screen) {
M src/FocusableList.hhsrc/FocusableList.hh

@@ -82,30 +82,12 @@ /**

@name signals @{ */ - FbTk::Subject &orderSig() { return m_ordersig; } - const FbTk::Subject &orderSig() const { return m_ordersig; } - FbTk::Subject &addSig() { return m_addsig; } - const FbTk::Subject &addSig() const { return m_addsig; } - FbTk::Subject &removeSig() { return m_removesig; } - const FbTk::Subject &removeSig() const { return m_removesig; } - FbTk::Subject &resetSig() { return m_resetsig; } - const FbTk::Subject &resetSig() const { return m_resetsig; } + FbTk::Signal<Focusable *> &orderSig() { return m_ordersig; } + FbTk::Signal<Focusable *> &addSig() { return m_addsig; } + FbTk::Signal<Focusable *> &removeSig() { return m_removesig; } + FbTk::Signal<> &resetSig() { return m_resetsig; } /** @} */ // end group signals - /** - * Signaling object to attatch observers to. - */ - class FocusableListSubject: public FbTk::Subject { - public: - explicit FocusableListSubject(): m_win(0) { } - void notify(Focusable *win) { m_win = win; FbTk::Subject::notify(); } - /// @return context for this signal - Focusable *win() { return m_win; } - - private: - Focusable *m_win; - }; - private: void init(); void addMatching();

@@ -120,13 +102,18 @@ void focusedWindowChanged(BScreen &screen, FluxboxWindow *win, WinClient *client);

/// Title has changed for a window /// @param win The window that title changed for. void updateTitle(Focusable& win); + void parentOrderChanged(Focusable* win); + void parentWindowAdded(Focusable* win); + void parentWindowRemoved(Focusable* win); + std::auto_ptr<ClientPattern> m_pat; const FocusableList *m_parent; BScreen &m_screen; std::list<Focusable *> m_list; - mutable FocusableListSubject m_ordersig, m_addsig, m_removesig, m_resetsig; + mutable FbTk::Signal<Focusable *> m_ordersig, m_addsig, m_removesig; + mutable FbTk::Signal<> m_resetsig; typedef std::map<Focusable*, FbTk::RefCount<FbTk::SignalTracker> > SignalMap; SignalMap m_signal_map; };
M src/IconbarTool.ccsrc/IconbarTool.cc

@@ -331,7 +331,7 @@ }

void IconbarTool::setAlignment(FbTk::Container::Alignment align) { *m_rc_alignment = align; - update(0); + update(ALIGN, NULL); m_menu.reconfigure(); }

@@ -344,22 +344,24 @@

// lock graphics update m_icon_container.setUpdateLock(true); - if (m_winlist.get()) { - m_winlist->addSig().detach(this); - m_winlist->removeSig().detach(this); - m_winlist->orderSig().detach(this); - m_winlist->resetSig().detach(this); - } if (mode == "none") m_winlist.reset(new FocusableList(m_screen)); else m_winlist.reset(new FocusableList(m_screen, mode + " (iconhidden=no)")); if (m_winlist.get()) { - m_winlist->addSig().attach(this); - m_winlist->removeSig().attach(this); - m_winlist->orderSig().attach(this); - m_winlist->resetSig().attach(this); + m_winlist->addSig().connect( + std::bind1st(FbTk::MemFun(*this, &IconbarTool::update), LIST_ADD) + ); + m_winlist->removeSig().connect( + std::bind1st(FbTk::MemFun(*this, &IconbarTool::update), LIST_REMOVE) + ); + m_winlist->addSig().connect( + std::bind1st(FbTk::MemFun(*this, &IconbarTool::update), LIST_ORDER) + ); + m_winlist->resetSig().connect(FbTk::MemFunBind( + *this, &IconbarTool::update, LIST_RESET, static_cast<Focusable *>(0) + )); } reset();

@@ -389,7 +391,7 @@ void IconbarTool::themeReconfigured() {

setMode(*m_rc_mode); } -void IconbarTool::update(FbTk::Subject *subj) { +void IconbarTool::update(UpdateReason reason, Focusable *win) { // ignore updates if we're shutting down if (m_screen.isShuttingdown()) { if (!m_icons.empty())

@@ -405,17 +407,18 @@

// lock graphic update m_icon_container.setUpdateLock(true); - if (subj && typeid(*subj) == typeid(FocusableList::FocusableListSubject)) { - FocusableList::FocusableListSubject *fsubj = - static_cast<FocusableList::FocusableListSubject *>(subj); - if (subj == &m_winlist->addSig()) - insertWindow(*fsubj->win()); - else if (subj == &m_winlist->removeSig()) - removeWindow(*fsubj->win()); - else if (subj == &m_winlist->resetSig()) + switch(reason) { + case LIST_ADD: case LIST_ORDER: + insertWindow(*win); + break; + case LIST_REMOVE: + removeWindow(*win); + break; + case LIST_RESET: reset(); - else if (subj == &m_winlist->orderSig()) - insertWindow(*fsubj->win()); + break; + case ALIGN: + break; } // unlock container and update graphics
M src/IconbarTool.hhsrc/IconbarTool.hh

@@ -28,7 +28,6 @@ #include "FbMenu.hh"

#include "FbTk/Container.hh" #include "FbTk/CachedPixmap.hh" -#include "FbTk/Observer.hh" #include "FbTk/Resource.hh" #include <map>

@@ -39,7 +38,7 @@ class IconButton;

class Focusable; class FocusableList; -class IconbarTool: public ToolbarItem, public FbTk::Observer { +class IconbarTool: public ToolbarItem { public: typedef std::map<Focusable *, IconButton *> IconMap;

@@ -54,7 +53,6 @@ void resize(unsigned int width, unsigned int height);

void moveResize(int x, int y, unsigned int width, unsigned int height); - void update(FbTk::Subject *subj); void show(); void hide(); void setAlignment(FbTk::Container::Alignment a);

@@ -72,6 +70,7 @@ FbTk::Container::Alignment alignment() const { return m_icon_container.alignment(); }

const BScreen &screen() const { return m_screen; } private: + enum UpdateReason { LIST_ORDER, LIST_ADD, LIST_REMOVE, LIST_RESET, ALIGN }; void updateSizing();

@@ -94,6 +93,9 @@ /// remove all windows and add again

void reset(); /// add icons to the list void updateList(); + + /// called when the list emits a signal + void update(UpdateReason reason, Focusable *win); void themeReconfigured();