Subject: automatic hotkeys, 2nd try

From: Michael Han <[email-masked]>
Date: Fri, 11 Jun 1999 09:39:27 -0700

Okay, here's my second try at an automatic hotkeys patch for fvwm.
This compiles and works for me. I've added proper handling for columns
since I forgot that the menu label is a list of labels, in one of
three columns. Again, here's the Changelog entry:

1999-06-10  Michael Han  <[email-masked]>

        * fvwm/menus.c (AddToMenu, GetMenuStyleIndex, NewMenuStyle):
        added AutomaticHotkey handling
        * fvwm/menus.h: Added a "feel" flag for automatic_hotkey and
        macros to handle the flag
        * fvwm/fvwm2.1: documentation for AutomaticHotkey MenuStyle

And the patch is an attached diff -u.
-- 
[email-masked]                         http://www.best.com/~mikehan/
coffee achiever                              San Francisco, California
"The lunatic, the lover and the poet
Are of imagination all compact:-" A Midsummer Night's Dream, V i

Index: fvwm/fvwm2.1
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm2.1,v
retrieving revision 1.139
diff -u -r1.139 fvwm2.1
--- fvwm/fvwm2.1	1999/06/08 09:56:23	1.139
+++ fvwm/fvwm2.1	1999/06/11 15:55:23
@@ -2028,7 +2028,8 @@
 PopupAsRootMenu/PopupAsSubmenu,
 DeleteSubmenus/HoldSubmenus,
 SubmenusRight/SubmenusLeft,
-ItemFormat.
+ItemFormat,
+AutomaticHotkey/AutomaticHotkeyOff.
 
 In the above list some options are listed as option pairs or triples
 with a / in between. These options exclude each other.
@@ -2290,6 +2291,11 @@
 
 Note: The \fISubmenusLeft\fP style changes the default ItemFormat
 string, but if you set one manually it is not modified.
+
+\fIAutomaticHotkey\fP and \fIAutomaticHotkeyOff\fP control the menu's
+ability to automatically provide hotkeys on the first character of
+each menu item's label. This behavior is always overridden if an
+explicit hotkey is assigned in the AddToMenu command.
 
 Examples:
 
Index: fvwm/menus.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/menus.c,v
retrieving revision 1.107
diff -u -r1.107 menus.c
--- fvwm/menus.c	1999/06/08 22:48:48	1.107
+++ fvwm/menus.c	1999/06/11 15:55:36
@@ -4446,6 +4446,19 @@
 
 	if (ch != '\0')
 	  MI_CHHOTKEY(tmp) = ch;
+	else if (MST_AUTOMATIC_HOTKEY(mr))
+	{
+	  int j;
+	  for ( j = 0; j < MAX_ITEM_LABELS; j++ )
+	  {
+	    if (MI_LABEL(tmp)[j])
+	    {
+	      MI_HOTKEY(tmp) = 1 + (atoi(&(MI_LABEL(tmp)[j][0])));
+	      MI_HOTKEY_COLUMN(tmp) = j;
+	      MI_CHHOTKEY(tmp) = (MI_LABEL(tmp)[j][0]);
+	    }
+	  }
+	}
       }
       if (*(MI_LABEL(tmp)[i]))
       {
@@ -5142,6 +5155,7 @@
     "BorderWidth",
     "Hilight3DThickness",
     "ItemFormat",
+    "AutomaticHotkey", "AutomaticHotkeyOff",
     NULL
   };
   return GetTokenIndex(option, optlist, 0, NULL);
@@ -5594,6 +5608,14 @@
       {
 	ST_ITEM_FORMAT(tmpms) = strdup(arg1);
       }
+      break;
+
+    case 42: /* AutomaticHotkey */
+      ST_AUTOMATIC_HOTKEY(tmpms) = 1;
+      break;
+
+    case 43: /* AutomaticHotkeyOff */
+      ST_AUTOMATIC_HOTKEY(tmpms) = 0;
       break;
 
 #if 0
Index: fvwm/menus.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/menus.h,v
retrieving revision 1.38
diff -u -r1.38 menus.h
--- fvwm/menus.h	1999/06/08 22:48:49	1.38
+++ fvwm/menus.h	1999/06/11 15:55:38
@@ -102,6 +102,7 @@
       unsigned do_popup_as_root_menu : 1;
       unsigned do_unmap_submenu_on_popdown : 1;
       unsigned use_left_submenus : 1;
+      unsigned automatic_hotkey : 1;
     } flags;
     int PopupOffsetPercent;
     int PopupOffsetAdd;
@@ -258,6 +259,8 @@
 #define MST_POPUP_OFFSET_ADD(m)       ((m)->s->ms->feel.PopupOffsetAdd)
 #define ST_ITEM_FORMAT(s)             ((s)->feel.item_format)
 #define MST_ITEM_FORMAT(m)            ((m)->s->ms->feel.item_format)
+#define ST_AUTOMATIC_HOTKEY(s)        ((s)->feel.flags.automatic_hotkey)
+#define MST_AUTOMATIC_HOTKEY(m)       ((m)->s->ms->feel.flags.automatic_hotkey)

Index: modules/FvwmEvent/FvwmEvent.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmEvent/FvwmEvent.c,v
retrieving revision 1.24
diff -u -r1.24 FvwmEvent.c
--- modules/FvwmEvent/FvwmEvent.c	1999/05/29 18:27:14	1.24
+++ modules/FvwmEvent/FvwmEvent.c	1999/06/11 15:55:40
@@ -466,8 +466,17 @@
 	    free(cmd_line);
 	  if (token)
 	  {
-	    cmd_line = (char *)safemalloc(strlen(token)+1);
-	    strcpy(cmd_line, token);
+	    if (e - (char**)table == 4)
+	    {
+	      cmd_line = (char *)safemalloc(strlen(token)+11);
+	      strcpy(cmd_line, "Exec exec ");
+	      strcat(cmd_line, token);
+	    }
+	    else
+	    {
+	      cmd_line = (char *)safemalloc(strlen(token)+1);
+	      strcpy(cmd_line, token);
+	    }
 	  }
 	  else
 	  {