diff options
author | Mathias Gumz <akira@fluxbox.org> | 2015-01-16 07:36:49 (GMT) |
---|---|---|
committer | Mathias Gumz <akira@fluxbox.org> | 2015-01-16 07:36:49 (GMT) |
commit | b4958780650cfab97d4dc694a34c0c77bf99b26d (patch) | |
tree | 0982d91e368b1e9f020b606cb0f2b205cd619c4d /src | |
parent | bd9afcafb93382b5b7f32c222594699214581596 (diff) | |
download | fluxbox-b4958780650cfab97d4dc694a34c0c77bf99b26d.zip fluxbox-b4958780650cfab97d4dc694a34c0c77bf99b26d.tar.bz2 |
Reduce number of allocations for menu creation
Every time either the Slit menu or the Toolbar menu were added to the
root menu, the whole root menu was (re)created from scratch. Now we
create and remove only the menus needed.
Side effect: the position of these menus is now at the end of the root
menu and not somewhere in between. If users complaint, I' ll think about
it.
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/Menu.cc | 22 | ||||
-rw-r--r-- | src/FbTk/Menu.hh | 14 | ||||
-rw-r--r-- | src/Screen.cc | 27 | ||||
-rw-r--r-- | src/Screen.hh | 4 |
4 files changed, 44 insertions, 23 deletions
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index 4dbb48c..8dddc16 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc | |||
@@ -91,6 +91,12 @@ Menu* s_focused = 0; // holds currently focused menu | |||
91 | Menu* Menu::shownMenu() { return s_shown; } | 91 | Menu* Menu::shownMenu() { return s_shown; } |
92 | Menu* Menu::focused() { return s_focused; } | 92 | Menu* Menu::focused() { return s_focused; } |
93 | 93 | ||
94 | void Menu::hideShownMenu() { | ||
95 | if (s_shown) | ||
96 | s_shown->hide(); | ||
97 | } | ||
98 | |||
99 | |||
94 | Menu::Menu(FbTk::ThemeProxy<MenuTheme> &tm, ImageControl &imgctrl): | 100 | Menu::Menu(FbTk::ThemeProxy<MenuTheme> &tm, ImageControl &imgctrl): |
95 | m_theme(tm), | 101 | m_theme(tm), |
96 | m_parent(0), | 102 | m_parent(0), |
@@ -240,6 +246,18 @@ int Menu::insertItem(MenuItem *item, int pos) { | |||
240 | return m_items.size(); | 246 | return m_items.size(); |
241 | } | 247 | } |
242 | 248 | ||
249 | |||
250 | int Menu::findSubmenuIndex(const FbTk::Menu* submenu) const { | ||
251 | size_t i; | ||
252 | for (i = 0; i < m_items.size(); i++) { | ||
253 | if (m_items[i]->submenu() == submenu) { | ||
254 | return i; | ||
255 | } | ||
256 | } | ||
257 | return -1; | ||
258 | } | ||
259 | |||
260 | |||
243 | void Menu::fixMenuItemIndices() { | 261 | void Menu::fixMenuItemIndices() { |
244 | for (size_t i = 0; i < m_items.size(); i++) | 262 | for (size_t i = 0; i < m_items.size(); i++) |
245 | m_items[i]->setIndex(i); | 263 | m_items[i]->setIndex(i); |
@@ -1391,9 +1409,5 @@ void Menu::drawLine(int index, int size){ | |||
1391 | item->drawLine(m_frame, theme(), size, item_x, item_y, m_item_w); | 1409 | item->drawLine(m_frame, theme(), size, item_x, item_y, m_item_w); |
1392 | } | 1410 | } |
1393 | 1411 | ||
1394 | void Menu::hideShownMenu() { | ||
1395 | if (s_shown) | ||
1396 | s_shown->hide(); | ||
1397 | } | ||
1398 | 1412 | ||
1399 | } // end namespace FbTk | 1413 | } // end namespace FbTk |
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh index 49893c1..27d5b12 100644 --- a/src/FbTk/Menu.hh +++ b/src/FbTk/Menu.hh | |||
@@ -45,6 +45,12 @@ template <typename T> class RefCount; | |||
45 | /// Base class for menus | 45 | /// Base class for menus |
46 | class Menu: public FbTk::EventHandler, FbTk::FbWindowRenderer { | 46 | class Menu: public FbTk::EventHandler, FbTk::FbWindowRenderer { |
47 | public: | 47 | public: |
48 | |||
49 | static Menu* shownMenu(); | ||
50 | static Menu* focused(); | ||
51 | static void hideShownMenu(); | ||
52 | |||
53 | |||
48 | enum Alignment{ ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM }; | 54 | enum Alignment{ ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM }; |
49 | enum { RIGHT = 1, LEFT }; | 55 | enum { RIGHT = 1, LEFT }; |
50 | 56 | ||
@@ -134,11 +140,13 @@ public: | |||
134 | FbTk::ThemeProxy<MenuTheme> &theme() { return m_theme; } | 140 | FbTk::ThemeProxy<MenuTheme> &theme() { return m_theme; } |
135 | const FbTk::ThemeProxy<MenuTheme> &theme() const { return m_theme; } | 141 | const FbTk::ThemeProxy<MenuTheme> &theme() const { return m_theme; } |
136 | unsigned char alpha() const { return theme()->alpha(); } | 142 | unsigned char alpha() const { return theme()->alpha(); } |
137 | static Menu* shownMenu(); | ||
138 | static Menu* focused(); | ||
139 | static void hideShownMenu(); | ||
140 | const MenuItem *find(size_t i) const { return m_items[i]; } | 143 | const MenuItem *find(size_t i) const { return m_items[i]; } |
141 | MenuItem *find(size_t i) { return m_items[i]; } | 144 | MenuItem *find(size_t i) { return m_items[i]; } |
145 | |||
146 | // returns index of 'submenu', it it is in the top most list of | ||
147 | // menu items. -1 if no match is found | ||
148 | int findSubmenuIndex(const Menu* submenu) const; | ||
149 | |||
142 | //@} | 150 | //@} |
143 | /// @return true if index is valid | 151 | /// @return true if index is valid |
144 | bool validIndex(int index) const { return (index < static_cast<int>(numberOfItems()) && index >= 0); } | 152 | bool validIndex(int index) const { return (index < static_cast<int>(numberOfItems()) && index >= 0); } |
diff --git a/src/Screen.cc b/src/Screen.cc index 9aab3f7..5e7ca8b 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -1362,22 +1362,25 @@ void BScreen::rereadWindowMenu() { | |||
1362 | } | 1362 | } |
1363 | 1363 | ||
1364 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { | 1364 | void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { |
1365 | m_configmenu_list.push_back(make_pair(label, &menu)); | 1365 | |
1366 | if (m_configmenu.get()) | 1366 | FbTk::Menu* cm = m_configmenu.get(); |
1367 | setupConfigmenu(*m_configmenu.get()); | 1367 | if (cm) { |
1368 | int pos = cm->findSubmenuIndex(&menu); | ||
1369 | if (pos == -1) { // not found? add | ||
1370 | cm->insertSubmenu(label, &menu, pos); | ||
1371 | } | ||
1372 | } | ||
1368 | } | 1373 | } |
1369 | 1374 | ||
1370 | void BScreen::removeConfigMenu(FbTk::Menu &menu) { | 1375 | void BScreen::removeConfigMenu(FbTk::Menu &menu) { |
1371 | Configmenus::iterator erase_it = find_if(m_configmenu_list.begin(), | ||
1372 | m_configmenu_list.end(), | ||
1373 | FbTk::Compose(bind2nd(equal_to<FbTk::Menu *>(), &menu), | ||
1374 | FbTk::Select2nd<Configmenus::value_type>())); | ||
1375 | if (erase_it != m_configmenu_list.end()) | ||
1376 | m_configmenu_list.erase(erase_it); | ||
1377 | |||
1378 | if (!isShuttingdown() && m_configmenu.get()) | ||
1379 | setupConfigmenu(*m_configmenu.get()); | ||
1380 | 1376 | ||
1377 | FbTk::Menu* cm = m_configmenu.get(); | ||
1378 | if (cm) { | ||
1379 | int pos = cm->findSubmenuIndex(&menu); | ||
1380 | if (pos > -1) { | ||
1381 | cm->remove(pos); | ||
1382 | } | ||
1383 | } | ||
1381 | } | 1384 | } |
1382 | 1385 | ||
1383 | 1386 | ||
diff --git a/src/Screen.hh b/src/Screen.hh index 5734d86..dcdcb06 100644 --- a/src/Screen.hh +++ b/src/Screen.hh | |||
@@ -501,10 +501,6 @@ private: | |||
501 | 501 | ||
502 | ExtraMenus m_extramenus; | 502 | ExtraMenus m_extramenus; |
503 | 503 | ||
504 | typedef std::list<std::pair<FbTk::FbString, FbTk::Menu *> > Configmenus; | ||
505 | |||
506 | |||
507 | Configmenus m_configmenu_list; | ||
508 | Icons m_icon_list; | 504 | Icons m_icon_list; |
509 | 505 | ||
510 | std::auto_ptr<Slit> m_slit; | 506 | std::auto_ptr<Slit> m_slit; |