From 474e2017454d3c6492eb9f428aee039d36d76e05 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 11 Dec 2007 19:29:00 +0000 Subject: only allow one open menu at a time --- ChangeLog | 3 +++ src/FbCommands.cc | 9 +-------- src/FbTk/Menu.cc | 37 +++++++++++++++++-------------------- src/FbTk/Menu.hh | 3 ++- src/IconbarTool.cc | 3 +-- src/MenuCreator.cc | 6 ++---- src/Screen.cc | 37 ------------------------------------- src/Screen.hh | 6 ------ src/ToolFactory.cc | 1 - src/Toolbar.cc | 36 +++++++++++++++--------------------- src/Window.cc | 3 +-- src/fluxbox.cc | 13 ------------- src/fluxbox.hh | 2 -- 13 files changed, 42 insertions(+), 117 deletions(-) diff --git a/ChangeLog b/ChangeLog index 353af01..2cbf181 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ (Format: Year/Month/Day) Changes for 1.0.1: +*07/12/11: + * Only allow one menu to be open at a time (Mark) + FbTk/Menu.cc/hh *07/12/09: * Added OnTitlebar and Double modifiers to the keys file for clicks on the titlebar and double clicks, respectively (Mark, thanks Matteo Galiazzo) diff --git a/src/FbCommands.cc b/src/FbCommands.cc index 1cc1afe..de14f73 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc @@ -261,14 +261,7 @@ void KeyModeCmd::execute() { } void HideMenuCmd::execute() { - BScreen *screen = Fluxbox::instance()->mouseScreen(); - screen->hideMenus(); - if (screen->rootMenu().isVisible()) - screen->rootMenu().hide(); - if (screen->workspaceMenu().isVisible()) - screen->workspaceMenu().hide(); - if (FbTk::Menu::shownMenu()) - FbTk::Menu::shownMenu()->hide(); + FbTk::Menu::hideShownMenu(); } void ShowClientMenuCmd::execute() { diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index 23efcfe..4c41161 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc @@ -207,7 +207,6 @@ int Menu::insert(const FbString &label, int pos) { } int Menu::insert(const FbString &label, Menu *submenu, int pos) { - submenu->m_parent = this; return insert(new MenuItem(label, submenu), pos); } @@ -516,32 +515,24 @@ void Menu::show() { menu.window.show(); raise(); - if (! m_parent && shown != this) { - if (shown && (! shown->m_torn)) - shown->hide(); - - shown = this; - } + if (shown && shown != this && shown != m_parent) + shown->hide(true); + shown = this; } -void Menu::hide() { +void Menu::hide(bool force) { - if (!isVisible()) + if (!isVisible() || m_torn && !force) return; - // if not m_torn and parent is m_visible, go to first parent - // and hide it - if (!m_torn && m_parent && m_parent->isVisible()) { - Menu *p = m_parent; + // if parent is visible, go to first parent and hide it + Menu *p = this; + while (p->m_parent && p->m_parent->isVisible()) + p = p->m_parent; - while ((! p->m_torn) && p->m_parent && p->m_parent->isVisible()) - p = p->m_parent; - - p->internal_hide(); - } else if (!m_torn) // if we dont have a parent then do hide here - internal_hide(); + p->internal_hide(); } @@ -590,7 +581,7 @@ void Menu::internal_hide(bool first) { m_active_index = -1; clearItem(old); // clear old area from highlight - if (shown && shown->menu.window == menu.window) { + if (shown == this) { if (m_parent && m_parent->isVisible()) shown = m_parent; else @@ -604,6 +595,7 @@ void Menu::internal_hide(bool first) { s_focused && !s_focused->isVisible()) m_parent->grabInputFocus(); + m_parent = 0; menu.window.hide(); } @@ -1281,4 +1273,9 @@ void Menu::drawLine(int index, int size){ item->drawLine(menu.frame, theme(), size, item_x, item_y, menu.item_w); } +void Menu::hideShownMenu(bool force) { + if (shown) + shown->hide(force); +} + }; // end namespace FbTk diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh index 06af08d..2a84c77 100644 --- a/src/FbTk/Menu.hh +++ b/src/FbTk/Menu.hh @@ -124,7 +124,7 @@ public: /// show menu virtual void show(); /// hide menu - virtual void hide(); + virtual void hide(bool force = false); virtual void clearWindow(); #ifdef NOT_USED void setActiveIndex(int index) { m_active_index = index; } @@ -160,6 +160,7 @@ public: inline unsigned char alpha() const { return theme().alpha(); } inline static Menu *shownMenu() { return shown; } inline static Menu *focused() { return s_focused; } + static void hideShownMenu(bool force = true); /// @return menuitem at index inline const MenuItem *find(unsigned int index) const { return menuitems[index]; } inline MenuItem *find(unsigned int index) { return menuitems[index]; } diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 625d358..2574762 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -217,10 +217,9 @@ public: void execute() { // hide the menu if it's already showing for this FluxboxWindow if (m_win.menu().isVisible() && WindowCmd::window() == &m_win) { - m_win.screen().hideMenus(); + m_win.menu().hide(); return; } - m_win.screen().hideMenus(); // get last button pos const XEvent &event = Fluxbox::instance()->lastEvent(); int x = event.xbutton.x_root - (m_win.menu().width() / 2); diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index a99d785..8cc483a 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -256,8 +256,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem, FbTk::StringConve // execute and hide menu using namespace FbTk; RefCount exec_cmd(CommandParser::instance().parseLine("exec " + str_cmd)); - RefCount hide_menu(new SimpleCommand(menu, - &Menu::hide)); + RefCount hide_menu(CommandParser::instance().parseLine("hidemenus")); MacroCommand *exec_and_hide = new FbTk::MacroCommand(); exec_and_hide->add(hide_menu); exec_and_hide->add(exec_cmd); @@ -266,8 +265,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem, FbTk::StringConve } else if (str_key == "macrocmd") { using namespace FbTk; RefCount macro_cmd(CommandParser::instance().parseLine("macrocmd " + str_cmd)); - RefCount hide_menu(new SimpleCommand(menu, - &Menu::hide)); + RefCount hide_menu(CommandParser::instance().parseLine("hidemenus")); MacroCommand *exec_and_hide = new FbTk::MacroCommand(); exec_and_hide->add(hide_menu); exec_and_hide->add(macro_cmd); diff --git a/src/Screen.cc b/src/Screen.cc index 7682075..79a75ef 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -909,43 +909,6 @@ void BScreen::addExtraWindowMenu(const FbTk::FbString &label, FbTk::Menu *menu) m_windowmenu->setInternalMenu(); } -void BScreen::hideMenus() { - // hide extra menus - Fluxbox::instance()->hideExtraMenus(*this); - -#ifdef SLIT - // hide slit menu - if (slit()) - slit()->menu().hide(); -#endif // SLIT - - // hide icon menus - if (!iconList().empty()) { - Icons::iterator it = iconList().begin(); - const Icons::iterator it_end = iconList().end(); - for (; it != it_end; ++it) - (*it)->menu().hide(); - } - // hide all client menus - hideWindowMenus(); - -} - -void BScreen::hideWindowMenus(const FluxboxWindow* except) { - Workspaces::iterator w_it = getWorkspacesList().begin(); - const Workspaces::iterator w_it_end = getWorkspacesList().end(); - for (; w_it != w_it_end; ++w_it) { - if (!(*w_it)->windowList().empty()) { - Workspace::Windows::iterator win_it = (*w_it)->windowList().begin(); - const Workspace::Windows::iterator win_it_end = (*w_it)->windowList().end(); - for (; win_it != win_it_end; ++win_it) { - if (*win_it != except) - (*win_it)->menu().hide(); - } - } - } -} - void BScreen::reconfigure() { Fluxbox *fluxbox = Fluxbox::instance(); diff --git a/src/Screen.hh b/src/Screen.hh index ac27df1..41a7b90 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -260,9 +260,6 @@ public: */ FbTk::Menu *createToggleMenu(const std::string &label); - /// hides all menus that are visible on this screen - void hideMenus(); - /** * For extras to add menus. * These menus will be marked internal, @@ -270,9 +267,6 @@ public: */ void addExtraWindowMenu(const FbTk::FbString &label, FbTk::Menu *menu); - /// hide all windowmenus except the given one (if given) - void hideWindowMenus(const FluxboxWindow* except= 0); - inline int getEdgeSnapThreshold() const { return *resource.edge_snap_threshold; } void setRootColormapInstalled(bool r) { root_colormap_installed = r; } diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc index ee1316a..3fa8714 100644 --- a/src/ToolFactory.cc +++ b/src/ToolFactory.cc @@ -50,7 +50,6 @@ class ShowMenuAboveToolbar: public FbTk::Command { public: explicit ShowMenuAboveToolbar(Toolbar &tbar):m_tbar(tbar) { } void execute() { - m_tbar.screen().hideMenus(); // get last button pos const XEvent &event = Fluxbox::instance()->lastEvent(); int head = m_tbar.screen().getHead(event.xbutton.x_root, event.xbutton.y_root); diff --git a/src/Toolbar.cc b/src/Toolbar.cc index f67311c..55ae1d3 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -534,27 +534,21 @@ void Toolbar::buttonPressEvent(XButtonEvent &be) { if (be.button != 3) return; - screen().hideMenus(); - - if (! menu().isVisible()) { - - int head = screen().getHead(be.x_root, be.y_root); - int borderw = menu().fbwindow().borderWidth(); - pair m = screen().clampToHead(head, - be.x_root - (menu().width() / 2), - be.y_root - (menu().titleWindow().height() / 2), - menu().width() + 2*borderw, - menu().height() + 2*borderw); - - menu().setScreen(screen().getHeadX(head), - screen().getHeadY(head), - screen().getHeadWidth(head), - screen().getHeadHeight(head)); - menu().move(m.first, m.second); - menu().show(); - menu().grabInputFocus(); - } else - menu().hide(); + int head = screen().getHead(be.x_root, be.y_root); + int borderw = menu().fbwindow().borderWidth(); + pair m = screen().clampToHead(head, + be.x_root - (menu().width() / 2), + be.y_root - (menu().titleWindow().height() / 2), + menu().width() + 2*borderw, + menu().height() + 2*borderw); + + menu().setScreen(screen().getHeadX(head), + screen().getHeadY(head), + screen().getHeadWidth(head), + screen().getHeadHeight(head)); + menu().move(m.first, m.second); + menu().show(); + menu().grabInputFocus(); } diff --git a/src/Window.cc b/src/Window.cc index 82bdc5e..2997794 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -2595,8 +2595,7 @@ void FluxboxWindow::buttonPressEvent(XButtonEvent &be) { } else if (frame().handle() == be.window) raise(); - Fluxbox::instance()->hideExtraMenus(screen()); - screen().hideWindowMenus(this); + menu().hide(); } } diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 7cf165e..d22f496 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -1581,19 +1581,6 @@ bool Fluxbox::menuTimestampsChanged() const { return false; } -void Fluxbox::hideExtraMenus(BScreen &screen) { - -#ifdef USE_TOOLBAR - // hide toolbar that matches screen - for (size_t toolbar = 0; toolbar < m_toolbars.size(); ++toolbar) { - if (&(m_toolbars[toolbar]->screen()) == &screen) - m_toolbars[toolbar]->menu().hide(); - } - -#endif // USE_TOOLBAR - -} - void Fluxbox::rereadMenu(bool show_after_reread) { m_reread_menu_wait = true; m_show_menu_after_reread = show_after_reread; diff --git a/src/fluxbox.hh b/src/fluxbox.hh index d5a48c6..a6544e3 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -157,8 +157,6 @@ public: void rereadMenu(bool show_after_reread = false); /// reloads the menus if the timestamps changed - void hideExtraMenus(BScreen &screen); - /// handle any system signal sent to the application void handleSignal(int signum); void update(FbTk::Subject *changed); -- cgit v0.11.2