]> Dogcows Code - chaz/openbox/blobdiff - openbox/menu.c
changes to the client menu, which entries are there, and reorganizing, and renaming.
[chaz/openbox] / openbox / menu.c
index 1f335c787dac724b26bc3b0a97c3f964b4cf861d..741e27c12be7a5fc79375d96c8aa64ee5d9f2a25 100644 (file)
@@ -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,13 +379,13 @@ 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) {
+        /* select the first entry if it's not a submenu */
         ObMenuEntryFrame *e = frame->entries->data;
-        if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
-            e->entry->data.normal.enabled)
-                menu_frame_select(frame, e, FALSE);
+        if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL)
+            menu_frame_select(frame, e, FALSE);
     }
 }
 
@@ -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:
This page took 0.029475 seconds and 4 git commands to generate.