From 2073ae12a4e633d18f49559111131fffbc495dbd Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavelo@centrum.sk>
Date: Fri, 6 May 2011 23:17:13 +0200
Subject: Convert FbWinFrame::frameExtentSig to FbTk::Signal

Also, I spotted a potential bug in the code. I marked the place with XXX. Someone should take a
look at that.
---
 src/FbWinFrame.cc |  6 +++---
 src/FbWinFrame.hh |  7 +++----
 src/Window.cc     |  9 +++++----
 src/Window.hh     | 14 ++------------
 4 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc
index 2b64fa5..a8ee4d5 100644
--- a/src/FbWinFrame.cc
+++ b/src/FbWinFrame.cc
@@ -533,7 +533,7 @@ void FbWinFrame::applyState() {
     }
 
     moveResize(new_x, new_y, new_w, new_h);
-    frameExtentSig().notify();
+    frameExtentSig().emit();
 }
 
 void FbWinFrame::setAlpha(bool focused, int alpha) {
@@ -1478,7 +1478,7 @@ void FbWinFrame::applyDecorations(bool do_move) {
         m_state.saveGeometry(x(), y(), width(), height());
     }
     if (client_move)
-        frameExtentSig().notify();
+        frameExtentSig().emit();
 }
 
 bool FbWinFrame::setBorderWidth(bool do_move) {
@@ -1529,7 +1529,7 @@ bool FbWinFrame::setBorderWidth(bool do_move) {
         alignTabs();
 
     if (do_move) {
-        frameExtentSig().notify();
+        frameExtentSig().emit();
         gravityTranslate(grav_x, grav_y, sizeHints().win_gravity,
                          m_active_orig_client_bw, false);
         // if the location changes, shift it
diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh
index 6c52566..5e13301 100644
--- a/src/FbWinFrame.hh
+++ b/src/FbWinFrame.hh
@@ -27,13 +27,13 @@
 #include "FbTk/FbWindow.hh"
 #include "FbTk/EventHandler.hh"
 #include "FbTk/RefCount.hh"
-#include "FbTk/Subject.hh"
 #include "FbTk/Color.hh"
 #include "FbTk/LayerItem.hh"
 #include "FbTk/TextButton.hh"
 #include "FbTk/DefaultValue.hh"
 #include "FbTk/Container.hh"
 #include "FbTk/Shape.hh"
+#include "FbTk/Signal.hh"
 
 #include <vector>
 #include <memory>
@@ -231,8 +231,7 @@ public:
     const FbTk::LayerItem &layerItem() const { return m_layeritem; }
     FbTk::LayerItem &layerItem() { return m_layeritem; }
 
-    const FbTk::Subject &frameExtentSig() const { return m_frame_extent_sig; }
-    FbTk::Subject &frameExtentSig() { return m_frame_extent_sig; }
+    FbTk::Signal<> &frameExtentSig() { return m_frame_extent_sig; }
     /// @returns true if the window is inside titlebar, 
     /// assuming window is an event window that was generated for this frame.
     bool insideTitlebar(Window win) const;
@@ -318,7 +317,7 @@ private:
     FbTk::FbWindow m_clientarea; ///< window that sits behind client window to fill gaps @see setClientWindow
     //@}
 
-    FbTk::Subject m_frame_extent_sig;
+    FbTk::Signal<> m_frame_extent_sig;
 
     typedef std::vector<FbTk::Button *> ButtonList;
     ButtonList m_buttons_left, ///< buttons to the left
diff --git a/src/Window.cc b/src/Window.cc
index b3c0698..6e60a80 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -288,7 +288,7 @@ FluxboxWindow::FluxboxWindow(WinClient &client):
     m_resize_corner(RIGHTBOTTOM) {
 
     join(m_theme.reconfigSig(), FbTk::MemFun(*this, &FluxboxWindow::themeReconfigured));
-    m_frame.frameExtentSig().attach(this);
+    join(m_frame.frameExtentSig(), FbTk::MemFun(*this, &FluxboxWindow::frameExtentChanged));
 
     init();
 
@@ -538,7 +538,7 @@ void FluxboxWindow::init() {
     gettimeofday(&now, NULL);
     m_creation_time = now.tv_sec;
 
-    frame().frameExtentSig().notify();
+    frame().frameExtentSig().emit();
 
     setupWindow();
 
@@ -1452,6 +1452,7 @@ void FluxboxWindow::setFullscreenLayer() {
 void FluxboxWindow::attachWorkAreaSig() {
     // notify when struts change, so we can resize accordingly
     // Subject checks for duplicates for us
+    // XXX: this is no longer true with signals
     if (m_state.maximized || m_state.fullscreen)
         join(screen().workspaceAreaSig(),
              FbTk::MemFun(*this, &FluxboxWindow::workspaceAreaChanged));
@@ -2677,8 +2678,8 @@ void FluxboxWindow::setTitle(const std::string& title, Focusable &client) {
     titleSig().emit(title, *this);
 }
 
-void FluxboxWindow::update(FbTk::Subject *subj) {
-    if (m_initialized && subj == &m_frame.frameExtentSig()) {
+void FluxboxWindow::frameExtentChanged() {
+    if (m_initialized) {
         Fluxbox::instance()->updateFrameExtents(*this);
         sendConfigureNotify();
     }
diff --git a/src/Window.hh b/src/Window.hh
index 966631d..4ecfe05 100644
--- a/src/Window.hh
+++ b/src/Window.hh
@@ -33,8 +33,6 @@
 
 #include "FbTk/DefaultValue.hh"
 #include "FbTk/Timer.hh"
-#include "FbTk/Subject.hh"
-#include "FbTk/Observer.hh"
 #include "FbTk/EventHandler.hh"
 #include "FbTk/LayerItem.hh"
 #include "FbTk/Signal.hh"
@@ -58,7 +56,7 @@ class Layer;
 }
 
 /// Creates the window frame and handles any window event for it
-class FluxboxWindow: public Focusable, public FbTk::Observer,
+class FluxboxWindow: public Focusable,
                      public FbTk::EventHandler,
                      private FbTk::SignalTracker {
 public:
@@ -466,15 +464,6 @@ public:
 
     //@}
 
-    class WinSubject: public FbTk::Subject {
-    public:
-        WinSubject(FluxboxWindow &w):m_win(w) { }
-        FluxboxWindow &win() { return m_win; }
-        const FluxboxWindow &win() const { return m_win; }
-    private:
-        FluxboxWindow &m_win;
-    };
-
     bool oplock; ///< Used to help stop transient loops occurring by locking a window during certain operations
 
 private:
@@ -534,6 +523,7 @@ private:
     void focusedWindowChanged(BScreen &screen, FluxboxWindow *focused_win, WinClient* client);
     /// Called when workspace area on screen changed.
     void workspaceAreaChanged(BScreen &screen);
+    void frameExtentChanged();
 
 
     // state and hint signals
-- 
cgit v0.11.2