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

Added GetShortcutKey().

The function getShortcutString() was defined statically in winmenu.c.

Replace it with the new function GetShortcutKey() which calls the
existing function GetShortcutString() so it can be used elsewhere and
cut down on code duplication.

A result of this change is that shortcuts are now labelled consistently.
Previously the format was different in generated menus, which used, for
example, M1 to refer to Mod1 whereas window menus used the full string
Mod1.  Now both use the shorter form.

One could argue that the new function name is more consistent, as now
GetShortcutString() takes a char * argument and GetShortcutKey() takes a
WShortcutKey argument.  That argument assumes that the original
intention behind the name of GetShortcutString() was not to hint that it
returns a String...
This commit is contained in:
Iain Patterson
2013-03-27 11:58:47 +00:00
committed by Carlos R. Mafra
parent 0da2b6e928
commit cd5382cedf
3 changed files with 33 additions and 28 deletions

View File

@@ -26,6 +26,7 @@
#include "window.h" #include "window.h"
#include "defaults.h" #include "defaults.h"
#include "keybind.h"
typedef void (WCallBack)(void *cdata); typedef void (WCallBack)(void *cdata);
typedef void (WDeathHandler)(pid_t pid, unsigned int status, void *cdata); typedef void (WDeathHandler)(pid_t pid, unsigned int status, void *cdata);
@@ -67,6 +68,7 @@ char * ExpandOptions(WScreen *scr, char *cmdline);
char * ShrinkString(WMFont *font, char *string, int width); char * ShrinkString(WMFont *font, char *string, int width);
char * FindImage(char *paths, char *file); char * FindImage(char *paths, char *file);
char * GetShortcutString(char *text); char * GetShortcutString(char *text);
char * GetShortcutKey(WShortKey key);
char * EscapeWM_CLASS(char *name, char *class); char * EscapeWM_CLASS(char *name, char *class);
Bool IsDoubleClick(WScreen *scr, XEvent *event); Bool IsDoubleClick(WScreen *scr, XEvent *event);

View File

@@ -33,6 +33,8 @@
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include <X11/XKBlib.h>
#include <WINGs/WUtil.h> #include <WINGs/WUtil.h>
#include <wraster.h> #include <wraster.h>
@@ -771,6 +773,25 @@ char *GetShortcutString(char *text)
return buffer; return buffer;
} }
char *GetShortcutKey(WShortKey key)
{
char *tmp = NULL;
char *k = XKeysymToString(XkbKeycodeToKeysym(dpy, key.keycode, 0, 0));
if (!k) return NULL;
char **m = wPreferences.modifier_labels;
if (key.modifier & ControlMask) tmp = wstrappend(tmp, m[1] ? m[1] : "Ctrl+");
if (key.modifier & ShiftMask) tmp = wstrappend(tmp, m[0] ? m[0] : "Shift+");
if (key.modifier & Mod1Mask) tmp = wstrappend(tmp, m[2] ? m[2] : "Mod1+");
if (key.modifier & Mod2Mask) tmp = wstrappend(tmp, m[3] ? m[3] : "Mod2+");
if (key.modifier & Mod3Mask) tmp = wstrappend(tmp, m[4] ? m[4] : "Mod3+");
if (key.modifier & Mod4Mask) tmp = wstrappend(tmp, m[5] ? m[5] : "Mod4+");
if (key.modifier & Mod5Mask) tmp = wstrappend(tmp, m[6] ? m[6] : "Mod5+");
tmp = wstrappend(tmp, k);
return GetShortcutString(tmp);
}
char *EscapeWM_CLASS(char *name, char *class) char *EscapeWM_CLASS(char *name, char *class)
{ {
char *ret; char *ret;

View File

@@ -38,6 +38,7 @@
#include "client.h" #include "client.h"
#include "application.h" #include "application.h"
#include "keybind.h" #include "keybind.h"
#include "funcs.h"
#include "framewin.h" #include "framewin.h"
#include "workspace.h" #include "workspace.h"
#include "winspector.h" #include "winspector.h"
@@ -244,25 +245,6 @@ static void updateWorkspaceMenu(WMenu * menu)
wMenuRealize(menu); wMenuRealize(menu);
} }
static char *getShortcutString(WShortKey key)
{
char *tmp = NULL;
char *k = XKeysymToString(XkbKeycodeToKeysym(dpy, key.keycode, 0, 0));
if (!k) return NULL;
char **m = wPreferences.modifier_labels;
if (key.modifier & ControlMask) tmp = wstrappend(tmp, m[1] ? m[1] : "Ctrl+");
if (key.modifier & ShiftMask) tmp = wstrappend(tmp, m[0] ? m[0] : "Shift+");
if (key.modifier & Mod1Mask) tmp = wstrappend(tmp, m[2] ? m[2] : "Mod1+");
if (key.modifier & Mod2Mask) tmp = wstrappend(tmp, m[3] ? m[3] : "Mod2+");
if (key.modifier & Mod3Mask) tmp = wstrappend(tmp, m[4] ? m[4] : "Mod3+");
if (key.modifier & Mod4Mask) tmp = wstrappend(tmp, m[5] ? m[5] : "Mod4+");
if (key.modifier & Mod5Mask) tmp = wstrappend(tmp, m[6] ? m[6] : "Mod5+");
tmp = wstrappend(tmp, k);
return tmp;
}
static void updateMakeShortcutMenu(WMenu * menu, WWindow * wwin) static void updateMakeShortcutMenu(WMenu * menu, WWindow * wwin)
{ {
WMenu *smenu = menu->cascades[menu->entries[MC_SHORTCUT]->cascade]; WMenu *smenu = menu->cascades[menu->entries[MC_SHORTCUT]->cascade];
@@ -304,7 +286,7 @@ static void updateMakeShortcutMenu(WMenu * menu, WWindow * wwin)
kcode = wKeyBindings[WKBD_WINDOW1 + shortcutNo].keycode; kcode = wKeyBindings[WKBD_WINDOW1 + shortcutNo].keycode;
if (kcode) { if (kcode) {
if ((tmp = getShortcutString(wKeyBindings[WKBD_WINDOW1 + shortcutNo])) if ((tmp = GetShortcutKey(wKeyBindings[WKBD_WINDOW1 + shortcutNo]))
&& (!entry->rtext || strcmp(tmp, entry->rtext) != 0)) { && (!entry->rtext || strcmp(tmp, entry->rtext) != 0)) {
if (entry->rtext) if (entry->rtext)
wfree(entry->rtext); wfree(entry->rtext);
@@ -428,22 +410,22 @@ static WMenu *createWindowMenu(WScreen * scr)
* this file. * this file.
*/ */
entry = wMenuAddCallback(menu, _("Maximize"), execMenuCommand, NULL); entry = wMenuAddCallback(menu, _("Maximize"), execMenuCommand, NULL);
entry->rtext = getShortcutString(wKeyBindings[WKBD_MAXIMIZE]); entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MAXIMIZE]);
entry = wMenuAddCallback(menu, _("Miniaturize"), execMenuCommand, NULL); entry = wMenuAddCallback(menu, _("Miniaturize"), execMenuCommand, NULL);
entry->rtext = getShortcutString(wKeyBindings[WKBD_MINIATURIZE]); entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MINIATURIZE]);
entry = wMenuAddCallback(menu, _("Shade"), execMenuCommand, NULL); entry = wMenuAddCallback(menu, _("Shade"), execMenuCommand, NULL);
entry->rtext = getShortcutString(wKeyBindings[WKBD_SHADE]); entry->rtext = GetShortcutKey(wKeyBindings[WKBD_SHADE]);
entry = wMenuAddCallback(menu, _("Hide"), execMenuCommand, NULL); entry = wMenuAddCallback(menu, _("Hide"), execMenuCommand, NULL);
entry->rtext = getShortcutString(wKeyBindings[WKBD_HIDE]); entry->rtext = GetShortcutKey(wKeyBindings[WKBD_HIDE]);
entry = wMenuAddCallback(menu, _("Resize/Move"), execMenuCommand, NULL); entry = wMenuAddCallback(menu, _("Resize/Move"), execMenuCommand, NULL);
entry->rtext = getShortcutString(wKeyBindings[WKBD_MOVERESIZE]); entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVERESIZE]);
entry = wMenuAddCallback(menu, _("Select"), execMenuCommand, NULL); entry = wMenuAddCallback(menu, _("Select"), execMenuCommand, NULL);
entry->rtext = getShortcutString(wKeyBindings[WKBD_SELECT]); entry->rtext = GetShortcutKey(wKeyBindings[WKBD_SELECT]);
entry = wMenuAddCallback(menu, _("Move To"), NULL, NULL); entry = wMenuAddCallback(menu, _("Move To"), NULL, NULL);
scr->workspace_submenu = makeWorkspaceMenu(scr); scr->workspace_submenu = makeWorkspaceMenu(scr);
@@ -461,10 +443,10 @@ static WMenu *createWindowMenu(WScreen * scr)
*/ */
entry = wMenuAddCallback(menu, _("Launch"), execMenuCommand, NULL); entry = wMenuAddCallback(menu, _("Launch"), execMenuCommand, NULL);
entry->rtext = getShortcutString(wKeyBindings[WKBD_RELAUNCH]); entry->rtext = GetShortcutKey(wKeyBindings[WKBD_RELAUNCH]);
entry = wMenuAddCallback(menu, _("Close"), execMenuCommand, NULL); entry = wMenuAddCallback(menu, _("Close"), execMenuCommand, NULL);
entry->rtext = getShortcutString(wKeyBindings[WKBD_CLOSE]); entry->rtext = GetShortcutKey(wKeyBindings[WKBD_CLOSE]);
entry = wMenuAddCallback(menu, _("Kill"), execMenuCommand, NULL); entry = wMenuAddCallback(menu, _("Kill"), execMenuCommand, NULL);