diff options
author | sabetts <sabetts> | 2001-09-04 07:24:39 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2001-09-04 07:24:39 +0000 |
commit | 2d594205560e963ac4595cdbb5430492619486ce (patch) | |
tree | 2d1bd38b2c9ab4f5e55dbad1f340c824e94ff7ec | |
parent | 6e659e8c781fcff977c326c7a9eefc6788e6f8c2 (diff) | |
download | ratpoison-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.
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | src/actions.c | 88 | ||||
-rw-r--r-- | src/actions.h | 3 |
3 files changed, 94 insertions, 15 deletions
@@ -1,3 +1,21 @@ +2001-09-04 shawn <sabetts@diggin.lamenet.tmp> + + * 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. + 2001-08-31 Shawn <sabetts@hotdog> * src/split.c (set_active_frame): Only show the frame indicator 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; diff --git a/src/actions.h b/src/actions.h index 5a32952..5410d5a 100644 --- a/src/actions.h +++ b/src/actions.h @@ -74,10 +74,11 @@ char * cmd_help (int interactive, void *data); char * cmd_quit(int interactive, void *data); char * cmd_number (int interactive, void *data); char * cmd_rudeness (int interactive, void *data); +char * cmd_unbind (int interactive, void *data); /* void cmd_xterm (void *data); */ void initialize_default_keybindings (void); -rp_action* find_keybinding (int keysym, int state); +rp_action* find_keybinding (KeySym keysym, int state); #endif /* ! _RATPOISON_ACTIONS_H */ |