diff options
author | Mathias Gumz <akira@fluxbox.org> | 2015-01-16 07:39:05 (GMT) |
---|---|---|
committer | Mathias Gumz <akira@fluxbox.org> | 2015-01-16 07:39:05 (GMT) |
commit | 6d5781ce7198a8a82fd0cae8554e4c120d01df3d (patch) | |
tree | 265fd89d382dcf6d9a8e2ea84813db0332aa83cd | |
parent | b4958780650cfab97d4dc694a34c0c77bf99b26d (diff) | |
download | fluxbox-6d5781ce7198a8a82fd0cae8554e4c120d01df3d.zip fluxbox-6d5781ce7198a8a82fd0cae8554e4c120d01df3d.tar.bz2 |
Refactor: move some menu-creation functions to MenuCreator
Another patch to trim down the code that needs to be part of BScreen
-rw-r--r-- | src/ConfigMenu.cc | 37 | ||||
-rw-r--r-- | src/FbCommands.cc | 2 | ||||
-rw-r--r-- | src/MenuCreator.cc | 18 | ||||
-rw-r--r-- | src/MenuCreator.hh | 6 | ||||
-rw-r--r-- | src/Remember.cc | 3 | ||||
-rw-r--r-- | src/Screen.cc | 26 | ||||
-rw-r--r-- | src/Screen.hh | 21 |
7 files changed, 48 insertions, 65 deletions
diff --git a/src/ConfigMenu.cc b/src/ConfigMenu.cc index e4be129..cfce697 100644 --- a/src/ConfigMenu.cc +++ b/src/ConfigMenu.cc | |||
@@ -20,12 +20,14 @@ | |||
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | #include "ConfigMenu.hh" | 22 | #include "ConfigMenu.hh" |
23 | #include "MenuCreator.hh" | ||
23 | #include "Screen.hh" | 24 | #include "Screen.hh" |
24 | #include "fluxbox.hh" | 25 | #include "fluxbox.hh" |
25 | 26 | ||
26 | #include "FocusModelMenuItem.hh" | 27 | #include "FocusModelMenuItem.hh" |
27 | #include "ScreenPlacement.hh" | 28 | #include "ScreenPlacement.hh" |
28 | #include "FbMenu.hh" | 29 | #include "FbMenu.hh" |
30 | #include "ToggleMenu.hh" | ||
29 | #include "FbTk/Menu.hh" | 31 | #include "FbTk/Menu.hh" |
30 | #include "FbTk/BoolMenuItem.hh" | 32 | #include "FbTk/BoolMenuItem.hh" |
31 | #include "FbTk/IntMenuItem.hh" | 33 | #include "FbTk/IntMenuItem.hh" |
@@ -67,19 +69,30 @@ private: | |||
67 | 69 | ||
68 | typedef FbTk::RefCount<FbTk::Command<void> > _Cmd; | 70 | typedef FbTk::RefCount<FbTk::Command<void> > _Cmd; |
69 | 71 | ||
70 | enum { | ||
71 | L_ALPHA = 0, | ||
72 | L_PSEUDO_TRANS, | ||
73 | L_FOCUS_ALPHA, | ||
74 | L_UNFOCUS_ALPHA, | ||
75 | L_MENU_ALPHA, | ||
76 | }; | ||
77 | 72 | ||
73 | // NOTE: might also be placed into MenuCreator; for now it ends up here | ||
74 | // because it's just used here | ||
75 | FbMenu *createToggleMenu(const std::string &label, BScreen& screen) { | ||
76 | FbTk::Layer* layer = screen.layerManager().getLayer(ResourceLayer::MENU); | ||
77 | FbMenu *menu = new ToggleMenu(screen.menuTheme(), screen.imageControl(), *layer); | ||
78 | if (!label.empty()) | ||
79 | menu->setLabel(label); | ||
80 | |||
81 | return menu; | ||
82 | } | ||
78 | 83 | ||
79 | void setupAlphaMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_reconf) { | 84 | void setupAlphaMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_reconf) { |
80 | #ifdef HAVE_XRENDER | 85 | #ifdef HAVE_XRENDER |
81 | _FB_USES_NLS; | 86 | _FB_USES_NLS; |
82 | 87 | ||
88 | enum { | ||
89 | L_ALPHA = 0, | ||
90 | L_PSEUDO_TRANS, | ||
91 | L_FOCUS_ALPHA, | ||
92 | L_UNFOCUS_ALPHA, | ||
93 | L_MENU_ALPHA, | ||
94 | }; | ||
95 | |||
83 | static const FbTk::FbString _labels[] = { | 96 | static const FbTk::FbString _labels[] = { |
84 | _FB_XTEXT(Configmenu, Transparency, "Transparency", "Menu containing various transparency options"), | 97 | _FB_XTEXT(Configmenu, Transparency, "Transparency", "Menu containing various transparency options"), |
85 | _FB_XTEXT(Configmenu, ForcePseudoTrans, "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"), | 98 | _FB_XTEXT(Configmenu, ForcePseudoTrans, "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"), |
@@ -90,7 +103,7 @@ void setupAlphaMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_ | |||
90 | 103 | ||
91 | 104 | ||
92 | FbTk::FbString label = _labels[L_ALPHA]; | 105 | FbTk::FbString label = _labels[L_ALPHA]; |
93 | FbTk::Menu* menu = sh.screen.createMenu(label); | 106 | FbTk::Menu* menu = MenuCreator::createMenu(label, sh.screen); |
94 | 107 | ||
95 | if (FbTk::Transparent::haveComposite(true)) { | 108 | if (FbTk::Transparent::haveComposite(true)) { |
96 | static FbTk::SimpleAccessor<bool> s_pseudo = Fluxbox::instance()->getPseudoTrans(); | 109 | static FbTk::SimpleAccessor<bool> s_pseudo = Fluxbox::instance()->getPseudoTrans(); |
@@ -131,7 +144,7 @@ void setupFocusMenu(FbTk::Menu& menu, ConfigMenu::SetupHelper& sh, _Cmd& save_rc | |||
131 | // we don't set this to internal menu so will | 144 | // we don't set this to internal menu so will |
132 | // be deleted toghether with the parent | 145 | // be deleted toghether with the parent |
133 | FbTk::FbString label = _FB_XTEXT(Configmenu, FocusModel, "Focus Model", "Method used to give focus to windows"); | 146 | FbTk::FbString label = _FB_XTEXT(Configmenu, FocusModel, "Focus Model", "Method used to give focus to windows"); |
134 | FbMenu* fm = sh.screen.createMenu(label); | 147 | FbMenu* fm = MenuCreator::createMenu(label, sh.screen); |
135 | 148 | ||
136 | #define _FOCUSITEM(a, b, c, d, e) \ | 149 | #define _FOCUSITEM(a, b, c, d, e) \ |
137 | fm->insertItem(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), sh.screen.focusControl(), \ | 150 | fm->insertItem(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), sh.screen.focusControl(), \ |
@@ -197,7 +210,7 @@ void setupMaximizeMenu(FbTk::Menu& menu, ConfigMenu::SetupHelper& sh, _Cmd& save | |||
197 | 210 | ||
198 | FbTk::FbString label = _FB_XTEXT(Configmenu, MaxMenu, | 211 | FbTk::FbString label = _FB_XTEXT(Configmenu, MaxMenu, |
199 | "Maximize Options", "heading for maximization options"); | 212 | "Maximize Options", "heading for maximization options"); |
200 | FbTk::Menu* mm = sh.screen.createMenu(label); | 213 | FbTk::Menu* mm = MenuCreator::createMenu(label, sh.screen); |
201 | 214 | ||
202 | _BOOLITEM(*mm, Configmenu, FullMax, | 215 | _BOOLITEM(*mm, Configmenu, FullMax, |
203 | "Full Maximization", "Maximise over slit, toolbar, etc", | 216 | "Full Maximization", "Maximise over slit, toolbar, etc", |
@@ -224,8 +237,8 @@ void setupTabMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_re | |||
224 | FbTk::FbString label = _FB_XTEXT(Configmenu, TabMenu, "Tab Options", "heading for tab-related options"); | 237 | FbTk::FbString label = _FB_XTEXT(Configmenu, TabMenu, "Tab Options", "heading for tab-related options"); |
225 | // TODO: main-category is 'Menu'?? should be 'ConfigMenu'??? | 238 | // TODO: main-category is 'Menu'?? should be 'ConfigMenu'??? |
226 | FbTk::FbString p_label = _FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"); | 239 | FbTk::FbString p_label = _FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"); |
227 | FbTk::Menu* menu = sh.screen.createMenu(label); | 240 | FbTk::Menu* menu = MenuCreator::createMenu(label, sh.screen); |
228 | FbTk::Menu* p_menu = sh.screen.createToggleMenu(p_label); | 241 | FbTk::Menu* p_menu = createToggleMenu(p_label, sh.screen); |
229 | 242 | ||
230 | menu->insertSubmenu(p_label, p_menu); | 243 | menu->insertSubmenu(p_label, p_menu); |
231 | 244 | ||
diff --git a/src/FbCommands.cc b/src/FbCommands.cc index 10d98e7..0708b1e 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc | |||
@@ -323,7 +323,7 @@ void ShowCustomMenuCmd::execute() { | |||
323 | return; | 323 | return; |
324 | 324 | ||
325 | if (!m_menu.get() || screen->screenNumber() != m_menu->screenNumber()) { | 325 | if (!m_menu.get() || screen->screenNumber() != m_menu->screenNumber()) { |
326 | m_menu.reset(screen->createMenu("")); | 326 | m_menu.reset(MenuCreator::createMenu("", *screen)); |
327 | m_menu->setReloadHelper(new FbTk::AutoReloadHelper()); | 327 | m_menu->setReloadHelper(new FbTk::AutoReloadHelper()); |
328 | m_menu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<ShowCustomMenuCmd>(*this, &ShowCustomMenuCmd::reload))); | 328 | m_menu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<ShowCustomMenuCmd>(*this, &ShowCustomMenuCmd::reload))); |
329 | m_menu->reloadHelper()->setMainFile(custom_menu_file); | 329 | m_menu->reloadHelper()->setMainFile(custom_menu_file); |
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index b2b15f5..e8fb90b 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc | |||
@@ -482,20 +482,24 @@ bool getStart(FbMenuParser &parser, string &label, FbTk::StringConvertor &labelc | |||
482 | 482 | ||
483 | } // end of anonymous namespace | 483 | } // end of anonymous namespace |
484 | 484 | ||
485 | FbMenu *MenuCreator::createMenu(const string &label, int screen_number) { | ||
486 | BScreen *screen = Fluxbox::instance()->findScreen(screen_number); | ||
487 | if (screen == 0) | ||
488 | return 0; | ||
489 | 485 | ||
490 | FbMenu *menu = new FbMenu(screen->menuTheme(), | 486 | |
491 | screen->imageControl(), | 487 | FbMenu* MenuCreator::createMenu(const std::string& label, BScreen& screen) { |
492 | *screen->layerManager().getLayer(ResourceLayer::MENU)); | 488 | FbTk::Layer* layer = screen.layerManager().getLayer(ResourceLayer::MENU); |
489 | FbMenu *menu = new FbMenu(screen.menuTheme(), screen.imageControl(), *layer); | ||
493 | if (!label.empty()) | 490 | if (!label.empty()) |
494 | menu->setLabel(label); | 491 | menu->setLabel(label); |
495 | 492 | ||
496 | return menu; | 493 | return menu; |
497 | } | 494 | } |
498 | 495 | ||
496 | FbMenu *MenuCreator::createMenu(const string &label, int screen_number) { | ||
497 | BScreen *screen = Fluxbox::instance()->findScreen(screen_number); | ||
498 | if (screen == 0) | ||
499 | return 0; | ||
500 | return MenuCreator::createMenu(label, *screen); | ||
501 | } | ||
502 | |||
499 | bool MenuCreator::createFromFile(const string &filename, | 503 | bool MenuCreator::createFromFile(const string &filename, |
500 | FbTk::Menu &inject_into, | 504 | FbTk::Menu &inject_into, |
501 | AutoReloadHelper *reloader, bool begin) { | 505 | AutoReloadHelper *reloader, bool begin) { |
diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh index 91add47..b8f260b 100644 --- a/src/MenuCreator.hh +++ b/src/MenuCreator.hh | |||
@@ -34,11 +34,13 @@ class Menu; | |||
34 | 34 | ||
35 | class FbMenu; | 35 | class FbMenu; |
36 | class FluxboxWindow; | 36 | class FluxboxWindow; |
37 | class BScreen; | ||
37 | 38 | ||
38 | namespace MenuCreator { | 39 | namespace MenuCreator { |
39 | 40 | ||
40 | FbMenu *createMenu(const std::string &label, int screen_num); | 41 | FbMenu* createMenu(const std::string& label, BScreen& screen); |
41 | FbMenu *createMenuType(const std::string &label, int screen_num); | 42 | FbMenu* createMenu(const std::string& label, int screen_num); |
43 | FbMenu* createMenuType(const std::string &label, int screen_num); | ||
42 | bool createFromFile(const std::string &filename, | 44 | bool createFromFile(const std::string &filename, |
43 | FbTk::Menu &inject_into, | 45 | FbTk::Menu &inject_into, |
44 | FbTk::AutoReloadHelper *reloader = NULL, | 46 | FbTk::AutoReloadHelper *reloader = NULL, |
diff --git a/src/Remember.cc b/src/Remember.cc index 41d7256..acbbddf 100644 --- a/src/Remember.cc +++ b/src/Remember.cc | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "Window.hh" | 27 | #include "Window.hh" |
28 | #include "WinClient.hh" | 28 | #include "WinClient.hh" |
29 | #include "FbMenu.hh" | 29 | #include "FbMenu.hh" |
30 | #include "MenuCreator.hh" | ||
30 | #include "FbCommands.hh" | 31 | #include "FbCommands.hh" |
31 | #include "fluxbox.hh" | 32 | #include "fluxbox.hh" |
32 | #include "Layer.hh" | 33 | #include "Layer.hh" |
@@ -305,7 +306,7 @@ private: | |||
305 | FbTk::Menu *createRememberMenu(BScreen &screen) { | 306 | FbTk::Menu *createRememberMenu(BScreen &screen) { |
306 | // each fluxboxwindow has its own windowmenu | 307 | // each fluxboxwindow has its own windowmenu |
307 | // so we also create a remember menu just for it... | 308 | // so we also create a remember menu just for it... |
308 | FbTk::Menu *menu = screen.createMenu("Remember"); | 309 | FbTk::Menu *menu = MenuCreator::createMenu("Remember", screen); |
309 | 310 | ||
310 | // if enabled, then we want this to be a unavailable menu | 311 | // if enabled, then we want this to be a unavailable menu |
311 | /* | 312 | /* |
diff --git a/src/Screen.cc b/src/Screen.cc index 5e7ca8b..296fec0 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -359,17 +359,17 @@ BScreen::BScreen(FbTk::ResourceManager &rm, | |||
359 | 359 | ||
360 | m_current_workspace = m_workspaces_list.front(); | 360 | m_current_workspace = m_workspaces_list.front(); |
361 | 361 | ||
362 | m_windowmenu.reset(createMenu("")); | 362 | m_windowmenu.reset(MenuCreator::createMenu("", *this)); |
363 | m_windowmenu->setInternalMenu(); | 363 | m_windowmenu->setInternalMenu(); |
364 | m_windowmenu->setReloadHelper(new FbTk::AutoReloadHelper()); | 364 | m_windowmenu->setReloadHelper(new FbTk::AutoReloadHelper()); |
365 | m_windowmenu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<BScreen>(*this, &BScreen::rereadWindowMenu))); | 365 | m_windowmenu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<BScreen>(*this, &BScreen::rereadWindowMenu))); |
366 | 366 | ||
367 | m_rootmenu.reset(createMenu("")); | 367 | m_rootmenu.reset(MenuCreator::createMenu("", *this)); |
368 | m_rootmenu->setReloadHelper(new FbTk::AutoReloadHelper()); | 368 | m_rootmenu->setReloadHelper(new FbTk::AutoReloadHelper()); |
369 | m_rootmenu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<BScreen>(*this, &BScreen::rereadMenu))); | 369 | m_rootmenu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<BScreen>(*this, &BScreen::rereadMenu))); |
370 | 370 | ||
371 | m_configmenu.reset(createMenu(_FB_XTEXT(Menu, Configuration, | 371 | m_configmenu.reset(MenuCreator::createMenu(_FB_XTEXT(Menu, Configuration, |
372 | "Configuration", "Title of configuration menu"))); | 372 | "Configuration", "Title of configuration menu"), *this)); |
373 | setupConfigmenu(*m_configmenu.get()); | 373 | setupConfigmenu(*m_configmenu.get()); |
374 | m_configmenu->setInternalMenu(); | 374 | m_configmenu->setInternalMenu(); |
375 | 375 | ||
@@ -745,24 +745,6 @@ void BScreen::cycleFocus(int options, const ClientPattern *pat, bool reverse) { | |||
745 | 745 | ||
746 | } | 746 | } |
747 | 747 | ||
748 | FbMenu *BScreen::createMenu(const string &label) { | ||
749 | FbTk::Layer* layer = layerManager().getLayer(ResourceLayer::MENU); | ||
750 | FbMenu *menu = new FbMenu(menuTheme(), imageControl(), *layer); | ||
751 | if (!label.empty()) | ||
752 | menu->setLabel(label); | ||
753 | |||
754 | return menu; | ||
755 | } | ||
756 | |||
757 | FbMenu *BScreen::createToggleMenu(const string &label) { | ||
758 | FbTk::Layer* layer = layerManager().getLayer(ResourceLayer::MENU); | ||
759 | FbMenu *menu = new ToggleMenu(menuTheme(), imageControl(), *layer); | ||
760 | if (!label.empty()) | ||
761 | menu->setLabel(label); | ||
762 | |||
763 | return menu; | ||
764 | } | ||
765 | |||
766 | void BScreen::addExtraWindowMenu(const FbTk::FbString &label, FbTk::Menu *menu) { | 748 | void BScreen::addExtraWindowMenu(const FbTk::FbString &label, FbTk::Menu *menu) { |
767 | menu->setInternalMenu(); | 749 | menu->setInternalMenu(); |
768 | menu->disableTitle(); | 750 | menu->disableTitle(); |
diff --git a/src/Screen.hh b/src/Screen.hh index dcdcb06..eb2a306 100644 --- a/src/Screen.hh +++ b/src/Screen.hh | |||
@@ -43,13 +43,7 @@ | |||
43 | 43 | ||
44 | #include "FocusControl.hh" | 44 | #include "FocusControl.hh" |
45 | 45 | ||
46 | #include <X11/Xresource.h> | 46 | #include <cstdio> |
47 | |||
48 | #ifdef HAVE_CSTDIO | ||
49 | #include <cstdio> | ||
50 | #else | ||
51 | #include <stdio.h> | ||
52 | #endif | ||
53 | #include <list> | 47 | #include <list> |
54 | #include <vector> | 48 | #include <vector> |
55 | #include <fstream> | 49 | #include <fstream> |
@@ -234,19 +228,6 @@ public: | |||
234 | bool isCycling() const { return m_cycling; } | 228 | bool isCycling() const { return m_cycling; } |
235 | 229 | ||
236 | /** | 230 | /** |
237 | * Creates an empty menu with specified label | ||
238 | * @param label for the menu | ||
239 | * @return created menu | ||
240 | */ | ||
241 | FbMenu *createMenu(const std::string &label); | ||
242 | /** | ||
243 | * Creates an empty toggle menu with a specific label | ||
244 | * @param label | ||
245 | * @return created menu | ||
246 | */ | ||
247 | FbMenu *createToggleMenu(const std::string &label); | ||
248 | |||
249 | /** | ||
250 | * For extras to add menus. | 231 | * For extras to add menus. |
251 | * These menus will be marked internal, | 232 | * These menus will be marked internal, |
252 | * and deleted when the window dies (as opposed to Screen | 233 | * and deleted when the window dies (as opposed to Screen |