explicit merge of '2e4b4b7c9ddd56214d8b2d37d3d9a779d844c818'
and '0112d74ae38c8db1bf91dd14aee9794a358da49c'
--- a/gntmenu.c Wed Oct 10 03:54:14 2007 +0000
+++ b/gntmenu.c Fri Nov 16 22:38:00 2007 +0000
@@ -459,3 +459,34 @@
menu->list = g_list_append(menu->list, item);
+GntMenuItem *gnt_menu_get_item(GntMenu *menu, const char *id) + GntMenuItem *item = NULL; + GList *iter = menu->list; + for (; iter; iter = iter->next) { + sub = gnt_menuitem_get_submenu(item); + item = gnt_menu_get_item(sub, id); + const char *itid = gnt_menuitem_get_id(item); + if (itid && strcmp(itid, id) == 0) + /* XXX: Perhaps look at the menu-label as well? */ + menuitem_activate(menu, item); --- a/gntmenu.h Wed Oct 10 03:54:14 2007 +0000
+++ b/gntmenu.h Fri Nov 16 22:38:00 2007 +0000
@@ -86,27 +86,37 @@
+ * @return The GType for GntMenu. GType gnt_menu_get_gtype(void);
+ * @param type The type of the menu, whether it's a toplevel menu or a popup menu. + * @return The newly created menu. GntWidget * gnt_menu_new(GntMenuType type);
+ * Add an item to the menu. + * @param menu The menu. + * @param item The item to add to the menu. void gnt_menu_add_item(GntMenu *menu, GntMenuItem *item);
+ * Get the GntMenuItem with the given ID. + * @param menu The menu. + * @param id The ID for an item. + * @return The menuitem with the given ID, or @c NULL. +GntMenuItem *gnt_menu_get_item(GntMenu *menu, const char *id); --- a/gntmenuitem.c Wed Oct 10 03:54:14 2007 +0000
+++ b/gntmenuitem.c Fri Nov 16 22:38:00 2007 +0000
@@ -33,6 +33,7 @@
gnt_widget_destroy(GNT_WIDGET(item->submenu));
parent_class->dispose(obj);
@@ -104,6 +105,11 @@
+GntMenu *gnt_menuitem_get_submenu(GntMenuItem *item) void gnt_menuitem_set_trigger(GntMenuItem *item, char trigger)
item->priv.trigger = trigger;
@@ -114,3 +120,14 @@
return item->priv.trigger;
+void gnt_menuitem_set_id(GntMenuItem *item, const char *id) + item->priv.id = g_strdup(id); +const char * gnt_menuitem_get_id(GntMenuItem *item) --- a/gntmenuitem.h Wed Oct 10 03:54:14 2007 +0000
+++ b/gntmenuitem.h Fri Nov 16 22:38:00 2007 +0000
@@ -53,6 +53,7 @@
typedef void (*GntMenuItemCallback)(GntMenuItem *item, gpointer data);
@@ -86,36 +87,46 @@
+ * @return GType for GntMenuItem. GType gnt_menuitem_get_gtype(void);
+ * Create a new menuitem.
+ * @param text Label for the menuitem. + * @return The newly created menuitem. GntMenuItem * gnt_menuitem_new(const char *text);
+ * Set a callback function for a menuitem. + * @param item The menuitem. + * @param callback The callback function. + * @param data Data to send to the callback function. void gnt_menuitem_set_callback(GntMenuItem *item, GntMenuItemCallback callback, gpointer data);
+ * Set a submenu for a menuitem. A menuitem with a submenu cannot have a callback. + * @param item The menuitem. + * @param menu The submenu. void gnt_menuitem_set_submenu(GntMenuItem *item, GntMenu *menu);
+ * Get the submenu for a menuitem. + * @param item The menuitem. + * @return The submenu, or @c NULL. +GntMenu *gnt_menuitem_get_submenu(GntMenuItem *item); * Set a trigger key for the item.
* @param item The menuitem
@@ -134,6 +145,23 @@
char gnt_menuitem_get_trigger(GntMenuItem *item);
+ * Set an ID for the menuitem. + * @param item The menuitem. + * @param id The ID for the menuitem. +void gnt_menuitem_set_id(GntMenuItem *item, const char *id); + * Get the ID of the menuitem. + * @param item The menuitem. + * @return The ID for the menuitem. +const char * gnt_menuitem_get_id(GntMenuItem *item); #endif /* GNT_MENUITEM_H */
--- a/gntstyle.c Wed Oct 10 03:54:14 2007 +0000
+++ b/gntstyle.c Fri Nov 16 22:38:00 2007 +0000
@@ -227,6 +227,65 @@
+gboolean gnt_style_read_menu_accels(const char *name, GHashTable *table) +#if GLIB_CHECK_VERSION(2,6,0) + kname = g_strdup_printf("%s::menu", name); + if (g_key_file_has_group(gkfile, kname)) + keys = g_key_file_get_keys(gkfile, kname, &len, &error); + g_printerr("GntStyle: %s\n", error->message); + key = g_strdup(keys[len]); + menuid = g_key_file_get_string(gkfile, kname, keys[len], &error); + g_printerr("GntStyle: %s\n", error->message); + const char *keycode = parse_key(key); + g_printerr("GntStyle: Invalid key-binding %s\n", key); + g_hash_table_replace(table, g_strdup(keycode), menuid); void gnt_styles_get_keyremaps(GType type, GHashTable *hash)
#if GLIB_CHECK_VERSION(2,6,0)
--- a/gntstyle.h Wed Oct 10 03:54:14 2007 +0000
+++ b/gntstyle.h Fri Nov 16 22:38:00 2007 +0000
@@ -93,6 +93,16 @@
void gnt_style_read_actions(GType type, GntBindableClass *klass);
+ * Read menu-accels from ~/.gntrc + * @param name The name of the window. + * @param table The hastable to store the accel information. + * @return @c TRUE if some accels were read, @c FALSE otherwise. +gboolean gnt_style_read_menu_accels(const char *name, GHashTable *table); void gnt_style_read_workspaces(GntWM *wm);
--- a/gntwindow.c Wed Oct 10 03:54:14 2007 +0000
+++ b/gntwindow.c Fri Nov 16 22:38:00 2007 +0000
@@ -25,6 +25,11 @@
+ GHashTable *accels; /* key => menuitem-id */ @@ -55,6 +60,10 @@
GntWindow *window = GNT_WINDOW(widget);
gnt_widget_destroy(GNT_WIDGET(window->menu));
+ g_hash_table_destroy(window->priv->accels); @@ -98,8 +107,11 @@
gnt_window_init(GTypeInstance *instance, gpointer class)
GntWidget *widget = GNT_WIDGET(instance);
+ GntWindow *win = GNT_WINDOW(widget); GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS);
+ win->priv = g_new0(GntWindowPriv, 1); + win->priv->accels = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); @@ -170,8 +182,23 @@
void gnt_window_set_menu(GntWindow *window, GntMenu *menu)
/* If a menu already existed, then destroy that first. */
+ const char *name = gnt_widget_get_name(GNT_WIDGET(window)); gnt_widget_destroy(GNT_WIDGET(window->menu));
+ if (name && window->priv) { + if (!gnt_style_read_menu_accels(name, window->priv->accels)) { + g_hash_table_destroy(window->priv->accels); +const char * gnt_window_get_accel_item(GntWindow *window, const char *key) + return g_hash_table_lookup(window->priv->accels, key); --- a/gntwindow.h Wed Oct 10 03:54:14 2007 +0000
+++ b/gntwindow.h Fri Nov 16 22:38:00 2007 +0000
@@ -52,6 +52,7 @@
@@ -99,6 +100,8 @@
void gnt_window_set_menu(GntWindow *window, GntMenu *menu);
+const char * gnt_window_get_accel_item(GntWindow *window, const char *key); void gnt_window_workspace_hiding(GntWindow *);
void gnt_window_workspace_showing(GntWindow *);
--- a/gntwm.c Wed Oct 10 03:54:14 2007 +0000
+++ b/gntwm.c Fri Nov 16 22:38:00 2007 +0000
@@ -1852,8 +1852,19 @@
ret = gnt_widget_key_pressed(GNT_WIDGET(wm->menu), keys);
else if (wm->_list.window)
ret = gnt_widget_key_pressed(wm->_list.window, keys);
- else if (wm->cws->ordered)
- ret = gnt_widget_key_pressed(GNT_WIDGET(wm->cws->ordered->data), keys);
+ else if (wm->cws->ordered) { + GntWidget *win = wm->cws->ordered->data; + if (GNT_IS_WINDOW(win)) { + GntMenu *menu = GNT_WINDOW(win)->menu; + const char *id = gnt_window_get_accel_item(GNT_WINDOW(win), keys); + ret = (gnt_menu_get_item(menu, id) != NULL); + ret = gnt_widget_key_pressed(win, keys);