*
********************************************************/
+#include "config.h"
+
#include "keymap.h"
#include "text.h"
LookupString(const LookupEntry tab[], const char *string,
unsigned int *value_rtrn)
{
- const LookupEntry *entry;
-
if (!string)
return false;
- for (entry = tab; entry->name; entry++) {
+ for (const LookupEntry *entry = tab; entry->name; entry++) {
if (istreq(entry->name, string)) {
*value_rtrn = entry->value;
return true;
const char *
LookupValue(const LookupEntry tab[], unsigned int value)
{
- const LookupEntry *entry;
-
- for (entry = tab; entry->name; entry++)
+ for (const LookupEntry *entry = tab; entry->name; entry++)
if (entry->value == value)
return entry->name;
};
const LookupEntry modComponentMaskNames[] = {
- {"base", XKB_STATE_DEPRESSED},
- {"latched", XKB_STATE_LATCHED},
- {"locked", XKB_STATE_LOCKED},
- {"effective", XKB_STATE_EFFECTIVE},
- {"compat", XKB_STATE_EFFECTIVE},
- {"any", XKB_STATE_EFFECTIVE},
- {"none", 0},
- {NULL, 0}
+ { "base", XKB_STATE_MODS_DEPRESSED },
+ { "latched", XKB_STATE_MODS_LATCHED },
+ { "locked", XKB_STATE_MODS_LOCKED },
+ { "effective", XKB_STATE_MODS_EFFECTIVE },
+ { "compat", XKB_STATE_MODS_EFFECTIVE },
+ { "any", XKB_STATE_MODS_EFFECTIVE },
+ { "none", 0 },
+ { NULL, 0 }
};
const LookupEntry groupComponentMaskNames[] = {
- {"base", XKB_STATE_DEPRESSED},
- {"latched", XKB_STATE_LATCHED},
- {"locked", XKB_STATE_LOCKED},
- {"effective", XKB_STATE_EFFECTIVE},
- {"any", XKB_STATE_EFFECTIVE},
- {"none", 0},
- {NULL, 0}
+ { "base", XKB_STATE_LAYOUT_DEPRESSED },
+ { "latched", XKB_STATE_LAYOUT_LATCHED },
+ { "locked", XKB_STATE_LAYOUT_LOCKED },
+ { "effective", XKB_STATE_LAYOUT_EFFECTIVE },
+ { "any", XKB_STATE_LAYOUT_EFFECTIVE },
+ { "none", 0 },
+ { NULL, 0 }
};
const LookupEntry groupMaskNames[] = {
- {"group1", 0x01},
- {"group2", 0x02},
- {"group3", 0x04},
- {"group4", 0x08},
- {"group5", 0x10},
- {"group6", 0x20},
- {"group7", 0x40},
- {"group8", 0x80},
- {"none", 0x00},
- {"all", 0xff},
- {NULL, 0}
+ { "Group1", 0x01 },
+ { "Group2", 0x02 },
+ { "Group3", 0x04 },
+ { "Group4", 0x08 },
+ { "Group5", 0x10 },
+ { "Group6", 0x20 },
+ { "Group7", 0x40 },
+ { "Group8", 0x80 },
+ { "none", 0x00 },
+ { "all", 0xff },
+ { NULL, 0 }
};
const LookupEntry groupNames[] = {
- {"group1", 1},
- {"group2", 2},
- {"group3", 3},
- {"group4", 4},
- {"group5", 5},
- {"group6", 6},
- {"group7", 7},
- {"group8", 8},
- {NULL, 0}
+ { "Group1", 1 },
+ { "Group2", 2 },
+ { "Group3", 3 },
+ { "Group4", 4 },
+ { "Group5", 5 },
+ { "Group6", 6 },
+ { "Group7", 7 },
+ { "Group8", 8 },
+ { NULL, 0 }
};
const LookupEntry levelNames[] = {
- { "level1", 1 },
- { "level2", 2 },
- { "level3", 3 },
- { "level4", 4 },
- { "level5", 5 },
- { "level6", 6 },
- { "level7", 7 },
- { "level8", 8 },
+ { "Level1", 1 },
+ { "Level2", 2 },
+ { "Level3", 3 },
+ { "Level4", 4 },
+ { "Level5", 5 },
+ { "Level6", 6 },
+ { "Level7", 7 },
+ { "Level8", 8 },
{ NULL, 0 }
};
const LookupEntry buttonNames[] = {
- { "button1", 1 },
- { "button2", 2 },
- { "button3", 3 },
- { "button4", 4 },
- { "button5", 5 },
+ { "Button1", 1 },
+ { "Button2", 2 },
+ { "Button3", 3 },
+ { "Button4", 4 },
+ { "Button5", 5 },
{ "default", 0 },
{ NULL, 0 }
};
const LookupEntry useModMapValueNames[] = {
- { "levelone", 1 },
- { "level1", 1 },
- { "anylevel", 0 },
+ { "LevelOne", 1 },
+ { "Level1", 1 },
+ { "AnyLevel", 0 },
{ "any", 0 },
{ NULL, 0 }
};
{ "SwitchScreen", ACTION_TYPE_SWITCH_VT },
{ "SetControls", ACTION_TYPE_CTRL_SET },
{ "LockControls", ACTION_TYPE_CTRL_LOCK },
- { "RedirectKey", ACTION_TYPE_KEY_REDIRECT },
- { "Redirect", ACTION_TYPE_KEY_REDIRECT },
{ "Private", ACTION_TYPE_PRIVATE },
/* deprecated actions below here - unused */
+ { "RedirectKey", ACTION_TYPE_NONE },
+ { "Redirect", ACTION_TYPE_NONE },
{ "ISOLock", ACTION_TYPE_NONE },
{ "ActionMessage", ACTION_TYPE_NONE },
{ "MessageAction", ACTION_TYPE_NONE },
{ "AnyOf", MATCH_ANY },
{ "AllOf", MATCH_ALL },
{ "Exactly", MATCH_EXACTLY },
+ { NULL, 0 },
};
-#define BUFFER_SIZE 1024
-
-static char *
-GetBuffer(size_t size)
+const char *
+ModIndexText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
+ xkb_mod_index_t ndx)
{
- static char buffer[BUFFER_SIZE];
- static size_t next;
- char *rtrn;
-
- if (size >= BUFFER_SIZE)
- return NULL;
+ if (ndx == XKB_MOD_INVALID)
+ return "none";
- if (BUFFER_SIZE - next <= size)
- next = 0;
+ if (ndx == XKB_MOD_NONE)
+ return "None";
- rtrn = &buffer[next];
- next += size;
+ if (ndx >= mods->num_mods)
+ return NULL;
- return rtrn;
+ return xkb_atom_text(ctx, mods->mods[ndx].name);
}
-/* Get a vmod name's text, where the vmod index is zero based. */
-static const char *
-VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
+const char *
+ActionTypeText(enum xkb_action_type type)
{
- if (ndx >= darray_size(keymap->vmods))
- return "illegal";
- return xkb_atom_text(keymap->ctx,
- darray_item(keymap->vmods, ndx).name);
+ const char *name = LookupValue(actionTypeNames, type);
+ return name ? name : "Private";
}
-/* Get a mod mask's text, where the mask is in rmods+vmods format. */
const char *
-VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
+KeysymText(struct xkb_context *ctx, xkb_keysym_t sym)
{
- xkb_mod_index_t i;
- xkb_mod_mask_t rmask, vmask;
- int len, rem;
- const char *mm = NULL;
- char *rtrn, *str;
- char buf[BUFFER_SIZE];
-
- rmask = cmask & 0xff;
- vmask = cmask >> XKB_NUM_CORE_MODS;
-
- if (rmask == 0 && vmask == 0)
- return "none";
-
- if (rmask != 0)
- mm = ModMaskText(rmask);
-
- str = buf;
- buf[0] = '\0';
- rem = BUFFER_SIZE;
-
- if (vmask != 0) {
- for (i = 0; i < darray_size(keymap->vmods) && rem > 1; i++) {
- if (!(vmask & (1 << i)))
- continue;
-
- len = snprintf(str, rem, "%s%s",
- (str != buf) ? "+" : "",
- VModIndexText(keymap, i));
- rem -= len;
- str += len;
- }
-
- str = buf;
- }
- else
- str = NULL;
-
- len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
- (str && mm ? 1 : 0);
- if (len >= BUFFER_SIZE)
- len = BUFFER_SIZE - 1;
-
- rtrn = GetBuffer(len + 1);
- rtrn[0] = '\0';
-
- snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
- (mm && str ? "+" : ""), (str ? str : ""));
-
- return rtrn;
+ char *buffer = xkb_context_get_buffer(ctx, 64);
+ xkb_keysym_get_name(sym, buffer, 64);
+ return buffer;
}
-/*
- * IMPORTATNT
- * The indices used for the legacy core modifiers is derived from
- * the order of the names in this table. It matches the values
- * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before
- * changing.
- */
-static const char *modNames[XKB_NUM_CORE_MODS] = {
- "Shift",
- "Lock",
- "Control",
- "Mod1",
- "Mod2",
- "Mod3",
- "Mod4",
- "Mod5",
-};
-
-xkb_mod_index_t
-ModNameToIndex(const char *name)
+const char *
+KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
{
- xkb_mod_index_t i;
-
- for (i = 0; i < XKB_NUM_CORE_MODS; i++)
- if (istreq(name, modNames[i]))
- return i;
-
- return XKB_MOD_INVALID;
+ const char *sname = xkb_atom_text(ctx, name);
+ size_t len = strlen_safe(sname) + 3;
+ char *buf = xkb_context_get_buffer(ctx, len);
+ snprintf(buf, len, "<%s>", strempty(sname));
+ return buf;
}
const char *
-ModIndexToName(xkb_mod_index_t ndx)
+SIMatchText(enum xkb_match_operation type)
{
- if (ndx < XKB_NUM_CORE_MODS)
- return modNames[ndx];
- return NULL;
+ return LookupValue(symInterpretMatchMaskNames, type);
}
const char *
-ModIndexText(xkb_mod_index_t ndx)
+ModMaskText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
+ xkb_mod_mask_t mask)
{
- const char *name;
- char *buf;
-
- name = ModIndexToName(ndx);
- if (name)
- return name;
+ char buf[1024] = {0};
+ size_t pos = 0;
+ xkb_mod_index_t i;
+ const struct xkb_mod *mod;
- if (ndx == XKB_MOD_INVALID)
+ if (mask == 0)
return "none";
- buf = GetBuffer(32);
- snprintf(buf, 32, "ILLEGAL_%02x", ndx);
+ if (mask == MOD_REAL_MASK_ALL)
+ return "all";
- return buf;
+ xkb_mods_enumerate(i, mod, mods) {
+ int ret;
+
+ if (!(mask & (1u << i)))
+ continue;
+
+ ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
+ pos == 0 ? "" : "+",
+ xkb_atom_text(ctx, mod->name));
+ if (ret <= 0 || pos + ret >= sizeof(buf))
+ break;
+ else
+ pos += ret;
+ }
+
+ return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
}
-/* Gets the text for the real modifiers only. */
const char *
-ModMaskText(xkb_mod_mask_t mask)
+LedStateMaskText(struct xkb_context *ctx, enum xkb_state_component mask)
{
- int i, rem;
- xkb_mod_index_t bit;
- char *str, *buf;
-
- if ((mask & 0xff) == 0xff)
- return "all";
+ char buf[1024];
+ size_t pos = 0;
- if ((mask & 0xff) == 0)
- return "none";
+ if (mask == 0)
+ return "0";
- rem = 64;
- buf = GetBuffer(rem);
- str = buf;
- buf[0] = '\0';
- for (i = 0, bit = 1; i < XKB_NUM_CORE_MODS && rem > 1; i++, bit <<= 1) {
- int len;
+ for (unsigned i = 0; mask; i++) {
+ int ret;
- if (!(mask & bit))
+ if (!(mask & (1u << i)))
continue;
- len = snprintf(str, rem, "%s%s",
- (str != buf ? "+" : ""), modNames[i]);
- rem -= len;
- str += len;
- }
+ mask &= ~(1u << i);
- return buf;
-}
+ ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
+ pos == 0 ? "" : "+",
+ LookupValue(modComponentMaskNames, 1u << i));
+ if (ret <= 0 || pos + ret >= sizeof(buf))
+ break;
+ else
+ pos += ret;
+ }
-const char *
-ActionTypeText(unsigned type)
-{
- const char *name = LookupValue(actionTypeNames, type);
- return name ? name : "Private";
+ return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
}
const char *
-KeysymText(xkb_keysym_t sym)
+ControlMaskText(struct xkb_context *ctx, enum xkb_action_controls mask)
{
- static char buffer[64];
+ char buf[1024];
+ size_t pos = 0;
- xkb_keysym_get_name(sym, buffer, sizeof buffer);
+ if (mask == 0)
+ return "none";
- return buffer;
-}
+ if (mask == CONTROL_ALL)
+ return "all";
-const char *
-KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
-{
- const char *sname = xkb_atom_text(ctx, name);
- size_t len = strlen(sname) + 3;
- char *buf = GetBuffer(len);
- snprintf(buf, len, "<%s>", sname);
- return buf;
-}
+ for (unsigned i = 0; mask; i++) {
+ int ret;
-const char *
-SIMatchText(enum xkb_match_operation type)
-{
- const char *name;
- char *buf;
+ if (!(mask & (1u << i)))
+ continue;
- type &= MATCH_OP_MASK;
+ mask &= ~(1u << i);
- name = LookupValue(symInterpretMatchMaskNames, type);
- if (name)
- return name;
+ ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
+ pos == 0 ? "" : "+",
+ LookupValue(ctrlMaskNames, 1u << i));
+ if (ret <= 0 || pos + ret >= sizeof(buf))
+ break;
+ else
+ pos += ret;
+ }
- buf = GetBuffer(40);
- snprintf(buf, 40, "0x%x", type);
- return buf;
+ return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
}