From 93b0c5322a7482d83e38657b36e9814f8415e47b Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Sun, 11 May 2008 17:22:40 -0700 Subject: refactor menu reloading, added FbTk::AutoReloadHelper --- src/FbCommands.cc | 10 ++-- src/FbMenu.hh | 7 +++ src/FbTk/AutoReloadHelper.cc | 66 +++++++++++++++++++++++++ src/FbTk/AutoReloadHelper.hh | 54 +++++++++++++++++++++ src/FbTk/Makefile.am | 1 + src/MenuCreator.cc | 113 ++++++++++++++++++++----------------------- src/MenuCreator.hh | 14 ++++-- src/Screen.cc | 85 ++++++++++++++++++++------------ src/Screen.hh | 27 ++++++----- src/fluxbox.cc | 59 ---------------------- src/fluxbox.hh | 15 ------ 11 files changed, 263 insertions(+), 188 deletions(-) create mode 100644 src/FbTk/AutoReloadHelper.cc create mode 100644 src/FbTk/AutoReloadHelper.hh diff --git a/src/FbCommands.cc b/src/FbCommands.cc index 4eabae2..3a09b69 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc @@ -73,11 +73,11 @@ namespace { void showMenu(const BScreen &screen, FbTk::Menu &menu) { - // special case for root menu - if (&menu == &screen.rootMenu()) { - Fluxbox* fb = Fluxbox::instance(); - if(fb->menuTimestampsChanged()) - fb->rereadMenu(); + // check if menu has changed + if (typeid(menu) == typeid(FbMenu)) { + FbMenu *fbmenu = static_cast(&menu); + if (fbmenu->reloadHelper()) + fbmenu->reloadHelper()->checkReload(); } Window root_ret; // not used diff --git a/src/FbMenu.hh b/src/FbMenu.hh index b9c4654..11ed3c3 100644 --- a/src/FbMenu.hh +++ b/src/FbMenu.hh @@ -22,8 +22,11 @@ #ifndef FBMENU_HH #define FBMENU_HH +#include + #include "FbTk/Menu.hh" #include "FbTk/XLayerItem.hh" +#include "FbTk/AutoReloadHelper.hh" class FluxboxWindow; @@ -44,11 +47,15 @@ public: void buttonReleaseEvent(XButtonEvent &be); void keyPressEvent(XKeyEvent &ke); + void setReloadHelper(FbTk::AutoReloadHelper *helper) { m_reloader.reset(helper); } + FbTk::AutoReloadHelper *reloadHelper() { return m_reloader.get(); } + static void setWindow(FluxboxWindow *win) { s_window = win; } static FluxboxWindow *window() { return s_window; } private: FbTk::XLayerItem m_layeritem; + std::auto_ptr m_reloader; static FluxboxWindow *s_window; }; diff --git a/src/FbTk/AutoReloadHelper.cc b/src/FbTk/AutoReloadHelper.cc new file mode 100644 index 0000000..e3c1d59 --- /dev/null +++ b/src/FbTk/AutoReloadHelper.cc @@ -0,0 +1,66 @@ +// AutoReloadHelper.cc +// Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#include "AutoReloadHelper.hh" + +#include "FileUtil.hh" +#include "StringUtil.hh" + +namespace FbTk { + +void AutoReloadHelper::checkReload() { + if (!m_reload_cmd.get()) + return; + TimestampMap::const_iterator it = m_timestamps.begin(); + TimestampMap::const_iterator it_end = m_timestamps.end(); + for (; it != it_end; ++it) { + if (FileUtil::getLastStatusChangeTimestamp(it->first.c_str()) != + it->second) { + reload(); + return; + } + } +} + +void AutoReloadHelper::setMainFile(std::string file) { + file = StringUtil::expandFilename(file); + if (file == m_main_file) + return; + m_main_file = file; + reload(); +} + +void AutoReloadHelper::addFile(std::string file) { + if (file.empty()) + return; + file = StringUtil::expandFilename(file); + m_timestamps[file] = FileUtil::getLastStatusChangeTimestamp(file.c_str()); +} + +void AutoReloadHelper::reload() { + if (!m_reload_cmd.get()) + return; + m_timestamps.clear(); + addFile(m_main_file); + m_reload_cmd->execute(); +} + +} // end namespace FbTk diff --git a/src/FbTk/AutoReloadHelper.hh b/src/FbTk/AutoReloadHelper.hh new file mode 100644 index 0000000..36be8f1 --- /dev/null +++ b/src/FbTk/AutoReloadHelper.hh @@ -0,0 +1,54 @@ +// AutoReloadHelper.hh +// Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#ifndef AUTORELOADHELPER_HH +#define AUTORELOADHELPER_HH + +#include +#include +#include + +#include "Command.hh" +#include "RefCount.hh" + +namespace FbTk { + +class AutoReloadHelper { +public: + + void setMainFile(std::string filename); + void addFile(std::string filename); + void setReloadCmd(RefCount > cmd) { m_reload_cmd = cmd; } + + void checkReload(); + void reload(); + +private: + RefCount > m_reload_cmd; + std::string m_main_file; + + typedef std::map TimestampMap; + TimestampMap m_timestamps; +}; + +} // end namespace FbTk + +#endif // AUTORELOADHELPER_HH diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am index fcf0304..f830e4a 100644 --- a/src/FbTk/Makefile.am +++ b/src/FbTk/Makefile.am @@ -45,6 +45,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ RegExp.hh RegExp.cc \ FbString.hh FbString.cc \ Subject.hh Subject.cc Observer.hh Observer.cc SimpleObserver.hh \ + AutoReloadHelper.hh AutoReloadHelper.cc \ Transparent.hh Transparent.cc \ FbPixmap.hh FbPixmap.cc \ FbDrawable.hh FbDrawable.cc \ diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 25f99ca..1af5482 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -59,6 +59,7 @@ using std::string; using std::vector; using std::list; using std::less; +using FbTk::AutoReloadHelper; list MenuCreator::encoding_stack; list MenuCreator::stacksize_stack; @@ -68,13 +69,16 @@ FbTk::StringConvertor MenuCreator::m_stringconvertor(FbTk::StringConvertor::ToFb namespace { void createStyleMenu(FbTk::Menu &parent, const string &label, - const string &directory) { + AutoReloadHelper *reloader, const string &directory) { // perform shell style ~ home directory expansion string stylesdir(FbTk::StringUtil::expandFilename(directory)); if (!FbTk::FileUtil::isDirectory(stylesdir.c_str())) return; + if (reloader) + reloader->addFile(stylesdir); + FbTk::Directory dir(stylesdir.c_str()); // create a vector of all the filenames in the directory @@ -99,18 +103,21 @@ void createStyleMenu(FbTk::Menu &parent, const string &label, } // update menu graphics parent.updateMenu(); - Fluxbox::instance()->saveMenuFilename(stylesdir.c_str()); } void createRootCmdMenu(FbTk::Menu &parent, const string &label, - const string &directory, const string &cmd) { + const string &directory, AutoReloadHelper *reloader, + const string &cmd) { // perform shell style ~ home directory expansion string rootcmddir(FbTk::StringUtil::expandFilename(directory)); if (!FbTk::FileUtil::isDirectory(rootcmddir.c_str())) return; + if (reloader) + reloader->addFile(rootcmddir); + FbTk::Directory dir(rootcmddir.c_str()); // create a vector of all the filenames in the directory @@ -134,7 +141,6 @@ void createRootCmdMenu(FbTk::Menu &parent, const string &label, } // update menu graphics parent.updateMenu(); - Fluxbox::instance()->saveMenuFilename(rootcmddir.c_str()); } @@ -172,20 +178,26 @@ public: }; -void translateMenuItem(FbTk::Parser &parse, ParseItem &item, FbTk::StringConvertor &labelconvertor); +void translateMenuItem(FbTk::Parser &parse, ParseItem &item, + FbTk::StringConvertor &labelconvertor, + AutoReloadHelper *reloader); -void parseMenu(FbTk::Parser &pars, FbTk::Menu &menu, FbTk::StringConvertor &label_convertor) { +void parseMenu(FbTk::Parser &pars, FbTk::Menu &menu, + FbTk::StringConvertor &label_convertor, + AutoReloadHelper *reloader) { ParseItem pitem(&menu); while (!pars.eof()) { pitem.load(pars, label_convertor); if (pitem.key() == "end") return; - translateMenuItem(pars, pitem, label_convertor); + translateMenuItem(pars, pitem, label_convertor, reloader); } } -void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::StringConvertor &labelconvertor) { +void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, + FbTk::StringConvertor &labelconvertor, + AutoReloadHelper *reloader) { if (pitem.menu() == 0) throw string("translateMenuItem: We must have a menu in ParseItem!"); @@ -255,13 +267,13 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::StringConver if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) && (filelist[file_index][0] != '.') && (thisfile[thisfile.length() - 1] != '~')) { - MenuCreator::createFromFile(thisfile, menu, false); + MenuCreator::createFromFile(thisfile, menu, reloader, false); } } } else { // inject this file into the current menu - MenuCreator::createFromFile(newfile, menu, false); + MenuCreator::createFromFile(newfile, menu, reloader, false); } safe_counter--; @@ -278,22 +290,22 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::StringConver else submenu->setLabel(str_label); - parseMenu(parse, *submenu, labelconvertor); + parseMenu(parse, *submenu, labelconvertor, reloader); submenu->updateMenu(); menu.insert(str_label, submenu); } // end of submenu else if (str_key == "stylesdir" || str_key == "stylesmenu") { - createStyleMenu(menu, str_label, + createStyleMenu(menu, str_label, reloader, str_key == "stylesmenu" ? str_cmd : str_label); } // end of stylesdir else if (str_key == "themesdir" || str_key == "themesmenu") { - createStyleMenu(menu, str_label, + createStyleMenu(menu, str_label, reloader, str_key == "themesmenu" ? str_cmd : str_label); } // end of themesdir else if (str_key == "wallpapers" || str_key == "wallpapermenu" || str_key == "rootcommands") { - createRootCmdMenu(menu, str_label, str_label, + createRootCmdMenu(menu, str_label, str_label, reloader, str_cmd == "" ? realProgramName("fbsetbg") : str_cmd); } // end of wallpapers else if (str_key == "workspaces") { @@ -335,7 +347,9 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::StringConver } -void parseWindowMenu(FbTk::Parser &parse, FbTk::Menu &menu, FbTk::StringConvertor &labelconvertor) { +void parseWindowMenu(FbTk::Parser &parse, FbTk::Menu &menu, + FbTk::StringConvertor &labelconvertor, + AutoReloadHelper *reloader) { ParseItem pitem(&menu); while (!parse.eof()) { @@ -343,16 +357,16 @@ void parseWindowMenu(FbTk::Parser &parse, FbTk::Menu &menu, FbTk::StringConverto if (MenuCreator::createWindowMenuItem(pitem.key(), pitem.label(), menu)) continue; - if (pitem.key() == "end") { + if (pitem.key() == "end") return; - } else if (pitem.key() == "submenu") { + if (pitem.key() == "submenu") { FbTk::Menu *submenu = MenuCreator::createMenu(pitem.label(), menu.screenNumber()); - parseWindowMenu(parse, *submenu, labelconvertor); + parseWindowMenu(parse, *submenu, labelconvertor, reloader); submenu->updateMenu(); menu.insert(pitem.label(), submenu); } else { // try non window menu specific stuff - translateMenuItem(parse, pitem, labelconvertor); + translateMenuItem(parse, pitem, labelconvertor, reloader); } } } @@ -376,12 +390,12 @@ bool getStart(FbMenuParser &parser, string &label, FbTk::StringConvertor &labelc }; // end of anonymous namespace -FbTk::Menu *MenuCreator::createMenu(const string &label, int screen_number) { +FbMenu *MenuCreator::createMenu(const string &label, int screen_number) { BScreen *screen = Fluxbox::instance()->findScreen(screen_number); if (screen == 0) return 0; - FbTk::Menu *menu = new FbMenu(screen->menuTheme(), + FbMenu *menu = new FbMenu(screen->menuTheme(), screen->imageControl(), *screen->layerManager().getLayer(Layer::MENU)); if (!label.empty()) @@ -391,7 +405,8 @@ FbTk::Menu *MenuCreator::createMenu(const string &label, int screen_number) { } bool MenuCreator::createFromFile(const string &filename, - FbTk::Menu &inject_into, bool begin) { + FbTk::Menu &inject_into, + AutoReloadHelper *reloader, bool begin) { string real_filename = FbTk::StringUtil::expandFilename(filename); FbMenuParser parser(real_filename); @@ -409,73 +424,49 @@ bool MenuCreator::createFromFile(const string &filename, } // save menu filename, so we can check if it changes - Fluxbox::instance()->saveMenuFilename(real_filename.c_str()); + if (reloader) + reloader->addFile(real_filename); - parseMenu(parser, inject_into, m_stringconvertor); + parseMenu(parser, inject_into, m_stringconvertor, reloader); endFile(); return true; } -bool MenuCreator::createWindowMenuFromFile(const string &filename, - FbTk::Menu &inject_into) { +void MenuCreator::createWindowMenuFromFile(const string &filename, + FbTk::Menu &inject_into, + AutoReloadHelper *reloader) { string real_filename = FbTk::StringUtil::expandFilename(filename); FbMenuParser parser(real_filename); if (!parser.isLoaded()) - return false; + return; string label; startFile(); if (!getStart(parser, label, m_stringconvertor)) { endFile(); - return false; + return; } - parseWindowMenu(parser, inject_into, m_stringconvertor); - endFile(); + if (reloader) + reloader->addFile(real_filename); - return true; + parseWindowMenu(parser, inject_into, m_stringconvertor, reloader); + endFile(); } -FbTk::Menu *MenuCreator::createMenuType(const string &type, int screen_num) { +FbMenu *MenuCreator::createMenuType(const string &type, int screen_num) { BScreen *screen = Fluxbox::instance()->findScreen(screen_num); if (screen == 0) return 0; - if (type == "iconmenu") { + if (type == "iconmenu") return new ClientMenu(*screen, screen->iconList(), &screen->iconListSig()); - } else if (type == "workspacemenu") { + else if (type == "workspacemenu") return new WorkspaceMenu(*screen); - } else if (type == "windowmenu") { - FbTk::Menu *menu = createMenu("", screen_num); - - menu->disableTitle(); // not titlebar - if (screen->windowMenuFilename().empty() || - ! createWindowMenuFromFile(screen->windowMenuFilename(), *menu)) { - const char *default_menu[] = { - "shade", - "stick", - "maximize", - "iconify", - "raise", - "lower", - "sendto", - "layer", - "alpha", - "extramenus", - "separator", - "close", - 0 - }; - for (unsigned int i=0; default_menu[i]; ++i) - createWindowMenuItem(default_menu[i], "", *menu); - } - menu->reconfigure(); // update graphics - return menu; - } return 0; } diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh index 660d097..8fb0242 100644 --- a/src/MenuCreator.hh +++ b/src/MenuCreator.hh @@ -28,18 +28,24 @@ #include namespace FbTk { +class AutoReloadHelper; class Menu; } +class FbMenu; class FluxboxWindow; class MenuCreator { public: - static FbTk::Menu *createMenu(const std::string &label, int screen_num); - static FbTk::Menu *createMenuType(const std::string &label, int screen_num); + static FbMenu *createMenu(const std::string &label, int screen_num); + static FbMenu *createMenuType(const std::string &label, int screen_num); static bool createFromFile(const std::string &filename, - FbTk::Menu &inject_into, bool begin = true); - static bool createWindowMenuFromFile(const std::string &filename, FbTk::Menu &inject_into); + FbTk::Menu &inject_into, + FbTk::AutoReloadHelper *reloader = NULL, + bool begin = true); + static void createWindowMenuFromFile(const std::string &filename, + FbTk::Menu &inject_into, + FbTk::AutoReloadHelper *reloader); static bool createWindowMenuItem(const std::string &type, const std::string &label, FbTk::Menu &inject_into); diff --git a/src/Screen.cc b/src/Screen.cc index 8b00186..609da60 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -502,6 +502,15 @@ BScreen::BScreen(FbTk::ResourceManager &rm, // own resources we must do this. fluxbox->load_rc(*this); + m_windowmenu.reset(createMenu("")); + m_windowmenu->setInternalMenu(); + m_windowmenu->setReloadHelper(new FbTk::AutoReloadHelper()); + m_windowmenu->reloadHelper()->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &BScreen::rereadWindowMenu))); + + m_rootmenu.reset(createMenu("")); + m_rootmenu->setReloadHelper(new FbTk::AutoReloadHelper()); + m_rootmenu->reloadHelper()->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &BScreen::rereadMenu))); + m_configmenu.reset(createMenu(_FB_XTEXT(Menu, Configuration, "Configuration", "Title of configuration menu"))); setupConfigmenu(*m_configmenu.get()); @@ -889,8 +898,8 @@ void BScreen::cycleFocus(int options, const ClientPattern *pat, bool reverse) { } -FbTk::Menu *BScreen::createMenu(const string &label) { - FbTk::Menu *menu = new FbMenu(menuTheme(), +FbMenu *BScreen::createMenu(const string &label) { + FbMenu *menu = new FbMenu(menuTheme(), imageControl(), *layerManager().getLayer(Layer::MENU)); if (!label.empty()) @@ -898,8 +907,9 @@ FbTk::Menu *BScreen::createMenu(const string &label) { return menu; } -FbTk::Menu *BScreen::createToggleMenu(const string &label) { - FbTk::Menu *menu = new ToggleMenu(menuTheme(), + +FbMenu *BScreen::createToggleMenu(const string &label) { + FbMenu *menu = new ToggleMenu(menuTheme(), imageControl(), *layerManager().getLayer(Layer::MENU)); if (!label.empty()) @@ -912,9 +922,7 @@ void BScreen::addExtraWindowMenu(const FbTk::FbString &label, FbTk::Menu *menu) menu->setInternalMenu(); menu->disableTitle(); m_extramenus.push_back(make_pair(label, menu)); - // recreate window menu - m_windowmenu.reset(MenuCreator::createMenuType("windowmenu", screenNumber())); - m_windowmenu->setInternalMenu(); + rereadWindowMenu(); } void BScreen::reconfigure() { @@ -956,10 +964,9 @@ void BScreen::reconfigure() { } } - //reconfigure menus - // recreate window menu - m_windowmenu.reset(MenuCreator::createMenuType("windowmenu", screenNumber())); - m_windowmenu->setInternalMenu(); + // update menu filenames + m_rootmenu->reloadHelper()->setMainFile(fluxbox->getMenuFilename()); + m_windowmenu->reloadHelper()->setMainFile(windowMenuFilename()); // reconfigure workspaces for_each(m_workspaces_list.begin(), @@ -992,12 +999,6 @@ void BScreen::reconfigureTabs() { (*it)->fbwindow()->applyDecorations(); } - -void BScreen::rereadMenu() { - initMenu(); - m_rootmenu->reconfigure(); -} - void BScreen::updateWorkspaceName(unsigned int w) { Workspace *space = getWorkspace(w); if (space) { @@ -1489,23 +1490,20 @@ void BScreen::reassociateWindow(FluxboxWindow *w, unsigned int wkspc_id, void BScreen::initMenus() { m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber())); - m_windowmenu.reset(MenuCreator::createMenuType("windowmenu", screenNumber())); - m_windowmenu->setInternalMenu(); - initMenu(); + m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename()); + m_windowmenu->reloadHelper()->setMainFile(windowMenuFilename()); } -void BScreen::initMenu() { +void BScreen::rereadMenu() { - if (m_rootmenu.get()) { - m_rootmenu->removeAll(); - m_rootmenu->setLabel(""); - } else - m_rootmenu.reset(createMenu("")); + m_rootmenu->removeAll(); + m_rootmenu->setLabel(""); Fluxbox * const fb = Fluxbox::instance(); if (!fb->getMenuFilename().empty()) - MenuCreator::createFromFile(fb->getMenuFilename(), *m_rootmenu); + MenuCreator::createFromFile(fb->getMenuFilename(), *m_rootmenu, + m_rootmenu->reloadHelper()); if (m_rootmenu->numberOfItems() == 0) { _FB_USES_NLS; @@ -1521,14 +1519,39 @@ void BScreen::initMenu() { restart_fb); m_rootmenu->insert(_FB_XTEXT(Menu, Exit, "Exit", "Exit command"), exit_fb); - // still save the menu filename, in case it becomes valid later - if (!fb->getMenuFilename().empty()) - fb->saveMenuFilename(fb->getMenuFilename().c_str()); } - m_rootmenu->updateMenu(); } +void BScreen::rereadWindowMenu() { + + m_windowmenu->removeAll(); + if (!windowMenuFilename().empty()) + MenuCreator::createWindowMenuFromFile(windowMenuFilename(), + *m_windowmenu, + m_windowmenu->reloadHelper()); + + if (m_windowmenu->numberOfItems() == 0) { + const char *defaults[] = { + "shade", + "stick", + "maximize", + "iconify", + "raise", + "lower", + "sendto", + "layer", + "alpha", + "extramenus", + "separator", + "close", + 0 + }; + for (unsigned int i=0; defaults[i]; ++i) + MenuCreator::createWindowMenuItem(defaults[i], "", *m_windowmenu); + } + +} void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { m_configmenu_list.push_back(make_pair(label, &menu)); diff --git a/src/Screen.hh b/src/Screen.hh index 7758c90..57c41b6 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -54,6 +54,7 @@ #include class ClientPattern; +class FbMenu; class Focusable; class FluxboxWindow; class WinClient; @@ -122,12 +123,12 @@ public: const std::string &windowMenuFilename() const { return *resource.windowmenufile; } FbTk::ImageControl &imageControl() { return *m_image_control.get(); } // menus - const FbTk::Menu &rootMenu() const { return *m_rootmenu.get(); } - FbTk::Menu &rootMenu() { return *m_rootmenu.get(); } - const FbTk::Menu &configMenu() const { return *m_configmenu.get(); } - FbTk::Menu &configMenu() { return *m_configmenu.get(); } - const FbTk::Menu &windowMenu() const { return *m_windowmenu.get(); } - FbTk::Menu &windowMenu() { return *m_windowmenu.get(); } + const FbMenu &rootMenu() const { return *m_rootmenu.get(); } + FbMenu &rootMenu() { return *m_rootmenu.get(); } + const FbMenu &configMenu() const { return *m_configmenu.get(); } + FbMenu &configMenu() { return *m_configmenu.get(); } + const FbMenu &windowMenu() const { return *m_windowmenu.get(); } + FbMenu &windowMenu() { return *m_windowmenu.get(); } ExtraMenus &extraWindowMenus() { return m_extramenus; } const ExtraMenus &extraWindowMenus() const { return m_extramenus; } @@ -166,9 +167,9 @@ public: Workspace *currentWorkspace() { return m_current_workspace; } const Workspace *currentWorkspace() const { return m_current_workspace; } /// @return the workspace menu - const FbTk::Menu &workspaceMenu() const { return *m_workspacemenu.get(); } + const FbMenu &workspaceMenu() const { return *m_workspacemenu.get(); } /// @return the workspace menu - FbTk::Menu &workspaceMenu() { return *m_workspacemenu.get(); } + FbMenu &workspaceMenu() { return *m_workspacemenu.get(); } /// @return focus control handler const FocusControl &focusControl() const { return *m_focus_control; } /// @return focus control handler @@ -251,15 +252,15 @@ public: /** * Creates an empty menu with specified label * @param label for the menu - * @return create menu + * @return created menu */ - FbTk::Menu *createMenu(const std::string &label); + FbMenu *createMenu(const std::string &label); /** * Creates an empty toggle menu with a specific label * @param label * @return created menu */ - FbTk::Menu *createToggleMenu(const std::string &label); + FbMenu *createToggleMenu(const std::string &label); /** * For extras to add menus. @@ -383,6 +384,7 @@ public: void reconfigure(); void reconfigureTabs(); void rereadMenu(); + void rereadWindowMenu(); void shutdown(); /// show position window centered on the screen with "X x Y" text void showPosition(int x, int y); @@ -489,7 +491,6 @@ public: private: void setupConfigmenu(FbTk::Menu &menu); - void initMenu(); void renderGeomWindow(); void renderPosWindow(); @@ -515,7 +516,7 @@ private: std::auto_ptr m_image_control; - std::auto_ptr m_configmenu, m_rootmenu, m_workspacemenu, m_windowmenu; + std::auto_ptr m_configmenu, m_rootmenu, m_workspacemenu, m_windowmenu; ExtraMenus m_extramenus; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 7d774cc..70503a5 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -437,8 +437,6 @@ Fluxbox::~Fluxbox() { delete (*it).first; } m_atomhandler.clear(); - - clearMenuFilenames(); } @@ -1469,63 +1467,6 @@ BScreen *Fluxbox::findScreen(int id) { return *it; } -bool Fluxbox::menuTimestampsChanged() const { - list::const_iterator it = m_menu_timestamps.begin(); - list::const_iterator it_end = m_menu_timestamps.end(); - for (; it != it_end; ++it) { - - time_t timestamp = FbTk::FileUtil::getLastStatusChangeTimestamp((*it)->filename.c_str()); - - if (timestamp != (*it)->timestamp) - return true; - } - - // no timestamp changed - return false; -} - -void Fluxbox::rereadMenu() { - clearMenuFilenames(); - - for_each(m_screen_list.begin(), - m_screen_list.end(), - mem_fun(&BScreen::rereadMenu)); -} - -void Fluxbox::saveMenuFilename(const char *filename) { - if (filename == 0) - return; - - bool found = false; - - list::iterator it = m_menu_timestamps.begin(); - list::iterator it_end = m_menu_timestamps.end(); - for (; it != it_end; ++it) { - if ((*it)->filename == filename) { - found = true; - break; - } - } - - if (! found) { - time_t timestamp = FbTk::FileUtil::getLastStatusChangeTimestamp(filename); - - MenuTimestamp *ts = new MenuTimestamp; - - ts->filename = filename; - ts->timestamp = timestamp; - - m_menu_timestamps.push_back(ts); - } -} - -void Fluxbox::clearMenuFilenames() { - while(!m_menu_timestamps.empty()) { - delete m_menu_timestamps.back(); - m_menu_timestamps.pop_back(); - } -} - void Fluxbox::timed_reconfigure() { if (m_reconfigure_wait) real_reconfigure(); diff --git a/src/fluxbox.hh b/src/fluxbox.hh index e7c7556..8b22a04 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -136,8 +136,6 @@ public: void shutdown(); void load_rc(BScreen &scr); void saveStyleFilename(const char *val) { m_rc_stylefile = (val == 0 ? "" : val); } - void saveMenuFilename(const char *); - void clearMenuFilenames(); void saveWindowSearch(Window win, WinClient *winclient); // some windows relate to the group, not the client, so we record separately // searchWindow on these windows will give the active client in the group @@ -149,8 +147,6 @@ public: void removeGroupSearch(Window win); void restart(const char *command = 0); void reconfigure(); - void rereadMenu(); - /// reloads the menus if the timestamps changed /// handle any system signal sent to the application void handleSignal(int signum); @@ -176,8 +172,6 @@ public: typedef std::list ScreenList; const ScreenList screenList() const { return m_screen_list; } - /// @return whether the timestamps on the menu changed - bool menuTimestampsChanged() const; bool haveShape() const { return m_have_shape; } int shapeEventbase() const { return m_shape_eventbase; } void getDefaultDataFilename(const char *name, std::string &) const; @@ -190,14 +184,6 @@ public: AttentionNoticeHandler &attentionHandler() { return m_attention_handler; } private: - - typedef struct MenuTimestamp { - std::string filename; - time_t timestamp; - } MenuTimestamp; - - - std::string getRcFilename(); void load_rc(); @@ -241,7 +227,6 @@ private: // will have it's window being the group index std::multimap m_group_search; - std::list m_menu_timestamps; ScreenList m_screen_list; FluxboxWindow *m_masked_window; -- cgit v0.11.2