97 lines
2.7 KiB
C
97 lines
2.7 KiB
C
/*
|
|
* xmodifier.c — modifier mask state shared between backends.
|
|
*
|
|
* The actual X11 keymap discovery (XGetModifierMapping et al.) lives in
|
|
* the X11 backend; on Wayland the masks come from xkb via
|
|
* wSetModifierMasks called from the Wayland backend. This file only
|
|
* holds the cached masks and the portable name↔mask conversions used
|
|
* by shared policy code (rootmenu.c, defaults.c, misc.c, usermenu.c).
|
|
*
|
|
* History: this file used to contain the modifier-keymap-walking code
|
|
* (taken from XEmacs 20.3, original copyright Sudish Joseph, 1997, and
|
|
* Free Software Foundation 1991-1995). That code now lives in
|
|
* src/backend/x11/x11_backend.c (function x11_reset_modifier_mapping).
|
|
*/
|
|
|
|
#include "wconfig.h"
|
|
|
|
#include <string.h>
|
|
#include <strings.h>
|
|
|
|
#include <X11/X.h> /* ShiftMask, ControlMask, ModNMask constants */
|
|
|
|
#include <WINGs/WUtil.h>
|
|
#include "WindowMaker.h"
|
|
#include "xmodifier.h"
|
|
|
|
static int MetaMask, HyperMask, SuperMask, AltMask;
|
|
|
|
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+";
|
|
|
|
wwarning(_("Can't convert keymask 0x%04X to a shortcut label"), mask);
|
|
return NULL;
|
|
}
|
|
|
|
int wXModifierFromKey(const char *key)
|
|
{
|
|
if (strcasecmp(key, "SHIFT") == 0 && ShiftMask != 0)
|
|
return ShiftMask;
|
|
else if (strcasecmp(key, "CONTROL") == 0 && ControlMask != 0)
|
|
return ControlMask;
|
|
else if (strcasecmp(key, "ALT") == 0 && AltMask != 0)
|
|
return AltMask;
|
|
else if (strcasecmp(key, "META") == 0 && MetaMask != 0)
|
|
return MetaMask;
|
|
else if (strcasecmp(key, "SUPER") == 0 && SuperMask != 0)
|
|
return SuperMask;
|
|
else if (strcasecmp(key, "HYPER") == 0 && HyperMask != 0)
|
|
return HyperMask;
|
|
else if (strcasecmp(key, "MOD1") == 0 && Mod1Mask != 0)
|
|
return Mod1Mask;
|
|
else if (strcasecmp(key, "MOD2") == 0 && Mod2Mask != 0)
|
|
return Mod2Mask;
|
|
else if (strcasecmp(key, "MOD3") == 0 && Mod3Mask != 0)
|
|
return Mod3Mask;
|
|
else if (strcasecmp(key, "MOD4") == 0 && Mod4Mask != 0)
|
|
return Mod4Mask;
|
|
else if (strcasecmp(key, "MOD5") == 0 && Mod5Mask != 0)
|
|
return Mod5Mask;
|
|
else
|
|
return -1;
|
|
}
|
|
|
|
/*
|
|
* Set the standard modifier masks. Called from x11_backend.c after
|
|
* XGetModifierMapping discovery, or from wl_backend.c with XKB defaults
|
|
* (Mod1=Alt=Meta, Mod4=Super, Hyper=0).
|
|
*/
|
|
void wSetModifierMasks(int alt, int meta, int super, int hyper)
|
|
{
|
|
AltMask = alt;
|
|
MetaMask = meta;
|
|
SuperMask = super;
|
|
HyperMask = hyper;
|
|
}
|