From 6a0280aa4d8b468617a7dd5f7a6523d0422364e8 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 6 May 2011 22:26:20 +0200 Subject: Convert FluxboxWindow::layerSig to FbTk::Signal --- src/FocusableList.cc | 71 +++++++++++++++------------------------------------- src/FocusableList.hh | 5 +--- src/Window.cc | 5 ++-- src/Window.hh | 8 +++--- src/fluxbox.cc | 26 +++++-------------- src/fluxbox.hh | 5 ++-- 6 files changed, 34 insertions(+), 86 deletions(-) diff --git a/src/FocusableList.cc b/src/FocusableList.cc index 0368442..77ff247 100644 --- a/src/FocusableList.cc +++ b/src/FocusableList.cc @@ -107,17 +107,6 @@ void FocusableList::init() { } } -void FocusableList::update(FbTk::Subject *subj) { - if (subj == 0 || m_screen.isShuttingdown()) - return; - - if (typeid(*subj) == typeid(FluxboxWindow::WinSubject)) { - FluxboxWindow::WinSubject *fsubj = - static_cast(subj); - windowUpdated(fsubj->win()); - } -} - void FocusableList::windowUpdated(FluxboxWindow &fbwin) { if (m_screen.isShuttingdown()) return; @@ -243,7 +232,7 @@ void FocusableList::remove(Focusable &win) { // if the window isn't already in this list, we could send a bad signal bool contained = contains(win); - detachSignals(win); + m_signal_map.erase(&win); if (!contained) { return; } @@ -257,50 +246,30 @@ void FocusableList::updateTitle(Focusable& win) { #include "Debug.hh" void FocusableList::attachSignals(Focusable &win) { - if (m_parent) { - FluxboxWindow *fbwin = win.fbwindow(); - - // attach various signals for matching - FbTk::RefCount &tracker = m_signal_map[&win]; - if (! tracker) { - // we have not attached to this window yet - 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) - ); - tracker->join(fbwin->stateSig(), - MemFun(*this, &FocusableList::windowUpdated) - ); - } - } - - if (!fbwin) - return; - fbwin->layerSig().attach(this); - // TODO: can't watch (head=...) yet - } -} + if (m_parent == NULL) + return; -void FocusableList::detachSignals(Focusable &win) { - m_signal_map.erase(&win); - if (m_parent) { - // detach various signals for matching - FluxboxWindow *fbwin = win.fbwindow(); - if (!fbwin) - return; - fbwin->layerSig().detach(this); - // TODO: can't watch (head=...) yet + FluxboxWindow *fbwin = win.fbwindow(); + + // attach various signals for matching + FbTk::RefCount &tracker = m_signal_map[&win]; + if (! tracker) { + // we have not attached to this window yet + 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)); + tracker->join(fbwin->stateSig(), MemFun(*this, &FocusableList::windowUpdated)); + tracker->join(fbwin->layerSig(), MemFun(*this, &FocusableList::windowUpdated)); + // TODO: can't watch (head=...) yet + } } } void FocusableList::reset() { - while (!m_list.empty()) { - detachSignals(*m_list.back()); - m_list.pop_back(); - } + m_signal_map.clear(); + m_list.clear(); m_pat->resetMatches(); if (m_parent) addMatching(); diff --git a/src/FocusableList.hh b/src/FocusableList.hh index af73e3e..aea7909 100644 --- a/src/FocusableList.hh +++ b/src/FocusableList.hh @@ -39,7 +39,7 @@ class Focusable; class WinClient; class FluxboxWindow; -class FocusableList: public FbTk::Observer, private FbTk::NotCopyable, +class FocusableList: private FbTk::NotCopyable, private FbTk::SignalTracker { public: typedef std::list Focusables; @@ -58,8 +58,6 @@ public: static void parseArgs(const std::string &in, int &opts, std::string &out); static const FocusableList *getListFromOptions(BScreen &scr, int opts); - void update(FbTk::Subject *subj); - /// functions for modifying the list contents void pushFront(Focusable &win); void pushBack(Focusable &win); @@ -94,7 +92,6 @@ private: void checkUpdate(Focusable &win); bool insertFromParent(Focusable &win); void attachSignals(Focusable &win); - void detachSignals(Focusable &win); void reset(); void attachChild(FocusableList &child) const; void workspaceChanged(BScreen &screen); diff --git a/src/Window.cc b/src/Window.cc index c43ab36..11d46bc 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -260,7 +260,6 @@ FluxboxWindow::FluxboxWindow(WinClient &client): Focusable(client.screen(), this), oplock(false), m_hintsig(*this), - m_layersig(*this), m_creation_time(0), moving(false), resizing(false), m_initialized(false), @@ -626,7 +625,7 @@ void FluxboxWindow::attachClient(WinClient &client, int x, int y) { // affected clients if possible m_statesig.emit(*this); m_workspacesig.emit(*this); - m_layersig.notify(); + m_layersig.emit(*this); if (was_focused) { // don't ask me why, but client doesn't seem to keep focus in new window @@ -1545,7 +1544,7 @@ void FluxboxWindow::setLayerNum(int layernum) { if (m_initialized) { fbdbg< &stateSig() { return m_statesig; } - FbTk::Subject &layerSig() { return m_layersig; } - const FbTk::Subject &layerSig() const { return m_layersig; } + FbTk::Signal &layerSig() { return m_layersig; } FbTk::Subject &hintSig() { return m_hintsig; } const FbTk::Subject &hintSig() const { return m_hintsig; } FbTk::Signal &workspaceSig() { return m_workspacesig; } @@ -539,9 +538,8 @@ private: // state and hint signals - WinSubject m_hintsig, - m_layersig; - FbTk::Signal m_workspacesig, m_statesig; + WinSubject m_hintsig; + FbTk::Signal m_workspacesig, m_statesig, m_layersig; time_t m_creation_time; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 9c30b03..0dc958d 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -940,24 +940,6 @@ void Fluxbox::handleSignal(int signum) { } -void Fluxbox::update(FbTk::Subject *changedsub) { - //TODO: fix signaling, this does not look good - FluxboxWindow *fbwin = 0; - - if (typeid(*changedsub) == typeid(FluxboxWindow::WinSubject)) { - FluxboxWindow::WinSubject *winsub = dynamic_cast(changedsub); - fbwin = &winsub->win(); - } else if (typeid(*changedsub) == typeid(Focusable::FocusSubject)) { - Focusable::FocusSubject *winsub = dynamic_cast(changedsub); - fbwin = winsub->win().fbwindow(); - } - - if (fbwin && &fbwin->layerSig() == changedsub) { // layer signal - STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), - CallMemFunWithRefArg(&AtomHandler::updateLayer, *fbwin)); - } -} - void Fluxbox::windowDied(Focusable &focusable) { FluxboxWindow *fbwin = focusable.fbwindow(); @@ -1024,11 +1006,15 @@ void Fluxbox::windowStateChanged(FluxboxWindow &win) { } } +void Fluxbox::windowLayerChanged(FluxboxWindow &win) { + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + CallMemFunWithRefArg(&AtomHandler::updateLayer, win)); +} + void Fluxbox::attachSignals(FluxboxWindow &win) { - win.hintSig().attach(this); join(win.stateSig(), FbTk::MemFun(*this, &Fluxbox::windowStateChanged)); join(win.workspaceSig(), FbTk::MemFun(*this, &Fluxbox::windowWorkspaceChanged)); - win.layerSig().attach(this); + join(win.layerSig(), FbTk::MemFun(*this, &Fluxbox::windowLayerChanged)); join(win.dieSig(), FbTk::MemFun(*this, &Fluxbox::windowDied)); STLUtil::forAll(m_atomhandler, CallMemFunWithRefArg(&AtomHandler::setupFrame, win)); diff --git a/src/fluxbox.hh b/src/fluxbox.hh index af28ac7..d1e8e93 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -28,7 +28,6 @@ #include "FbTk/App.hh" #include "FbTk/Resource.hh" #include "FbTk/Timer.hh" -#include "FbTk/Observer.hh" #include "FbTk/SignalHandler.hh" #include "FbTk/Signal.hh" @@ -76,7 +75,6 @@ class FbAtoms; */ class Fluxbox : public FbTk::App, public FbTk::SignalEventHandler, - public FbTk::Observer, private FbTk::SignalTracker { public: Fluxbox(int argc, char **argv, @@ -156,7 +154,6 @@ public: /// handle any system signal sent to the application void handleSignal(int signum); - void update(FbTk::Subject *changed); /// todo, remove this. just temporary void updateFrameExtents(FluxboxWindow &win); @@ -225,6 +222,8 @@ private: void windowWorkspaceChanged(FluxboxWindow &win); /// Called when a window changes state void windowStateChanged(FluxboxWindow &win); + /// Called when a window layer changes + void windowLayerChanged(FluxboxWindow &win); std::auto_ptr m_fbatoms; -- cgit v0.11.2