Subject: menu hotkeys

From: Michael Han <[email-masked]>
Date: Thu, 10 Jun 1999 19:41:45 -0700

I thought it might be nice to allow menus to be hotkey-able
automagically. So I wrote a little patch that does this. It's now a
MenuStyle option called AutomaticHotkey/AutomaticHotkeyOff. Naturally
it defaults to being off... It's a pretty trivial patch which seems to
work fine. 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

-- 
[email-masked]                         http://www.best.com/~mikehan/
coffee achiever                              San Francisco, California
"How can someone with glasses that thick be so stupid?" - Bart

===================================================================
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 02:30:34
@@ -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 02:30:47
@@ -4446,6 +4446,12 @@
 
 	if (ch != '\0')
 	  MI_CHHOTKEY(tmp) = ch;
+	else if (MST_AUTOMATIC_HOTKEY(mr) && MI_LABEL(tmp))
+	{
+	  MI_HOTKEY(tmp) = 1 + (atoi(MI_LABEL(tmp)[0]));
+	  MI_HOTKEY_COLUMN(tmp) = 0;
+	  MI_CHHOTKEY(tmp) = *(MI_LABEL(tmp)[0]);
+	}
       }
       if (*(MI_LABEL(tmp)[i]))
       {
@@ -5142,6 +5148,7 @@
     "BorderWidth",
     "Hilight3DThickness",
     "ItemFormat",
+    "AutomaticHotkey", "AutomaticHotkeyOff",
     NULL
   };
   return GetTokenIndex(option, optlist, 0, NULL);
@@ -5594,6 +5601,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 02:30:49
@@ -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)

---

From: Tim Phipps <[email-masked]>
Date: Fri, 11 Jun 1999 09:58:03 +0100

> work fine. Here's the Changelog entry:

And it's very useful and is almost no size penalty (172 bytes extra in
the executable but 97 bytes saved from my .fvwm2rc).  I vote for
adoption.

Cheers,
Tim.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Fri, 11 Jun 1999 16:25:15 -0600

On Thu, Jun 10, 1999 at 07:41:45PM -0700, [email-masked] wrote:
> work fine.

Doe the code use just the first letter of the item or does it try to find
meaningful hotkeysr? E.g. if you have twenty entries beginning with
'fvwm ', do they all get the 'f' as the hotkey?

Bye

Dominik ^_^

-- 
Dominik Vogt, Hewlett-Packard GmbH, Dept. BVS
Herrenberger Str.130, 71034 Boeblingen, Germany
phone: 07031/14-4596, fax: 07031/14-3883, [email-masked]
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Michael Han <[email-masked]>
Date: Fri, 11 Jun 1999 07:45:06 -0700

Previously...
>'fvwm ', do they all get the 'f' as the hotkey?

Unfortunately, it's the former. A simple-minded hotkey the first
letter approach (MI_LABEL(tmp)[0]). I figured a "smart" approach would
be way too difficult to do well, and would probably lead to
unnecessary bloat... Still, I think that it could be a useful
timesaver when writing .fvwm2rc from scratch, since if you enable
Menustyle * AutomaticHotkey
you get first letter hotkeys for free, and need only worry yourself
with exceptions.
-- 
[email-masked]
I will not trade pants with others
 - The collected wisdom of Bart Simpson
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Fri, 11 Jun 1999 16:54:34 -0600

On Fri, Jun 11, 1999 at 07:45:06AM -0700, [email-masked] wrote:
> Unfortunately, it's the former.

Hm, can I override the automatic hotkeys with my own?

> A simple-minded hotkey the first
> letter approach (MI_LABEL(tmp)[0]).

MI_LABEL(tmp)[0] returns the first label, not the first letter of the
first label (use MI_LABEL(tmo)[0][0]). Do you check if MI_LABEL(tmp)[0]
is NULL first?

> I figured a "smart" approach would

Bye

Dominik ^_^

---

From: Mike Kachline <[email-masked]>
Date: Fri, 11 Jun 1999 10:55:00 -0400 (EDT)

<snip>
> letter approach (MI_LABEL(tmp)[0]). I figured a "smart" approach would
<snip>
	I think that using the first character of each menu item is the
best way to go... So long that 1: If one has > 1 menu entries hotkeyed to
a letter, then pressing the hotkey multiple times will step through each
item and 2: Explicit hotkey assignments could over-ride implicit
(automatic) hotkey assignments.

						My $0.02,
							- Mike
====================================================================
Michael Kachline CS, Georgia Institute of Technlology
[email-masked]
http://brightstar.gt.ed.net/kachline
====================================================================

---

From: Michael Han <[email-masked]>
Date: Fri, 11 Jun 1999 08:37:54 -0700

Previously...
>Hm, can I override the automatic hotkeys with my own?

Certainly.

>first label (use MI_LABEL(tmo)[0][0]). Do you check if MI_LABEL(tmp)[0]

Aiee! I knew there was something confusing me about that... it's that
the label is a list of labels in each column! I *do* check for the
presence of MI_LABEL before trying to play any games. Strangely, my
code works correctly... Anyway, I'll go back and fold in proper
handling of label columns, including the case where the left-most
column MI_LABEL(tmp)[0] == NULL but some other label isn't.
-- 
[email-masked]
The Pledge of Allegiance does not end with Hail Satan
 - The collected wisdom of Bart Simpson
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

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

Previously...
>best way to go... So long that

>1: If one has > 1 menu entries hotkeyed to
>item and

Yes, this is a patch I wrote a month or three back.

>2: Explicit hotkey assignments could over-ride implicit

Well if that weren't the case, I'd be one rude boy!
-- 
[email-masked]
I will not bring sheep to class
 - The collected wisdom of Bart Simpson
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Tim Phipps <[email-masked]>
Date: Fri, 11 Jun 1999 16:40:20 +0100

Michael Han wrote:
> be way too difficult to do well,

I tried doing this yonks ago on a text menuing system, it sucks unless
the smartness is at least as good as a human (highly unlikely from my
code).  If you just pick unique letters as the items come in you quickly
get hot keys that look just like random choices e.g.:

Bilbo
Baggins
Aragorn

gives hot keys of B, a & r. A better choice would be B, g & A but you
can't choose this without knowing all the menu items first.  For fvwm
this would mean recalculating the hotkeys every time the menu is popped
and the contents have changed.  If someone has a menu e.g. that is a
list of recently edited files they will find the hotkeys will jump
around as the history builds up.  If that's not enough a smart system
should pick consonants from the start of syllables that form the
emphasized parts of words e.g: if e is not available "elephant" should
have p rather than l and definitely not h.

I would stick to the first letter, it's predictable and fvwm handles
having the same hot key twice in one menu nicely.

Cheers,
Tim.

---

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

Previously...
>first label (use MI_LABEL(tmo)[0][0]). Do you check if MI_LABEL(tmp)[0]

Hmm... I've had to throw in a quick 'int j;' in my AddToMenu change,
in order to be able to walk a for loop from j=0;j<MAX_ITEM_LABELS;j++
to acount for the possibility of a menu labeled like "^I^IRight-side
text", where I want to give the hotkey to "R". Any objections here?
I'll just take some time to look over my new diff to make sure it's
sane and that I didn't do any other silly things.
-- 
[email-masked]
I will not grease the monkey bars
 - The collected wisdom of Bart Simpson
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Sat, 6 Nov 1999 18:30:33 -0700

> sane and that I didn't do any other silly things.

No objections. I will proof read the patch anyway when I apply it.

Bye

Dominik ^_^