all repos — fluxbox @ 72a45fae3c39323206e7d19913bb3ab17a691691

custom fork of the fluxbox windowmanager

reuse some menu pointers instead of using delete/new
Mark Tiefenbruck mark@fluxbox.org
commit

72a45fae3c39323206e7d19913bb3ab17a691691

parent

85d8ac754974aae0a513b585e4f1810007cb157c

6 files changed, 36 insertions(+), 59 deletions(-)

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

@@ -76,13 +76,8 @@

// special case for root menu if (&menu == &screen.rootMenu()) { Fluxbox* fb = Fluxbox::instance(); - if(fb->menuTimestampsChanged()) { - // we dont show the menu here because fluxbox - // will bring up the rootmenu after the timed - // reread of the menu + if(fb->menuTimestampsChanged()) fb->rereadMenu(); - return; - } } Window root_ret; // not used

@@ -335,8 +330,8 @@ if (typeid(**it) == typeid(FluxboxWindow) && m_pat.match(**it))

m_list.push_back(static_cast<FluxboxWindow *>(*it)); } - m_menu = new ClientMenu(*screen, m_list, 0); - ::showMenu(*screen, **m_menu); + m_menu.reset(new ClientMenu(*screen, m_list, 0)); + ::showMenu(*screen, *m_menu.get()); } REGISTER_COMMAND_WITH_ARGS(custommenu, FbCommands::ShowCustomMenuCmd, void);

@@ -347,11 +342,15 @@ void ShowCustomMenuCmd::execute() {

BScreen *screen = Fluxbox::instance()->mouseScreen(); if (screen == 0) return; - m_menu = MenuCreator::createFromFile(custom_menu_file, - screen->screenNumber()); - if (!m_menu.get()) - return; - ::showMenu(*screen, **m_menu); + + if (m_menu.get()) { + m_menu->removeAll(); + m_menu->setLabel(""); + } else + m_menu.reset(screen->createMenu("")); + + MenuCreator::createFromFile(custom_menu_file, *m_menu.get()); + ::showMenu(*screen, *m_menu.get()); } REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void);
M src/FbCommands.hhsrc/FbCommands.hh

@@ -25,7 +25,8 @@ #ifndef FBCOMMANDS_HH

#define FBCOMMANDS_HH #include "FbTk/Command.hh" -#include "FbTk/RefCount.hh" + +#include <memory> #include "ClientMenu.hh" #include "ClientPattern.hh"

@@ -124,7 +125,7 @@ private:

const int m_option; const ClientPattern m_pat; std::list<FluxboxWindow *> m_list; - FbTk::RefCount<ClientMenu> m_menu; + std::auto_ptr<ClientMenu> m_menu; }; class ShowCustomMenuCmd: public FbTk::Command<void> {

@@ -133,7 +134,7 @@ explicit ShowCustomMenuCmd(const std::string &arguments);

void execute(); private: std::string custom_menu_file; - FbTk::RefCount<FbTk::Menu> m_menu; + std::auto_ptr<FbTk::Menu> m_menu; }; class ShowRootMenuCmd: public FbTk::Command<void> {
M src/MenuCreator.ccsrc/MenuCreator.cc

@@ -255,13 +255,13 @@

if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) && (filelist[file_index][0] != '.') && (thisfile[thisfile.length() - 1] != '~')) { - MenuCreator::createFromFile(thisfile, menu); + MenuCreator::createFromFile(thisfile, menu, false); } } } else { // inject this file into the current menu - MenuCreator::createFromFile(newfile, menu); + MenuCreator::createFromFile(newfile, menu, false); } safe_counter--;

@@ -390,33 +390,8 @@

return menu; } -FbTk::Menu *MenuCreator::createFromFile(const string &filename, int screen_number) { - string real_filename = FbTk::StringUtil::expandFilename(filename); - Fluxbox::instance()->saveMenuFilename(real_filename.c_str()); - - FbMenuParser parser(real_filename); - if (!parser.isLoaded()) - return 0; - - startFile(); - string label; - if (!getStart(parser, label, m_stringconvertor)) { - endFile(); - return 0; - } - - FbTk::Menu *menu = createMenu(label, screen_number); - if (menu != 0) - parseMenu(parser, *menu, m_stringconvertor); - - endFile(); - - return menu; -} - - bool MenuCreator::createFromFile(const string &filename, - FbTk::Menu &inject_into) { + FbTk::Menu &inject_into, bool begin) { string real_filename = FbTk::StringUtil::expandFilename(filename); FbMenuParser parser(real_filename);

@@ -424,6 +399,14 @@ if (!parser.isLoaded())

return false; startFile(); + if (begin) { + string label; + if (!getStart(parser, label, m_stringconvertor)) { + endFile(); + return false; + } + inject_into.setLabel(label); + } // save menu filename, so we can check if it changes Fluxbox::instance()->saveMenuFilename(real_filename.c_str());

@@ -467,7 +450,7 @@ &screen->iconListSig());

} else if (type == "workspacemenu") { return new WorkspaceMenu(*screen); } else if (type == "windowmenu") { - FbTk::Menu *menu = screen->createMenu(""); + FbTk::Menu *menu = createMenu("", screen_num); menu->disableTitle(); // not titlebar if (screen->windowMenuFilename().empty() ||
M src/MenuCreator.hhsrc/MenuCreator.hh

@@ -36,9 +36,9 @@

class MenuCreator { public: static FbTk::Menu *createMenu(const std::string &label, int screen_num); - static FbTk::Menu *createFromFile(const std::string &filename, int screen_num); static FbTk::Menu *createMenuType(const std::string &label, int screen_num); - static bool createFromFile(const std::string &filename, FbTk::Menu &inject_into); + 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); static bool createWindowMenuItem(const std::string &type, const std::string &label, FbTk::Menu &inject_into);
M src/Screen.ccsrc/Screen.cc

@@ -1498,21 +1498,18 @@

void BScreen::initMenu() { if (m_rootmenu.get()) { - while (m_rootmenu->numberOfItems()) - m_rootmenu->remove(0); + m_rootmenu->removeAll(); + m_rootmenu->setLabel(""); } else m_rootmenu.reset(createMenu("")); Fluxbox * const fb = Fluxbox::instance(); - if (!fb->getMenuFilename().empty()) { - m_rootmenu.reset(MenuCreator::createFromFile(fb->getMenuFilename(), - screenNumber())); + if (!fb->getMenuFilename().empty()) + MenuCreator::createFromFile(fb->getMenuFilename(), *m_rootmenu); - } - - if (m_rootmenu.get() == 0 || m_rootmenu->numberOfItems() == 0) { + if (m_rootmenu->numberOfItems() == 0) { _FB_USES_NLS; - m_rootmenu.reset(createMenu(_FB_XTEXT(Menu, DefaultRootMenu, "Fluxbox default menu", "Title of fallback root menu"))); + m_rootmenu->setLabel(_FB_XTEXT(Menu, DefaultRootMenu, "Fluxbox default menu", "Title of fallback root menu")); FbTk::RefCount<FbTk::Command<void> > restart_fb(FbTk::CommandParser<void>::instance().parse("restart")); FbTk::RefCount<FbTk::Command<void> > exit_fb(FbTk::CommandParser<void>::instance().parse("exit")); FbTk::RefCount<FbTk::Command<void> > execute_xterm(FbTk::CommandParser<void>::instance().parse("exec xterm"));
M src/fluxbox.ccsrc/fluxbox.cc

@@ -1490,9 +1490,6 @@

for_each(m_screen_list.begin(), m_screen_list.end(), mem_fun(&BScreen::rereadMenu)); - - FbCommands::ShowRootMenuCmd showcmd; - showcmd.execute(); } void Fluxbox::saveMenuFilename(const char *filename) {