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);
Created attachment 1119 [details] The patch
Finally! Support for keyboard shortcuts has been added. Yay! Thanks for all your input.
Closing
Created attachment 1119 [details] The patch