Commit 7a61c62c authored by Ulrich Sibiller's avatar Ulrich Sibiller

Keystroke.c: rework read_binding_from_xmlnode()

code cleanup
parent d8bc4913
...@@ -167,8 +167,12 @@ static Bool modifier_matches(unsigned int mask, int compare_alt_meta, unsigned i ...@@ -167,8 +167,12 @@ static Bool modifier_matches(unsigned int mask, int compare_alt_meta, unsigned i
static int read_binding_from_xmlnode(xmlNode *node, struct nxagentSpecialKeystrokeMap *ret) static int read_binding_from_xmlnode(xmlNode *node, struct nxagentSpecialKeystrokeMap *ret)
{ {
int successful = 0; struct nxagentSpecialKeystrokeMap newkm = {
struct nxagentSpecialKeystrokeMap new = {0, 0, 0, 0}; .stroke = 0,
.modifierMask = 0,
.modifierAltMeta = 0,
.keysym = NoSymbol
};
xmlAttr *attr; xmlAttr *attr;
for (attr = node->properties; attr; attr = attr->next) for (attr = node->properties; attr; attr = attr->next)
...@@ -176,20 +180,21 @@ static int read_binding_from_xmlnode(xmlNode *node, struct nxagentSpecialKeystro ...@@ -176,20 +180,21 @@ static int read_binding_from_xmlnode(xmlNode *node, struct nxagentSpecialKeystro
/* ignore attributes without data (which should never happen anyways) */ /* ignore attributes without data (which should never happen anyways) */
if (attr->children->content == NULL) if (attr->children->content == NULL)
{ {
#ifdef DEBUG
char *aname = (attr->name)?((char *)attr->name):"unknown"; char *aname = (attr->name)?((char *)attr->name):"unknown";
fprintf(stderr, "attribute %s with NULL value", aname); fprintf(stderr, "attribute %s with NULL value", aname);
#endif
continue; continue;
} }
if (strcmp((char *)attr->name, "action") == 0) if (strcmp((char *)attr->name, "action") == 0)
{ {
int i; for (int i = 0; nxagentSpecialKeystrokeNames[i] != NULL; i++)
for (i = 0; nxagentSpecialKeystrokeNames[i] != NULL; i++)
{ {
if (strcmp(nxagentSpecialKeystrokeNames[i],(char *)attr->children->content) == 0) if (strcmp(nxagentSpecialKeystrokeNames[i],(char *)attr->children->content) == 0)
{ {
/* this relies on the values of enum nxagentSpecialKeystroke and the /* this relies on the values of enum nxagentSpecialKeystroke and the
* indices of nxagentSpecialKeystrokeNames being in sync */ * indices of nxagentSpecialKeystrokeNames being in sync */
new.stroke = i; newkm.stroke = i;
break; break;
} }
} }
...@@ -197,12 +202,9 @@ static int read_binding_from_xmlnode(xmlNode *node, struct nxagentSpecialKeystro ...@@ -197,12 +202,9 @@ static int read_binding_from_xmlnode(xmlNode *node, struct nxagentSpecialKeystro
} }
else if (strcmp((char *)attr->name, "key") == 0) else if (strcmp((char *)attr->name, "key") == 0)
{ {
new.keysym = XStringToKeysym((char *)attr->children->content); if (strcmp((char *)attr->children->content, "0") != 0 && strcmp((char *)attr->children->content, "false") != 0)
/* NoSymbol is usually 0, but could there be weird implementations? */ newkm.keysym = XStringToKeysym((char *)attr->children->content);
if (new.keysym == NoSymbol)
{
new.keysym = 0;
}
continue; continue;
} }
...@@ -210,47 +212,24 @@ static int read_binding_from_xmlnode(xmlNode *node, struct nxagentSpecialKeystro ...@@ -210,47 +212,24 @@ static int read_binding_from_xmlnode(xmlNode *node, struct nxagentSpecialKeystro
if (strcmp((char *)attr->children->content, "0") == 0 || strcmp((char *)attr->children->content, "false") == 0) if (strcmp((char *)attr->children->content, "0") == 0 || strcmp((char *)attr->children->content, "false") == 0)
continue; continue;
if (strcmp((char *)attr->name, "Mod1") == 0) if (strcmp((char *)attr->name, "Mod1") == 0) { newkm.modifierMask |= Mod1Mask; }
{ else if (strcmp((char *)attr->name, "Mod2") == 0) { newkm.modifierMask |= Mod2Mask; }
new.modifierMask |= Mod1Mask; else if (strcmp((char *)attr->name, "Mod3") == 0) { newkm.modifierMask |= Mod3Mask; }
} else if (strcmp((char *)attr->name, "Mod4") == 0) { newkm.modifierMask |= Mod4Mask; }
else if (strcmp((char *)attr->name, "Mod2") == 0) else if (strcmp((char *)attr->name, "Control") == 0) { newkm.modifierMask |= ControlMask; }
{ else if (strcmp((char *)attr->name, "Shift") == 0) { newkm.modifierMask |= ShiftMask; }
new.modifierMask |= Mod2Mask; else if (strcmp((char *)attr->name, "Lock") == 0) { newkm.modifierMask |= LockMask; }
} else if (strcmp((char *)attr->name, "AltMeta") == 0) { newkm.modifierAltMeta = 1; }
else if (strcmp((char *)attr->name, "Mod3") == 0)
{
new.modifierMask |= Mod3Mask;
}
else if (strcmp((char *)attr->name, "Mod4") == 0)
{
new.modifierMask |= Mod4Mask;
}
else if (strcmp((char *)attr->name, "Control") == 0)
{
new.modifierMask |= ControlMask;
}
else if (strcmp((char *)attr->name, "Shift") == 0)
{
new.modifierMask |= ShiftMask;
}
else if (strcmp((char *)attr->name, "Lock") == 0)
{
new.modifierMask |= LockMask;
}
else if (strcmp((char *)attr->name, "AltMeta") == 0)
{
new.modifierAltMeta = 1;
}
} }
if (new.stroke != 0 && new.keysym != 0) if (newkm.stroke != 0 && newkm.keysym != NoSymbol)
{ {
/* keysym and stroke are required, everything else is optional */ /* keysym and stroke are required, everything else is optional */
successful = 1; memcpy(ret, &newkm, sizeof(struct nxagentSpecialKeystrokeMap));
memcpy(ret, &new, sizeof(struct nxagentSpecialKeystrokeMap)); return True;
} }
return successful; else
return False;
} }
/* /*
...@@ -378,13 +357,10 @@ free(filename); ...@@ -378,13 +357,10 @@ free(filename);
for (bindings = cur->children; bindings; bindings = bindings->next) for (bindings = cur->children; bindings; bindings = bindings->next)
{ {
if (bindings->type == XML_ELEMENT_NODE && strcmp((char *)bindings->name, "keystroke") == 0) if (bindings->type == XML_ELEMENT_NODE &&
{ strcmp((char *)bindings->name, "keystroke") == 0 &&
int res = 0; read_binding_from_xmlnode(bindings, &(map[idx])))
res = read_binding_from_xmlnode(bindings, &(map[idx])); idx++;
if (res)
idx++;
}
} }
map[idx].stroke = KEYSTROKE_END_MARKER; map[idx].stroke = KEYSTROKE_END_MARKER;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment