From ca9e2e0d15bc9958959c4636018a3c7384c81157 Mon Sep 17 00:00:00 2001
From: Mark Tiefenbruck <mark@fluxbox.org>
Date: Sat, 8 Aug 2009 10:20:45 -0700
Subject: allow navigating multi-column menus with left and right arrows

---
 src/FbTk/Menu.cc | 25 +++++++++++++++++++++----
 src/FbTk/Menu.hh |  2 ++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc
index 7cf2ac9..4489d0f 100644
--- a/src/FbTk/Menu.cc
+++ b/src/FbTk/Menu.cc
@@ -328,9 +328,11 @@ void Menu::cycleItems(bool reverse) {
             new_index = vec[i]->getIndex();
     }
 
-    if (new_index == -1)
-        return;
+    if (new_index != -1)
+        setActiveIndex(new_index);
+}
 
+void Menu::setActiveIndex(int new_index) {
     // clear the items and close any open submenus
     int old_active_index = m_active_index;
     m_active_index = new_index;
@@ -1065,11 +1067,26 @@ void Menu::keyPressEvent(XKeyEvent &event) {
         break;
     case XK_Left: // enter parent if we have one
         resetTypeAhead();
-        internal_hide();
+        if (menu.sublevels > 1 && m_active_index >= menu.persub) {
+            int new_index = m_active_index - menu.persub;
+            while (new_index >= 0 && !isItemEnabled(new_index))
+                new_index -= menu.persub;
+            if (new_index >= 0)
+                setActiveIndex(new_index);
+        } else
+            internal_hide();
         break;
     case XK_Right: // enter submenu if we have one
         resetTypeAhead();
-        enterSubmenu();
+        if (menu.sublevels > 1 && validIndex(m_active_index) &&
+            validIndex(m_active_index + menu.persub)) {
+            int new_index = m_active_index + menu.persub;
+            while (validIndex(new_index) && !isItemEnabled(new_index))
+                new_index += menu.persub;
+            if (validIndex(new_index))
+                setActiveIndex(new_index);
+        } else
+            enterSubmenu();
         break;
     case XK_Escape: // close menu
         m_type_ahead.reset();
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh
index 519a78b..4eb5e27 100644
--- a/src/FbTk/Menu.hh
+++ b/src/FbTk/Menu.hh
@@ -83,6 +83,8 @@ public:
     virtual void lower();
     /// cycle through menuitems
     void cycleItems(bool reverse);
+    /// set and highlight new active index
+    void setActiveIndex(int new_index);
     void enterSubmenu();
 
     void disableTitle();
-- 
cgit v0.11.2