all repos — fluxbox @ 31df2d8bd618cae590d9b0e76aee11021d4c77d3

custom fork of the fluxbox windowmanager

make MenuItem responsible for decision to close menu when clicked
Mark Tiefenbruck mark@fluxbox.org
commit

31df2d8bd618cae590d9b0e76aee11021d4c77d3

parent

c39af52bfca7f6962048a102597d88337c949b67

M src/BoolMenuItem.hhsrc/BoolMenuItem.hh

@@ -34,11 +34,13 @@ FbTk::RefCount<FbTk::Command> &cmd):

FbTk::MenuItem(label, cmd), m_item(item) { FbTk::MenuItem::setSelected(m_item); setToggleItem(true); + setCloseOnClick(false); } BoolMenuItem(const FbTk::FbString &label, bool &item): FbTk::MenuItem(label), m_item(item) { FbTk::MenuItem::setSelected(m_item); - setToggleItem(true); + setToggleItem(true); + setCloseOnClick(false); } bool isSelected() const { return m_item; } // toggle state
M src/FbTk/Menu.ccsrc/FbTk/Menu.cc

@@ -199,15 +199,15 @@ s_focused = 0;

} int Menu::insert(const FbString &label, RefCount<Command> &cmd, int pos) { - return insert(new MenuItem(label, cmd), pos); + return insert(new MenuItem(label, cmd, this), pos); } int Menu::insert(const FbString &label, int pos) { - return insert(new MenuItem(label), pos); + return insert(new MenuItem(label, *this), pos); } int Menu::insert(const FbString &label, Menu *submenu, int pos) { - return insert(new MenuItem(label, submenu), pos); + return insert(new MenuItem(label, submenu, this), pos); } int Menu::insert(MenuItem *item, int pos) {

@@ -516,15 +516,15 @@ menu.window.show();

raise(); if (shown && shown != this && shown != m_parent) - shown->hide(true); + shown->hide(); shown = this; } -void Menu::hide(bool force) { +void Menu::hide() { - if (!isVisible() || m_torn && !force) + if (!isVisible()) return; // if parent is visible, go to first parent and hide it

@@ -569,6 +569,9 @@

} void Menu::internal_hide(bool first) { + + if (!first && m_torn) + return; if (validIndex(m_which_sub)) { MenuItem *tmp = menuitems[m_which_sub];

@@ -815,8 +818,6 @@ void Menu::handleEvent(XEvent &event) {

if (event.type == FocusOut) { if (s_focused == this) s_focused = 0; - if (shown == this && !m_torn) - hide(); // I don't know why, but I get a FocusIn event when closing the menu with // the mouse over it -- probably an xorg bug, but it's easy to address here } else if (event.type == FocusIn && m_visible) {

@@ -1275,9 +1276,9 @@ FbTk::MenuItem *item = find(index);

item->drawLine(menu.frame, theme(), size, item_x, item_y, menu.item_w); } -void Menu::hideShownMenu(bool force) { +void Menu::hideShownMenu() { if (shown) - shown->hide(force); + shown->hide(); } }; // end namespace FbTk
M src/FbTk/Menu.hhsrc/FbTk/Menu.hh

@@ -124,7 +124,7 @@ virtual void drawSubmenu(unsigned int index);

/// show menu virtual void show(); /// hide menu - virtual void hide(bool force = false); + virtual void hide(); virtual void clearWindow(); #ifdef NOT_USED void setActiveIndex(int index) { m_active_index = index; }

@@ -160,7 +160,7 @@ inline const MenuTheme &theme() const { return m_theme; }

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); + static void hideShownMenu(); /// @return menuitem at index inline const MenuItem *find(unsigned int index) const { return menuitems[index]; } inline MenuItem *find(unsigned int index) { return menuitems[index]; }
M src/FbTk/MenuItem.ccsrc/FbTk/MenuItem.cc

@@ -35,6 +35,8 @@ namespace FbTk {

void MenuItem::click(int button, int time) { if (m_command.get() != 0) { + if (m_menu && m_close_on_click) + m_menu->hide(); // we need a local variable, since the command may destroy this object RefCount<Command> tmp(m_command); tmp->execute();
M src/FbTk/MenuItem.hhsrc/FbTk/MenuItem.hh

@@ -47,15 +47,16 @@ m_menu(0),

m_submenu(0), m_enabled(true), m_selected(false), + m_close_on_click(true), m_toggle_item(false) { } - explicit MenuItem( - const FbString &label) + explicit MenuItem(const FbString &label) : m_label(label), m_menu(0), m_submenu(0), m_enabled(true), m_selected(false), + m_close_on_click(true), m_toggle_item(false) { }

@@ -65,26 +66,28 @@ m_menu(&host_menu),

m_submenu(0), m_enabled(true), m_selected(false), + m_close_on_click(true), m_toggle_item(false) { } /// create a menu item with a specific command to be executed on click - MenuItem(const FbString &label, RefCount<Command> &cmd, Menu *menu = 0): - m_label(label), - m_menu(menu), - m_submenu(0), - m_command(cmd), - m_enabled(true), - m_selected(false), - m_toggle_item(false) { - - } + MenuItem(const FbString &label, RefCount<Command> &cmd, Menu *menu = 0) + : m_label(label), + m_menu(menu), + m_submenu(0), + m_command(cmd), + m_enabled(true), + m_selected(false), + m_close_on_click(true), + m_toggle_item(false) + { } MenuItem(const FbString &label, Menu *submenu, Menu *host_menu = 0) - : m_label(label) - , m_menu(host_menu) - , m_submenu(submenu) - , m_enabled(true) - , m_selected(false), + : m_label(label), + m_menu(host_menu), + m_submenu(submenu), + m_enabled(true), + m_selected(false), + m_close_on_click(true), m_toggle_item(false) { } virtual ~MenuItem() { }

@@ -94,6 +97,7 @@ virtual void setSelected(bool selected) { m_selected = selected; }

virtual void setEnabled(bool enabled) { m_enabled = enabled; } virtual void setLabel(const FbString &label) { m_label = label; } virtual void setToggleItem(bool val) { m_toggle_item = val; } + void setCloseOnClick(bool val) { m_close_on_click = val; } void setIcon(const std::string &filename, int screen_num); virtual Menu *submenu() { return m_submenu; } /**

@@ -150,7 +154,7 @@ Menu *m_menu; ///< the menu we live in

Menu *m_submenu; ///< a submenu, 0 if we don't have one RefCount<Command> m_command; ///< command to be executed bool m_enabled, m_selected; - bool m_toggle_item; + bool m_close_on_click, m_toggle_item; int m_index; struct Icon {
M src/IntResMenuItem.hhsrc/IntResMenuItem.hh

@@ -37,6 +37,7 @@ IntResMenuItem(const FbTk::FbString &label, Type &res, int min_val, int max_val, FbTk::Menu &host_menu) :

FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()), m_max(max_val), m_min(min_val), m_res(res) { updateLabel(); + setCloseOnClick(false); } /* Utility, but doesn't get found in anonymous namespace? */
M src/RootCmdMenuItem.ccsrc/RootCmdMenuItem.cc

@@ -40,6 +40,7 @@ FbTk::RefCount<FbTk::Command>

setwp_cmd(new FbCommands::ExecuteCmd(prog + " \"" + m_filename + "\"")); setCommand(setwp_cmd); setToggleItem(true); + setCloseOnClick(false); }
M src/StyleMenuItem.ccsrc/StyleMenuItem.cc

@@ -39,6 +39,7 @@ setstyle_cmd(new FbCommands::

SetStyleCmd(m_filename)); setCommand(setstyle_cmd); setToggleItem(true); + setCloseOnClick(false); }