summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-04-15 16:40:08 +0200
committerSebastien Helleu <flashcode@flashtux.org>2008-04-15 16:40:08 +0200
commitdae4068a0e1639f351c89b6b8f97a8036d411228 (patch)
treeb8be49bed2b9ccb9222eb74cabb85dd418c41df9 /src/gui
parent26f55917322c5177efc20c9763ef47fa8e2505ee (diff)
downloadweechat-dae4068a0e1639f351c89b6b8f97a8036d411228.zip
Added keys by buffer (useful for buffers with free content that need own keys)
These keys can be set thru API function "buffer_set", for example: weechat_buffer_set(my_buffer, "key_bind_meta2-A", "/mycommand up"); weechat_buffer_set(my_buffer, "key_bind_meta2-B", "/mycommand down"); weechat_buffer_set(my_buffer, "key_unbind_meta2-B", ""); weechat_buffer_set(my_buffer, "key_unbind_*", ""); These keys are volatile and not saved in any config file. So they must be set when buffer is open.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-chat.c7
-rw-r--r--src/gui/curses/gui-curses-keyboard.c194
-rw-r--r--src/gui/curses/gui-curses-window.c2
-rw-r--r--src/gui/gui-bar.c2
-rw-r--r--src/gui/gui-buffer.c25
-rw-r--r--src/gui/gui-buffer.h4
-rw-r--r--src/gui/gui-keyboard.c123
-rw-r--r--src/gui/gui-keyboard.h16
8 files changed, 232 insertions, 141 deletions
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index b17b9bcdc..497a25ac2 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -1002,6 +1002,8 @@ void
gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
int y)
{
+ int pair;
+
/* reset color & style for a new line */
gui_chat_reset_style (window);
@@ -1015,6 +1017,11 @@ gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
gui_chat_display_word_raw (window, line->message,
window->win_chat_width, 1);
+
+ pair = (GUI_CURSES(window)->current_style_bg < 0) ?
+ 63 : GUI_CURSES(window)->current_style_bg * 8;
+ wbkgdset (GUI_CURSES(window)->win_chat, ' ' | COLOR_PAIR (pair));
+ wclrtoeol (GUI_CURSES(window)->win_chat);
}
/*
diff --git a/src/gui/curses/gui-curses-keyboard.c b/src/gui/curses/gui-curses-keyboard.c
index 0c337da60..73e8ca608 100644
--- a/src/gui/curses/gui-curses-keyboard.c
+++ b/src/gui/curses/gui-curses-keyboard.c
@@ -52,108 +52,108 @@ gui_keyboard_default_bindings ()
char key_str[32], command[32];
/* keys bound with internal functions */
- gui_keyboard_bind (/* RC */ "ctrl-M", "return");
- gui_keyboard_bind (/* RC */ "ctrl-J", "return");
- gui_keyboard_bind (/* tab */ "ctrl-I", "tab");
- gui_keyboard_bind (/* s-tab */ "meta2-Z", "tab_previous");
- gui_keyboard_bind (/* basckpace */ "ctrl-H", "backspace");
- gui_keyboard_bind (/* basckpace */ "ctrl-?", "backspace");
- gui_keyboard_bind (/* del */ "meta2-3~", "delete");
- gui_keyboard_bind (/* ^D */ "ctrl-D", "delete");
- gui_keyboard_bind (/* ^K */ "ctrl-K", "delete_end_line");
- gui_keyboard_bind (/* ^U */ "ctrl-U", "delete_beginning_line");
- gui_keyboard_bind (/* ^W */ "ctrl-W", "delete_previous_word");
- gui_keyboard_bind (/* ^Y */ "ctrl-Y", "clipboard_paste");
- gui_keyboard_bind (/* ^T */ "ctrl-T", "transpose_chars");
- gui_keyboard_bind (/* home */ "meta2-1~", "home");
- gui_keyboard_bind (/* home */ "meta2-H", "home");
- gui_keyboard_bind (/* home */ "meta2-7~", "home");
- gui_keyboard_bind (/* ^A */ "ctrl-A", "home");
- gui_keyboard_bind (/* end */ "meta2-4~", "end");
- gui_keyboard_bind (/* end */ "meta2-F", "end");
- gui_keyboard_bind (/* end */ "meta2-8~", "end");
- gui_keyboard_bind (/* ^E */ "ctrl-E", "end");
- gui_keyboard_bind (/* left */ "meta2-D", "left");
- gui_keyboard_bind (/* ^B */ "ctrl-B", "left");
- gui_keyboard_bind (/* right */ "meta2-C", "right");
- gui_keyboard_bind (/* ^F */ "ctrl-F", "right");
- gui_keyboard_bind (/* up */ "meta2-A", "up");
- gui_keyboard_bind (/* ^up */ "meta-Oa", "up_global");
- gui_keyboard_bind (/* down */ "meta2-B", "down");
- gui_keyboard_bind (/* ^down */ "meta-Ob", "down_global");
- gui_keyboard_bind (/* pgup */ "meta2-5~", "page_up");
- gui_keyboard_bind (/* pgup */ "meta2-I", "page_up");
- gui_keyboard_bind (/* pgdn */ "meta2-6~", "page_down");
- gui_keyboard_bind (/* pgdn */ "meta2-G", "page_down");
- gui_keyboard_bind (/* m-pgup */ "meta-meta2-5~", "scroll_up");
- gui_keyboard_bind (/* m-pgdn */ "meta-meta2-6~", "scroll_down");
- gui_keyboard_bind (/* m-home */ "meta-meta2-1~", "scroll_top");
- gui_keyboard_bind (/* m-end */ "meta-meta2-4~", "scroll_bottom");
- gui_keyboard_bind (/* F9 */ "meta2-20~", "scroll_topic_left");
- gui_keyboard_bind (/* F10 */ "meta2-21~", "scroll_topic_right");
- gui_keyboard_bind (/* F11 */ "meta2-23~", "nick_page_up");
- gui_keyboard_bind (/* F12 */ "meta2-24~", "nick_page_down");
- gui_keyboard_bind (/* m-F11 */ "meta-meta2-23~", "nick_beginning");
- gui_keyboard_bind (/* m-F12 */ "meta-meta2-24~", "nick_end");
- gui_keyboard_bind (/* ^L */ "ctrl-L", "refresh");
- gui_keyboard_bind (/* m-a */ "meta-a", "jump_smart");
- gui_keyboard_bind (/* m-b */ "meta-b", "previous_word");
- gui_keyboard_bind (/* ^left */ "meta-Od", "previous_word");
- gui_keyboard_bind (/* m-d */ "meta-d", "delete_next_word");
- gui_keyboard_bind (/* m-f */ "meta-f", "next_word");
- gui_keyboard_bind (/* ^right */ "meta-Oc", "next_word");
- gui_keyboard_bind (/* m-h */ "meta-h", "hotlist_clear");
- gui_keyboard_bind (/* m-i */ "meta-i" , "infobar_clear");
- gui_keyboard_bind (/* m-j,m-d */ "meta-jmeta-d", "jump_dcc");
- gui_keyboard_bind (/* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer");
- gui_keyboard_bind (/* m-j,m-p */ "meta-jmeta-p", "jump_previous_buffer");
- gui_keyboard_bind (/* m-j,m-s */ "meta-jmeta-s", "jump_server");
- gui_keyboard_bind (/* m-j,m-x */ "meta-jmeta-x", "jump_next_server");
- gui_keyboard_bind (/* m-k */ "meta-k", "grab_key");
- gui_keyboard_bind (/* m-n */ "meta-n", "scroll_next_highlight");
- gui_keyboard_bind (/* m-p */ "meta-p", "scroll_previous_highlight");
- gui_keyboard_bind (/* m-r */ "meta-r", "delete_line");
- gui_keyboard_bind (/* m-s */ "meta-s", "switch_server");
- gui_keyboard_bind (/* m-u */ "meta-u", "scroll_unread");
- gui_keyboard_bind (/* ^S^U */ "ctrl-Sctrl-U", "set_unread");
- gui_keyboard_bind (/* ^R */ "ctrl-R", "search_text");
- gui_keyboard_bind (/* ^Cb */ "ctrl-Cb", "insert \\x02");
- gui_keyboard_bind (/* ^Cc */ "ctrl-Cc", "insert \\x03");
- gui_keyboard_bind (/* ^Co */ "ctrl-Co", "insert \\x0F");
- gui_keyboard_bind (/* ^Cr */ "ctrl-Cr", "insert \\x12");
- gui_keyboard_bind (/* ^Cu */ "ctrl-Cu", "insert \\x15");
+ gui_keyboard_bind (NULL, /* RC */ "ctrl-M", "return");
+ gui_keyboard_bind (NULL, /* RC */ "ctrl-J", "return");
+ gui_keyboard_bind (NULL, /* tab */ "ctrl-I", "tab");
+ gui_keyboard_bind (NULL, /* s-tab */ "meta2-Z", "tab_previous");
+ gui_keyboard_bind (NULL, /* basckpace */ "ctrl-H", "backspace");
+ gui_keyboard_bind (NULL, /* basckpace */ "ctrl-?", "backspace");
+ gui_keyboard_bind (NULL, /* del */ "meta2-3~", "delete");
+ gui_keyboard_bind (NULL, /* ^D */ "ctrl-D", "delete");
+ gui_keyboard_bind (NULL, /* ^K */ "ctrl-K", "delete_end_line");
+ gui_keyboard_bind (NULL, /* ^U */ "ctrl-U", "delete_beginning_line");
+ gui_keyboard_bind (NULL, /* ^W */ "ctrl-W", "delete_previous_word");
+ gui_keyboard_bind (NULL, /* ^Y */ "ctrl-Y", "clipboard_paste");
+ gui_keyboard_bind (NULL, /* ^T */ "ctrl-T", "transpose_chars");
+ gui_keyboard_bind (NULL, /* home */ "meta2-1~", "home");
+ gui_keyboard_bind (NULL, /* home */ "meta2-H", "home");
+ gui_keyboard_bind (NULL, /* home */ "meta2-7~", "home");
+ gui_keyboard_bind (NULL, /* ^A */ "ctrl-A", "home");
+ gui_keyboard_bind (NULL, /* end */ "meta2-4~", "end");
+ gui_keyboard_bind (NULL, /* end */ "meta2-F", "end");
+ gui_keyboard_bind (NULL, /* end */ "meta2-8~", "end");
+ gui_keyboard_bind (NULL, /* ^E */ "ctrl-E", "end");
+ gui_keyboard_bind (NULL, /* left */ "meta2-D", "left");
+ gui_keyboard_bind (NULL, /* ^B */ "ctrl-B", "left");
+ gui_keyboard_bind (NULL, /* right */ "meta2-C", "right");
+ gui_keyboard_bind (NULL, /* ^F */ "ctrl-F", "right");
+ gui_keyboard_bind (NULL, /* up */ "meta2-A", "up");
+ gui_keyboard_bind (NULL, /* ^up */ "meta-Oa", "up_global");
+ gui_keyboard_bind (NULL, /* down */ "meta2-B", "down");
+ gui_keyboard_bind (NULL, /* ^down */ "meta-Ob", "down_global");
+ gui_keyboard_bind (NULL, /* pgup */ "meta2-5~", "page_up");
+ gui_keyboard_bind (NULL, /* pgup */ "meta2-I", "page_up");
+ gui_keyboard_bind (NULL, /* pgdn */ "meta2-6~", "page_down");
+ gui_keyboard_bind (NULL, /* pgdn */ "meta2-G", "page_down");
+ gui_keyboard_bind (NULL, /* m-pgup */ "meta-meta2-5~", "scroll_up");
+ gui_keyboard_bind (NULL, /* m-pgdn */ "meta-meta2-6~", "scroll_down");
+ gui_keyboard_bind (NULL, /* m-home */ "meta-meta2-1~", "scroll_top");
+ gui_keyboard_bind (NULL, /* m-end */ "meta-meta2-4~", "scroll_bottom");
+ gui_keyboard_bind (NULL, /* F9 */ "meta2-20~", "scroll_topic_left");
+ gui_keyboard_bind (NULL, /* F10 */ "meta2-21~", "scroll_topic_right");
+ gui_keyboard_bind (NULL, /* F11 */ "meta2-23~", "nick_page_up");
+ gui_keyboard_bind (NULL, /* F12 */ "meta2-24~", "nick_page_down");
+ gui_keyboard_bind (NULL, /* m-F11 */ "meta-meta2-23~", "nick_beginning");
+ gui_keyboard_bind (NULL, /* m-F12 */ "meta-meta2-24~", "nick_end");
+ gui_keyboard_bind (NULL, /* ^L */ "ctrl-L", "refresh");
+ gui_keyboard_bind (NULL, /* m-a */ "meta-a", "jump_smart");
+ gui_keyboard_bind (NULL, /* m-b */ "meta-b", "previous_word");
+ gui_keyboard_bind (NULL, /* ^left */ "meta-Od", "previous_word");
+ gui_keyboard_bind (NULL, /* m-d */ "meta-d", "delete_next_word");
+ gui_keyboard_bind (NULL, /* m-f */ "meta-f", "next_word");
+ gui_keyboard_bind (NULL, /* ^right */ "meta-Oc", "next_word");
+ gui_keyboard_bind (NULL, /* m-h */ "meta-h", "hotlist_clear");
+ gui_keyboard_bind (NULL, /* m-i */ "meta-i" , "infobar_clear");
+ gui_keyboard_bind (NULL, /* m-j,m-d */ "meta-jmeta-d", "jump_dcc");
+ gui_keyboard_bind (NULL, /* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer");
+ gui_keyboard_bind (NULL, /* m-j,m-p */ "meta-jmeta-p", "jump_previous_buffer");
+ gui_keyboard_bind (NULL, /* m-j,m-s */ "meta-jmeta-s", "jump_server");
+ gui_keyboard_bind (NULL, /* m-j,m-x */ "meta-jmeta-x", "jump_next_server");
+ gui_keyboard_bind (NULL, /* m-k */ "meta-k", "grab_key");
+ gui_keyboard_bind (NULL, /* m-n */ "meta-n", "scroll_next_highlight");
+ gui_keyboard_bind (NULL, /* m-p */ "meta-p", "scroll_previous_highlight");
+ gui_keyboard_bind (NULL, /* m-r */ "meta-r", "delete_line");
+ gui_keyboard_bind (NULL, /* m-s */ "meta-s", "switch_server");
+ gui_keyboard_bind (NULL, /* m-u */ "meta-u", "scroll_unread");
+ gui_keyboard_bind (NULL, /* ^S^U */ "ctrl-Sctrl-U", "set_unread");
+ gui_keyboard_bind (NULL, /* ^R */ "ctrl-R", "search_text");
+ gui_keyboard_bind (NULL, /* ^Cb */ "ctrl-Cb", "insert \\x02");
+ gui_keyboard_bind (NULL, /* ^Cc */ "ctrl-Cc", "insert \\x03");
+ gui_keyboard_bind (NULL, /* ^Co */ "ctrl-Co", "insert \\x0F");
+ gui_keyboard_bind (NULL, /* ^Cr */ "ctrl-Cr", "insert \\x12");
+ gui_keyboard_bind (NULL, /* ^Cu */ "ctrl-Cu", "insert \\x15");
/* keys bound with commands */
- gui_keyboard_bind (/* m-left */ "meta-meta2-D", "/buffer -1");
- gui_keyboard_bind (/* m-left (kde) */ "meta2-1;3D", "/buffer -1");
- gui_keyboard_bind (/* F5 */ "meta2-15~", "/buffer -1");
- gui_keyboard_bind (/* m-right */ "meta-meta2-C", "/buffer +1");
- gui_keyboard_bind (/* m-right (kde) */ "meta2-1;3C", "/buffer +1");
- gui_keyboard_bind (/* F6 */ "meta2-17~", "/buffer +1");
- gui_keyboard_bind (/* F7 */ "meta2-18~", "/window -1");
- gui_keyboard_bind (/* F8 */ "meta2-19~", "/window +1");
- gui_keyboard_bind (/* m-w,m-up */ "meta-wmeta-meta2-A", "/window up");
- gui_keyboard_bind (/* m-w,m-down */ "meta-wmeta-meta2-B", "/window down");
- gui_keyboard_bind (/* m-w,m-left */ "meta-wmeta-meta2-D", "/window left");
- gui_keyboard_bind (/* m-w,m-right */ "meta-wmeta-meta2-C", "/window right");
- gui_keyboard_bind (/* m-= */ "meta-=", "/filter toggle");
- gui_keyboard_bind (/* m-0 */ "meta-0", "/buffer 10");
- gui_keyboard_bind (/* m-1 */ "meta-1", "/buffer 1");
- gui_keyboard_bind (/* m-2 */ "meta-2", "/buffer 2");
- gui_keyboard_bind (/* m-3 */ "meta-3", "/buffer 3");
- gui_keyboard_bind (/* m-4 */ "meta-4", "/buffer 4");
- gui_keyboard_bind (/* m-5 */ "meta-5", "/buffer 5");
- gui_keyboard_bind (/* m-6 */ "meta-6", "/buffer 6");
- gui_keyboard_bind (/* m-7 */ "meta-7", "/buffer 7");
- gui_keyboard_bind (/* m-8 */ "meta-8", "/buffer 8");
- gui_keyboard_bind (/* m-9 */ "meta-9", "/buffer 9");
+ gui_keyboard_bind (NULL, /* m-left */ "meta-meta2-D", "/buffer -1");
+ gui_keyboard_bind (NULL, /* m-left (kde) */ "meta2-1;3D", "/buffer -1");
+ gui_keyboard_bind (NULL, /* F5 */ "meta2-15~", "/buffer -1");
+ gui_keyboard_bind (NULL, /* m-right */ "meta-meta2-C", "/buffer +1");
+ gui_keyboard_bind (NULL, /* m-right (kde) */ "meta2-1;3C", "/buffer +1");
+ gui_keyboard_bind (NULL, /* F6 */ "meta2-17~", "/buffer +1");
+ gui_keyboard_bind (NULL, /* F7 */ "meta2-18~", "/window -1");
+ gui_keyboard_bind (NULL, /* F8 */ "meta2-19~", "/window +1");
+ gui_keyboard_bind (NULL, /* m-w,m-up */ "meta-wmeta-meta2-A", "/window up");
+ gui_keyboard_bind (NULL, /* m-w,m-down */ "meta-wmeta-meta2-B", "/window down");
+ gui_keyboard_bind (NULL, /* m-w,m-left */ "meta-wmeta-meta2-D", "/window left");
+ gui_keyboard_bind (NULL, /* m-w,m-right */ "meta-wmeta-meta2-C", "/window right");
+ gui_keyboard_bind (NULL, /* m-= */ "meta-=", "/filter toggle");
+ gui_keyboard_bind (NULL, /* m-0 */ "meta-0", "/buffer 10");
+ gui_keyboard_bind (NULL, /* m-1 */ "meta-1", "/buffer 1");
+ gui_keyboard_bind (NULL, /* m-2 */ "meta-2", "/buffer 2");
+ gui_keyboard_bind (NULL, /* m-3 */ "meta-3", "/buffer 3");
+ gui_keyboard_bind (NULL, /* m-4 */ "meta-4", "/buffer 4");
+ gui_keyboard_bind (NULL, /* m-5 */ "meta-5", "/buffer 5");
+ gui_keyboard_bind (NULL, /* m-6 */ "meta-6", "/buffer 6");
+ gui_keyboard_bind (NULL, /* m-7 */ "meta-7", "/buffer 7");
+ gui_keyboard_bind (NULL, /* m-8 */ "meta-8", "/buffer 8");
+ gui_keyboard_bind (NULL, /* m-9 */ "meta-9", "/buffer 9");
/* bind meta-j + {01..99} to switch to buffers # > 10 */
for (i = 1; i < 100; i++)
{
sprintf (key_str, "meta-j%02d", i);
sprintf (command, "/buffer %d", i);
- gui_keyboard_bind (key_str, command);
+ gui_keyboard_bind (NULL, key_str, command);
}
}
@@ -174,9 +174,6 @@ gui_keyboard_flush ()
if (gui_keyboard_buffer_size > 0)
gui_keyboard_last_activity_time = time (NULL);
- if (gui_key_grab && (gui_key_grab_count > 0))
- gui_keyboard_grab_end ();
-
for (i = 0; i < gui_keyboard_buffer_size; i++)
{
key = gui_keyboard_buffer[i];
@@ -332,6 +329,9 @@ gui_keyboard_flush ()
free (input_old);
}
+ if (gui_key_grab && (gui_key_grab_count > 0))
+ gui_keyboard_grab_end ();
+
gui_keyboard_buffer_reset ();
}
}
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index 23798e3df..38c7f69e6 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -194,7 +194,7 @@ gui_window_curses_clear (WINDOW *window, int num_color)
if (!gui_ok)
return;
- wbkgdset(window, ' ' | COLOR_PAIR (gui_color_get_pair (num_color)));
+ wbkgdset (window, ' ' | COLOR_PAIR (gui_color_get_pair (num_color)));
werase (window);
wmove (window, 0, 0);
}
diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c
index 976cfa4a7..292f8e6c8 100644
--- a/src/gui/gui-bar.c
+++ b/src/gui/gui-bar.c
@@ -901,12 +901,10 @@ gui_bar_use_temp_bars ()
for (ptr_temp_bar = gui_temp_bars; ptr_temp_bar;
ptr_temp_bar = ptr_temp_bar->next_bar)
{
- log_printf ("use temp bar");
if (ptr_temp_bar->type && ptr_temp_bar->position
&& ptr_temp_bar->size && ptr_temp_bar->separator
&& ptr_temp_bar->items)
{
- log_printf ("creation barre %s", ptr_temp_bar->name);
gui_bar_new_with_options (NULL, ptr_temp_bar->name,
ptr_temp_bar->type,
ptr_temp_bar->position,
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 51fb06960..ba6883123 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -46,6 +46,7 @@
#include "gui-history.h"
#include "gui-hotlist.h"
#include "gui-input.h"
+#include "gui-keyboard.h"
#include "gui-main.h"
#include "gui-nicklist.h"
#include "gui-status.h"
@@ -163,6 +164,10 @@ gui_buffer_new (struct t_weechat_plugin *plugin, char *category, char *name,
new_buffer->text_search_found = 0;
new_buffer->text_search_input = NULL;
+ /* keys */
+ new_buffer->keys = NULL;
+ new_buffer->last_key = NULL;
+
/* add buffer to buffers list */
new_buffer->prev_buffer = last_gui_buffer;
if (gui_buffers)
@@ -460,6 +465,17 @@ gui_buffer_set (struct t_gui_buffer *buffer, char *property, char *value)
gui_hotlist_add (buffer, number, NULL, 1);
}
}
+ else if (string_strncasecmp (property, "key_bind_", 9) == 0)
+ {
+ gui_keyboard_bind (buffer, property + 9, value);
+ }
+ else if (string_strncasecmp (property, "key_unbind_", 11) == 0)
+ {
+ if (strcmp (property + 11, "*") == 0)
+ gui_keyboard_free_all (&buffer->keys, &buffer->last_key);
+ else
+ gui_keyboard_unbind (buffer, property + 11);
+ }
}
/*
@@ -747,6 +763,7 @@ gui_buffer_close (struct t_gui_buffer *buffer, int switch_to_another)
if (buffer->text_search_input)
free (buffer->text_search_input);
gui_nicklist_remove_all (buffer);
+ gui_keyboard_free_all (&buffer->keys, &buffer->last_key);
/* remove buffer from buffers list */
if (buffer->prev_buffer)
@@ -1072,6 +1089,14 @@ gui_buffer_print_log ()
log_printf ("");
log_printf (" => nicklist_root (addr:0x%x):", ptr_buffer->nicklist_root);
gui_nicklist_print_log (ptr_buffer->nicklist_root, 0);
+
+ if (ptr_buffer->keys)
+ {
+ log_printf ("");
+ log_printf (" => keys = 0x%x, last_key = 0x%x:",
+ ptr_buffer->keys, ptr_buffer->last_key);
+ gui_keyboard_print_log (ptr_buffer);
+ }
log_printf ("");
log_printf (" => last 100 lines:");
diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h
index 89a63a107..21ac6f776 100644
--- a/src/gui/gui-buffer.h
+++ b/src/gui/gui-buffer.h
@@ -129,6 +129,10 @@ struct t_gui_buffer
int text_search_found; /* 1 if text found, otherwise 0 */
char *text_search_input; /* input saved before text search */
+ /* keys associated to buffer */
+ struct t_gui_key *keys; /* keys specific to buffer */
+ struct t_gui_key *last_key; /* last key for buffer */
+
/* link to previous/next buffer */
struct t_gui_buffer *prev_buffer; /* link to previous buffer */
struct t_gui_buffer *next_buffer; /* link to next buffer */
diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c
index 00b6aeda7..c2ed6a1f3 100644
--- a/src/gui/gui-keyboard.c
+++ b/src/gui/gui-keyboard.c
@@ -324,11 +324,11 @@ gui_keyboard_get_expanded_name (char *key)
*/
struct t_gui_key *
-gui_keyboard_find_pos (struct t_gui_key *key)
+gui_keyboard_find_pos (struct t_gui_key *keys, struct t_gui_key *key)
{
struct t_gui_key *ptr_key;
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+ for (ptr_key = keys; ptr_key; ptr_key = ptr_key->next_key)
{
if (string_strcasecmp (key->key, ptr_key->key) < 0)
return ptr_key;
@@ -341,13 +341,14 @@ gui_keyboard_find_pos (struct t_gui_key *key)
*/
void
-gui_keyboard_insert_sorted (struct t_gui_key *key)
+gui_keyboard_insert_sorted (struct t_gui_key **keys, struct t_gui_key **last_key,
+ struct t_gui_key *key)
{
struct t_gui_key *pos_key;
- if (gui_keys)
+ if (*keys)
{
- pos_key = gui_keyboard_find_pos (key);
+ pos_key = gui_keyboard_find_pos (*keys, key);
if (pos_key)
{
@@ -357,33 +358,36 @@ gui_keyboard_insert_sorted (struct t_gui_key *key)
if (pos_key->prev_key)
pos_key->prev_key->next_key = key;
else
- gui_keys = key;
+ *keys = key;
pos_key->prev_key = key;
}
else
{
/* add key to the end */
- key->prev_key = last_gui_key;
+ key->prev_key = *last_key;
key->next_key = NULL;
- last_gui_key->next_key = key;
- last_gui_key = key;
+ (*last_key)->next_key = key;
+ *last_key = key;
}
}
else
{
key->prev_key = NULL;
key->next_key = NULL;
- gui_keys = key;
- last_gui_key = key;
+ *keys = key;
+ *last_key = key;
}
}
/*
* gui_keyboard_new: add a new key in keys list
+ * if buffer is not null, then key is specific to buffer
+ * otherwise it's general key (for most keys)
*/
struct t_gui_key *
-gui_keyboard_new (char *key, char *command, t_gui_key_func *function,
+gui_keyboard_new (struct t_gui_buffer *buffer,
+ char *key, char *command, t_gui_key_func *function,
char *args)
{
struct t_gui_key *new_key;
@@ -413,7 +417,11 @@ gui_keyboard_new (char *key, char *command, t_gui_key_func *function,
}
else
new_key->args = NULL;
- gui_keyboard_insert_sorted (new_key);
+
+ if (buffer)
+ gui_keyboard_insert_sorted (&buffer->keys, &buffer->last_key, new_key);
+ else
+ gui_keyboard_insert_sorted (&gui_keys, &last_gui_key, new_key);
}
else
return NULL;
@@ -426,11 +434,12 @@ gui_keyboard_new (char *key, char *command, t_gui_key_func *function,
*/
struct t_gui_key *
-gui_keyboard_search (char *key)
+gui_keyboard_search (struct t_gui_buffer *buffer, char *key)
{
struct t_gui_key *ptr_key;
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+ for (ptr_key = (buffer) ? buffer->keys : gui_keys; ptr_key;
+ ptr_key = ptr_key->next_key)
{
if (string_strcasecmp (ptr_key->key, key) == 0)
return ptr_key;
@@ -463,11 +472,12 @@ gui_keyboard_cmp (char *key, char *search)
*/
struct t_gui_key *
-gui_keyboard_search_part (char *key)
+gui_keyboard_search_part (struct t_gui_buffer *buffer, char *key)
{
struct t_gui_key *ptr_key;
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+ for (ptr_key = (buffer) ? buffer->keys : gui_keys; ptr_key;
+ ptr_key = ptr_key->next_key)
{
if (gui_keyboard_cmp (ptr_key->key, key) == 0)
return ptr_key;
@@ -521,10 +531,12 @@ gui_keyboard_function_search_by_ptr (t_gui_key_func *function)
/*
* gui_keyboard_bind: bind a key to a function (command or special function)
+ * if buffer is not null, then key is specific to buffer
+ * otherwise it's general key (for most keys)
*/
struct t_gui_key *
-gui_keyboard_bind (char *key, char *command)
+gui_keyboard_bind (struct t_gui_buffer *buffer, char *key, char *command)
{
t_gui_key_func *ptr_function;
struct t_gui_key *new_key;
@@ -566,9 +578,10 @@ gui_keyboard_bind (char *key, char *command)
}
}
- gui_keyboard_unbind (key);
+ gui_keyboard_unbind (buffer, key);
- new_key = gui_keyboard_new (key,
+ new_key = gui_keyboard_new (buffer,
+ key,
(ptr_function) ? NULL : command,
ptr_function,
ptr_args);
@@ -586,16 +599,21 @@ gui_keyboard_bind (char *key, char *command)
*/
int
-gui_keyboard_unbind (char *key)
+gui_keyboard_unbind (struct t_gui_buffer *buffer, char *key)
{
struct t_gui_key *ptr_key;
char *internal_code;
internal_code = gui_keyboard_get_internal_code (key);
- ptr_key = gui_keyboard_search ((internal_code) ? internal_code : key);
+ ptr_key = gui_keyboard_search (buffer, (internal_code) ? internal_code : key);
if (ptr_key)
- gui_keyboard_free (ptr_key);
+ {
+ if (buffer)
+ gui_keyboard_free (&buffer->keys, &buffer->last_key, ptr_key);
+ else
+ gui_keyboard_free (&gui_keys, &last_gui_key, ptr_key);
+ }
if (internal_code)
free (internal_code);
@@ -628,8 +646,14 @@ gui_keyboard_pressed (char *key_str)
return 0;
}
- /* look for key combo in key table */
- ptr_key = gui_keyboard_search_part (gui_key_combo_buffer);
+ /* look for key combo in key table for current buffer */
+ ptr_key = gui_keyboard_search_part (gui_current_window->buffer,
+ gui_key_combo_buffer);
+ /* if key is not found for buffer, then look in general table */
+ if (!ptr_key)
+ ptr_key = gui_keyboard_search_part (NULL, gui_key_combo_buffer);
+
+ /* if key is found, then execute action */
if (ptr_key)
{
if (string_strcasecmp (ptr_key->key, gui_key_combo_buffer) == 0)
@@ -683,7 +707,8 @@ gui_keyboard_pressed (char *key_str)
*/
void
-gui_keyboard_free (struct t_gui_key *key)
+gui_keyboard_free (struct t_gui_key **keys, struct t_gui_key **last_key,
+ struct t_gui_key *key)
{
/* free memory */
if (key->key)
@@ -695,13 +720,13 @@ gui_keyboard_free (struct t_gui_key *key)
/* remove key from keys list */
if (key->prev_key)
- key->prev_key->next_key = key->next_key;
+ (key->prev_key)->next_key = key->next_key;
if (key->next_key)
- key->next_key->prev_key = key->prev_key;
- if (gui_keys == key)
- gui_keys = key->next_key;
- if (last_gui_key == key)
- last_gui_key = key->prev_key;
+ (key->next_key)->prev_key = key->prev_key;
+ if (*keys == key)
+ *keys = key->next_key;
+ if (*last_key == key)
+ *last_key = key->prev_key;
free (key);
}
@@ -711,11 +736,11 @@ gui_keyboard_free (struct t_gui_key *key)
*/
void
-gui_keyboard_free_all ()
+gui_keyboard_free_all (struct t_gui_key **keys, struct t_gui_key **last_key)
{
- while (gui_keys)
+ while (*keys)
{
- gui_keyboard_free (gui_keys);
+ gui_keyboard_free (keys, last_key, *keys);
}
}
@@ -842,5 +867,31 @@ gui_keyboard_end ()
free (gui_keyboard_buffer);
/* free all keys */
- gui_keyboard_free_all ();
+ gui_keyboard_free_all (&gui_keys, &last_gui_key);
+}
+
+/*
+ * gui_keyboard_print_log: print key infos in log (usually for crash dump)
+ */
+
+void
+gui_keyboard_print_log (struct t_gui_buffer *buffer)
+{
+ struct t_gui_key *ptr_key;
+ char prefix[32];
+
+ snprintf (prefix, sizeof (prefix), "%s", (buffer) ? " " : "");
+
+ for (ptr_key = (buffer) ? buffer->keys : gui_keys; ptr_key;
+ ptr_key = ptr_key->next_key)
+ {
+ log_printf ("");
+ log_printf ("%s[key (addr:0x%x)]", prefix, ptr_key);
+ log_printf ("%skey. . . . . . . . . : '%s'", prefix, ptr_key->key);
+ log_printf ("%scommand. . . . . . . : '%s'", prefix, ptr_key->command);
+ log_printf ("%sfunction . . . . . . : 0x%x", prefix, ptr_key->function);
+ log_printf ("%sargs . . . . . . . . : '%s'", prefix, ptr_key->args);
+ log_printf ("%sprev_key . . . . . . : 0x%x", prefix, ptr_key->prev_key);
+ log_printf ("%snext_key . . . . . . : 0x%x", prefix, ptr_key->next_key);
+ }
}
diff --git a/src/gui/gui-keyboard.h b/src/gui/gui-keyboard.h
index 065d59f54..b726ec4b5 100644
--- a/src/gui/gui-keyboard.h
+++ b/src/gui/gui-keyboard.h
@@ -63,20 +63,26 @@ extern void gui_keyboard_grab_init ();
extern void gui_keyboard_grab_end ();
extern char *gui_keyboard_get_internal_code (char *key);
extern char *gui_keyboard_get_expanded_name (char *key);
-extern struct t_gui_key *gui_keyboard_search (char *key);
+extern struct t_gui_key *gui_keyboard_search (struct t_gui_buffer *buffer,
+ char *key);
extern t_gui_key_func *gui_keyboard_function_search_by_name (char *name);
extern char *gui_keyboard_function_search_by_ptr (t_gui_key_func *function);
-extern struct t_gui_key *gui_keyboard_bind (char *key, char *command);
-extern int gui_keyboard_unbind (char *key);
+extern struct t_gui_key *gui_keyboard_bind (struct t_gui_buffer *buffer,
+ char *key, char *command);
+extern int gui_keyboard_unbind (struct t_gui_buffer *buffer, char *key);
extern int gui_keyboard_pressed (char *key_str);
-extern void gui_keyboard_free (struct t_gui_key *key);
-extern void gui_keyboard_free_all ();
+extern void gui_keyboard_free (struct t_gui_key **keys,
+ struct t_gui_key **last_key,
+ struct t_gui_key *key);
+extern void gui_keyboard_free_all (struct t_gui_key **keys,
+ struct t_gui_key **last_key);
extern void gui_keyboard_buffer_reset ();
extern void gui_keyboard_buffer_add (int key);
extern int gui_keyboard_get_paste_lines ();
extern void gui_keyboard_paste_accept ();
extern void gui_keyboard_paste_cancel ();
extern void gui_keyboard_end ();
+extern void gui_keyboard_print_log (struct t_gui_buffer *buffer);
/* keyboard functions (GUI dependent) */