summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions.c61
-rw-r--r--src/input.c37
2 files changed, 69 insertions, 29 deletions
diff --git a/src/actions.c b/src/actions.c
index a9ed3d7..6bf0d06 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -213,19 +213,67 @@ parse_keydesc (char *keydesc)
{
static struct rp_key key;
struct rp_key *p = &key;
+ char *token, *next_token;
if (!keydesc)
return NULL;
- if (keydesc[0] == '^')
+ p->state = 0;
+ p->sym = 0;
+
+ if (!strchr (keydesc, '-'))
{
- p->state = ControlMask;
- p->sym = string_to_keysym (keydesc + 1);
+ /* Its got no hyphens in it, so just grab the keysym */
+ p->sym = string_to_keysym (keydesc);
}
- else
+ else
{
- p->state = 0;
- p->sym = string_to_keysym (keydesc);
+ /* Its got hyphens, so parse out the modifiers and keysym */
+ token = strtok (keydesc, "-");
+
+ do
+ {
+ next_token = strtok (NULL, "-");
+
+ if (next_token == NULL)
+ {
+ /* There is nothing more to parse and token contains the
+ keysym name. */
+ p->sym = string_to_keysym (token);
+ }
+ else
+ {
+ /* Which modifier is it? Only accept modifiers that are
+ present. ie don't accept a hyper modifier if the keymap
+ has no hyper key. */
+ if (!strcmp (token, "C"))
+ {
+ p->state |= ControlMask;
+ }
+ else if (!strcmp (token, "M") && rp_modifier_info.meta_mod_mask)
+ {
+ p->state |= rp_modifier_info.meta_mod_mask;
+ }
+ else if (!strcmp (token, "A") && rp_modifier_info.alt_mod_mask)
+ {
+ p->state |= rp_modifier_info.alt_mod_mask;
+ }
+ else if (!strcmp (token, "S") && rp_modifier_info.super_mod_mask)
+ {
+ p->state |= rp_modifier_info.super_mod_mask;
+ }
+ else if (!strcmp (token, "H") && rp_modifier_info.hyper_mod_mask)
+ {
+ p->state |= rp_modifier_info.hyper_mod_mask;
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+
+ token = next_token;
+ } while (next_token != NULL);
}
if (!p->sym)
@@ -713,6 +761,7 @@ cmd_clock (void *data)
tmp = ctime(&timep);
msg = xmalloc (strlen (tmp));
strncpy(msg, tmp, strlen (tmp) - 1); /* Remove the newline */
+ msg[strlen(tmp) - 1] = 0;
message (msg);
free (msg);
diff --git a/src/input.c b/src/input.c
index d64135f..1818f5d 100644
--- a/src/input.c
+++ b/src/input.c
@@ -115,33 +115,24 @@ init_modifier_map ()
char *
keysym_to_string (KeySym keysym, unsigned int modifier)
{
- const unsigned int mod_table[] = {ControlMask,
- Mod1Mask,
- Mod2Mask,
- Mod3Mask,
- Mod4Mask,
- Mod5Mask};
- const unsigned char str_table[] = "CM2345";
+ struct sbuf *name;
+ char *tmp;
- unsigned char *name;
- int pos, i;
+ name = sbuf_new (0);
- name = xmalloc (15);
+ if (modifier & ControlMask) sbuf_concat (name, "C-");
+ if (modifier & rp_modifier_info.meta_mod_mask) sbuf_concat (name, "M-");
+ if (modifier & rp_modifier_info.alt_mod_mask) sbuf_concat (name, "A-");
+ if (modifier & rp_modifier_info.hyper_mod_mask) sbuf_concat (name, "H-");
+ if (modifier & rp_modifier_info.super_mod_mask) sbuf_concat (name, "S-");
+
+ sbuf_concat (name, XKeysymToString (keysym));
- for (pos = 0, i = 0; i < 6; i++)
- {
- if (modifier & mod_table[i])
- {
- name[pos] = str_table[i];
- name[pos+1] = '-';
- pos += 2;
- }
- }
-
- name[pos] = keysym;
- name[pos+1] = '\0';
+ /* Eat the nut and throw away the shells. */
+ tmp = sbuf_get (name);
+ free (name);
- return name;
+ return tmp;
}
/* Cooks a keycode + modifier into a keysym + modifier. This should be