summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fe-common/core/keyboard.c479
-rw-r--r--src/fe-common/core/keyboard.h18
-rw-r--r--src/fe-text/gui-readline.c322
-rw-r--r--src/fe-text/screen.c2
4 files changed, 581 insertions, 240 deletions
diff --git a/src/fe-common/core/keyboard.c b/src/fe-common/core/keyboard.c
index 203558c8..7754feae 100644
--- a/src/fe-common/core/keyboard.c
+++ b/src/fe-common/core/keyboard.c
@@ -1,7 +1,7 @@
/*
keyboard.c : irssi
- Copyright (C) 1999 Timo Sirainen
+ Copyright (C) 1999-2001 Timo Sirainen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -32,7 +32,105 @@
#include "printtext.h"
GSList *keyinfos;
-static GHashTable *keys;
+static GHashTable *keys, *default_keys;
+
+/* contains list of all key bindings of which command is "key" -
+ this can be used to check fast if some command queue exists or not.
+ Format is _always_ in key1-key2-key3 format (like ^W-^N,
+ not ^W^N) */
+static GTree *key_states;
+/* List of all key combo names */
+static GSList *key_combos;
+static int key_config_frozen;
+
+struct KEYBOARD_REC {
+ /* example:
+ /BIND ^[ key meta
+ /BIND meta-O key meta2
+ /BIND meta-[ key meta2
+
+ /BIND meta2-C key right
+ /BIND ^W-meta-right /echo ^W Meta-right key pressed
+
+ When ^W Meta-Right is pressed, the full char combination
+ is "^W^[^[[C".
+
+ We'll get there with key states:
+ ^W - key_prev_state = NULL, key_state = NULL -> ^W
+ ^[ - key_prev_state = NULL, key_state = ^W -> meta
+ ^[ - key_prev_state = ^W, key_state = meta -> meta
+ [ - key_prev_state = ^W-meta, key_state = meta -> meta2
+ C - key_prev_state = ^W-meta, key_state = meta2 -> right
+ key_prev_state = ^W-meta, key_state = right -> ^W-meta-right
+
+ key_state is moved to key_prev_state if there's nothing else in
+ /BINDs matching for key_state-newkey.
+
+ ^X^Y equals to ^X-^Y, ABC equals to A-B-C unless there's ABC
+ named key. ^ can be used with ^^ and - with -- */
+ char *key_state, *key_prev_state;
+
+ /* GUI specific data sent in "key pressed" signal */
+ void *gui_data;
+};
+
+/* Creates a new "keyboard" - this is used only for keeping track of
+ key combo states and sending the gui_data parameter in "key pressed"
+ signal */
+KEYBOARD_REC *keyboard_create(void *data)
+{
+ KEYBOARD_REC *rec;
+
+ rec = g_new0(KEYBOARD_REC, 1);
+ rec->gui_data = data;
+
+ signal_emit("keyboard created", 1, rec);
+ return rec;
+}
+
+/* Destroys a keyboard */
+void keyboard_destroy(KEYBOARD_REC *keyboard)
+{
+ signal_emit("keyboard destroyed", 1, keyboard);
+
+ g_free_not_null(keyboard->key_state);
+ g_free_not_null(keyboard->key_prev_state);
+ g_free(keyboard);
+}
+
+static void key_destroy(KEY_REC *rec, GHashTable *hash)
+{
+ g_hash_table_remove(hash, rec->key);
+
+ g_free_not_null(rec->data);
+ g_free(rec->key);
+ g_free(rec);
+}
+
+static void key_default_add(const char *id, const char *key, const char *data)
+{
+ KEYINFO_REC *info;
+ KEY_REC *rec;
+
+ info = key_info_find(id);
+ if (info == NULL)
+ return;
+
+ rec = g_hash_table_lookup(default_keys, key);
+ if (rec != NULL) {
+ /* key already exists, replace */
+ rec->info->default_keys =
+ g_slist_remove(rec->info->default_keys, rec);
+ key_destroy(rec, default_keys);
+ }
+
+ rec = g_new0(KEY_REC, 1);
+ rec->key = g_strdup(key);
+ rec->info = info;
+ rec->data = g_strdup(data);
+ info->default_keys = g_slist_append(info->default_keys, rec);
+ g_hash_table_insert(default_keys, rec->key, rec);
+}
static void keyconfig_save(const char *id, const char *key, const char *data)
{
@@ -43,9 +141,10 @@ static void keyconfig_save(const char *id, const char *key, const char *data)
/* remove old keyboard settings */
node = iconfig_node_traverse("keyboard", TRUE);
- node = config_node_section(node, id, NODE_TYPE_BLOCK);
+ node = config_node_section(node, key, NODE_TYPE_BLOCK);
- iconfig_node_set_str(node, key, data == NULL ? "" : data);
+ iconfig_node_set_str(node, "id", id);
+ iconfig_node_set_str(node, "data", data);
}
static void keyconfig_clear(const char *id, const char *key)
@@ -86,11 +185,12 @@ void key_bind(const char *id, const char *description,
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(func != NULL);
+
if (description == NULL)
g_warning("key_bind(%s) should have description!", id);
info = g_new0(KEYINFO_REC, 1);
@@ -106,31 +206,26 @@ void key_bind(const char *id, const char *description,
signal_emit("keyinfo created", 1, info);
}
- if (key_default != NULL && *key_default != '\0')
+ if (key_default != NULL && *key_default != '\0') {
+ key_default_add(id, key_default, data);
key_configure_add(id, key_default, data);
+ }
}
static void keyinfo_remove(KEYINFO_REC *info)
{
- GSList *tmp;
-
g_return_if_fail(info != NULL);
keyinfos = g_slist_remove(keyinfos, info);
signal_emit("keyinfo destroyed", 1, info);
/* destroy all keys */
- for (tmp = info->keys; tmp != NULL; tmp = tmp->next) {
- KEY_REC *rec = tmp->data;
-
- g_hash_table_remove(keys, rec->key);
- g_free_not_null(rec->data);
- g_free(rec->key);
- g_free(rec);
- }
+ g_slist_foreach(info->keys, (GFunc) key_destroy, keys);
+ g_slist_foreach(info->default_keys, (GFunc) key_destroy, default_keys);
/* destroy key info */
g_slist_free(info->keys);
+ g_slist_free(info->default_keys);
g_free_not_null(info->description);
g_free(info->id);
g_free(info);
@@ -156,6 +251,104 @@ void key_unbind(const char *id, SIGNAL_FUNC func)
g_free(key);
}
+static KEY_REC *key_combo_find(const char *key)
+{
+ KEYINFO_REC *info;
+ GSList *tmp;
+
+ info = key_info_find("key");
+ if (info == NULL)
+ return NULL;
+
+ for (tmp = info->keys; tmp != NULL; tmp = tmp->next) {
+ KEY_REC *rec = tmp->data;
+
+ if (strcmp(rec->data, key) == 0)
+ return rec;
+ }
+
+ return NULL;
+}
+
+static void key_states_scan_key(const char *key, KEY_REC *rec, GString *temp)
+{
+ char **keys, **tmp, *p;
+
+ g_string_truncate(temp, 0);
+
+ /* meta-^W^Gfoo -> meta-^W-^G-f-o-o */
+ keys = g_strsplit(key, "-", -1);
+ for (tmp = keys; *tmp != NULL; tmp++) {
+ if (key_combo_find(*tmp)) {
+ /* key combo */
+ g_string_append(temp, *tmp);
+ g_string_append_c(temp, '-');
+ continue;
+ }
+
+ if (**tmp == '\0') {
+ /* '-' */
+ g_string_append(temp, "--");
+ continue;
+ }
+
+ for (p = *tmp; *p != '\0'; p++) {
+ g_string_append_c(temp, *p);
+
+ if (*p == '^') {
+ /* ctrl-code */
+ if (p[1] != '\0')
+ p++;
+ g_string_append_c(temp, *p);
+ }
+
+ g_string_append_c(temp, '-');
+ }
+ }
+ g_strfreev(keys);
+
+ if (temp->len > 0)
+ g_string_truncate(temp, temp->len-1);
+
+ g_tree_insert(key_states, g_strdup(temp->str), rec);
+}
+
+static int key_state_destroy(char *key)
+{
+ g_free(key);
+ return FALSE;
+}
+
+/* Rescan all the key combos and figure out which characters are supposed
+ to be treated as characters and which as key combos.
+ Yes, this is pretty slow function... */
+static void key_states_rescan(void)
+{
+ GString *temp;
+
+ g_tree_traverse(key_states, (GTraverseFunc) key_state_destroy,
+ G_IN_ORDER, NULL);
+ g_tree_destroy(key_states);
+ key_states = g_tree_new((GCompareFunc) strcmp);
+
+ temp = g_string_new(NULL);
+ g_hash_table_foreach(keys, (GHFunc) key_states_scan_key, temp);
+ g_string_free(temp, TRUE);
+}
+
+void key_configure_freeze(void)
+{
+ key_config_frozen++;
+}
+
+void key_configure_thaw(void)
+{
+ g_return_if_fail(key_config_frozen > 0);
+
+ if (--key_config_frozen == 0)
+ key_states_rescan();
+}
+
/* Configure new key */
static void key_configure_create(const char *id, const char *key,
const char *data)
@@ -178,6 +371,9 @@ static void key_configure_create(const char *id, const char *key,
rec->data = g_strdup(data);
info->keys = g_slist_append(info->keys, rec);
g_hash_table_insert(keys, rec->key, rec);
+
+ if (!key_config_frozen)
+ key_states_rescan();
}
/* Configure new key */
@@ -197,6 +393,9 @@ static void key_configure_destroy(KEY_REC *rec)
rec->info->keys = g_slist_remove(rec->info->keys, rec);
g_hash_table_remove(keys, rec->key);
+ if (!key_config_frozen)
+ key_states_rescan();
+
g_free_not_null(rec->data);
g_free(rec->key);
g_free(rec);
@@ -216,22 +415,116 @@ void key_configure_remove(const char *key)
key_configure_destroy(rec);
}
-int key_pressed(const char *key, void *data)
+static int key_emit_signal(KEYBOARD_REC *keyboard, KEY_REC *key)
+{
+ int consumed;
+ char *str;
+
+ str = g_strconcat("key ", key->info->id, NULL);
+ consumed = signal_emit(str, 3, key->data, keyboard->gui_data, key->info);
+ g_free(str);
+
+ return consumed;
+}
+
+int key_states_search(const char *combo, const char *search)
+{
+ while (*search != '\0') {
+ if (*combo != *search)
+ return *search - *combo;
+ search++; combo++;
+ }
+
+ return *combo == '\0' || *combo == '-' ? 0 : -1;
+}
+
+/* Returns TRUE if key press was consumed. Control characters should be sent
+ as "^@" .. "^_" instead of #0..#31 chars, #127 should be sent as ^? */
+int key_pressed(KEYBOARD_REC *keyboard, const char *key)
{
KEY_REC *rec;
char *str;
- int ret;
+ int consumed;
+
+ g_return_val_if_fail(keyboard != NULL, FALSE);
+ g_return_val_if_fail(key != NULL && *key != '\0', FALSE);
+
+ if (keyboard->key_state == NULL) {
+ rec = g_tree_search(key_states,
+ (GSearchFunc) key_states_search,
+ (void *) key);
+ if (rec == NULL || strcmp(rec->info->id, "key") != 0) {
+ /* a single non-combo key was pressed */
+ rec = g_hash_table_lookup(keys, key);
+ if (rec == NULL)
+ return FALSE;
+ consumed = key_emit_signal(keyboard, rec);
+
+ /* never consume non-control characters */
+ return consumed && key[1] != '\0';
+ }
+ }
+
+ if (keyboard->key_state == NULL) {
+ /* first key in combo */
+ rec = g_tree_lookup(key_states, (void *) key);
+ } else {
+ /* continuing key combination */
+ str = g_strconcat(keyboard->key_state, "-", key, NULL);
+ rec = g_tree_lookup(key_states, str);
+ g_free(str);
+ }
- g_return_val_if_fail(key != NULL, FALSE);
+ if (rec != NULL && strcmp(rec->info->id, "key") == 0) {
+ /* combo has a specified name, use it */
+ g_free_not_null(keyboard->key_state);
+ keyboard->key_state = g_strdup(rec->data);
+ } else {
+ /* some unnamed key - move key_state after key_prev_state
+ and replace key_state with this new key */
+ if (keyboard->key_prev_state == NULL)
+ keyboard->key_prev_state = keyboard->key_state;
+ else {
+ str = g_strconcat(keyboard->key_prev_state, "-",
+ keyboard->key_state, NULL);
+ g_free(keyboard->key_prev_state);
+ g_free(keyboard->key_state);
+ keyboard->key_prev_state = str;
+ }
- rec = g_hash_table_lookup(keys, key);
- if (rec == NULL) return FALSE;
+ keyboard->key_state = g_strdup(key);
+ }
- str = g_strconcat("key ", rec->info->id, NULL);
- ret = signal_emit(str, 3, rec->data, data, rec->info);
- g_free(str);
+ /* what to do with the key combo? */
+ str = keyboard->key_prev_state == NULL ?
+ g_strdup(keyboard->key_state) :
+ g_strconcat(keyboard->key_prev_state, "-",
+ keyboard->key_state, NULL);
+
+ rec = g_tree_lookup(key_states, str);
+ if (rec != NULL) {
+ if (strcmp(rec->info->id, "key") == 0)
+ rec = g_tree_lookup(key_states, rec->data);
+
+ if (rec != NULL) {
+ /* full key combo */
+ key_emit_signal(keyboard, rec);
+ rec = NULL;
+ }
+ } else {
+ /* check that combo is possible */
+ rec = g_tree_search(key_states,
+ (GSearchFunc) key_states_search, str);
+ }
+
+ if (rec == NULL) {
+ /* a) key combo finished, b) unknown key combo, abort */
+ g_free_and_null(keyboard->key_prev_state);
+ g_free_and_null(keyboard->key_state);
+ }
- return ret;
+ g_free(str);
+ return TRUE;
}
void keyboard_entry_redirect(SIGNAL_FUNC func, const char *entry,
@@ -255,45 +548,29 @@ static void sig_command(const char *data)
g_free(str);
}
-void read_keyinfo(KEYINFO_REC *info, CONFIG_NODE *node)
+static void sig_key(const char *data)
{
- GSList *tmp;
-
- g_return_if_fail(info != NULL);
- g_return_if_fail(node != NULL);
- g_return_if_fail(is_node_list(node));
-
- /* remove all old keys */
- while (info->keys != NULL)
- key_configure_destroy(info->keys->data);
-
- /* add the new keys */
- for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
- node = tmp->data;
-
- if (node->key != NULL)
- key_configure_create(info->id, node->key, node->value);
- }
+ /* we should never get here */
}
-static void read_keyboard_config(void)
+static void sig_multi(const char *data, void *gui_data)
{
- KEYINFO_REC *info;
- CONFIG_NODE *node;
- GSList *tmp;
-
- node = iconfig_node_traverse("keyboard", FALSE);
- if (node == NULL) return;
-
- for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
- node = tmp->data;
-
- if (node->key == NULL || node->value == NULL)
- continue;
-
- info = key_info_find(node->key);
- if (info != NULL) read_keyinfo(info, node);
+ KEYINFO_REC *info;
+ char **list, **tmp, *p, *str;
+
+ list = g_strsplit(data, ";", -1);
+ for (tmp = list; *tmp != NULL; tmp++) {
+ p = strchr(*tmp, ' ');
+ if (p != NULL) *p++ = '\0'; else p = "";
+
+ info = key_info_find(*tmp);
+ if (info != NULL) {
+ str = g_strconcat("key ", info->id, NULL);
+ signal_emit(str, 3, p, gui_data, info);
+ g_free(str);
+ }
}
+ g_strfreev(list);
}
static void cmd_show_keys(const char *searchkey, int full)
@@ -393,12 +670,89 @@ static void sig_complete_bind(GList **list, WINDOW_REC *window,
if (*list != NULL) signal_stop();
}
+static int key_destroy_hash(const char *key, KEY_REC *rec)
+{
+ rec->info->keys = g_slist_remove(rec->info->keys, rec);
+
+ g_free_not_null(rec->data);
+ g_free(rec->key);
+ g_free(rec);
+ return TRUE;
+}
+
+static void key_copy_default(const char *key, KEY_REC *orig)
+{
+ KEY_REC *rec;
+
+ rec = g_new0(KEY_REC, 1);
+ rec->key = g_strdup(orig->key);
+ rec->info = orig->info;
+ rec->data = g_strdup(orig->data);
+
+ rec->info->keys = g_slist_append(rec->info->keys, rec);
+ g_hash_table_insert(keys, rec->key, rec);
+}
+
+static void keyboard_reset_defaults(void)
+{
+ g_hash_table_foreach_remove(keys, (GHRFunc) key_destroy_hash, NULL);
+ g_hash_table_foreach(default_keys, (GHFunc) key_copy_default, NULL);
+}
+
+static void read_keyboard_config(void)
+{
+ CONFIG_NODE *node, *tmpnode;
+ GSList *tmp;
+ char *id, *data;
+
+ key_configure_freeze();
+
+ keyboard_reset_defaults();
+
+ node = iconfig_node_traverse("keyboard", FALSE);
+ if (node == NULL) {
+ key_configure_thaw();
+ return;
+ }
+
+ /* FIXME: backward "compatibility" - remove after irssi .99 */
+ tmpnode = node->value;
+ if (tmpnode != NULL &&
+ config_node_get_str(tmpnode->value, "id", NULL) == NULL) {
+ iconfig_node_clear(node);
+ key_configure_thaw();
+ return;
+ }
+
+ for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
+ node = tmp->data;
+
+ if (node->key == NULL || node->value == NULL)
+ continue;
+
+ id = config_node_get_str(node->value, "id", NULL);
+ data = config_node_get_str(node->value, "data", NULL);
+ if (id != NULL)
+ key_configure_create(id, node->key, data);
+ }
+
+ key_configure_thaw();
+}
+
void keyboard_init(void)
{
- keys = g_hash_table_new((GHashFunc) g_istr_hash, (GCompareFunc) g_istr_equal);
+ keys = g_hash_table_new((GHashFunc) g_str_hash,
+ (GCompareFunc) g_str_equal);
+ default_keys = g_hash_table_new((GHashFunc) g_str_hash,
+ (GCompareFunc) g_str_equal);
keyinfos = NULL;
+ key_states = g_tree_new((GCompareFunc) strcmp);
+ key_combos = NULL;
+ key_config_frozen = 0;
key_bind("command", "Run any IRC command", NULL, NULL, (SIGNAL_FUNC) sig_command);
+ key_bind("key", "Specify name for key binding", NULL, NULL, (SIGNAL_FUNC) sig_key);
+ key_bind("multi", "Run multiple commands", NULL, NULL, (SIGNAL_FUNC) sig_multi);
/* read the keyboard config when all key binds are known */
signal_add("irssi init read settings", (SIGNAL_FUNC) read_keyboard_config);
@@ -414,6 +768,11 @@ void keyboard_deinit(void)
while (keyinfos != NULL)
keyinfo_remove(keyinfos->data);
g_hash_table_destroy(keys);
+ g_hash_table_destroy(default_keys);
+
+ g_tree_traverse(key_states, (GTraverseFunc) key_state_destroy,
+ G_IN_ORDER, 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);
diff --git a/src/fe-common/core/keyboard.h b/src/fe-common/core/keyboard.h
index f3cc4d1a..9f2652e0 100644
--- a/src/fe-common/core/keyboard.h
+++ b/src/fe-common/core/keyboard.h
@@ -3,11 +3,13 @@
#include "signals.h"
+typedef struct KEYBOARD_REC KEYBOARD_REC;
+
typedef struct {
char *id;
char *description;
- GSList *keys;
+ GSList *keys, *default_keys;
} KEYINFO_REC;
typedef struct {
@@ -19,15 +21,27 @@ typedef struct {
extern GSList *keyinfos;
+/* Creates a new "keyboard" - this is used only for keeping track of
+ key combo states and sending the gui_data parameter in "key pressed"
+ signal */
+KEYBOARD_REC *keyboard_create(void *gui_data);
+/* Destroys a keyboard */
+void keyboard_destroy(KEYBOARD_REC *keyboard);
+/* Returns TRUE if key press was consumed. Control characters should be sent
+ as "^@" .. "^_" instead of #0..#31 chars, #127 should be sent as ^? */
+int key_pressed(KEYBOARD_REC *keyboard, const char *key);
+
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_freeze(void);
+void key_configure_thaw(void);
+
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(const char *id);
-int key_pressed(const char *key, void *data);
#define ENTRY_REDIRECT_FLAG_HOTKEY 0x01
#define ENTRY_REDIRECT_FLAG_HIDDEN 0x02
diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c
index 1f54190a..d1fc769b 100644
--- a/src/fe-text/gui-readline.c
+++ b/src/fe-text/gui-readline.c
@@ -46,6 +46,7 @@ typedef struct {
void *data;
} ENTRY_REDIRECT_REC;
+static KEYBOARD_REC *keyboard;
static ENTRY_REDIRECT_REC *redir;
char *cutbuffer;
@@ -115,55 +116,9 @@ static void window_next_page(void)
gui_window_scroll(active_win, get_scroll_count());
}
-static const char *get_key_name(int key)
-{
- switch (key) {
- case 8:
- case 127:
- case KEY_BACKSPACE:
- return "Backspace";
- case 9:
- return "Tab";
- case KEY_HOME:
- return "Home";
-#ifdef KEY_END
- case KEY_END:
-#endif
-#ifdef KEY_LL
- case KEY_LL:
-#endif
-#if defined (KEY_END) || defined (KEY_LL)
- return "End";
-#endif
- case KEY_PPAGE:
- return "Prior";
- case KEY_NPAGE:
- return "Next";
- case KEY_UP:
- return "Up";
- case KEY_DOWN:
- return "Down";
- case KEY_LEFT:
- return "Left";
- case KEY_RIGHT:
- return "Right";
- case KEY_DC:
- return "Delete";
- case KEY_IC:
- return "Insert";
- case '\n':
- case 13:
- return "Return";
- default:
- return NULL;
- }
-}
-
void handle_key(int key)
{
- const char *keyname;
- char *str;
- int add_history;
+ char str[3];
/* Quit if we get 5 CTRL-C's in a row. */
if (key != CTRL('c'))
@@ -178,95 +133,57 @@ void handle_key(int key)
return;
}
- switch (key)
- {
- case 27:
- key = getch();
- if (key == 'O') {
- key = getch();
- switch (key) {
- case 'a':
- str = g_strdup("CTRL-Up");
- break;
- case 'b':
- str = g_strdup("CTRL-Down");
- break;
- case 'c':
- str = g_strdup("CTRL-Right");
- break;
- case 'd':
- str = g_strdup("CTRL-Left");
- break;
- default:
- return;
- }
- } else if (key == toupper(key) && key != tolower(key))
- str = g_strdup_printf("ALT-SHIFT-%c", key);
- else {
- keyname = get_key_name(key);
- if (keyname != NULL)
- str = g_strdup_printf("ALT-%s", keyname);
- else if (key >= 32 && key < 256 && key != 128)
- str = g_strdup_printf("ALT-%c", toupper(key));
- else {
- str = g_strdup_printf("ALT-%d", key);
- }
- }
- key_pressed(str, NULL);
- g_free(str);
- break;
- case '\n':
- case 13:
- key_pressed("Return", NULL);
-
- str = gui_entry_get_text();
- if (*str == '\0') break;
-
- translate_output(str);
-
- add_history = TRUE;
- if (redir == NULL) {
- signal_emit("send command", 3, str,
- active_win->active_server,
- active_win->active);
- } else {
- if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
- add_history = FALSE;
- handle_entry_redirect(str);
- }
+ if (key >= 0 && key < 32) {
+ /* control key */
+ str[0] = '^';
+ str[1] = key+'@';
+ str[2] = '\0';
+ } else if (key == 127) {
+ str[0] = '^';
+ str[1] = '?';
+ str[2] = '\0';
+ } else {
+ str[0] = key;
+ str[1] = '\0';
+ }
- if (add_history) {
- command_history_add(active_win, gui_entry_get_text(),
- FALSE);
- }
- gui_entry_set_text("");
- command_history_clear_pos(active_win);
- break;
-
- default:
- keyname = get_key_name(key);
- if (keyname != NULL) {
- key_pressed(keyname, NULL);
- break;
- }
- if (key >= 0 && key < 32) {
- str = g_strdup_printf("CTRL-%c",
- key == 0 ? ' ' :
- (key == 31 ? '-' : key+'A'-1));
- key_pressed(str, NULL);
- g_free(str);
- break;
- }
+ if (!key_pressed(keyboard, str)) {
+ /* key wasn't used for anything, print it */
+ gui_entry_insert_char((char) key);
+ }
+}
+
+static void key_send_line(void)
+{
+ int add_history;
+ char *str;
- if (key < 256) {
- char str[2];
+ str = gui_entry_get_text();
+ if (*str == '\0') return;
- str[0] = toupper(key); str[1] = '\0';
- key_pressed(str, NULL);
- gui_entry_insert_char((char) key);
- }
- break;
+ translate_output(str);
+
+ add_history = TRUE;
+ if (redir == NULL) {
+ signal_emit("send command", 3, str,
+ active_win->active_server,
+ active_win->active);
+ } else {
+ if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
+ add_history = FALSE;
+ handle_entry_redirect(str);
}
+
+ if (add_history) {
+ command_history_add(active_win, gui_entry_get_text(),
+ FALSE);
+ }
+ gui_entry_set_text("");
+ command_history_clear_pos(active_win);
+}
+
+static void key_combo(void)
+{
}
static void key_backward_history(void)
@@ -571,7 +488,7 @@ static void sig_gui_entry_redirect(SIGNAL_FUNC func, const char *entry,
void gui_readline_init(void)
{
- static char changekeys[] = "1234567890QWERTYUIO";
+ static char changekeys[] = "1234567890qwertyuio";
char *key, data[MAX_INT_STRLEN];
int n;
@@ -584,66 +501,112 @@ void gui_readline_init(void)
settings_add_str("history", "scroll_page_count", "/2");
- key_bind("backward_character", "", "Left", NULL, (SIGNAL_FUNC) key_backward_character);
- key_bind("forward_character", "", "Right", NULL, (SIGNAL_FUNC) key_forward_character);
- key_bind("backward_word", "", "Ctrl-Left", NULL, (SIGNAL_FUNC) key_backward_word);
- key_bind("forward_word", "", "Ctrl-Right", NULL, (SIGNAL_FUNC) key_forward_word);
- key_bind("beginning_of_line", "", "Home", NULL, (SIGNAL_FUNC) key_beginning_of_line);
- key_bind("beginning_of_line", NULL, "Ctrl-A", NULL, (SIGNAL_FUNC) key_beginning_of_line);
- key_bind("end_of_line", "", "End", NULL, (SIGNAL_FUNC) key_end_of_line);
- key_bind("end_of_line", NULL, "Ctrl-E", NULL, (SIGNAL_FUNC) key_end_of_line);
-
- key_bind("backward_history", "", "Up", NULL, (SIGNAL_FUNC) key_backward_history);
- key_bind("forward_history", "", "Down", NULL, (SIGNAL_FUNC) key_forward_history);
-
- key_bind("backspace", "", "Backspace", NULL, (SIGNAL_FUNC) key_backspace);
- key_bind("delete_character", "", "Delete", NULL, (SIGNAL_FUNC) key_delete_character);
- key_bind("delete_character", NULL, "Ctrl-D", NULL, (SIGNAL_FUNC) key_delete_character);
+ keyboard = keyboard_create(NULL);
+ key_configure_freeze();
+
+ key_bind("key", NULL, "^M", "return", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "^J", "return", (SIGNAL_FUNC) key_combo);
+
+ /* meta */
+ key_bind("key", NULL, "^[", "meta", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta-[", "meta2", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta-O", "meta2", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta-[O", "meta2", (SIGNAL_FUNC) key_combo);
+
+ /* arrow keys */
+ key_bind("key", NULL, "meta2-A", "up", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-B", "down", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-C", "right", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-D", "left", (SIGNAL_FUNC) key_combo);
+
+ key_bind("key", NULL, "meta2-1~", "home", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-7~", "home", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-H", "home", (SIGNAL_FUNC) key_combo);
+
+ key_bind("key", NULL, "meta2-4~", "end", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-8~", "end", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-F", "end", (SIGNAL_FUNC) key_combo);
+
+ key_bind("key", NULL, "meta2-5~", "prior", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-I", "prior", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-6~", "next", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-G", "next", (SIGNAL_FUNC) key_combo);
+
+ key_bind("key", NULL, "meta2-2~", "insert", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-3~", "delete", (SIGNAL_FUNC) key_combo);
+
+ /* cursor movement */
+ key_bind("backward_character", "", "left", NULL, (SIGNAL_FUNC) key_backward_character);
+ key_bind("forward_character", "", "right", NULL, (SIGNAL_FUNC) key_forward_character);
+ key_bind("backward_word", "", "meta2-d", NULL, (SIGNAL_FUNC) key_backward_word);
+ key_bind("forward_word", "", "meta2-c", NULL, (SIGNAL_FUNC) key_forward_word);
+ key_bind("beginning_of_line", "", "home", NULL, (SIGNAL_FUNC) key_beginning_of_line);
+ key_bind("beginning_of_line", NULL, "^A", NULL, (SIGNAL_FUNC) key_beginning_of_line);
+ key_bind("end_of_line", "", "end", NULL, (SIGNAL_FUNC) key_end_of_line);
+ key_bind("end_of_line", NULL, "^E", NULL, (SIGNAL_FUNC) key_end_of_line);
+
+ /* history */
+ key_bind("backward_history", "", "up", NULL, (SIGNAL_FUNC) key_backward_history);
+ key_bind("forward_history", "", "down", NULL, (SIGNAL_FUNC) key_forward_history);
+
+ /* line editing */
+ key_bind("backspace", "", "^H", NULL, (SIGNAL_FUNC) key_backspace);
+ key_bind("backspace", "", "^?", NULL, (SIGNAL_FUNC) key_backspace);
+ key_bind("delete_character", "", "delete", NULL, (SIGNAL_FUNC) key_delete_character);
+ key_bind("delete_character", NULL, "^D", NULL, (SIGNAL_FUNC) key_delete_character);
key_bind("delete_next_word", "", NULL, NULL, (SIGNAL_FUNC) key_delete_next_word);
key_bind("delete_previous_word", "", NULL, NULL, (SIGNAL_FUNC) key_delete_previous_word);
- key_bind("delete_to_previous_space", "", "Ctrl-W", NULL, (SIGNAL_FUNC) key_delete_to_previous_space);
- key_bind("erase_line", "", "Ctrl-U", NULL, (SIGNAL_FUNC) key_erase_line);
+ key_bind("delete_to_previous_space", "", "^W", NULL, (SIGNAL_FUNC) key_delete_to_previous_space);
+ key_bind("erase_line", "", "^U", NULL, (SIGNAL_FUNC) key_erase_line);
key_bind("erase_to_beg_of_line", "", NULL, NULL, (SIGNAL_FUNC) key_erase_to_beg_of_line);
- key_bind("erase_to_end_of_line", "", "Ctrl-K", NULL, (SIGNAL_FUNC) key_erase_to_end_of_line);
- key_bind("yank_from_cutbuffer", "", "Ctrl-Y", NULL, (SIGNAL_FUNC) key_yank_from_cutbuffer);
- key_bind("transpose_characters", "Swap current and previous character", "Ctrl-T", NULL, (SIGNAL_FUNC) key_transpose_characters);
-
- key_bind("word_completion", "", "Tab", NULL, (SIGNAL_FUNC) key_word_completion);
+ key_bind("erase_to_end_of_line", "", "^K", NULL, (SIGNAL_FUNC) key_erase_to_end_of_line);
+ key_bind("yank_from_cutbuffer", "", "^Y", NULL, (SIGNAL_FUNC) key_yank_from_cutbuffer);
+ key_bind("transpose_characters", "Swap current and previous character", "^T", NULL, (SIGNAL_FUNC) key_transpose_characters);
+
+ /* line transmitting */
+ key_bind("send_line", "Execute the input line", "return", NULL, (SIGNAL_FUNC) key_send_line);
+ key_bind("word_completion", "", "^I", NULL, (SIGNAL_FUNC) key_word_completion);
key_bind("check_replaces", "Check word replaces", " ", NULL, (SIGNAL_FUNC) key_check_replaces);
- key_bind("check_replaces", NULL, "Return", NULL, (SIGNAL_FUNC) key_check_replaces);
-
- key_bind("previous_window", "Previous window", "CTRL-P", NULL, (SIGNAL_FUNC) key_previous_window);
- key_bind("left_window", "Window in left", "ALT-Left", NULL, (SIGNAL_FUNC) key_left_window);
- key_bind("next_window", "Next window", "CTRL-N", NULL, (SIGNAL_FUNC) key_next_window);
- key_bind("right_window", "Window in right", "ALT-Right", NULL, (SIGNAL_FUNC) key_right_window);
- key_bind("upper_window", "Upper window", "ALT-Up", NULL, (SIGNAL_FUNC) key_upper_window);
- key_bind("lower_window", "Lower window", "ALT-Down", NULL, (SIGNAL_FUNC) key_lower_window);
- key_bind("active_window", "Go to next window with the highest activity", "ALT-A", NULL, (SIGNAL_FUNC) key_active_window);
- key_bind("next_window_item", "Next channel/query", "CTRL-X", NULL, (SIGNAL_FUNC) key_next_window_item);
+ key_bind("check_replaces", NULL, NULL, NULL, (SIGNAL_FUNC) key_check_replaces);
+
+ /* window managing */
+ key_bind("previous_window", "Previous window", "^P", NULL, (SIGNAL_FUNC) key_previous_window);
+ key_bind("left_window", "Window in left", "meta-left", NULL, (SIGNAL_FUNC) key_left_window);
+ key_bind("next_window", "Next window", "^N", NULL, (SIGNAL_FUNC) key_next_window);
+ key_bind("right_window", "Window in right", "meta-right", NULL, (SIGNAL_FUNC) key_right_window);
+ key_bind("upper_window", "Upper window", "meta-up", NULL, (SIGNAL_FUNC) key_upper_window);
+ key_bind("lower_window", "Lower window", "meta-down", NULL, (SIGNAL_FUNC) key_lower_window);
+ key_bind("active_window", "Go to next window with the highest activity", "meta-a", NULL, (SIGNAL_FUNC) key_active_window);
+ key_bind("next_window_item", "Next channel/query", "^X", NULL, (SIGNAL_FUNC) key_next_window_item);
key_bind("previous_window_item", "Previous channel/query", NULL, NULL, (SIGNAL_FUNC) key_previous_window_item);
- key_bind("refresh_screen", "Redraw screen", "CTRL-L", NULL, (SIGNAL_FUNC) irssi_redraw);
- key_bind("scroll_backward", "Previous page", "Prior", NULL, (SIGNAL_FUNC) key_scroll_backward);
- key_bind("scroll_backward", NULL, "ALT-P", NULL, (SIGNAL_FUNC) key_scroll_backward);
- key_bind("scroll_forward", "Next page", "Next", NULL, (SIGNAL_FUNC) key_scroll_forward);
- key_bind("scroll_forward", NULL, "ALT-N", NULL, (SIGNAL_FUNC) key_scroll_forward);
+ key_bind("refresh_screen", "Redraw screen", "^L", NULL, (SIGNAL_FUNC) irssi_redraw);
+ key_bind("scroll_backward", "Previous page", "prior", NULL, (SIGNAL_FUNC) key_scroll_backward);
+ key_bind("scroll_backward", NULL, "meta-p", NULL, (SIGNAL_FUNC) key_scroll_backward);
+ key_bind("scroll_forward", "Next page", "next", NULL, (SIGNAL_FUNC) key_scroll_forward);
+ key_bind("scroll_forward", NULL, "meta-n", NULL, (SIGNAL_FUNC) key_scroll_forward);
key_bind("scroll_start", "Beginning of the window", "", NULL, (SIGNAL_FUNC) key_scroll_start);
key_bind("scroll_end", "End of the window", "", NULL, (SIGNAL_FUNC) key_scroll_end);
- key_bind("special_char", "Insert special character", "CTRL-B", "\002", (SIGNAL_FUNC) key_addchar);
- key_bind("special_char", NULL, "CTRL--", "\037", (SIGNAL_FUNC) key_addchar);
- key_bind("special_char", NULL, "CTRL-C", "\003", (SIGNAL_FUNC) key_addchar);
- key_bind("special_char", NULL, "CTRL-V", "\026", (SIGNAL_FUNC) key_addchar);
- key_bind("special_char", NULL, "CTRL-G", "\007", (SIGNAL_FUNC) key_addchar);
- key_bind("special_char", NULL, "CTRL-O", "\017", (SIGNAL_FUNC) key_addchar);
+ /* inserting special input characters to line.. */
+ key_bind("special_char", "Insert special character", "^B", "\002", (SIGNAL_FUNC) key_addchar);
+ key_bind("special_char", NULL, "^-", "\037", NULL);
+ key_bind("special_char", NULL, "^C", "\003", NULL);
+ key_bind("special_char", NULL, "^V", "\026", NULL);
+ key_bind("special_char", NULL, "^G", "\007", NULL);
+ key_bind("special_char", NULL, "^O", "\017", NULL);
+
+ key_bind("multi", NULL, "return", "check_replaces;send_line", NULL);
for (n = 0; changekeys[n] != '\0'; n++) {
- key = g_strdup_printf("ALT-%c", changekeys[n]);
+ key = g_strdup_printf("meta-%c", changekeys[n]);
ltoa(data, n+1);
key_bind("change_window", "Change window", key, data, (SIGNAL_FUNC) key_change_window);
g_free(key);
}
+ key_configure_thaw();
+
signal_add("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed);
signal_add("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect);
}
@@ -653,6 +616,8 @@ void gui_readline_deinit(void)
g_free_not_null(cutbuffer);
g_source_remove(readtag);
+ key_configure_freeze();
+
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);
@@ -693,6 +658,9 @@ void gui_readline_deinit(void)
key_unbind("special_char", (SIGNAL_FUNC) key_addchar);
key_unbind("change_window", (SIGNAL_FUNC) key_change_window);
+ keyboard_destroy(keyboard);
+
+ key_configure_thaw();
signal_remove("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed);
signal_remove("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect);
diff --git a/src/fe-text/screen.c b/src/fe-text/screen.c
index ba1651e3..5f24dfce 100644
--- a/src/fe-text/screen.c
+++ b/src/fe-text/screen.c
@@ -139,7 +139,7 @@ static int init_curses(void)
#ifdef HAVE_CURSES_IDCOK
idcok(stdscr, 1);
#endif
- intrflush(stdscr, FALSE); nodelay(stdscr, TRUE); keypad(stdscr, 1);
+ intrflush(stdscr, FALSE); nodelay(stdscr, TRUE);
if (has_colors())
start_color();