X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=openbox%2Fmenu.c;h=9aed40aa8d6311bffc4adb20da9635a94ac83849;hb=e5d6a552a46bce27cbe25c92023094b44c9a8284;hp=1f335c787dac724b26bc3b0a97c3f964b4cf861d;hpb=5d5be2ba2a6e0b3886e0076475ed9d7a2d4ac9ab;p=chaz%2Fopenbox diff --git a/openbox/menu.c b/openbox/menu.c index 1f335c78..9aed40aa 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -54,8 +54,8 @@ static void parse_menu_separator(ObParseInst *i, gpointer data); static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, gpointer data); -static gunichar parse_shortcut(const gchar *label, gchar **strippedlabel, - guint *position); +static gunichar parse_shortcut(const gchar *label, gboolean allow_shortcut, + gchar **strippedlabel, guint *position); static void client_dest(ObClient *client, gpointer data) @@ -185,8 +185,8 @@ static ObMenu* menu_from_name(gchar *name) ((c) >= 'A' && (c) <= 'Z') || \ ((c) >= 'a' && (c) <= 'z')) -static gunichar parse_shortcut(const gchar *label, gchar **strippedlabel, - guint *position) +static gunichar parse_shortcut(const gchar *label, gboolean allow_shortcut, + gchar **strippedlabel, guint *position) { gunichar shortcut = 0; @@ -201,8 +201,12 @@ static gunichar parse_shortcut(const gchar *label, gchar **strippedlabel, *strippedlabel = g_strdup(label); + /* if allow_shortcut is false, then you can't use the &, instead you + have to just use the first valid character + */ + i = strchr(*strippedlabel, '&'); - if (i != NULL) { + if (allow_shortcut && i != NULL) { /* there is an ampersand in the string */ /* you have to use a printable ascii character for shortcuts @@ -248,7 +252,7 @@ static void parse_menu_item(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, if (a) acts = g_slist_append(acts, a); } - menu_add_normal(state->parent, -1, label, acts); + menu_add_normal(state->parent, -1, label, acts, FALSE); g_free(label); } } @@ -285,7 +289,7 @@ static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, if (!parse_attr_string("label", node, &title)) goto parse_menu_fail; - if ((menu = menu_new(name, title, NULL))) { + if ((menu = menu_new(name, title, FALSE, NULL))) { menu->pipe_creator = state->pipe_creator; if (parse_attr_string("execute", node, &script)) { menu->execute = parse_expand_tilde(script); @@ -309,7 +313,8 @@ parse_menu_fail: g_free(script); } -ObMenu* menu_new(const gchar *name, const gchar *title, gpointer data) +ObMenu* menu_new(const gchar *name, const gchar *title, + gboolean allow_shortcut, gpointer data) { ObMenu *self; @@ -317,7 +322,7 @@ ObMenu* menu_new(const gchar *name, const gchar *title, gpointer data) self->name = g_strdup(name); self->data = data; - self->shortcut = parse_shortcut(title, &self->title, + self->shortcut = parse_shortcut(title, allow_shortcut, &self->title, &self->shortcut_position); g_hash_table_replace(menu_hash, self->name, self); @@ -355,7 +360,7 @@ void menu_free(ObMenu *menu) g_hash_table_remove(menu_hash, menu->name); } -void menu_show(gchar *name, gint x, gint y, ObClient *client) +void menu_show(gchar *name, gint x, gint y, gint button, ObClient *client) { ObMenu *self; ObMenuFrame *frame; @@ -374,7 +379,7 @@ void menu_show(gchar *name, gint x, gint y, ObClient *client) menu_frame_hide_all(); frame = menu_frame_new(self, client); - if (!menu_frame_show_topmenu(frame, x, y)) + if (!menu_frame_show_topmenu(frame, x, y, button)) menu_frame_free(frame); else if (frame->entries) { ObMenuEntryFrame *e = frame->entries->data; @@ -459,14 +464,14 @@ void menu_entry_remove(ObMenuEntry *self) } ObMenuEntry* menu_add_normal(ObMenu *self, gint id, const gchar *label, - GSList *actions) + GSList *actions, gboolean allow_shortcut) { ObMenuEntry *e; e = menu_entry_new(self, OB_MENU_ENTRY_TYPE_NORMAL, id); e->data.normal.actions = actions; - menu_entry_set_label(e, label); + menu_entry_set_label(e, label, allow_shortcut); self->entries = g_list_append(self->entries, e); return e; @@ -489,7 +494,7 @@ ObMenuEntry* menu_add_separator(ObMenu *self, gint id, const gchar *label) e = menu_entry_new(self, OB_MENU_ENTRY_TYPE_SEPARATOR, id); - menu_entry_set_label(e, label); + menu_entry_set_label(e, label, FALSE); self->entries = g_list_append(self->entries, e); return e; @@ -510,6 +515,11 @@ void menu_set_destroy_func(ObMenu *self, ObMenuDestroyFunc func) self->destroy_func = func; } +void menu_set_place_func(ObMenu *self, ObMenuPlaceFunc func) +{ + self->place_func = func; +} + ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id) { ObMenuEntry *ret = NULL; @@ -538,7 +548,8 @@ void menu_find_submenus(ObMenu *self) } } -void menu_entry_set_label(ObMenuEntry *self, const gchar *label) +void menu_entry_set_label(ObMenuEntry *self, const gchar *label, + gboolean allow_shortcut) { switch (self->type) { case OB_MENU_ENTRY_TYPE_SEPARATOR: @@ -548,7 +559,7 @@ void menu_entry_set_label(ObMenuEntry *self, const gchar *label) case OB_MENU_ENTRY_TYPE_NORMAL: g_free(self->data.normal.label); self->data.normal.shortcut = - parse_shortcut(label, &self->data.normal.label, + parse_shortcut(label, allow_shortcut, &self->data.normal.label, &self->data.normal.shortcut_position); break; default: