mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 04:13:32 +02:00
keyboard handling rewrite
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1462 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
5377dc90aa
commit
711c17b746
4 changed files with 581 additions and 240 deletions
|
|
@ -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 (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 < 256) {
|
||||
char str[2];
|
||||
|
||||
str[0] = toupper(key); str[1] = '\0';
|
||||
key_pressed(str, NULL);
|
||||
gui_entry_insert_char((char) key);
|
||||
}
|
||||
break;
|
||||
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 (!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;
|
||||
|
||||
str = gui_entry_get_text();
|
||||
if (*str == '\0') return;
|
||||
|
||||
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);
|
||||
keyboard = keyboard_create(NULL);
|
||||
key_configure_freeze();
|
||||
|
||||
key_bind("backward_history", "", "Up", NULL, (SIGNAL_FUNC) key_backward_history);
|
||||
key_bind("forward_history", "", "Down", NULL, (SIGNAL_FUNC) key_forward_history);
|
||||
key_bind("key", NULL, "^M", "return", (SIGNAL_FUNC) key_combo);
|
||||
key_bind("key", NULL, "^J", "return", (SIGNAL_FUNC) key_combo);
|
||||
|
||||
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);
|
||||
/* 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("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("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);
|
||||
|
||||
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);
|
||||
/* 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, 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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue