From 51ef22c2845892c6cee078ec29807fc0d1ecf29e Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Thu, 28 Jul 2011 15:36:39 +0200 Subject: [PATCH] core: improve mouse support: process utf-8 codes, add option weechat.look.mouse_timer_delay, remove key meta2-M, fix problem with iso chars when grabbing mouse codes --- ChangeLog | 6 +- doc/de/autogen/user/weechat_options.txt | 5 ++ doc/en/autogen/user/weechat_options.txt | 5 ++ doc/fr/autogen/user/weechat_options.txt | 5 ++ doc/it/autogen/user/weechat_options.txt | 5 ++ po/cs.po | 7 +- po/de.po | 7 +- po/es.po | 7 +- po/fr.po | 11 ++- po/hu.po | 7 +- po/it.po | 7 +- po/pl.po | 7 +- po/pt_BR.po | 7 +- po/ru.po | 7 +- po/weechat.pot | 7 +- src/core/wee-command.c | 6 -- src/core/wee-config.c | 7 ++ src/core/wee-config.h | 1 + src/gui/curses/gui-curses-key.c | 1 - src/gui/curses/gui-curses-mouse.c | 114 +++++++++++++++++++++--- src/gui/gui-key.c | 63 +++++++++---- src/gui/gui-key.h | 2 + src/gui/gui-mouse.c | 2 + src/gui/gui-mouse.h | 2 +- 24 files changed, 246 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d8cb7741..ee12786b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,15 +1,15 @@ WeeChat ChangeLog ================= Sébastien Helleu -v0.3.6-dev, 2011-07-27 +v0.3.6-dev, 2011-07-28 Version 0.3.6 (under dev!) -------------------------- * core: allow buffer name in /buffer close -* core: add support of mouse: new command /mouse, new option weechat.look.mouse - and new key context "mouse" (task #5435) +* core: add support of mouse: new command /mouse, new key context "mouse", + new options weechat.look.mouse and weechat.look.mouse_timer_delay (task #5435) * core: add command /cursor (free movement of cursor on screen), with key context "search" * core: automatic scroll direction in /bar scroll (x/y is now optional) diff --git a/doc/de/autogen/user/weechat_options.txt b/doc/de/autogen/user/weechat_options.txt index 772ba463e..ad4da6069 100644 --- a/doc/de/autogen/user/weechat_options.txt +++ b/doc/de/autogen/user/weechat_options.txt @@ -478,6 +478,11 @@ ** Typ: boolesch ** Werte: on, off (Standardwert: `off`) +* *weechat.look.mouse_timer_delay* +** Beschreibung: `delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay before processing event` +** Typ: integer +** Werte: 1 .. 10000 (Standardwert: `100`) + * *weechat.look.nickmode* ** Beschreibung: `Nickmode ((half)op/voice [@%+]) vor dem Nicknamen anzeigen` ** Typ: boolesch diff --git a/doc/en/autogen/user/weechat_options.txt b/doc/en/autogen/user/weechat_options.txt index 787bb77b4..88f1f8870 100644 --- a/doc/en/autogen/user/weechat_options.txt +++ b/doc/en/autogen/user/weechat_options.txt @@ -478,6 +478,11 @@ ** type: boolean ** values: on, off (default value: `off`) +* *weechat.look.mouse_timer_delay* +** description: `delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay before processing event` +** type: integer +** values: 1 .. 10000 (default value: `100`) + * *weechat.look.nickmode* ** description: `display nick mode ((half)op/voice) before each nick` ** type: boolean diff --git a/doc/fr/autogen/user/weechat_options.txt b/doc/fr/autogen/user/weechat_options.txt index 1c1ec44e4..c5eed781f 100644 --- a/doc/fr/autogen/user/weechat_options.txt +++ b/doc/fr/autogen/user/weechat_options.txt @@ -478,6 +478,11 @@ ** type: booléen ** valeurs: on, off (valeur par défaut: `off`) +* *weechat.look.mouse_timer_delay* +** description: `délai (en millisecondes) pour capturer un évènement de la souris: WeeChat attendra ce délai avant de traiter l'évènement` +** type: entier +** valeurs: 1 .. 10000 (valeur par défaut: `100`) + * *weechat.look.nickmode* ** description: `afficher le mode du pseudo ((half)op/voice) devant chaque utilisateur` ** type: booléen diff --git a/doc/it/autogen/user/weechat_options.txt b/doc/it/autogen/user/weechat_options.txt index 3a8127340..02b448a1b 100644 --- a/doc/it/autogen/user/weechat_options.txt +++ b/doc/it/autogen/user/weechat_options.txt @@ -478,6 +478,11 @@ ** tipo: bool ** valori: on, off (valore predefinito: `off`) +* *weechat.look.mouse_timer_delay* +** descrizione: `delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay before processing event` +** tipo: intero +** valori: 1 .. 10000 (valore predefinito: `100`) + * *weechat.look.nickmode* ** descrizione: `mostra modalità nick ((half)op/voice) prima di ogni nick` ** tipo: bool diff --git a/po/cs.po b/po/cs.po index 7d4154106..da80feb36 100644 --- a/po/cs.po +++ b/po/cs.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.6-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" "PO-Revision-Date: 2011-07-05 15:37+0200\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -2348,6 +2348,11 @@ msgstr "" msgid "enable mouse support at startup (to enable it now, see /help mouse)" msgstr "" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "zobrazit mód přezdívky ((částečný)op/voice) před každou přezdívkou" diff --git a/po/de.po b/po/de.po index 9e2908347..10abed28c 100644 --- a/po/de.po +++ b/po/de.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.6-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" "PO-Revision-Date: 2011-07-14 20:53+0100\n" "Last-Translator: Nils Görs\n" "Language-Team: weechat-dev \n" @@ -2474,6 +2474,11 @@ msgstr "" msgid "enable mouse support at startup (to enable it now, see /help mouse)" msgstr "" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "Nickmode ((half)op/voice [@%+]) vor dem Nicknamen anzeigen" diff --git a/po/es.po b/po/es.po index 5b80acc56..ba8eeb078 100644 --- a/po/es.po +++ b/po/es.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.6-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" "PO-Revision-Date: 2011-07-05 15:37+0200\n" "Last-Translator: Elián Hanisch \n" "Language-Team: weechat-dev \n" @@ -2380,6 +2380,11 @@ msgstr "" msgid "enable mouse support at startup (to enable it now, see /help mouse)" msgstr "" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "mostrar modo del usuario ((semi-)op/voz) antes de cada usuario" diff --git a/po/fr.po b/po/fr.po index 59ca181f7..f64697a48 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.6-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" -"PO-Revision-Date: 2011-07-27 12:56+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" +"PO-Revision-Date: 2011-07-28 14:58+0200\n" "Last-Translator: Sebastien Helleu \n" "Language-Team: weechat-dev \n" "Language: French\n" @@ -2457,6 +2457,13 @@ msgstr "" "activer le support de la souris au démarrage (pour l'activer maintenant, " "voir /help mouse)" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" +"délai (en millisecondes) pour capturer un évènement de la souris: WeeChat " +"attendra ce délai avant de traiter l'évènement" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "afficher le mode du pseudo ((half)op/voice) devant chaque utilisateur" diff --git a/po/hu.po b/po/hu.po index 11046350a..e62f50716 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.6-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" "PO-Revision-Date: 2011-05-15 10:51+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -2004,6 +2004,11 @@ msgstr "" msgid "enable mouse support at startup (to enable it now, see /help mouse)" msgstr "" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "a felhasználó módjának ((fél)operátor/voice) mutatása a név előtt" diff --git a/po/it.po b/po/it.po index 9e3be2bd2..d9e15eee4 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.6-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" "PO-Revision-Date: 2011-07-16 11:32+0200\n" "Last-Translator: Marco Paolone \n" "Language-Team: weechat-dev \n" @@ -2402,6 +2402,11 @@ msgstr "" msgid "enable mouse support at startup (to enable it now, see /help mouse)" msgstr "" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "mostra modalità nick ((half)op/voice) prima di ogni nick" diff --git a/po/pl.po b/po/pl.po index 0a79ebbb6..db502b2ea 100644 --- a/po/pl.po +++ b/po/pl.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.6-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" "PO-Revision-Date: 2011-07-05 15:38+0200\n" "Last-Translator: Krzysztof Koroscik \n" "Language-Team: weechat-dev \n" @@ -2377,6 +2377,11 @@ msgstr "" msgid "enable mouse support at startup (to enable it now, see /help mouse)" msgstr "" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "wyświetl atrybut nicku ((half)op/voice) przed każdym nickiem" diff --git a/po/pt_BR.po b/po/pt_BR.po index 37059132d..866289317 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.6-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" "PO-Revision-Date: 2011-05-15 10:52+0200\n" "Last-Translator: Ivan Sichmann Freitas \n" "Language-Team: weechat-dev \n" @@ -2355,6 +2355,11 @@ msgstr "" msgid "enable mouse support at startup (to enable it now, see /help mouse)" msgstr "" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "" diff --git a/po/ru.po b/po/ru.po index c041d9c85..8e33e5f97 100644 --- a/po/ru.po +++ b/po/ru.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.6-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" "PO-Revision-Date: 2011-05-15 10:52+0200\n" "Last-Translator: Pavel Shevchuk \n" "Language-Team: weechat-dev \n" @@ -2021,6 +2021,11 @@ msgstr "" msgid "enable mouse support at startup (to enable it now, see /help mouse)" msgstr "" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "отображать режим ника (op/voice) перед каждым ником" diff --git a/po/weechat.pot b/po/weechat.pot index 97f3a619a..e67c11d3d 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2011-07-27 12:55+0200\n" +"POT-Creation-Date: 2011-07-28 15:34+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1760,6 +1760,11 @@ msgstr "" msgid "enable mouse support at startup (to enable it now, see /help mouse)" msgstr "" +msgid "" +"delay (in milliseconds) to grab a mouse event: WeeChat will wait this delay " +"before processing event" +msgstr "" + msgid "display nick mode ((half)op/voice) before each nick" msgstr "" diff --git a/src/core/wee-command.c b/src/core/wee-command.c index bb29c987b..d5dc38ed2 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -3112,12 +3112,6 @@ COMMAND_CALLBACK(mouse) return WEECHAT_RC_OK; } - if (string_strcasecmp (argv[1], "grab") == 0) - { - gui_mouse_grab_init (); - return WEECHAT_RC_OK; - } - return WEECHAT_RC_OK; } diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 92e552528..cd4654027 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -110,6 +110,7 @@ struct t_config_option *config_look_item_time_format; struct t_config_option *config_look_jump_current_to_previous_buffer; struct t_config_option *config_look_jump_previous_buffer_when_closing; struct t_config_option *config_look_mouse; +struct t_config_option *config_look_mouse_timer_delay; struct t_config_option *config_look_nickmode; struct t_config_option *config_look_nickmode_empty; struct t_config_option *config_look_paste_max_lines; @@ -1801,6 +1802,12 @@ config_weechat_init_options () "mouse", "boolean", N_("enable mouse support at startup (to enable it now, see /help mouse)"), NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); + config_look_mouse_timer_delay = config_file_new_option ( + weechat_config_file, ptr_section, + "mouse_timer_delay", "integer", + N_("delay (in milliseconds) to grab a mouse event: WeeChat will " + "wait this delay before processing event"), + NULL, 1, 10000, "100", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_look_nickmode = config_file_new_option ( weechat_config_file, ptr_section, "nickmode", "boolean", diff --git a/src/core/wee-config.h b/src/core/wee-config.h index a617e8f98..6ee81a216 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -134,6 +134,7 @@ extern struct t_config_option *config_look_item_time_format; extern struct t_config_option *config_look_jump_current_to_previous_buffer; extern struct t_config_option *config_look_jump_previous_buffer_when_closing; extern struct t_config_option *config_look_mouse; +extern struct t_config_option *config_look_mouse_timer_delay; extern struct t_config_option *config_look_nickmode; extern struct t_config_option *config_look_nickmode_empty; extern struct t_config_option *config_look_paste_max_lines; diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c index d1b7c222c..6edc6d797 100644 --- a/src/gui/curses/gui-curses-key.c +++ b/src/gui/curses/gui-curses-key.c @@ -203,7 +203,6 @@ gui_key_default_bindings (int context) BIND(/* m-9 */ "meta-9", "/buffer *9"); BIND(/* m-< */ "meta-<", "/input jump_previously_visited_buffer"); BIND(/* m-> */ "meta->", "/input jump_next_visited_buffer"); - BIND(/* mouse */ "meta2-M", "/mouse grab"); BIND(/* m-m */ "meta-m", "/mouse toggle"); /* bind meta-j + {01..99} to switch to buffers # > 10 */ diff --git a/src/gui/curses/gui-curses-mouse.c b/src/gui/curses/gui-curses-mouse.c index 7ca78c77b..45151e0bc 100644 --- a/src/gui/curses/gui-curses-mouse.c +++ b/src/gui/curses/gui-curses-mouse.c @@ -31,7 +31,11 @@ #include "../../core/weechat.h" #include "../../core/wee-config.h" +#include "../../core/wee-hook.h" +#include "../../core/wee-utf8.h" +#include "../../plugins/plugin.h" #include "../gui-chat.h" +#include "../gui-key.h" #include "../gui-mouse.h" @@ -69,6 +73,22 @@ gui_mouse_display_state () _("Mouse is enabled") : _("Mouse is disabled")); } +/* + * gui_mouse_grab_timer_cb: timer for grabbing mouse code + */ + +int +gui_mouse_grab_timer_cb (void *data, int remaining_calls) +{ + /* make C compiler happy */ + (void) data; + (void) remaining_calls; + + gui_mouse_grab_end (); + + return WEECHAT_RC_OK; +} + /* * gui_mouse_grab_init: init "grab mouse" mode */ @@ -77,37 +97,72 @@ void gui_mouse_grab_init () { gui_mouse_grab = 1; + + if (gui_mouse_event_timer) + unhook (gui_mouse_event_timer); + + gui_mouse_event_timer = hook_timer (NULL, + CONFIG_INTEGER(config_look_mouse_timer_delay), + 0, 1, + &gui_mouse_grab_timer_cb, NULL); } /* * gui_mouse_grab_code2key: get key name with a mouse code + * *extra_chars is set with first char following the + * end of mouse code (this can point to the '\0' or + * other chars) */ const char * -gui_mouse_grab_code2key (const char *code) +gui_mouse_grab_code2key (const char *code, char **extra_chars) { - int x, y; + int x, y, code_utf8, length; double diff_x, diff_y, distance, angle, pi4; static char key[128]; - char button[2]; + char button[2], *ptr_code; - /* mouse code must have at least 3 chars */ - if (strlen (code) < 3) - return NULL; + *extra_chars = NULL; key[0] = '\0'; - /* ignore code '#' (button released) if it's received as first event */ - if ((gui_mouse_event_index == 0) && (code[0] == '#')) - return key; + /* + * mouse code must have at least: + * one code (for event) + X + Y == 3 bytes or 3 UTF-8 chars + */ + code_utf8 = utf8_is_valid (code, NULL); + length = (code_utf8) ? utf8_strlen (code) : (int)strlen (code); + if (length < 3) + return NULL; /* get coordinates and button */ - x = ((unsigned char)code[1]) - 33; + if (code_utf8) + { + /* get coordinates using UTF-8 chars in code */ + x = utf8_char_int (code + 1) - 33; + ptr_code = utf8_next_char (code + 1); + if (!ptr_code) + return NULL; + y = utf8_char_int (ptr_code) - 33; + *extra_chars = utf8_next_char (ptr_code); + } + else + { + /* get coordinates using ISO chars in code */ + x = ((unsigned char)code[1]) - 33; + y = ((unsigned char)code[2]) - 33; + *extra_chars = (char *)code + 3; + } if (x < 0) x = 0; - y = ((unsigned char)code[2]) - 33; if (y < 0) y = 0; + + /* ignore code '#' (button released) if it's received as first event */ + if ((gui_mouse_event_index == 0) && (code[0] == '#')) + return NULL; + + /* set data in "gui_mouse_event_xxx" */ gui_mouse_event_x[gui_mouse_event_index] = x; gui_mouse_event_y[gui_mouse_event_index] = y; if (gui_mouse_event_index == 0) @@ -129,7 +184,7 @@ gui_mouse_grab_code2key (const char *code) } if (code[0] != '#') - return key; + return NULL; /* add button/wheel */ switch (gui_mouse_event_button) @@ -239,5 +294,40 @@ gui_mouse_grab_code2key (const char *code) void gui_mouse_grab_end () { + const char *mouse_key; + char *extra_chars; + int i; + gui_mouse_grab = 0; + + /* end mouse event timer */ + if (gui_mouse_event_timer) + { + unhook (gui_mouse_event_timer); + gui_mouse_event_timer = NULL; + } + + /* get key from mouse code and execute command (if found) */ + mouse_key = gui_mouse_grab_code2key (gui_key_combo_buffer, &extra_chars); + if (mouse_key && mouse_key[0]) + { + (void) gui_key_focus (mouse_key, + GUI_KEY_CONTEXT_MOUSE); + gui_mouse_reset_event (); + } + + gui_key_combo_buffer[0] = '\0'; + + /* + * if extra chars, use them as new input (this can happen if used typed + * something and that mouse timer was not reached yet + */ + if (extra_chars && extra_chars[0]) + { + for (i = 0; extra_chars[i]; i++) + { + gui_key_buffer_add ((unsigned char)extra_chars[i]); + } + gui_key_flush (); + } } diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index d82b983f5..d29d83851 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -66,7 +66,7 @@ char *gui_key_context_string[GUI_KEY_NUM_CONTEXTS] = int gui_key_verbose = 0; /* 1 to see some messages */ -char gui_key_combo_buffer[256]; /* buffer used for combos */ +char gui_key_combo_buffer[1024]; /* buffer used for combos */ int gui_key_grab = 0; /* 1 if grab mode enabled (alt-k) */ int gui_key_grab_count = 0; /* number of keys pressed in grab mode */ int gui_key_grab_command = 0; /* grab command bound to key? */ @@ -187,7 +187,7 @@ gui_key_grab_init (int grab_command, const char *delay) int gui_key_grab_end_timer_cb (void *data, int remaining_calls) { - char *expanded_key; + char *expanded_key, *expanded_key2; struct t_gui_key *ptr_key; /* make C compiler happy */ @@ -196,14 +196,35 @@ gui_key_grab_end_timer_cb (void *data, int remaining_calls) /* get expanded name (for example: \x01+U => ctrl-u) */ expanded_key = gui_key_get_expanded_name (gui_key_combo_buffer); - if (expanded_key) { + /* + * the expanded_key should be valid UTF-8 at this point, + * but some mouse codes can return ISO chars (for coordinates), + * then we will convert them to UTF-8 string + */ + if (!utf8_is_valid (expanded_key, NULL)) + { + expanded_key2 = string_iconv_to_internal ("iso-8859-1", + expanded_key); + if (expanded_key2) + { + free (expanded_key); + expanded_key = expanded_key2; + } + else + { + /* conversion failed, then just replace invalid chars by '?' */ + utf8_normalize (expanded_key, '?'); + } + } + /* add expanded key to input buffer */ if (gui_current_window->buffer->input) { gui_input_insert_string (gui_current_window->buffer, expanded_key, -1); if (gui_key_grab_command) { + /* add command bound to key (if found) */ ptr_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT], gui_key_combo_buffer); if (ptr_key) @@ -734,7 +755,7 @@ gui_key_focus_command (const char *key, int context, } /* - * gui_key_focus: treat key pressed in cursor or mouse mode, + * gui_key_focus: process key pressed in cursor or mouse mode, * looking for keys: "{area}key" in context "cursor" or "mouse" * return 1 if a command was executed, otherwise 0 */ @@ -748,6 +769,13 @@ gui_key_focus (const char *key, int context) { gui_cursor_get_info (gui_mouse_event_x[0], gui_mouse_event_y[0], &cursor_info); + if (gui_mouse_debug) + { + gui_chat_printf (NULL, "Mouse: %s, (%d,%d) -> (%d,%d)", + key, + gui_mouse_event_x[0], gui_mouse_event_y[0], + gui_mouse_event_x[1], gui_mouse_event_y[1]); + } } else { @@ -761,7 +789,7 @@ gui_key_focus (const char *key, int context) } /* - * gui_key_pressed: treat new key pressed + * gui_key_pressed: process new key pressed * return: 1 if key should be added to input buffer * 0 otherwise */ @@ -771,8 +799,7 @@ gui_key_pressed (const char *key_str) { int i, first_key, context, length, length_key; struct t_gui_key *ptr_key; - char **commands; - const char *mouse_key; + char **commands, *pos; /* add key to buffer */ first_key = (gui_key_combo_buffer[0] == '\0'); @@ -796,23 +823,23 @@ gui_key_pressed (const char *key_str) /* mode "mouse grab" (mouse event pending) */ if (gui_mouse_grab) { - mouse_key = gui_mouse_grab_code2key (gui_key_combo_buffer); - if (mouse_key) + pos = strstr (gui_key_combo_buffer, "\x1B[M"); + if (pos) { - gui_key_combo_buffer[0] = '\0'; - strcat (gui_key_combo_buffer, mouse_key); + pos[0] = '\0'; gui_mouse_grab_end (); - if (gui_key_combo_buffer[0]) - { - (void) gui_key_focus (gui_key_combo_buffer, - GUI_KEY_CONTEXT_MOUSE); - gui_key_combo_buffer[0] = '\0'; - gui_mouse_reset_event (); - } + gui_mouse_grab_init (); } return 0; } + if (strcmp (gui_key_combo_buffer, "\x01[[M") == 0) + { + gui_key_combo_buffer[0] = '\0'; + gui_mouse_grab_init (); + return 0; + } + ptr_key = NULL; context = gui_key_get_current_context (); diff --git a/src/gui/gui-key.h b/src/gui/gui-key.h index d05ef7391..da200c354 100644 --- a/src/gui/gui-key.h +++ b/src/gui/gui-key.h @@ -81,6 +81,7 @@ extern struct t_gui_key *gui_key_bind (struct t_gui_buffer *buffer, const char *command); extern int gui_key_unbind (struct t_gui_buffer *buffer, int context, const char *key, int send_signal); +extern int gui_key_focus (const char *key, int context); extern int gui_key_pressed (const char *key_str); extern void gui_key_free (struct t_gui_key **keys, struct t_gui_key **last_key, @@ -104,5 +105,6 @@ extern void gui_key_print_log (struct t_gui_buffer *buffer); /* key functions (GUI dependent) */ extern void gui_key_default_bindings (); +extern void gui_key_flush (); #endif /* __WEECHAT_GUI_KEY_H */ diff --git a/src/gui/gui-mouse.c b/src/gui/gui-mouse.c index 81fc9ffd3..6fe6ab8ff 100644 --- a/src/gui/gui-mouse.c +++ b/src/gui/gui-mouse.c @@ -35,6 +35,8 @@ int gui_mouse_enabled = 0; /* 1 if mouse support is enabled */ int gui_mouse_debug = 0; /* debug mode for mouse */ int gui_mouse_grab = 0; /* 1 if grab mouse code enabled */ +struct t_hook *gui_mouse_event_timer = NULL; /* timer to detect entire */ + /* mouse event */ int gui_mouse_event_index = 0; /* index for x/y in array (0 or 1) */ int gui_mouse_event_x[2] = { 0, 0 }; /* position of latest mouse event: */ /* (on click, on release) */ diff --git a/src/gui/gui-mouse.h b/src/gui/gui-mouse.h index a579655f8..b23f4d656 100644 --- a/src/gui/gui-mouse.h +++ b/src/gui/gui-mouse.h @@ -25,6 +25,7 @@ extern int gui_mouse_enabled; extern int gui_mouse_debug; extern int gui_mouse_grab; +extern struct t_hook *gui_mouse_event_timer; extern int gui_mouse_event_index; extern int gui_mouse_event_x[2]; extern int gui_mouse_event_y[2]; @@ -41,7 +42,6 @@ extern void gui_mouse_enable (); extern void gui_mouse_disable (); extern void gui_mouse_display_state (); extern void gui_mouse_grab_init (); -extern const char *gui_mouse_grab_code2key (const char *code); extern void gui_mouse_grab_end (); #endif /* __WEECHAT_GUI_MOUSE_H */