summaryrefslogtreecommitdiff
path: root/src/actions.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2001-09-04 07:24:39 +0000
committersabetts <sabetts>2001-09-04 07:24:39 +0000
commit2d594205560e963ac4595cdbb5430492619486ce (patch)
tree2d1bd38b2c9ab4f5e55dbad1f340c824e94ff7ec /src/actions.c
parent6e659e8c781fcff977c326c7a9eefc6788e6f8c2 (diff)
downloadratpoison-2d594205560e963ac4595cdbb5430492619486ce.zip
* src/actions.h (cmd_unbind): new prototype
* src/actions.c (find_keybinding): Change the first parameter's type to KeySym. Prototype updated. (add_keybinding): likewise (remove_keybinding): new function. (key_actions): new command 'unbind'. (key_actions): #if out the unimplemented bindings. (cmd_bind): Error messages are more accurate. (cmd_unbind): new function. (cmd_escape): update the "other" command before the "generate" command. (cmd_escape): When searching for the "other" and "generate" commands' keystrokes, verify that the located action is the right command.
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c88
1 files changed, 74 insertions, 14 deletions
diff --git a/src/actions.c b/src/actions.c
index d387602..c68ae5e 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -31,7 +31,7 @@ int key_actions_last;
int key_actions_table_size;
rp_action*
-find_keybinding (int keysym, int state)
+find_keybinding (KeySym keysym, int state)
{
int i;
for (i = 0; i < key_actions_last; i++)
@@ -44,7 +44,7 @@ find_keybinding (int keysym, int state)
}
static void
-add_keybinding (int keysym, int state, char *cmd)
+add_keybinding (KeySym keysym, int state, char *cmd)
{
if (key_actions_last >= key_actions_table_size)
{
@@ -72,6 +72,35 @@ replace_keybinding (rp_action *key_action, char *newcmd)
strcpy (key_action->data, newcmd);
}
+static int
+remove_keybinding (KeySym keysym, int state)
+{
+ int i;
+ int found = -1;
+
+ for (i=0; i<key_actions_last; i++)
+ {
+ if (key_actions[i].key == keysym && key_actions[i].state == state)
+ {
+ found = i;
+ break;
+ }
+ }
+
+ if (found >= 0)
+ {
+ free (key_actions[found].data);
+
+ memmove (&key_actions[found], &key_actions[found+1],
+ sizeof (rp_action) * (key_actions_last - found - 1));
+ key_actions_last--;
+
+ return 1;
+ }
+
+ return 0;
+}
+
void
initialize_default_keybindings (void)
{
@@ -157,6 +186,7 @@ user_command user_commands[] =
{"generate", cmd_generate, arg_STRING}, /* rename to stuff */
{"version", cmd_version, arg_VOID},
{"bind", cmd_bind, arg_VOID},
+ {"unbind", cmd_unbind, arg_STRING},
{"source", cmd_source, arg_STRING},
{"escape", cmd_escape, arg_STRING},
{"echo", cmd_echo, arg_STRING},
@@ -176,7 +206,7 @@ user_command user_commands[] =
/* the following screen commands may or may not be able to be
implemented. See the screen documentation for what should be
emulated with these commands */
-
+#if 0
{"stuff", cmd_unimplemented, arg_VOID},
{"hardcopy", cmd_unimplemented, arg_VOID},
{"lastmsg", cmd_unimplemented, arg_VOID},
@@ -194,6 +224,7 @@ user_command user_commands[] =
{"sleep", cmd_unimplemented, arg_VOID},
{"sorendition", cmd_unimplemented, arg_VOID},
{"startup_message", cmd_unimplemented, arg_VOID},
+#endif
{0, 0, 0} };
/* return a KeySym from a string that contains either a hex value or
@@ -299,7 +330,7 @@ cmd_bind (int interactive, void *data)
if (!data)
{
- message (" bind: at least one argument required ");
+ message (" bind: two arguments required ");
return NULL;
}
@@ -314,7 +345,7 @@ cmd_bind (int interactive, void *data)
}
if (!keydesc)
- message (" bind: at least one argument required ");
+ message (" bind: two arguments required ");
else
{
if (!cmd || !*cmd)
@@ -343,6 +374,36 @@ cmd_bind (int interactive, void *data)
}
char *
+cmd_unbind (int interactive, void *data)
+{
+ struct rp_key *key;
+ char *keydesc;
+
+ if (!data)
+ {
+ message (" unbind: one argument required ");
+ return NULL;
+ }
+
+ keydesc = (char*) xmalloc (strlen (data + 1));
+ sscanf (data, "%s", keydesc);
+ key = parse_keydesc (keydesc);
+
+ if (key)
+ {
+ if (!remove_keybinding (key->sym, key->state))
+ marked_message_printf (0, 0, " %s unbound key ", keydesc);
+ }
+ else
+ {
+ marked_message_printf (0, 0, " %s unknown key ", keydesc);
+ }
+
+ free (keydesc);
+ return NULL;
+}
+
+char *
cmd_unimplemented (int interactive, void *data)
{
marked_message (" FIXME: unimplemented command ",0,8);
@@ -945,22 +1006,21 @@ cmd_escape (int interactive, void *data)
if (key)
{
- /* Update the "generate" keybinding */
- action = find_keybinding(prefix_key.sym, 0);
- if (action != NULL)
- {
- action->key = key->sym;
- action->state = 0;
- }
-
/* Update the "other" keybinding */
action = find_keybinding(prefix_key.sym, prefix_key.state);
- if (action != NULL)
+ if (action != NULL && !strcmp (action->data, "other"))
{
action->key = key->sym;
action->state = key->state;
}
+ /* Update the "generate" keybinding */
+ action = find_keybinding(prefix_key.sym, 0);
+ if (action != NULL && !strcmp (action->data, "generate"))
+ {
+ action->key = key->sym;
+ action->state = 0;
+ }
/* Remove the grab on the current prefix key */
for (cur = rp_mapped_window_sentinel->next;