From 4faf1bf5c3fe07260b0a4c084db56b0bed12734a Mon Sep 17 00:00:00 2001
From: Tomas Janousek <tomi@nomi.cz>
Date: Mon, 6 Aug 2007 00:36:12 +0200
Subject: "On head" menu -- reloading and refreshing bugfix.

We should reload the contents of this menu on Xinerama layout change.

I switched it from FbMenu to ToggleMenu, because the selected head wasn't
being updated properly.

Signed-off-by: Tomas Janousek <tomi@nomi.cz>
---
 src/Slit.cc     | 12 ++++++++----
 src/Slit.hh     |  7 +++++++
 src/Toolbar.cc  | 12 ++++++++----
 src/Toolbar.hh  |  7 +++++++
 src/Xinerama.hh | 18 ++++++++++++++----
 5 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/src/Slit.cc b/src/Slit.cc
index 18c21f4..b8ff368 100644
--- a/src/Slit.cc
+++ b/src/Slit.cc
@@ -48,10 +48,6 @@
 #include "RootTheme.hh"
 #include "FbMenu.hh"
 
-#ifdef XINERAMA
-#include "Xinerama.hh"
-#endif // XINERAMA
-
 #include "SlitTheme.hh"
 #include "SlitClient.hh"
 #include "Xutil.hh"
@@ -270,6 +266,9 @@ Slit::Slit(BScreen &scr, FbTk::XLayer &layer, const char *filename)
       m_slitmenu(scr.menuTheme(),
                  scr.imageControl(),
                  *scr.layerManager().getLayer(Layer::MENU)),
+#ifdef XINERAMA
+      m_xineramaheadmenu(0),
+#endif // XINERAMA
       frame(scr.rootWindow()),
        //For KDE dock applets
       m_kwm1_dockwindow(XInternAtom(FbTk::App::instance()->display(),
@@ -1113,6 +1112,10 @@ void Slit::exposeEvent(XExposeEvent &ev) {
 
 void Slit::update(FbTk::Subject *subj) {
     reconfigure();
+#ifdef XINERAMA
+    if (subj == &m_screen.resizeSig() && m_xineramaheadmenu)
+        m_xineramaheadmenu->reloadHeads();
+#endif // XINERAMA
 }
 
 void Slit::clearWindow() {
@@ -1254,6 +1257,7 @@ void Slit::setupMenu() {
 #ifdef XINERAMA
     if (screen().hasXinerama()) {
         m_slitmenu.insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"),
+                          m_xineramaheadmenu =
                           new XineramaHeadMenu<Slit>(
                               screen().menuTheme(),
                               screen(),
diff --git a/src/Slit.hh b/src/Slit.hh
index 64ae6b4..a7f8e40 100644
--- a/src/Slit.hh
+++ b/src/Slit.hh
@@ -29,6 +29,10 @@
 #include "LayerMenu.hh"
 #include "Layer.hh"
 
+#ifdef XINERAMA
+#include "Xinerama.hh"
+#endif // XINERAMA
+
 #include "FbTk/Menu.hh"
 #include "FbTk/FbWindow.hh"
 #include "FbTk/Timer.hh"
@@ -144,6 +148,9 @@ private:
     SlitClients m_client_list;
     std::auto_ptr<LayerMenu> m_layermenu;
     FbMenu m_clientlist_menu, m_slitmenu;
+#ifdef XINERAMA
+    XineramaHeadMenu<Slit> *m_xineramaheadmenu;
+#endif // XINERAMA
     std::string m_filename;
 
     struct frame {
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index 2c7bde2..00cdfee 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -35,10 +35,6 @@
 #include "Screen.hh"
 #include "WindowCmd.hh"
 
-#ifdef XINERAMA
-#include "Xinerama.hh"
-#endif // XINERAMA
-
 #include "Strut.hh"
 #include "FbTk/CommandParser.hh"
 #include "Layer.hh"
@@ -216,6 +212,9 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, size_t width):
     m_toolbarmenu(scrn.menuTheme(),
                   scrn.imageControl(),
                   *scrn.layerManager().getLayer(Layer::MENU)),
+#ifdef XINERAMA
+    m_xineramaheadmenu(0),
+#endif // XINERAMA
     m_theme(scrn.screenNumber()),
     m_tool_factory(scrn),
     m_strut(0),
@@ -629,6 +628,10 @@ void Toolbar::update(FbTk::Subject *subj) {
     else
         reconfigure();
 
+#ifdef XINERAMA
+    if (subj == &m_screen.resizeSig() && m_xineramaheadmenu)
+        m_xineramaheadmenu->reloadHeads();
+#endif // XINERAMA
 }
 
 void Toolbar::setPlacement(Toolbar::Placement where) {
@@ -872,6 +875,7 @@ void Toolbar::setupMenus(bool skip_new_placement) {
 #ifdef XINERAMA
     if (screen().hasXinerama()) {
         menu().insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"),
+                      m_xineramaheadmenu =
                       new XineramaHeadMenu<Toolbar>(screen().menuTheme(),
                                                     screen(),
                                                     screen().imageControl(),
diff --git a/src/Toolbar.hh b/src/Toolbar.hh
index c528102..c295e24 100644
--- a/src/Toolbar.hh
+++ b/src/Toolbar.hh
@@ -31,6 +31,10 @@
 #include "ToolTheme.hh"
 #include "Layer.hh"
 
+#ifdef XINERAMA
+#include "Xinerama.hh"
+#endif // XINERAMA
+
 #include "FbTk/Timer.hh"
 #include "FbTk/Resource.hh"
 #include "FbTk/Observer.hh"
@@ -159,6 +163,9 @@ private:
     FbTk::XLayerItem m_layeritem; ///< layer item, must be declared before layermenu
     LayerMenu m_layermenu;
     FbMenu m_placementmenu, m_toolbarmenu;
+#ifdef XINERAMA
+    XineramaHeadMenu<Toolbar> *m_xineramaheadmenu;
+#endif // XINERAMA
 
 
     // themes
diff --git a/src/Xinerama.hh b/src/Xinerama.hh
index f58b4f0..eab2e37 100644
--- a/src/Xinerama.hh
+++ b/src/Xinerama.hh
@@ -25,6 +25,7 @@
 
 #include "FbMenu.hh"
 #include "fluxbox.hh"
+#include "Screen.hh"
 
 #include "FbTk/RefCount.hh"
 #include "FbTk/SimpleCommand.hh"
@@ -59,14 +60,16 @@ private:
 
 /// Create a xinerama menu
 template <typename ItemType>
-class XineramaHeadMenu : public FbMenu {
+class XineramaHeadMenu : public ToggleMenu {
 public:
     XineramaHeadMenu(FbTk::ThemeProxy<FbTk::MenuTheme> &tm, BScreen &screen,
                      FbTk::ImageControl &imgctrl, FbTk::XLayer &layer,
                      ItemType &item, const FbTk::FbString & title = "");
+    void reloadHeads();
 
 private:
     ItemType &m_object;
+    BScreen &m_screen;
 };
 
 
@@ -75,15 +78,22 @@ XineramaHeadMenu<ItemType>::XineramaHeadMenu(
         FbTk::ThemeProxy<FbTk::MenuTheme> &tm, BScreen &screen,
         FbTk::ImageControl &imgctrl, FbTk::XLayer &layer, ItemType &item,
         const FbTk::FbString & title):
-    FbMenu(tm, imgctrl, layer), 
-    m_object(item) 
+    ToggleMenu(tm, imgctrl, layer),
+    m_object(item), m_screen(screen)
 {
     setLabel(title);
+    reloadHeads();
+}
+
+template <typename ItemType>
+void XineramaHeadMenu<ItemType>::reloadHeads()
+{
+    removeAll();
     FbTk::RefCount<FbTk::Command<void> > saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(
                                      *Fluxbox::instance(), 
                                      &Fluxbox::save_rc));
     char tname[128];
-    for (int i=1; i <= screen.numHeads(); ++i) {
+    for (int i=1; i <= m_screen.numHeads(); ++i) {
         // TODO: nls
 /*
         sprintf(tname, I18n::instance()->
-- 
cgit v0.11.2