mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Reading and saving keyboard configuration actually works now.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@434 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
cd9efdf9fe
commit
7074381bea
@ -20,6 +20,7 @@
|
||||
|
||||
#include "module.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "lib-config/iconfig.h"
|
||||
#include "settings.h"
|
||||
|
||||
@ -29,12 +30,41 @@
|
||||
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)
|
||||
{
|
||||
CONFIG_NODE *node;
|
||||
|
||||
g_return_if_fail(id != NULL);
|
||||
g_return_if_fail(key != NULL);
|
||||
|
||||
/* remove old keyboard settings */
|
||||
node = iconfig_node_traverse("keyboard", TRUE);
|
||||
node = config_node_section(node, id, NODE_TYPE_BLOCK);
|
||||
|
||||
iconfig_node_set_str(node, key, data == NULL ? "" : data);
|
||||
}
|
||||
|
||||
static void keyconfig_clear(const char *id, const char *key)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
KEYINFO_REC *key_info_find(const char *id)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
for (tmp = keyinfos; tmp != NULL; tmp = tmp->next)
|
||||
{
|
||||
for (tmp = keyinfos; tmp != NULL; tmp = tmp->next) {
|
||||
KEYINFO_REC *rec = tmp->data;
|
||||
|
||||
if (g_strcasecmp(rec->id, id) == 0)
|
||||
@ -45,54 +75,35 @@ KEYINFO_REC *key_info_find(gchar *id)
|
||||
}
|
||||
|
||||
/* Bind a key for function */
|
||||
void key_bind(gchar *id, gchar *data, gchar *description, gchar *key_default, SIGNAL_FUNC func)
|
||||
void key_bind(const char *id, const char *description,
|
||||
const char *key_default, const char *data, SIGNAL_FUNC func)
|
||||
{
|
||||
KEYINFO_REC *info;
|
||||
KEY_REC *rec;
|
||||
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)
|
||||
{
|
||||
g_return_if_fail(description != NULL);
|
||||
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 */
|
||||
id = g_strconcat("key ", id, NULL);
|
||||
signal_add(id, func);
|
||||
g_free(id);
|
||||
key = g_strconcat("key ", id, NULL);
|
||||
signal_add(key, func);
|
||||
g_free(key);
|
||||
|
||||
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);
|
||||
if (key_default != NULL && *key_default != '\0')
|
||||
key_configure_add(id, key_default, data);
|
||||
}
|
||||
|
||||
static void keyinfo_remove(KEYINFO_REC *info)
|
||||
@ -105,27 +116,27 @@ static void keyinfo_remove(KEYINFO_REC *info)
|
||||
signal_emit("keyinfo destroyed", 1, info);
|
||||
|
||||
/* destroy all keys */
|
||||
for (tmp = info->keys; tmp != NULL; tmp = tmp->next)
|
||||
{
|
||||
for (tmp = info->keys; tmp != NULL; tmp = tmp->next) {
|
||||
KEY_REC *rec = tmp->data;
|
||||
|
||||
g_hash_table_remove(keys, rec->key);
|
||||
if (rec->data != NULL) g_free(rec->data);
|
||||
g_free_not_null(rec->data);
|
||||
g_free(rec->key);
|
||||
g_free(rec);
|
||||
}
|
||||
|
||||
/* destroy key info */
|
||||
g_slist_free(info->keys);
|
||||
g_free(info->description);
|
||||
g_free_not_null(info->description);
|
||||
g_free(info->id);
|
||||
g_free(info);
|
||||
}
|
||||
|
||||
/* Unbind key */
|
||||
void key_unbind(gchar *id, SIGNAL_FUNC func)
|
||||
void key_unbind(const char *id, SIGNAL_FUNC func)
|
||||
{
|
||||
KEYINFO_REC *info;
|
||||
char *key;
|
||||
|
||||
g_return_if_fail(id != NULL);
|
||||
g_return_if_fail(func != NULL);
|
||||
@ -136,13 +147,13 @@ void key_unbind(gchar *id, SIGNAL_FUNC func)
|
||||
keyinfo_remove(info);
|
||||
|
||||
/* remove signal */
|
||||
id = g_strconcat("key ", id, NULL);
|
||||
signal_remove(id, func);
|
||||
g_free(id);
|
||||
key = g_strconcat("key ", id, NULL);
|
||||
signal_remove(key, func);
|
||||
g_free(key);
|
||||
}
|
||||
|
||||
/* Configure new key */
|
||||
void key_configure_add(gchar *id, gchar *data, gchar *key)
|
||||
void key_configure_add(const char *id, const char *key, const char *data)
|
||||
{
|
||||
KEYINFO_REC *info;
|
||||
KEY_REC *rec;
|
||||
@ -154,17 +165,20 @@ void key_configure_add(gchar *id, gchar *data, gchar *key)
|
||||
if (info == NULL)
|
||||
return;
|
||||
|
||||
rec = g_new0(KEY_REC, 1);
|
||||
info->keys = g_slist_append(info->keys, rec);
|
||||
key_configure_remove(key);
|
||||
|
||||
rec->info = info;
|
||||
rec->data = data == NULL ? NULL : g_strdup(data);
|
||||
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);
|
||||
|
||||
keyconfig_save(id, key, data);
|
||||
}
|
||||
|
||||
/* Remove key */
|
||||
void key_configure_remove(gchar *key)
|
||||
void key_configure_remove(const char *key)
|
||||
{
|
||||
KEY_REC *rec;
|
||||
|
||||
@ -173,19 +187,21 @@ void key_configure_remove(gchar *key)
|
||||
rec = g_hash_table_lookup(keys, key);
|
||||
if (rec == NULL) return;
|
||||
|
||||
keyconfig_clear(rec->info->id, key);
|
||||
|
||||
rec->info->keys = g_slist_remove(rec->info->keys, rec);
|
||||
g_hash_table_remove(keys, key);
|
||||
|
||||
if (rec->data != NULL) g_free(rec->data);
|
||||
g_free_not_null(rec->data);
|
||||
g_free(rec->key);
|
||||
g_free(rec);
|
||||
}
|
||||
|
||||
gboolean key_pressed(gchar *key, gpointer data)
|
||||
int key_pressed(const char *key, void *data)
|
||||
{
|
||||
KEY_REC *rec;
|
||||
gboolean ret;
|
||||
gchar *str;
|
||||
char *str;
|
||||
int ret;
|
||||
|
||||
g_return_val_if_fail(key != NULL, FALSE);
|
||||
|
||||
@ -199,31 +215,7 @@ gboolean key_pressed(gchar *key, gpointer data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void keyboard_save(void)
|
||||
{
|
||||
CONFIG_NODE *keyboard, *node, *listnode;
|
||||
GSList *tmp, *tmp2;
|
||||
|
||||
/* remove old keyboard settings */
|
||||
iconfig_node_set_str(NULL, "(keyboard", NULL);
|
||||
keyboard = iconfig_node_traverse("(keyboard", TRUE);
|
||||
|
||||
for (tmp = keyinfos; tmp != NULL; tmp = tmp->next) {
|
||||
KEYINFO_REC *info = tmp->data;
|
||||
|
||||
node = config_node_section(keyboard, info->id, TRUE);
|
||||
for (tmp2 = info->keys; tmp2 != NULL; tmp2 = tmp2->next) {
|
||||
KEY_REC *key = tmp2->data;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,7 +266,7 @@ 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);
|
||||
|
@ -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);
|
||||
|
@ -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("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", 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("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", "\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("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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user