diff options
author | Timo Sirainen <cras@irssi.org> | 2000-07-08 21:47:05 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-07-08 21:47:05 +0000 |
commit | 7074381bea2027e0abd7bdbfa24a9acef0620c01 (patch) | |
tree | 94acd0d45472748f34af17db39f9042444368de4 /src | |
parent | cd9efdf9fe3e79d065985c66e03be0f89c1967c4 (diff) | |
download | irssi-7074381bea2027e0abd7bdbfa24a9acef0620c01.zip |
Reading and saving keyboard configuration actually works now.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@434 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r-- | src/fe-common/core/keyboard.c | 295 | ||||
-rw-r--r-- | src/fe-common/core/keyboard.h | 27 | ||||
-rw-r--r-- | src/fe-text/gui-readline.c | 48 |
3 files changed, 177 insertions, 193 deletions
diff --git a/src/fe-common/core/keyboard.c b/src/fe-common/core/keyboard.c index 0406c758..79f0fbe4 100644 --- a/src/fe-common/core/keyboard.c +++ b/src/fe-common/core/keyboard.c @@ -20,6 +20,7 @@ #include "module.h" #include "signals.h" +#include "commands.h" #include "lib-config/iconfig.h" #include "settings.h" @@ -29,201 +30,192 @@ GSList *keyinfos; static GHashTable *keys; -KEYINFO_REC *key_info_find(gchar *id) +static void keyconfig_save(const char *id, const char *key, const char *data) { - GSList *tmp; + CONFIG_NODE *node; - for (tmp = keyinfos; tmp != NULL; tmp = tmp->next) - { - KEYINFO_REC *rec = tmp->data; + g_return_if_fail(id != NULL); + g_return_if_fail(key != NULL); - if (g_strcasecmp(rec->id, id) == 0) - return rec; - } + /* remove old keyboard settings */ + node = iconfig_node_traverse("keyboard", TRUE); + node = config_node_section(node, id, NODE_TYPE_BLOCK); - return NULL; + iconfig_node_set_str(node, key, data == NULL ? "" : data); } -/* Bind a key for function */ -void key_bind(gchar *id, gchar *data, gchar *description, gchar *key_default, SIGNAL_FUNC func) +static void keyconfig_clear(const char *id, const char *key) { - KEYINFO_REC *info; - KEY_REC *rec; - - g_return_if_fail(id != NULL); - g_return_if_fail(func != NULL); - - /* create key info record */ - info = key_info_find(id); - if (info == NULL) - { - g_return_if_fail(description != NULL); - info = g_new0(KEYINFO_REC, 1); - info->id = g_strdup(id); - info->description = g_strdup(description); - keyinfos = g_slist_append(keyinfos, info); - - /* add the signal */ - id = g_strconcat("key ", id, NULL); - signal_add(id, func); - g_free(id); - - signal_emit("keyinfo created", 1, info); - } - - if (key_default == NULL || *key_default == '\0') - { - /* just create a possible key command, don't bind it to any key yet */ - return; - } - - /* create/replace key record */ - rec = g_hash_table_lookup(keys, key_default); - if (rec != NULL) - { - if (rec->data != NULL) - g_free(rec->data); - } - else - { - rec = g_new0(KEY_REC, 1); - info->keys = g_slist_append(info->keys, rec); - rec->key = g_strdup(key_default); - g_hash_table_insert(keys, rec->key, rec); - } - rec->info = info; - rec->data = data == NULL ? NULL : g_strdup(data); + CONFIG_NODE *node; + + g_return_if_fail(id != NULL); + + /* remove old keyboard settings */ + node = iconfig_node_traverse("keyboard", TRUE); + if (key == NULL) + iconfig_node_set_str(node, id, NULL); + else { + node = config_node_section(node, id, 0); + if (node != NULL) iconfig_node_set_str(node, key, NULL); + } } -static void keyinfo_remove(KEYINFO_REC *info) +KEYINFO_REC *key_info_find(const char *id) { - GSList *tmp; + GSList *tmp; - g_return_if_fail(info != NULL); + for (tmp = keyinfos; tmp != NULL; tmp = tmp->next) { + KEYINFO_REC *rec = tmp->data; - keyinfos = g_slist_remove(keyinfos, info); - signal_emit("keyinfo destroyed", 1, info); + if (g_strcasecmp(rec->id, id) == 0) + return rec; + } - /* destroy all keys */ - for (tmp = info->keys; tmp != NULL; tmp = tmp->next) - { - KEY_REC *rec = tmp->data; + return NULL; +} - g_hash_table_remove(keys, rec->key); - if (rec->data != NULL) g_free(rec->data); - g_free(rec->key); - g_free(rec); - } +/* Bind a key for function */ +void key_bind(const char *id, const char *description, + const char *key_default, const char *data, SIGNAL_FUNC func) +{ + KEYINFO_REC *info; + char *key; + + g_return_if_fail(id != NULL); + g_return_if_fail(func != NULL); + + /* create key info record */ + info = key_info_find(id); + if (info == NULL) { + if (description == NULL) + g_warning("key_bind(%s) should have description!", id); + info = g_new0(KEYINFO_REC, 1); + info->id = g_strdup(id); + info->description = g_strdup(description); + keyinfos = g_slist_append(keyinfos, info); + + /* add the signal */ + key = g_strconcat("key ", id, NULL); + signal_add(key, func); + g_free(key); + + signal_emit("keyinfo created", 1, info); + } - /* destroy key info */ - g_slist_free(info->keys); - g_free(info->description); - g_free(info->id); - g_free(info); + if (key_default != NULL && *key_default != '\0') + key_configure_add(id, key_default, data); } -/* Unbind key */ -void key_unbind(gchar *id, SIGNAL_FUNC func) +static void keyinfo_remove(KEYINFO_REC *info) { - KEYINFO_REC *info; + GSList *tmp; + + g_return_if_fail(info != NULL); - g_return_if_fail(id != NULL); - g_return_if_fail(func != NULL); + keyinfos = g_slist_remove(keyinfos, info); + signal_emit("keyinfo destroyed", 1, info); - /* remove keys */ - info = key_info_find(id); - if (info != NULL) - keyinfo_remove(info); + /* destroy all keys */ + for (tmp = info->keys; tmp != NULL; tmp = tmp->next) { + KEY_REC *rec = tmp->data; - /* remove signal */ - id = g_strconcat("key ", id, NULL); - signal_remove(id, func); - g_free(id); + g_hash_table_remove(keys, rec->key); + g_free_not_null(rec->data); + g_free(rec->key); + g_free(rec); + } + + /* destroy key info */ + g_slist_free(info->keys); + g_free_not_null(info->description); + g_free(info->id); + g_free(info); } -/* Configure new key */ -void key_configure_add(gchar *id, gchar *data, gchar *key) +/* Unbind key */ +void key_unbind(const char *id, SIGNAL_FUNC func) { - KEYINFO_REC *info; - KEY_REC *rec; - - g_return_if_fail(id != NULL); - g_return_if_fail(key != NULL && *key != '\0'); + KEYINFO_REC *info; + char *key; - info = key_info_find(id); - if (info == NULL) - return; + g_return_if_fail(id != NULL); + g_return_if_fail(func != NULL); - rec = g_new0(KEY_REC, 1); - info->keys = g_slist_append(info->keys, rec); + /* remove keys */ + info = key_info_find(id); + if (info != NULL) + keyinfo_remove(info); - rec->info = info; - rec->data = data == NULL ? NULL : g_strdup(data); - rec->key = g_strdup(key); - g_hash_table_insert(keys, rec->key, rec); + /* remove signal */ + key = g_strconcat("key ", id, NULL); + signal_remove(key, func); + g_free(key); } -/* Remove key */ -void key_configure_remove(gchar *key) +/* Configure new key */ +void key_configure_add(const char *id, const char *key, const char *data) { - KEY_REC *rec; + KEYINFO_REC *info; + KEY_REC *rec; + + g_return_if_fail(id != NULL); + g_return_if_fail(key != NULL && *key != '\0'); - g_return_if_fail(key != NULL); + info = key_info_find(id); + if (info == NULL) + return; - rec = g_hash_table_lookup(keys, key); - if (rec == NULL) return; + key_configure_remove(key); - rec->info->keys = g_slist_remove(rec->info->keys, rec); - g_hash_table_remove(keys, key); + rec = g_new0(KEY_REC, 1); + rec->key = g_strdup(key); + rec->info = info; + rec->data = g_strdup(data); + info->keys = g_slist_append(info->keys, rec); + g_hash_table_insert(keys, rec->key, rec); - if (rec->data != NULL) g_free(rec->data); - g_free(rec->key); - g_free(rec); + keyconfig_save(id, key, data); } -gboolean key_pressed(gchar *key, gpointer data) +/* Remove key */ +void key_configure_remove(const char *key) { - KEY_REC *rec; - gboolean ret; - gchar *str; + KEY_REC *rec; - g_return_val_if_fail(key != NULL, FALSE); + g_return_if_fail(key != NULL); - rec = g_hash_table_lookup(keys, key); - if (rec == NULL) return FALSE; + rec = g_hash_table_lookup(keys, key); + if (rec == NULL) return; - str = g_strconcat("key ", rec->info->id, NULL); - ret = signal_emit(str, 3, rec->data, data, rec->info); - g_free(str); + keyconfig_clear(rec->info->id, key); - return ret; + rec->info->keys = g_slist_remove(rec->info->keys, rec); + g_hash_table_remove(keys, key); + + g_free_not_null(rec->data); + g_free(rec->key); + g_free(rec); } -void keyboard_save(void) +int key_pressed(const char *key, void *data) { - CONFIG_NODE *keyboard, *node, *listnode; - GSList *tmp, *tmp2; + KEY_REC *rec; + char *str; + int ret; - /* remove old keyboard settings */ - iconfig_node_set_str(NULL, "(keyboard", NULL); - keyboard = iconfig_node_traverse("(keyboard", TRUE); + g_return_val_if_fail(key != NULL, FALSE); - for (tmp = keyinfos; tmp != NULL; tmp = tmp->next) { - KEYINFO_REC *info = tmp->data; + rec = g_hash_table_lookup(keys, key); + if (rec == NULL) return FALSE; - node = config_node_section(keyboard, info->id, TRUE); - for (tmp2 = info->keys; tmp2 != NULL; tmp2 = tmp2->next) { - KEY_REC *key = tmp2->data; + str = g_strconcat("key ", rec->info->id, NULL); + ret = signal_emit(str, 3, rec->data, data, rec->info); + g_free(str); - listnode = config_node_section(node, NULL, NODE_TYPE_BLOCK); - if (key->data != NULL) - iconfig_node_set_str(listnode, "data", key->data); - iconfig_node_set_str(listnode, "key", key->key); - } - } + return ret; } -static void sig_command(gchar *data) +static void sig_command(const char *data) { signal_emit("send command", 3, data, active_win->active_server, active_win->active); } @@ -231,7 +223,6 @@ static void sig_command(gchar *data) void read_keyinfo(KEYINFO_REC *info, CONFIG_NODE *node) { GSList *tmp; - char *data, *key; g_return_if_fail(info != NULL); g_return_if_fail(node != NULL); @@ -245,10 +236,8 @@ void read_keyinfo(KEYINFO_REC *info, CONFIG_NODE *node) for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; - data = config_node_get_str(node->value, "data", NULL); - key = config_node_get_str(node->value, "key", NULL); - - if (key != NULL) key_configure_add(info->id, data, key); + if (node->key != NULL) + key_configure_add(info->id, node->value, node->key); } } @@ -268,7 +257,7 @@ static void read_keyboard_config(void) continue; info = key_info_find(node->key); - if (info != NULL) read_keyinfo(info, node->value); + if (info != NULL) read_keyinfo(info, node); } } @@ -277,10 +266,10 @@ void keyboard_init(void) keys = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal); keyinfos = NULL; - key_bind("command", NULL, "Run any IRC command", NULL, (SIGNAL_FUNC) sig_command); + key_bind("command", "Run any IRC command", NULL, NULL, (SIGNAL_FUNC) sig_command); read_keyboard_config(); - signal_add("setup reread", (SIGNAL_FUNC) read_keyboard_config); + signal_add("setup reread", (SIGNAL_FUNC) read_keyboard_config); } void keyboard_deinit(void) diff --git a/src/fe-common/core/keyboard.h b/src/fe-common/core/keyboard.h index a6278adc..4bce8c2b 100644 --- a/src/fe-common/core/keyboard.h +++ b/src/fe-common/core/keyboard.h @@ -3,36 +3,31 @@ #include "signals.h" -typedef struct -{ +typedef struct { char *id; char *description; GSList *keys; -} -KEYINFO_REC; +} KEYINFO_REC; -typedef struct -{ +typedef struct { KEYINFO_REC *info; char *key; void *data; -} -KEY_REC; +} KEY_REC; extern GSList *keyinfos; -void key_bind(gchar *id, gchar *data, gchar *description, gchar *key_default, SIGNAL_FUNC func); -void key_unbind(gchar *id, SIGNAL_FUNC func); +void key_bind(const char *id, const char *description, + const char *key_default, const char *data, SIGNAL_FUNC func); +void key_unbind(const char *id, SIGNAL_FUNC func); -void key_configure_add(gchar *id, gchar *data, gchar *key); -void key_configure_remove(gchar *key); +void key_configure_add(const char *id, const char *key, const char *data); +void key_configure_remove(const char *key); -KEYINFO_REC *key_info_find(gchar *id); -gboolean key_pressed(gchar *key, gpointer data); - -void keyboard_save(void); +KEYINFO_REC *key_info_find(const char *id); +int key_pressed(const char *key, void *data); void keyboard_init(void); void keyboard_deinit(void); diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index bee0d285..14295eba 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -427,34 +427,34 @@ void gui_readline_init(void) idle_time = time(NULL); readtag = g_input_add(0, G_INPUT_READ, (GInputFunction) readline, NULL); - key_bind("completion", NULL, "Nick completion", "Tab", (SIGNAL_FUNC) sig_completion); - key_bind("check replaces", NULL, "Check word replaces", " ", (SIGNAL_FUNC) sig_replace); - key_bind("check replaces", NULL, NULL, "Return", (SIGNAL_FUNC) sig_replace); - key_bind("window prev", NULL, "Previous window", "CTRL-P", (SIGNAL_FUNC) sig_prev_window); - key_bind("window prev", NULL, NULL, "ALT-Left", (SIGNAL_FUNC) sig_prev_window); - key_bind("window next", NULL, "Next window", "CTRL-N", (SIGNAL_FUNC) sig_next_window); - key_bind("window next", NULL, NULL, "ALT-Right", (SIGNAL_FUNC) sig_next_window); - key_bind("window up", NULL, "Upper window", "ALT-Up", (SIGNAL_FUNC) sig_up_window); - key_bind("window down", NULL, "Lower window", "ALT-Down", (SIGNAL_FUNC) sig_down_window); - key_bind("window active", NULL, "Go to next window with the highest activity", "ALT-A", (SIGNAL_FUNC) sig_window_goto_active); - key_bind("window item next", NULL, "Next channel", "CTRL-X", (SIGNAL_FUNC) sig_next_window_item); - key_bind("window item prev", NULL, "Next channel", NULL, (SIGNAL_FUNC) sig_prev_window_item); - - key_bind("redraw", NULL, "Redraw window", "CTRL-L", (SIGNAL_FUNC) irssi_redraw); - key_bind("prev page", NULL, "Previous page", "ALT-P", (SIGNAL_FUNC) sig_prev_page); - key_bind("next page", NULL, "Next page", "ALT-N", (SIGNAL_FUNC) sig_next_page); - - key_bind("special char", "\x02", "Insert special character", "CTRL-B", (SIGNAL_FUNC) sig_addchar); - key_bind("special char", "\x1f", NULL, "CTRL--", (SIGNAL_FUNC) sig_addchar); - key_bind("special char", "\x03", NULL, "CTRL-C", (SIGNAL_FUNC) sig_addchar); - key_bind("special char", "\x16", NULL, "CTRL-V", (SIGNAL_FUNC) sig_addchar); - key_bind("special char", "\x07", NULL, "CTRL-G", (SIGNAL_FUNC) sig_addchar); - key_bind("special char", "\x0f", NULL, "CTRL-O", (SIGNAL_FUNC) sig_addchar); + key_bind("completion", "Nick completion", "Tab", NULL, (SIGNAL_FUNC) sig_completion); + key_bind("check replaces", "Check word replaces", " ", NULL, (SIGNAL_FUNC) sig_replace); + key_bind("check replaces", NULL, "Return", NULL, (SIGNAL_FUNC) sig_replace); + key_bind("window prev", "Previous window", "CTRL-P", NULL, (SIGNAL_FUNC) sig_prev_window); + key_bind("window prev", NULL, "ALT-Left", NULL, (SIGNAL_FUNC) sig_prev_window); + key_bind("window next", "Next window", "CTRL-N", NULL, (SIGNAL_FUNC) sig_next_window); + key_bind("window next", NULL, "ALT-Right", NULL, (SIGNAL_FUNC) sig_next_window); + key_bind("window up", "Upper window", "ALT-Up", NULL, (SIGNAL_FUNC) sig_up_window); + key_bind("window down", "Lower window", "ALT-Down", NULL, (SIGNAL_FUNC) sig_down_window); + key_bind("window active", "Go to next window with the highest activity", "ALT-A", NULL, (SIGNAL_FUNC) sig_window_goto_active); + key_bind("window item next", "Next channel", "CTRL-X", NULL, (SIGNAL_FUNC) sig_next_window_item); + key_bind("window item prev", "Previous channel", NULL, NULL, (SIGNAL_FUNC) sig_prev_window_item); + + key_bind("redraw", "Redraw window", "CTRL-L", NULL, (SIGNAL_FUNC) irssi_redraw); + key_bind("prev page", "Previous page", "ALT-P", NULL, (SIGNAL_FUNC) sig_prev_page); + key_bind("next page", "Next page", "ALT-N", NULL, (SIGNAL_FUNC) sig_next_page); + + key_bind("special char", "Insert special character", "CTRL-B", "\x02", (SIGNAL_FUNC) sig_addchar); + key_bind("special char", NULL, "CTRL--", "\x1f", (SIGNAL_FUNC) sig_addchar); + key_bind("special char", NULL, "CTRL-C", "\x03", (SIGNAL_FUNC) sig_addchar); + key_bind("special char", NULL, "CTRL-V", "\x16", (SIGNAL_FUNC) sig_addchar); + key_bind("special char", NULL, "CTRL-G", "\x07", (SIGNAL_FUNC) sig_addchar); + key_bind("special char", NULL, "CTRL-O", "\x0f", (SIGNAL_FUNC) sig_addchar); for (n = 0; changekeys[n] != '\0'; n++) { key = g_strdup_printf("ALT-%c", changekeys[n]); ltoa(data, n+1); - key_bind("change window", data, "Change window", key, (SIGNAL_FUNC) sig_change_window); + key_bind("change window", "Change window", key, data, (SIGNAL_FUNC) sig_change_window); g_free(key); } |