int key_bind(const char *context, const char *key, const char *cmd, int force) { const struct key *k; struct binding *b, *ptr, *prev; struct command *command; int c, size; c = find_context(context); if (c < 0) return -1; k = find_key(key); if (k == NULL) return -1; /* check if already bound */ b = find_binding(c, k); if (b) { if (!force) goto bound; key_unbind(context, key, 0); } if (*cmd == ':') cmd++; size = strlen(cmd) + 1; b = xmalloc(sizeof(struct binding) + size); b->key = k; b->ctx = c; memcpy(b->cmd, cmd, size); /* insert keeping sorted by key */ prev = NULL; ptr = key_bindings[c]; while (ptr) { if (strcmp(b->key->name, ptr->key->name) < 0) break; prev = ptr; ptr = ptr->next; } b->next = ptr; if (prev) { prev->next = b; } else { key_bindings[c] = b; } command = get_command(cmd); if (command && !command->bc++) help_remove_unbound(command); help_add_bound(b); return 0; bound: error_msg("key %s already bound in context %s", key, key_context_names[c]); return -1; }
void keyboard_deinit(void) { key_unbind("command", (SIGNAL_FUNC) sig_command); key_unbind("key", (SIGNAL_FUNC) sig_key); key_unbind("multi", (SIGNAL_FUNC) sig_multi); key_unbind("nothing", (SIGNAL_FUNC) sig_nothing); while (keyinfos != NULL) keyinfo_remove(keyinfos->data); g_hash_table_destroy(keys); g_hash_table_destroy(default_keys); g_tree_foreach(key_states, (GTraverseFunc) key_state_destroy, NULL); g_tree_destroy(key_states); signal_remove("irssi init read settings", (SIGNAL_FUNC) read_keyboard_config); signal_remove("setup reread", (SIGNAL_FUNC) read_keyboard_config); signal_remove("complete command bind", (SIGNAL_FUNC) sig_complete_bind); command_unbind("bind", (SIGNAL_FUNC) cmd_bind); }
void gui_readline_deinit(void) { g_free_not_null(cutbuffer); g_source_remove(readtag); key_unbind("backward_character", (SIGNAL_FUNC) key_backward_character); key_unbind("forward_character", (SIGNAL_FUNC) key_forward_character); key_unbind("backward_word", (SIGNAL_FUNC) key_backward_word); key_unbind("forward_word", (SIGNAL_FUNC) key_forward_word); key_unbind("beginning_of_line", (SIGNAL_FUNC) key_beginning_of_line); key_unbind("end_of_line", (SIGNAL_FUNC) key_end_of_line); key_unbind("backward_history", (SIGNAL_FUNC) key_backward_history); key_unbind("forward_history", (SIGNAL_FUNC) key_forward_history); key_unbind("backspace", (SIGNAL_FUNC) key_backspace); key_unbind("delete_character", (SIGNAL_FUNC) key_delete_character); key_unbind("delete_next_word", (SIGNAL_FUNC) key_delete_next_word); key_unbind("delete_previous_word", (SIGNAL_FUNC) key_delete_previous_word); key_unbind("delete_to_previous_space", (SIGNAL_FUNC) key_delete_to_previous_space); key_unbind("erase_line", (SIGNAL_FUNC) key_erase_line); key_unbind("erase_to_beg_of_line", (SIGNAL_FUNC) key_erase_to_beg_of_line); key_unbind("erase_to_end_of_line", (SIGNAL_FUNC) key_erase_to_end_of_line); key_unbind("yank_from_cutbuffer", (SIGNAL_FUNC) key_yank_from_cutbuffer); key_unbind("transpose_characters", (SIGNAL_FUNC) key_transpose_characters); key_unbind("word_completion", (SIGNAL_FUNC) key_word_completion); key_unbind("check_replaces", (SIGNAL_FUNC) key_check_replaces); key_unbind("previous_window", (SIGNAL_FUNC) key_previous_window); key_unbind("next_window", (SIGNAL_FUNC) key_next_window); key_unbind("upper_window", (SIGNAL_FUNC) key_upper_window); key_unbind("lower_window", (SIGNAL_FUNC) key_lower_window); key_unbind("active_window", (SIGNAL_FUNC) key_active_window); key_unbind("next_window_item", (SIGNAL_FUNC) key_next_window_item); key_unbind("previous_window_item", (SIGNAL_FUNC) key_previous_window_item); key_unbind("refresh_screen", (SIGNAL_FUNC) irssi_redraw); key_unbind("scroll_backward", (SIGNAL_FUNC) key_scroll_backward); key_unbind("scroll_forward", (SIGNAL_FUNC) key_scroll_forward); key_unbind("scroll_start", (SIGNAL_FUNC) key_scroll_start); key_unbind("scroll_end", (SIGNAL_FUNC) key_scroll_end); key_unbind("special_char", (SIGNAL_FUNC) key_addchar); key_unbind("change_window", (SIGNAL_FUNC) key_change_window); signal_remove("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed); signal_remove("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect); }