all repos — fluxbox @ 3f33657fb721645292f798480e9e0b46d64aedf8

custom fork of the fluxbox windowmanager

fix active menu item when inserting or removing other items
Mark Tiefenbruck mark@fluxbox.org
commit

3f33657fb721645292f798480e9e0b46d64aedf8

parent

ed53f3c623e7c3ae35672b33ae3b52759dc1a6ed

3 files changed, 11 insertions(+), 6 deletions(-)

jump to
M src/FbTk/Menu.ccsrc/FbTk/Menu.cc

@@ -219,6 +219,8 @@ menuitems.push_back(item);

} else { menuitems.insert(menuitems.begin() + pos, item); fixMenuItemIndices(); + if (m_active_index >= pos) + m_active_index++; } m_need_update = true; // we need to redraw the menu return menuitems.size();

@@ -233,7 +235,7 @@ int Menu::remove(unsigned int index) {

if (index >= menuitems.size()) { #ifdef DEBUG cout << "Bad index (" << index << ") given to Menu::remove()" - << " -- should be between 0 and " << menuitems.size() + << " -- should be between 0 and " << menuitems.size()-1 << " inclusive." << endl; #endif // DEBUG return -1;

@@ -270,6 +272,9 @@ if (static_cast<unsigned int>(m_which_sub) == index)

m_which_sub = -1; else if (static_cast<unsigned int>(m_which_sub) > index) m_which_sub--; + + if (static_cast<unsigned int>(m_active_index) > index) + m_active_index--; m_need_update = true; // we need to redraw the menu

@@ -366,7 +371,7 @@ void Menu::enableTitle() {

setTitleVisibility(true); } -void Menu::updateMenu(int active_index) { +void Menu::updateMenu() { if (m_title_vis) { menu.item_w = theme()->titleFont().textWidth(menu.label, menu.label.size());
M src/FbTk/Menu.hhsrc/FbTk/Menu.hh

@@ -109,7 +109,7 @@ /// set label string

void setLabel(const FbString &labelstr); /// move menu to x,y virtual void move(int x, int y); - virtual void updateMenu(int active_index = -1); + virtual void updateMenu(); void setItemSelected(unsigned int index, bool val); void setItemEnabled(unsigned int index, bool val); void setMinimumSublevels(int m) { menu.minsub = m; }
M src/WorkspaceMenu.ccsrc/WorkspaceMenu.cc

@@ -80,7 +80,7 @@ mb_menu->setCommand(3, jump_cmd);

insert(mb_menu, workspace + IDX_AFTER_ICONS); } - updateMenu(-1); + updateMenu(); } void WorkspaceMenu::workspaceChanged(BScreen& screen) {

@@ -89,12 +89,12 @@ for (unsigned int i = 0; i < screen.numberOfWorkspaces(); ++i) {

item = find(i + IDX_AFTER_ICONS); if (item && item->isSelected()) { setItemSelected(i + IDX_AFTER_ICONS, false); - updateMenu(i + IDX_AFTER_ICONS); + updateMenu(); break; } } setItemSelected(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS, true); - updateMenu(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS); + updateMenu(); } void WorkspaceMenu::init(BScreen &screen) {