diff --git a/src/WindowMaker.h b/src/WindowMaker.h index 75464fdf..dea943b9 100644 --- a/src/WindowMaker.h +++ b/src/WindowMaker.h @@ -393,6 +393,7 @@ extern struct WPreferences { signed char workspace_name_display_position; unsigned int modifier_mask; /* mask to use as kbd modifier */ char *modifier_labels[7]; /* Names of the modifiers */ + char *modifier_short_labels[9]; /* Short names of the modifiers */ unsigned int supports_tiff; /* Use tiff files */ diff --git a/src/defaults.c b/src/defaults.c index 43860599..6b6bc4c3 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -151,6 +151,7 @@ static WDECallbackUpdate setSwPOptions; static WDECallbackUpdate updateUsableArea; static WDECallbackUpdate setModifierKeyLabels; +static WDECallbackUpdate setModifierShortKeyLabels; static WDECallbackUpdate setHotCornerActions; static WDECallbackConvert getCursor; @@ -624,6 +625,8 @@ WDefaultEntry optionList[] = { NULL, getPropList, setSwPOptions, NULL, NULL}, {"ModifierKeyLabels", "(\"Shift+\", \"Control+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences, NULL, getPropList, setModifierKeyLabels, NULL, NULL}, + {"ModifierKeyShortLabels", "(\"Sh+\", \"^\", \"M1+\", \"M2+\", \"M3+\", \"M4+\", \"M5+\", \"M+\", \"A+\")", &wPreferences, + NULL, getPropList, setModifierShortKeyLabels, NULL, NULL}, {"FrameBorderWidth", "1", NULL, NULL, getInt, setFrameBorderWidth, NULL, NULL}, {"FrameBorderColor", "black", NULL, @@ -3499,6 +3502,42 @@ static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdat return 0; } +static int setModifierShortKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo) +{ + WMPropList *array = tdata; + int i; + struct WPreferences *prefs = foo; + + if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 9) { + wwarning(_("Value for option \"%s\" must be an array of 9 strings"), entry->key); + WMReleasePropList(array); + return 0; + } + + DestroyWindowMenu(scr); + + for (i = 0; i < 9; i++) { + if (prefs->modifier_short_labels[i]) + wfree(prefs->modifier_short_labels[i]); + + if (WMIsPLString(WMGetFromPLArray(array, i))) { + prefs->modifier_short_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i))); + if (prefs->modifier_short_labels[i][0] == '\0') { + wwarning(_("Invalid argument for option \"%s\" item %d, cannot be empty"), entry->key, i); + wfree(prefs->modifier_short_labels[i]); + prefs->modifier_short_labels[i] = NULL; + } + } else { + wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i); + prefs->modifier_short_labels[i] = NULL; + } + } + + WMReleasePropList(array); + + return 0; +} + static int setHotCornerActions(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo) { WMPropList *array = tdata; diff --git a/src/xmodifier.c b/src/xmodifier.c index e2c0fa2a..f4bdd0d0 100644 --- a/src/xmodifier.c +++ b/src/xmodifier.c @@ -280,24 +280,30 @@ const char *wXModifierToShortcutLabel(int mask) if (mask < 0) return NULL; - if (mask == ShiftMask) - return "Sh+"; - if (mask == ControlMask) - return "^"; - if (mask == AltMask) - return "A+"; - if (mask == Mod1Mask) - return "M1+"; - if (mask == Mod2Mask) - return "M2+"; - if (mask == Mod3Mask) - return "M3+"; - if (mask == Mod4Mask) - return "M4+"; - if (mask == Mod5Mask) - return "M5+"; - if (mask == MetaMask) - return "M+"; + struct map_entry { + int mask; + int label_index; + const char *def; + } maps[] = { + { ShiftMask, 0, "Sh+"}, + { ControlMask, 1, "^" }, + { AltMask, 8, "A+" }, + { Mod1Mask, 2, "M1+"}, + { Mod2Mask, 3, "M2+"}, + { Mod3Mask, 4, "M3+"}, + { Mod4Mask, 5, "M4+"}, + { Mod5Mask, 6, "M5+"}, + { MetaMask, 7, "M+" } + }; + + for (size_t i = 0; i < sizeof(maps)/sizeof(maps[0]); i++) { + if (mask == maps[i].mask) { + int idx = maps[i].label_index; + if (idx >= 0 && idx < 9 && wPreferences.modifier_short_labels[idx]) + return wPreferences.modifier_short_labels[idx]; + return maps[i].def; + } + } wwarning(_("Can't convert keymask 0x%04X to a shortcut label"), mask); return NULL;