cleanups for keyboard menu shotcuts. dont let & set a shortcut from stuff like menu...
authorDana Jansens <danakj@orodu.net>
Wed, 25 Apr 2007 02:50:59 +0000 (02:50 +0000)
committerDana Jansens <danakj@orodu.net>
Wed, 25 Apr 2007 02:50:59 +0000 (02:50 +0000)
openbox/client_list_combined_menu.c
openbox/client_list_menu.c
openbox/client_menu.c
openbox/event.c
openbox/menu.c
openbox/menu.h

index adf3ff0..8412abe 100644 (file)
@@ -70,10 +70,10 @@ static void self_update(ObMenuFrame *frame, gpointer data)
 
                 if (c->iconic) {
                     gchar *title = g_strdup_printf("(%s)", c->icon_title);
-                    e = menu_add_normal(menu, i, title, acts);
+                    e = menu_add_normal(menu, i, title, acts, FALSE);
                     g_free(title);
                 } else
-                    e = menu_add_normal(menu, i, c->title, acts);
+                    e = menu_add_normal(menu, i, c->title, acts, FALSE);
 
                 if (config_menu_client_list_icons
                         && (icon = client_icon(c, 32, 32))) {
@@ -94,7 +94,7 @@ static void self_update(ObMenuFrame *frame, gpointer data)
             act = action_from_string("Desktop", OB_USER_ACTION_MENU_SELECTION);
             act->data.desktop.desk = desktop;
             acts = g_slist_append(acts, act);
-            e = menu_add_normal(menu, 0, _("Go there..."), acts);
+            e = menu_add_normal(menu, 0, _("Go there..."), acts, TRUE);
             if (desktop == screen_desktop)
                 e->data.normal.enabled = FALSE;
         }
@@ -138,7 +138,7 @@ void client_list_combined_menu_startup(gboolean reconfig)
     if (!reconfig)
         client_add_destructor(client_dest, NULL);
 
-    combined_menu = menu_new(MENU_NAME, _("Windows"), NULL);
+    combined_menu = menu_new(MENU_NAME, _("Windows"), TRUE, NULL);
     menu_set_update_func(combined_menu, self_update);
     menu_set_execute_func(combined_menu, menu_execute);
 }
index 5fbb3a6..208b31c 100644 (file)
@@ -75,7 +75,8 @@ static void desk_menu_update(ObMenuFrame *frame, gpointer data)
             act->data.desktop.desk = d->desktop;
             acts = g_slist_append(acts, act);
             e = menu_add_normal(menu, i,
-                                (c->iconic ? c->icon_title : c->title), acts);
+                                (c->iconic ? c->icon_title : c->title),
+                                acts, FALSE);
 
             if (config_menu_client_list_icons
                 && (icon = client_icon(c, 32, 32))) {
@@ -96,7 +97,7 @@ static void desk_menu_update(ObMenuFrame *frame, gpointer data)
         act = action_from_string("Desktop", OB_USER_ACTION_MENU_SELECTION);
         act->data.desktop.desk = d->desktop;
         acts = g_slist_append(acts, act);
-        e = menu_add_normal(menu, 0, _("Go there..."), acts);
+        e = menu_add_normal(menu, 0, _("Go there..."), acts, TRUE);
         if (d->desktop == screen_desktop)
             e->data.normal.enabled = FALSE;
     }
@@ -138,7 +139,7 @@ static void self_update(ObMenuFrame *frame, gpointer data)
             DesktopData *data = g_new(DesktopData, 1);
 
             data->desktop = i;
-            submenu = menu_new(name, screen_desktop_names[i], data);
+            submenu = menu_new(name, screen_desktop_names[i], FALSE, data);
             menu_set_update_func(submenu, desk_menu_update);
             menu_set_execute_func(submenu, desk_menu_execute);
             menu_set_destroy_func(submenu, desk_menu_destroy);
@@ -187,7 +188,7 @@ void client_list_menu_startup(gboolean reconfig)
     if (!reconfig)
         client_add_destructor(client_dest, NULL);
 
-    menu = menu_new(MENU_NAME, _("Desktops"), NULL);
+    menu = menu_new(MENU_NAME, _("Desktops"), TRUE, NULL);
     menu_set_update_func(menu, self_update);
 }
 
index d8ac8e0..be76715 100644 (file)
@@ -72,12 +72,12 @@ static void client_update(ObMenuFrame *frame, gpointer data)
     e = menu_find_entry_id(menu, CLIENT_MAXIMIZE);
     menu_entry_set_label(e,
                          (frame->client->max_vert || frame->client->max_horz ?
-                          _("Restor&e") : _("Maximiz&e")));
+                          _("Restor&e") : _("Maximiz&e")), TRUE);
     e->data.normal.enabled =frame->client->functions & OB_CLIENT_FUNC_MAXIMIZE;
 
     e = menu_find_entry_id(menu, CLIENT_SHADE);
     menu_entry_set_label(e, (frame->client->shaded ?
-                             _("&Roll down") : _("&Roll up")));
+                             _("&Roll down") : _("&Roll up")), TRUE);
     e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_SHADE;
 
     e = menu_find_entry_id(menu, CLIENT_MOVE);
@@ -150,7 +150,7 @@ static void send_to_update(ObMenuFrame *frame, gpointer data)
         act->data.sendto.desk = desk;
         act->data.sendto.follow = FALSE;
         acts = g_slist_prepend(NULL, act);
-        e = menu_add_normal(menu, desk, name, acts);
+        e = menu_add_normal(menu, desk, name, acts, FALSE);
 
         if (frame->client->desktop == desk)
             e->data.normal.enabled = FALSE;
@@ -163,31 +163,30 @@ void client_menu_startup()
     ObMenu *menu;
     ObMenuEntry *e;
 
-    menu = menu_new(LAYER_MENU_NAME, _("&Layer"), NULL);
+    menu = menu_new(LAYER_MENU_NAME, _("&Layer"), TRUE, NULL);
     menu_show_all_shortcuts(menu, TRUE);
     menu_set_update_func(menu, layer_update);
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("SendToTopLayer", OB_USER_ACTION_MENU_SELECTION));
-    menu_add_normal(menu, LAYER_TOP, _("Always on &top"), acts);
+    menu_add_normal(menu, LAYER_TOP, _("Always on &top"), acts, TRUE);
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("SendToNormalLayer",
                             OB_USER_ACTION_MENU_SELECTION));
-    menu_add_normal(menu, LAYER_NORMAL, _("&Normal"), acts);
+    menu_add_normal(menu, LAYER_NORMAL, _("&Normal"), acts, TRUE);
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("SendToBottomLayer",
                             OB_USER_ACTION_MENU_SELECTION));
-    menu_add_normal(menu, LAYER_BOTTOM, _("Always on &bottom"),acts);
+    menu_add_normal(menu, LAYER_BOTTOM, _("Always on &bottom"),acts, TRUE);
 
 
-    menu = menu_new(SEND_TO_MENU_NAME, _("&Send to desktop"), NULL);
-    menu_show_all_shortcuts(menu, TRUE);
+    menu = menu_new(SEND_TO_MENU_NAME, _("&Send to desktop"), TRUE, NULL);
     menu_set_update_func(menu, send_to_update);
 
 
-    menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), NULL);
+    menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), TRUE, NULL);
     menu_show_all_shortcuts(menu, TRUE);
     menu_set_update_func(menu, client_update);
 
@@ -197,7 +196,7 @@ void client_menu_startup()
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("Iconify", OB_USER_ACTION_MENU_SELECTION));
-    e = menu_add_normal(menu, CLIENT_ICONIFY, _("Ico&nify"), acts);
+    e = menu_add_normal(menu, CLIENT_ICONIFY, _("Ico&nify"), acts, TRUE);
     e->data.normal.mask = ob_rr_theme->iconify_mask;
     e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
     e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
@@ -206,7 +205,7 @@ void client_menu_startup()
     acts = g_slist_prepend(NULL, action_from_string
                            ("ToggleMaximizeFull",
                             OB_USER_ACTION_MENU_SELECTION));
-    e = menu_add_normal(menu, CLIENT_MAXIMIZE, "MAXIMIZE", acts);
+    e = menu_add_normal(menu, CLIENT_MAXIMIZE, "MAXIMIZE", acts, TRUE);
     e->data.normal.mask = ob_rr_theme->max_mask; 
     e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
     e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
@@ -214,15 +213,15 @@ void client_menu_startup()
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("Raise", OB_USER_ACTION_MENU_SELECTION));
-    menu_add_normal(menu, CLIENT_RAISE, _("Raise to &top"), acts);
+    menu_add_normal(menu, CLIENT_RAISE, _("Raise to &top"), acts, TRUE);
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("Lower", OB_USER_ACTION_MENU_SELECTION));
-    menu_add_normal(menu, CLIENT_LOWER, _("Lower to &bottom"),acts);
+    menu_add_normal(menu, CLIENT_LOWER, _("Lower to &bottom"),acts, TRUE);
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("ToggleShade", OB_USER_ACTION_MENU_SELECTION));
-    e = menu_add_normal(menu, CLIENT_SHADE, "SHADE", acts);
+    e = menu_add_normal(menu, CLIENT_SHADE, "SHADE", acts, TRUE);
     e->data.normal.mask = ob_rr_theme->shade_mask;
     e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
     e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
@@ -231,23 +230,23 @@ void client_menu_startup()
     acts = g_slist_prepend(NULL, action_from_string
                            ("ToggleDecorations",
                             OB_USER_ACTION_MENU_SELECTION));
-    menu_add_normal(menu, CLIENT_DECORATE, _("&Decorate"), acts);
+    menu_add_normal(menu, CLIENT_DECORATE, _("&Decorate"), acts, TRUE);
 
     menu_add_separator(menu, -1, NULL);
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("Move", OB_USER_ACTION_MENU_SELECTION));
-    menu_add_normal(menu, CLIENT_MOVE, _("&Move"), acts);
+    menu_add_normal(menu, CLIENT_MOVE, _("&Move"), acts, TRUE);
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("Resize", OB_USER_ACTION_MENU_SELECTION));
-    menu_add_normal(menu, CLIENT_RESIZE, _("Resi&ze"), acts);
+    menu_add_normal(menu, CLIENT_RESIZE, _("Resi&ze"), acts, TRUE);
 
     menu_add_separator(menu, -1, NULL);
 
     acts = g_slist_prepend(NULL, action_from_string
                            ("Close", OB_USER_ACTION_MENU_SELECTION));
-    e = menu_add_normal(menu, CLIENT_CLOSE, _("&Close"), acts);
+    e = menu_add_normal(menu, CLIENT_CLOSE, _("&Close"), acts, TRUE);
     e->data.normal.mask = ob_rr_theme->close_mask;
     e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
     e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
index 9d6ff5f..4a60194 100644 (file)
@@ -52,6 +52,9 @@
 #ifdef HAVE_SIGNAL_H
 #  include <signal.h>
 #endif
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h> /* for usleep() */
+#endif
 #ifdef XKB
 #  include <X11/XKBlib.h>
 #endif
index 1f335c7..7197868 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);
@@ -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;
@@ -538,7 +543,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 +554,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:
index bdc0526..2315351 100644 (file)
@@ -133,7 +133,10 @@ struct _ObMenuEntry
 void menu_startup(gboolean reconfig);
 void menu_shutdown(gboolean reconfig);
 
-ObMenu* menu_new(const gchar *name, const gchar *title, gpointer data);
+/*! @param allow_shortcut this should be false when the label is coming from
+           outside data like window or desktop titles */
+ObMenu* menu_new(const gchar *name, const gchar *title,
+                 gboolean allow_shortcut, gpointer data);
 void menu_free(ObMenu *menu);
 
 /* Repopulate a pipe-menu by running its command */
@@ -148,15 +151,18 @@ void menu_set_execute_func(ObMenu *menu, ObMenuExecuteFunc func);
 void menu_set_destroy_func(ObMenu *menu, ObMenuDestroyFunc func);
 
 /* functions for building menus */
+/*! @param allow_shortcut this should be false when the label is coming from
+           outside data like window or desktop titles */
 ObMenuEntry* menu_add_normal(ObMenu *menu, gint id, const gchar *label,
-                             GSList *actions);
+                             GSList *actions, gboolean allow_shortcut);
 ObMenuEntry* menu_add_submenu(ObMenu *menu, gint id, const gchar *submenu);
 ObMenuEntry* menu_add_separator(ObMenu *menu, gint id, const gchar *label);
 
 void menu_clear_entries(ObMenu *menu);
 void menu_entry_remove(ObMenuEntry *self);
 
-void menu_entry_set_label(ObMenuEntry *self, const gchar *label);
+void menu_entry_set_label(ObMenuEntry *self, const gchar *label,
+                          gboolean allow_shortcut);
 
 ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id);