Bug 2898 - Patch adding advanced keyboard support in popup menus.
Status: CLOSED FIXED
Alias: None
Product: Openbox
Classification: Unclassified
Component: general
Version: 3.3.1
Hardware: PC Linux
: P1 enhancement
Assignee: Dana Jansens
QA Contact:
URL:
Depends on:
Blocks:
 
Reported: 2006-10-15 00:46 EDT by Hong Jen Yee (PCMan)
Modified: 2007-05-16 15:52:51 EDT
0 users

See Also:


Attachments
The patch (2.98 KB, patch)
2006-10-15 00:47 EDT, Hong Jen Yee (PCMan)

Description Hong Jen Yee (PCMan) 2006-10-15 00:46:29 EDT
Add more keyboard supports for frame popup menus.
Currently the patch uses the first character of item text for matching.
This can be extended to support mnemonic keys in the future, if underline for specific character can be drawn, and there is a data field to save the mnemonic key in frame menu entry.

Here's the patch:

Index: openbox/menuframe.c
===================================================================
--- openbox/menuframe.c	(revision 5497)
+++ openbox/menuframe.c	(working copy)
@@ -27,6 +27,8 @@
 #include "config.h"
 #include "render/theme.h"
 
+#include <stdlib.h>
+
 #define PADDING 2
 #define SEPARATOR_HEIGHT 3
 #define MAX_MENU_WIDTH 400
@@ -876,3 +878,54 @@
     }
     menu_frame_select(self, it ? it->data : NULL);
 }
+
+static GList*
+find_entry_by_char( ObMenuFrame *self, GList* start, char ch )
+{
+    GList *it = start;
+    while (TRUE) {
+        ObMenuEntryFrame *e;
+
+        it = it ? g_list_next(it) : self->entries;
+        if (it == start)
+            break;
+
+        if (it) {
+            e = it->data;
+            if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
+                if( e->entry->data.submenu.submenu &&
+                    e->entry->data.submenu.submenu->title &&
+                    toupper(e->entry->data.submenu.submenu->title[0]) == toupper(ch) )
+                {
+                    break;
+                }
+            }
+            if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
+                e->entry->data.normal.enabled) {
+                if( e->entry->data.normal.label &&
+                    toupper(e->entry->data.normal.label[0]) == toupper(ch) )
+                {
+                    break;
+                }
+            }
+        }
+    }
+    return it;
+}
+
+void menu_frame_select_by_char(ObMenuFrame *self, char ch)
+{
+    GList *it, *it2, *start;
+    if (self->entries) {
+        start = it = g_list_find(self->entries, self->selected);
+        if( it = find_entry_by_char( self, start, ch ) ) {
+            it2 = find_entry_by_char( self, it, ch );
+        }
+    }
+    if( it ) {
+        menu_frame_select(self, it->data);
+        if( it == it2 )
+            menu_entry_frame_execute( self->selected, 0 );
+    }
+}
+
Index: openbox/event.c
===================================================================
--- openbox/event.c	(revision 5497)
+++ openbox/event.c	(working copy)
@@ -1263,6 +1263,13 @@
             if ((f = find_active_or_last_menu()))
                 menu_frame_select_next(f);
         }
+        else {
+            ObMenuFrame *f;
+            if ((f = find_active_or_last_menu())) {
+                /* FIXME: don't know what index is, pass 0 and it works */
+                menu_frame_select_by_char( f, (char)XLookupKeysym(ev, 0) );
+            }
+        }
         break;
     }
 }
Index: openbox/menuframe.h
===================================================================
--- openbox/menuframe.h	(revision 5497)
+++ openbox/menuframe.h	(working copy)
@@ -115,6 +115,7 @@
 void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry);
 void menu_frame_select_previous(ObMenuFrame *self);
 void menu_frame_select_next(ObMenuFrame *self);
+void menu_frame_select_by_char(ObMenuFrame *self, char ch);
 
 ObMenuFrame* menu_frame_under(gint x, gint y);
 ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y);
Comment 1 Hong Jen Yee (PCMan) 2006-10-15 00:47:23 EDT
Created attachment 1119 [details]
The patch
Comment 2 Dana Jansens 2007-04-24 22:59:04 EDT
Finally! Support for keyboard shortcuts has been added. Yay! Thanks for all your input.
Comment 3 Dana Jansens 2007-04-24 22:59:14 EDT
Closing