A few small patches to fix some inconsistencies in the keyboard shortcut labels shown against window menu entries.

Some of them were only generated once and didn't change if the user updated the shortcut key while wmaker was running. Others, eg Shade, do update but not consistently on every preferences reload. In testing I found I had to click Save in WPrefs twice before the Shade label would update.

The Unmaximize entry is a special case. Its function is to unmaximize the window but the shortcut key shown against it does not always achieve that. The patch updates the label to show a shortcut key whose behaviour is consistent with the menu text.
>From 4f2652029763d8af7d4e97742e22cb6caff567af Mon Sep 17 00:00:00 2001
From: Iain Patterson <w...@iain.cx>
Date: Fri, 18 Oct 2013 17:33:50 +0100
Subject: [PATCH 1/3] Update shortcut label for Unmaximize menu entry.

The window menu Unmaximize entry had the Maximize shortcut key as its
label.  That's because the Maximize and Unmaximize menu options are in
fact the same single entry with different text depending on the window's
state.

It can, however, cause confusion if a window is maximized using one
of the "Other maximization" options such as Maximus.  Selecting the
Unmaximize entry from the window menu would indeed unmaximize the window
but pressing the listed shortcut key would not.

We now dynamically update the shortcut label so that it shows a key
which will actually unmaximize the window.  Thus the menu description
and shortcut action are now consistent.
---
 src/winmenu.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/src/winmenu.c b/src/winmenu.c
index 6f67afc..044342b 100644
--- a/src/winmenu.c
+++ b/src/winmenu.c
@@ -173,6 +173,63 @@ static void execMaximizeCommand(WMenu * menu, WMenuEntry * entry)
 	}
 }
 
+static void updateUnmaximizeShortcut(WMenuEntry * entry, int flags)
+{
+	int key;
+
+	switch (flags & (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS)) {
+	case MAX_HORIZONTAL:
+		key = WKBD_HMAXIMIZE;
+		break;
+
+	case MAX_VERTICAL:
+		key = WKBD_VMAXIMIZE;
+		break;
+
+	case MAX_LEFTHALF | MAX_VERTICAL:
+		key = WKBD_LHMAXIMIZE;
+		break;
+
+	case MAX_RIGHTHALF | MAX_VERTICAL:
+		key = WKBD_RHMAXIMIZE;
+		break;
+
+	case MAX_TOPHALF | MAX_HORIZONTAL:
+		key = WKBD_THMAXIMIZE;
+		break;
+
+	case MAX_BOTTOMHALF | MAX_HORIZONTAL:
+		key = WKBD_BHMAXIMIZE;
+		break;
+
+	case MAX_LEFTHALF | MAX_TOPHALF:
+		key = WKBD_LTCMAXIMIZE;
+		break;
+
+	case MAX_RIGHTHALF | MAX_TOPHALF:
+		key = WKBD_RTCMAXIMIZE;
+		break;
+
+	case MAX_LEFTHALF | MAX_BOTTOMHALF:
+		key = WKBD_LBCMAXIMIZE;
+		break;
+
+	case MAX_RIGHTHALF | MAX_BOTTOMHALF:
+		key = WKBD_RBCMAXIMIZE;
+		break;
+
+	case MAX_MAXIMUS:
+		key = WKBD_MAXIMUS;
+		break;
+
+	default:
+		key = WKBD_MAXIMIZE;
+		break;
+	}
+
+	entry->rtext = GetShortcutKey(wKeyBindings[key]);
+}
+
 static void execMenuCommand(WMenu * menu, WMenuEntry * entry)
 {
 	WWindow *wwin = (WWindow *) entry->clientdata;
@@ -644,12 +701,14 @@ static void updateMenuForWindow(WMenu * menu, WWindow * wwin)
 			text = _("Unmaximize");
 
 		menu->entries[MC_MAXIMIZE]->text = text;
+		updateUnmaximizeShortcut(menu->entries[MC_MAXIMIZE], wwin->flags.maximized);
 	} else {
 		static char *text = NULL;
 		if (!text)
 			text = _("Maximize");
 
 		menu->entries[MC_MAXIMIZE]->text = text;
+		menu->entries[MC_MAXIMIZE]->rtext = GetShortcutKey(wKeyBindings[WKBD_MAXIMIZE]);
 	}
 	wMenuSetEnabled(menu, MC_MAXIMIZE, IS_RESIZABLE(wwin));
 
-- 
1.8.3.1

>From 5224337497ce5e89493eed890042a93067a0c0d1 Mon Sep 17 00:00:00 2001
From: Iain Patterson <w...@iain.cx>
Date: Fri, 18 Oct 2013 17:38:25 +0100
Subject: [PATCH 2/3] Update shortcut labels for Other maximization submenu.

The shortcut labels for items in the "Other maximization" menu were set
at startup and not updated if the user changed the shortcut key.  Thus
the labels shown could be wrong.  They might even be missing if no
shortcut was assigned at startup but was subsequently set during the
session.

We now ensure that the shortcut labels are updated with the menu
whenever preferences are reloaded.
---
 src/winmenu.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/src/winmenu.c b/src/winmenu.c
index 044342b..5efdafb 100644
--- a/src/winmenu.c
+++ b/src/winmenu.c
@@ -481,16 +481,37 @@ static void updateMaximizeMenu(WMenu * menu, WWindow * wwin)
 	WMenu *smenu = menu->cascades[menu->entries[MC_OTHERMAX]->cascade];
 
 	smenu->entries[MAXC_V]->clientdata = wwin;
+	smenu->entries[MAXC_V]->rtext = GetShortcutKey(wKeyBindings[WKBD_VMAXIMIZE]);
+
 	smenu->entries[MAXC_H]->clientdata = wwin;
+	smenu->entries[MAXC_H]->rtext = GetShortcutKey(wKeyBindings[WKBD_HMAXIMIZE]);
+
 	smenu->entries[MAXC_LH]->clientdata = wwin;
+	smenu->entries[MAXC_LH]->rtext = GetShortcutKey(wKeyBindings[WKBD_LHMAXIMIZE]);
+
 	smenu->entries[MAXC_RH]->clientdata = wwin;
+	smenu->entries[MAXC_RH]->rtext = GetShortcutKey(wKeyBindings[WKBD_RHMAXIMIZE]);
+
 	smenu->entries[MAXC_TH]->clientdata = wwin;
+	smenu->entries[MAXC_TH]->rtext = GetShortcutKey(wKeyBindings[WKBD_THMAXIMIZE]);
+
 	smenu->entries[MAXC_BH]->clientdata = wwin;
+	smenu->entries[MAXC_BH]->rtext = GetShortcutKey(wKeyBindings[WKBD_BHMAXIMIZE]);
+
 	smenu->entries[MAXC_LTC]->clientdata = wwin;
+	smenu->entries[MAXC_LTC]->rtext = GetShortcutKey(wKeyBindings[WKBD_LTCMAXIMIZE]);
+
 	smenu->entries[MAXC_RTC]->clientdata = wwin;
+	smenu->entries[MAXC_RTC]->rtext = GetShortcutKey(wKeyBindings[WKBD_RTCMAXIMIZE]);
+
 	smenu->entries[MAXC_LBC]->clientdata = wwin;
+	smenu->entries[MAXC_LBC]->rtext = GetShortcutKey(wKeyBindings[WKBD_LBCMAXIMIZE]);
+
 	smenu->entries[MAXC_RBC]->clientdata = wwin;
+	smenu->entries[MAXC_RBC]->rtext = GetShortcutKey(wKeyBindings[WKBD_RBCMAXIMIZE]);
+
 	smenu->entries[MAXC_MAXIMUS]->clientdata = wwin;
+	smenu->entries[MAXC_MAXIMUS]->rtext = GetShortcutKey(wKeyBindings[WKBD_MAXIMUS]);
 
 	smenu->flags.realized = 0;
 	wMenuRealize(smenu);
@@ -563,36 +584,16 @@ static WMenu *makeMaximizeMenu(WScreen * scr)
 	}
 
 	entry = wMenuAddCallback(menu, _("Maximize vertically"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_VMAXIMIZE]);
 	entry = wMenuAddCallback(menu, _("Maximize horizontally"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_HMAXIMIZE]);
-
 	entry = wMenuAddCallback(menu, _("Maximize left half"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_LHMAXIMIZE]);
-
 	entry = wMenuAddCallback(menu, _("Maximize right half"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_RHMAXIMIZE]);
-
 	entry = wMenuAddCallback(menu, _("Maximize top half"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_THMAXIMIZE]);
-
 	entry = wMenuAddCallback(menu, _("Maximize bottom half"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_BHMAXIMIZE]);
-
 	entry = wMenuAddCallback(menu, _("Maximize left top corner"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_LTCMAXIMIZE]);
-
 	entry = wMenuAddCallback(menu, _("Maximize right top corner"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_RTCMAXIMIZE]);
-
 	entry = wMenuAddCallback(menu, _("Maximize left bottom corner"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_LBCMAXIMIZE]);
-
 	entry = wMenuAddCallback(menu, _("Maximize right bottom corner"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_RBCMAXIMIZE]);
-
 	entry = wMenuAddCallback(menu, _("Maximus: tiled maximization"), execMaximizeCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MAXIMUS]);
 
 	return menu;
 }
-- 
1.8.3.1

>From e1aa9a53ac35e64edb10845ba0a466ba888434e8 Mon Sep 17 00:00:00 2001
From: Iain Patterson <w...@iain.cx>
Date: Fri, 18 Oct 2013 18:04:38 +0100
Subject: [PATCH 3/3] Update other window menu shortcut labels.

Ensure that keyboard shortcut labels for other entries in the window
menu are updated if the user changes the shortcut.  Previously they were
only set when the menu was created and could get out of sync.
---
 src/winmenu.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/winmenu.c b/src/winmenu.c
index 5efdafb..5d56759 100644
--- a/src/winmenu.c
+++ b/src/winmenu.c
@@ -610,25 +610,19 @@ static WMenu *createWindowMenu(WScreen * scr)
 	 * this file.
 	 */
 	entry = wMenuAddCallback(menu, _("Maximize"), execMenuCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MAXIMIZE]);
 
 	entry = wMenuAddCallback(menu, _("Other maximization"), NULL, NULL);
 	wMenuEntrySetCascade(menu, entry, makeMaximizeMenu(scr));
 
 	entry = wMenuAddCallback(menu, _("Miniaturize"), execMenuCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MINIATURIZE]);
 
 	entry = wMenuAddCallback(menu, _("Shade"), execMenuCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_SHADE]);
 
 	entry = wMenuAddCallback(menu, _("Hide"), execMenuCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_HIDE]);
 
 	entry = wMenuAddCallback(menu, _("Resize/Move"), execMenuCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVERESIZE]);
 
 	entry = wMenuAddCallback(menu, _("Select"), execMenuCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_SELECT]);
 
 	entry = wMenuAddCallback(menu, _("Move To"), NULL, NULL);
 	w_global.workspace.submenu = makeWorkspaceMenu(scr);
@@ -641,10 +635,8 @@ static WMenu *createWindowMenu(WScreen * scr)
 	wMenuEntrySetCascade(menu, entry, makeMakeShortcutMenu(makeOptionsMenu(scr)));
 
 	entry = wMenuAddCallback(menu, _("Launch"), execMenuCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_RELAUNCH]);
 
 	entry = wMenuAddCallback(menu, _("Close"), execMenuCommand, NULL);
-	entry->rtext = GetShortcutKey(wKeyBindings[WKBD_CLOSE]);
 
 	entry = wMenuAddCallback(menu, _("Kill"), execMenuCommand, NULL);
 
@@ -755,6 +747,17 @@ static void updateMenuForWindow(WMenu * menu, WWindow * wwin)
 		wMenuSetEnabled(menu, MC_PROPERTIES, False);
 	}
 
+	/* Update shortcut labels except for (Un)Maximize which is
+	 * handled separately.
+	 */
+	menu->entries[MC_MINIATURIZE]->rtext = GetShortcutKey(wKeyBindings[WKBD_MINIATURIZE]);
+	menu->entries[MC_SHADE]->rtext = GetShortcutKey(wKeyBindings[WKBD_SHADE]);
+	menu->entries[MC_HIDE]->rtext = GetShortcutKey(wKeyBindings[WKBD_HIDE]);
+	menu->entries[MC_MOVERESIZE]->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVERESIZE]);
+	menu->entries[MC_SELECT]->rtext = GetShortcutKey(wKeyBindings[WKBD_SELECT]);
+	menu->entries[MC_RELAUNCH]->rtext = GetShortcutKey(wKeyBindings[WKBD_RELAUNCH]);
+	menu->entries[MC_CLOSE]->rtext = GetShortcutKey(wKeyBindings[WKBD_CLOSE]);
+
 	/* set the client data of the entries to the window */
 	for (i = 0; i < menu->entry_no; i++) {
 		menu->entries[i]->clientdata = wwin;
-- 
1.8.3.1

Reply via email to