1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 12:28:22 +01:00

wmaker: improve key shortcut labelling

This patch is improving the key shortcut labelling in the root menu.
It modifies the GetShortcutString function to save some cycles
as wXModifierFromKey is already doing all the string comparisons.
This patch introduces a new function called wXModifierToShortcutLabel
that is checking the return value from wXModifierFromKey.
Not sure why Control was set as a special key, as keyboards could
have 2 controls but also 2 shift keys.

Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
David Maciejak
2014-09-01 12:48:36 +07:00
committed by Carlos R. Mafra
parent 3bd9e8358f
commit 118beb2c60
3 changed files with 35 additions and 27 deletions

View File

@@ -731,49 +731,28 @@ static char *keysymToString(KeySym keysym, unsigned int state)
char *GetShortcutString(const char *shortcut)
{
char *buffer = NULL;
char *k;
int control = 0;
char *tmp, *text;
char *k, *tmp, *text;
tmp = text = wstrdup(shortcut);
/* get modifiers */
while ((k = strchr(text, '+')) != NULL) {
int mod;
const char *lbl;
*k = 0;
mod = wXModifierFromKey(text);
if (mod < 0) {
return wstrdup("bug");
}
if (strcasecmp(text, "Meta") == 0) {
buffer = wstrappend(buffer, "M+");
} else if (strcasecmp(text, "Alt") == 0) {
buffer = wstrappend(buffer, "A+");
} else if (strcasecmp(text, "Shift") == 0) {
buffer = wstrappend(buffer, "Sh+");
} else if (strcasecmp(text, "Mod1") == 0) {
buffer = wstrappend(buffer, "M1+");
} else if (strcasecmp(text, "Mod2") == 0) {
buffer = wstrappend(buffer, "M2+");
} else if (strcasecmp(text, "Mod3") == 0) {
buffer = wstrappend(buffer, "M3+");
} else if (strcasecmp(text, "Mod4") == 0) {
buffer = wstrappend(buffer, "M4+");
} else if (strcasecmp(text, "Mod5") == 0) {
buffer = wstrappend(buffer, "M5+");
} else if (strcasecmp(text, "Control") == 0) {
control = 1;
} else {
lbl = wXModifierToShortcutLabel(mod);
if (lbl)
buffer = wstrappend(buffer, lbl);
else
buffer = wstrappend(buffer, text);
}
text = k + 1;
}
if (control) {
buffer = wstrappend(buffer, "^");
}
buffer = wstrappend(buffer, text);
wfree(tmp);