summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrcyeske <rcyeske>2001-02-22 04:10:36 +0000
committerrcyeske <rcyeske>2001-02-22 04:10:36 +0000
commitaf8a1da648626a246514e2a4a0446a40ebf37a41 (patch)
treec64b8b7e9950fa7cc4a69ce361818afdf269d345 /src
parentc59150f7c0c5fa35c15d15814cc2d306f0fac16b (diff)
downloadratpoison-af8a1da648626a246514e2a4a0446a40ebf37a41.zip
added preliminar keybinding support
Diffstat (limited to 'src')
-rw-r--r--src/actions.c77
-rw-r--r--src/actions.h9
-rw-r--r--src/events.c6
3 files changed, 85 insertions, 7 deletions
diff --git a/src/actions.c b/src/actions.c
index ce1aaf2..a132abc 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -37,7 +37,7 @@ rp_action *key_actions;
int key_actions_last;
int key_actions_table_size;
-char *
+rp_action*
find_keybinding (int keysym, int state)
{
int i;
@@ -45,7 +45,7 @@ find_keybinding (int keysym, int state)
{
if (key_actions[i].key == keysym
&& key_actions[i].state == state)
- return strdup(key_actions[i].data);
+ return &key_actions[i];
}
return NULL;
}
@@ -63,7 +63,9 @@ add_keybinding (int keysym, int state, char *cmd)
key_actions[key_actions_last].key = keysym;
key_actions[key_actions_last].state = state;
- key_actions[key_actions_last].data = cmd;
+ key_actions[key_actions_last].data = strdup (cmd); /* free this on
+ shutdown, or
+ re/unbinding */
++key_actions_last;
}
@@ -138,6 +140,7 @@ user_command user_commands[] =
{"newwm", cmd_newwm, arg_STRING},
{"generate", cmd_generate, arg_STRING}, /* rename to stuff */
{"version", cmd_version, arg_VOID},
+ {"bind", cmd_bind, arg_VOID},
/* the following screen commands may or may not be able to be
implemented. See the screen documentation for what should be
@@ -168,6 +171,74 @@ user_command user_commands[] =
{"startup_message", cmd_unimplemented, arg_VOID},
{0, 0, 0} };
+struct key*
+parse_keydesc (char *keydesc)
+{
+ static struct key key;
+ struct key *p = &key;
+
+ if (!keydesc)
+ return NULL;
+
+ if (keydesc[0] == '^')
+ {
+ p->state = ControlMask;
+ p->sym = XStringToKeysym (keydesc + 1);
+ }
+ else
+ {
+ p->state = 0;
+ p->sym = XStringToKeysym (keydesc);
+ }
+
+ if (!p->sym)
+ return NULL;
+ else
+ return p;
+}
+
+void
+cmd_bind (void *data)
+{
+ char *keydesc;
+ char *cmd;
+
+ if (!data)
+ {
+ message (" FIXME: cmd_bind: need some args ");
+ return;
+ }
+
+ keydesc = (char*) malloc (strlen (data + 1));
+ sscanf (data, "%s", keydesc);
+ cmd = data + strlen (keydesc);
+
+ if (!keydesc)
+ message (" FIXME: cmd_bind: need a key ");
+ else
+ {
+ if (!cmd || !*cmd)
+ message (" FIXME: cmd_bind: need a command to bind to key ");
+ else
+ {
+ char foo[1000];
+
+ struct key *key = parse_keydesc (keydesc);
+
+ if (key)
+ {
+ sprintf (foo, " %ld %ld : '%s' ", key->state, key->sym, cmd);
+ add_keybinding (key->sym, key->state, cmd);
+ }
+ else
+ sprintf (foo, " FIXME: cmd_bind: couldnt parse key ");
+
+ message (foo);
+ }
+ }
+
+ free (keydesc);
+}
void
cmd_unimplemented (void *data)
diff --git a/src/actions.h b/src/actions.h
index bc1f410..4cf155b 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -59,10 +59,17 @@ void cmd_other (void *data);
void cmd_clock (void *data);
void cmd_version (void *data);
void cmd_unimplemented (void *data);
+void cmd_bind (void* data);
/* void cmd_xterm (void *data); */
void initialize_default_keybindings (void);
-char *find_keybinding (int keysym, int state);
+rp_action* find_keybinding (int keysym, int state);
+
+struct key
+{
+ long sym;
+ long state;
+};
#endif /* ! _RATPOISON_ACTIONS_H */
diff --git a/src/events.c b/src/events.c
index 5cbc08a..ce81d24 100644
--- a/src/events.c
+++ b/src/events.c
@@ -287,7 +287,7 @@ handle_key (screen_info *s)
{
char *keysym_name;
char *msg;
- char *cmd;
+ rp_action *key_action;
int revert;
Window fwin; /* Window currently in focus */
KeySym keysym; /* Key pressed */
@@ -304,10 +304,10 @@ handle_key (screen_info *s)
read_key (&keysym, &mod);
- if ((cmd = find_keybinding (keysym, mod)))
+ if ((key_action = find_keybinding (keysym, mod)))
{
XSetInputFocus (dpy, fwin, revert, CurrentTime);
- command (cmd);
+ command (key_action->data);
}
else
{