only allow one open menu at a time

This commit is contained in:
markt 2007-12-11 19:29:00 +00:00
parent 38877987c4
commit 474e201745
13 changed files with 41 additions and 116 deletions

View file

@ -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)

View file

@ -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() {

View file

@ -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

View file

@ -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]; }

View file

@ -217,10 +217,9 @@ public:
void execute() {
// hide the menu if it's already showing for this FluxboxWindow
if (m_win.menu().isVisible() && WindowCmd<void>::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);

View file

@ -256,8 +256,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem, FbTk::StringConve
// execute and hide menu
using namespace FbTk;
RefCount<Command> exec_cmd(CommandParser::instance().parseLine("exec " + str_cmd));
RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu,
&Menu::hide));
RefCount<Command> 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<Command> macro_cmd(CommandParser::instance().parseLine("macrocmd " + str_cmd));
RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu,
&Menu::hide));
RefCount<Command> 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);

View file

@ -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();

View file

@ -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; }

View file

@ -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);

View file

@ -534,27 +534,21 @@ void Toolbar::buttonPressEvent(XButtonEvent &be) {
if (be.button != 3)
return;
screen().hideMenus();
int head = screen().getHead(be.x_root, be.y_root);
int borderw = menu().fbwindow().borderWidth();
pair<int, int> 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);
if (! menu().isVisible()) {
int head = screen().getHead(be.x_root, be.y_root);
int borderw = menu().fbwindow().borderWidth();
pair<int, int> 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();
menu().setScreen(screen().getHeadX(head),
screen().getHeadY(head),
screen().getHeadWidth(head),
screen().getHeadHeight(head));
menu().move(m.first, m.second);
menu().show();
menu().grabInputFocus();
}

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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);