LOGIN / SIGN UP
2 Author: Claes Nästén
Date: Mon Mar 08 21:06:20 +0100 2010
Subject: Move menu handling from WindowManager to MenuHandler.

src/WindowManager.cc
 
38 @@ -38,6 +38,12 @@
38 #include "RegexString.hh"
39
40 #include "KeyGrabber.hh"
41 #ifdef MENUS
42 #include "MenuHandler.hh"
43 #ifdef HARBOUR
44 #include "HarbourMenu.hh"
45 #endif // HARBOUR
46 #endif // MENUS
47 #ifdef HARBOUR
48 #include "Harbour.hh"
49 #include "DockApp.hh"
...  
53 @@ -47,17 +53,6 @@
53 #include "StatusWindow.hh"
54 #include "WorkspaceIndicator.hh"
55
50 #include "PMenu.hh" // we need this for the "Alt+Tabbing"
51 #ifdef MENUS
52 #include "WORefMenu.hh"
53 #include "ActionMenu.hh"
54 #include "FrameListMenu.hh"
55 #include "DecorMenu.hh"
56 #ifdef HARBOUR
57 #include "HarbourMenu.hh"
58 #endif // HARBOUR
59 #endif // MENUS
60
67 #include <iostream>
68 #include <list>
69 #include <algorithm>
...  
88 @@ -93,27 +88,6 @@
88 // Static initializers
89 WindowManager *WindowManager::_instance = 0;
90
96 #ifdef MENUS
97 const char *WindowManager::MENU_NAMES_RESERVED[] = {
98 "ATTACHCLIENTINFRAME",
99 "ATTACHCLIENT",
100 "ATTACHFRAMEINFRAME",
101 "ATTACHFRAME",
102 "DECORMENU",
103 "GOTOCLIENT",
104 "GOTO",
105 "ICON",
106 "ROOTMENU",
107 "ROOT", // To avoid name conflict, ROOTMENU -> ROOT
108 "WINDOWMENU",
109 "WINDOW" // To avoid name conflict, WINDOWMENU -> WINDOW
110 };
111
112 const unsigned int WindowManager::MENU_NAMES_RESERVED_COUNT =
113 sizeof(WindowManager::MENU_NAMES_RESERVED)
114 / sizeof(WindowManager::MENU_NAMES_RESERVED[0]);
115 #endif // MENUS
116
112 extern "C" {
113
114 static bool is_signal_hup = false;
...  
214 @@ -240,10 +214,11 @@
214 delete _status_window;
215 delete _workspace_indicator;
216
217 #ifdef MENUS
218 MenuHandler::destroy();
219 #endif // MENUS
220 #ifdef HARBOUR
247 if (_harbour) {
248 delete _harbour;
249 }
224 delete _harbour;
225 #endif // HARBOUR
226
227 delete _root_wo;
...  
226 @@ -251,10 +226,6 @@
226 delete _action_handler;
227 delete _autoproperties;
228
254 #ifdef MENUS
255 deleteMenus();
256 #endif // MENUS
257
233 if (_keygrabber)
234 delete _keygrabber;
235 if (_workspaces)
...  
374 @@ -403,6 +374,9 @@
374 #ifdef HARBOUR
375 _harbour = new Harbour(_screen, _theme, _workspaces);
376 #endif // HARBOUR
377 #ifdef MENUS
378 MenuHandler::init(_theme);
379 #endif // MENUS
380
381 _cmd_dialog = new CmdDialog(_screen->getDpy(), _theme);
382 _search_dialog = new SearchDialog(_screen->getDpy(), _theme);
...  
394 @@ -420,10 +394,6 @@
394 _keygrabber->load(_config->getKeyFile());
395 _keygrabber->grabKeys(_screen->getRoot());
396
423 #ifdef MENUS
424 createMenus();
425 #endif // MENUS
426
401 // Create screen edge windows
402 screenEdgeCreate();
403 screenEdgeMapUnmap();
...  
595 @@ -625,7 +595,11 @@
595 doReloadAutoproperties();
596
597 #ifdef MENUS
628 doReloadMenus();
599 MenuHandler::instance()->reloadMenus();
600 #ifdef HARBOUR
601 // Special case for HARBOUR menu which is not included in the menu map
602 _harbour->getHarbourMenu()->reload(static_cast<CfgParser::Entry*>(0));
603 #endif // HARBOUR
604 #endif // MENUS
605 #ifdef HARBOUR
606 doReloadHarbour();
...  
1519 @@ -1545,139 +1519,6 @@
1519
1520 // Event handling routines stop ============================================
1521
1548 #ifdef MENUS
1549 //! @brief Creates reserved menus and populates _menu_map
1550 void
1551 WindowManager::createMenus(void)
1552 {
1553 // Make sure this is not called twice without an delete in between
1554 assert(! _menu_map.size());
1555
1556 _menu_map["ATTACHCLIENTINFRAME"] = new FrameListMenu(_screen, _theme, ATTACH_CLIENT_IN_FRAME_TYPE,
1557 L"Attach Client In Frame", "ATTACHCLIENTINFRAME");
1558 _menu_map["ATTACHCLIENT"] = new FrameListMenu(_screen, _theme, ATTACH_CLIENT_TYPE,
1559 L"Attach Client", "ATTACHCLIENT");
1560 _menu_map["ATTACHFRAMEINFRAME"] = new FrameListMenu(_screen, _theme, ATTACH_FRAME_IN_FRAME_TYPE,
1561 L"Attach Frame In Frame", "ATTACHFRAMEINFRAME");
1562 _menu_map["ATTACHFRAME"] = new FrameListMenu(_screen, _theme, ATTACH_FRAME_TYPE,
1563 L"Attach Frame", "ATTACHFRAME");
1564 _menu_map["GOTOCLIENT"] = new FrameListMenu(_screen, _theme, GOTOCLIENTMENU_TYPE,
1565 L"Focus Client", "GOTOCLIENT");
1566 _menu_map["DECORMENU"] = new DecorMenu(_screen, _theme, _action_handler, "DECORMENU");
1567 _menu_map["GOTO"] = new FrameListMenu(_screen, _theme, GOTOMENU_TYPE, L"Focus Frame", "GOTO");
1568 _menu_map["ICON"] = new FrameListMenu(_screen, _theme, ICONMENU_TYPE, L"Focus Iconified Frame", "ICON");
1569 _menu_map["ROOT"] = new ActionMenu(ROOTMENU_TYPE, L"", "ROOTMENU");
1570 _menu_map["WINDOW"] = new ActionMenu(WINDOWMENU_TYPE, L"", "WINDOWMENU");
1571
1572 // As the previous step is done manually, make sure it's done correct.
1573 assert(_menu_map.size() == (MENU_NAMES_RESERVED_COUNT - 2));
1574
1575 // Load configuration, pass specific section to loading
1576 CfgParser menu_cfg;
1577 if (menu_cfg.parse(_config->getMenuFile()) || menu_cfg.parse (string(SYSCONFDIR "/menu"))) {
1578 _menu_state = menu_cfg.get_file_list();
1579
1580 // Load standard menus
1581 map<string, PMenu*>::iterator it = _menu_map.begin();
1582 for (; it != _menu_map.end(); ++it) {
1583 it->second->reload(menu_cfg.get_entry_root()->find_section(it->second->getName()));
1584 }
1585
1586 // Load standalone menus
1587 updateMenusStandalone(menu_cfg.get_entry_root());
1588 }
1589 }
1590
1591 /**
1592 * (re)loads the menus in the menu configuration if the file has been
1593 * updated since last load.
1594 */
1595 void
1596 WindowManager::doReloadMenus(void)
1597 {
1598 if (! Util::requireReload(_menu_state, _config->getMenuFile())) {
1599 return;
1600 }
1601
1602 // Load configuration, pass specific section to loading
1603 bool cfg_ok = true;
1604 CfgParser menu_cfg;
1605 if (! menu_cfg.parse(_config->getMenuFile())) {
1606 if (! menu_cfg.parse(string(SYSCONFDIR "/menu"))) {
1607 cfg_ok = false;
1608 }
1609 }
1610
1611 // Make sure menu is reloaded next time as content is dynamically
1612 // generated from the configuration file.
1613 if (! cfg_ok || menu_cfg.is_dynamic_content()) {
1614 _menu_state.clear();
1615 } else {
1616 _menu_state = menu_cfg.get_file_list();
1617 }
1618
1619 // Update, delete standalone root menus, load decors on others
1620 map<string, PMenu*>::iterator it(_menu_map.begin());
1621 for (; it != _menu_map.end(); ++it) {
1622 if (it->second->getMenuType() == ROOTMENU_STANDALONE_TYPE) {
1623 delete it->second;
1624 _menu_map.erase(it);
1625 } else {
1626 // Only reload the menu if we got a ok configuration
1627 if (cfg_ok) {
1628 it->second->reload(menu_cfg.get_entry_root()->find_section(it->second->getName()));
1629 }
1630 }
1631 }
1632
1633 // Update standalone root menus (name != ROOTMENU)
1634 updateMenusStandalone(menu_cfg.get_entry_root());
1635
1636 // Special case for HARBOUR menu which is not included in the menu map
1637 #ifdef HARBOUR
1638 _harbour->getHarbourMenu()->reload(static_cast<CfgParser::Entry*>(0));
1639 #endif // HARBOUR
1640 }
1641
1642 //! @brief Updates standalone root menus
1643 void
1644 WindowManager::updateMenusStandalone(CfgParser::Entry *section)
1645 {
1646 // Temporary name, as names are stored uppercase
1647 string menu_name;
1648
1649 // Go through all but reserved section names and create menus
1650 CfgParser::iterator it(section->begin());
1651 for (; it != section->end(); ++it) {
1652 // Uppercase name
1653 menu_name = (*it)->get_name();
1654 Util::to_upper(menu_name);
1655
1656 // Create new menus, if the name is not reserved and not used
1657 if (! binary_search(MENU_NAMES_RESERVED,
1658 MENU_NAMES_RESERVED + MENU_NAMES_RESERVED_COUNT,
1659 menu_name)
1660 && ! getMenu(menu_name)) {
1661 // Create, parse and add to map
1662 PMenu *menu = new ActionMenu(ROOTMENU_STANDALONE_TYPE, L"", menu_name);
1663 menu->reload((*it)->get_section());
1664 _menu_map[menu->getName()] = menu;
1665 }
1666 }
1667 }
1668
1669 //! @brief Clears the menu map and frees up resources used by menus
1670 void
1671 WindowManager::deleteMenus(void)
1672 {
1673 map<std::string, PMenu*>::iterator it(_menu_map.begin());
1674 for (; it != _menu_map.end(); ++it) {
1675 delete it->second;
1676 }
1677 _menu_map.clear();
1678 }
1679 #endif // MENUS
1680
1655 //! @brief Searches for a PWinObj to focus, and then gives it input focus
1656 void
1657 WindowManager::findWOAndFocus(PWinObj *search)
...  
1832 @@ -1991,22 +1832,3 @@
1832
1833 return next_frame;
1834 }
1994
1995 #ifdef MENUS
1996 //! @brief Hides all menus
1997 void
1998 WindowManager::hideAllMenus(void)
1999 {
2000 bool do_focus = PWinObj::isFocusedPWinObj(PWinObj::WO_MENU);
2001
2002 map<std::string, PMenu*>::iterator it(_menu_map.begin());
2003 for (; it != _menu_map.end(); ++it) {
2004 it->second->unmapAll();
2005 }
2006
2007 if (do_focus) {
2008 findWOAndFocus(0);
2009 }
2010 }
2011 #endif // MENUS
2012 // here follows methods for hints and atoms
...  

src/WindowManager.hh
 
49 @@ -49,7 +49,6 @@
49 class Frame;
50 class Client;
51 class ClassHint;
52 class PMenu; // used together with Focus actions
53
54 class AutoProperty; // for findGroup
55 class CmdDialog;
...  
103 @@ -104,14 +103,6 @@
103 inline std::list<PWinObj*>::iterator mru_end(void) { return _mru_list.end(); }
104 inline std::list<PWinObj*>::reverse_iterator mru_rend(void) { return _mru_list.rend(); }
105
107 // menus
108 #ifdef MENUS
109 inline PMenu* getMenu(const std::string &name) {
110 std::map<std::string, PMenu*>::iterator it = _menu_map.find(name);
111 return (it != _menu_map.end()) ? it->second : 0;
112 }
113 #endif // MENUS
114
114 // adds
115 inline void addToFrameList(Frame *frame) {
116 if (frame) {
...  
139 @@ -148,10 +139,6 @@
139
140 void findWOAndFocus(PWinObj *wo);
141
151 #ifdef MENUS
152 void hideAllMenus(void);
153 #endif // MENUS
154
146 inline CmdDialog *getCmdDialog(void) { return _cmd_dialog; }
147 inline SearchDialog *getSearchDialog(void) { return _search_dialog; }
148 inline StatusWindow *getStatusWindow(void) { return _status_window; }
...  
209 @@ -222,13 +209,6 @@
209 void handleXRandrCrtcChangeEvent(XRRCrtcChangeNotifyEvent *ev);
210 #endif // HAVE_XRANDR
211
225 #ifdef MENUS
226 void createMenus(void);
227 void doReloadMenus(void);
228 void updateMenusStandalone(CfgParser::Entry *cfg_root);
229 void deleteMenus(void);
230 #endif // MENUS
231
219 void readDesktopNamesHint(void);
220
221 // private methods for the hints
...  
240 @@ -260,14 +240,6 @@
240
241 Timer<ActionPerformed> _timer_action;
242
263 #ifdef MENUS
264 std::map <std::string, time_t> _menu_state; /**< Map of file mtime for all files touched by a configuration. */
265 std::map<std::string, PMenu*> _menu_map;
266
267 static const char *MENU_NAMES_RESERVED[];
268 static const unsigned int MENU_NAMES_RESERVED_COUNT;
269 #endif // MENUS
270
251 std::string _command_line, _restart_command;
252 bool _startup; //!< Indicates startup status.
253 bool _shutdown; //!< Set to wheter we want to shutdown.
...