mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 23:36:37 +02:00
core: add context "search" for keys (to define keys used during search in buffer with ctrl+"r")
This commit is contained in:
+365
-153
@@ -59,7 +59,7 @@
|
||||
#include "../gui/gui-history.h"
|
||||
#include "../gui/gui-hotlist.h"
|
||||
#include "../gui/gui-input.h"
|
||||
#include "../gui/gui-keyboard.h"
|
||||
#include "../gui/gui-key.h"
|
||||
#include "../gui/gui-layout.h"
|
||||
#include "../gui/gui-main.h"
|
||||
#include "../gui/gui-window.h"
|
||||
@@ -2123,6 +2123,14 @@ COMMAND_CALLBACK(input)
|
||||
gui_input_complete_previous (buffer);
|
||||
else if (string_strcasecmp (argv[1], "search_text") == 0)
|
||||
gui_input_search_text (buffer);
|
||||
else if (string_strcasecmp (argv[1], "search_previous") == 0)
|
||||
gui_input_search_previous (buffer);
|
||||
else if (string_strcasecmp (argv[1], "search_next") == 0)
|
||||
gui_input_search_next (buffer);
|
||||
else if (string_strcasecmp (argv[1], "search_switch_case") == 0)
|
||||
gui_input_search_switch_case (buffer);
|
||||
else if (string_strcasecmp (argv[1], "search_stop") == 0)
|
||||
gui_input_search_stop (buffer);
|
||||
else if (string_strcasecmp (argv[1], "delete_previous_char") == 0)
|
||||
gui_input_delete_previous_char (buffer);
|
||||
else if (string_strcasecmp (argv[1], "delete_next_char") == 0)
|
||||
@@ -2208,7 +2216,7 @@ command_key_display (struct t_gui_key *key, struct t_gui_key *default_key)
|
||||
char str_spaces[20 + 1];
|
||||
int length_screen, num_spaces;
|
||||
|
||||
expanded_name = gui_keyboard_get_expanded_name (key->key);
|
||||
expanded_name = gui_key_get_expanded_name (key->key);
|
||||
|
||||
str_spaces[0] = '\0';
|
||||
length_screen = utf8_strlen_screen ((expanded_name) ?
|
||||
@@ -2255,17 +2263,20 @@ command_key_display (struct t_gui_key *key, struct t_gui_key *default_key)
|
||||
void
|
||||
command_key_display_list (const char *message_no_key,
|
||||
const char *message_keys,
|
||||
int context,
|
||||
struct t_gui_key *keys,
|
||||
int keys_count)
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
|
||||
if (keys_count == 0)
|
||||
gui_chat_printf (NULL, message_no_key);
|
||||
gui_chat_printf (NULL, message_no_key,
|
||||
gui_key_context_string[context]);
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL, "");
|
||||
gui_chat_printf (NULL, message_keys, keys_count);
|
||||
gui_chat_printf (NULL, message_keys,
|
||||
keys_count, gui_key_context_string[context]);
|
||||
for (ptr_key = keys; ptr_key; ptr_key = ptr_key->next_key)
|
||||
{
|
||||
command_key_display (ptr_key, NULL);
|
||||
@@ -2279,17 +2290,17 @@ command_key_display_list (const char *message_no_key,
|
||||
*/
|
||||
|
||||
void
|
||||
command_key_display_listdiff ()
|
||||
command_key_display_listdiff (int context)
|
||||
{
|
||||
struct t_gui_key *ptr_key, *ptr_default_key;
|
||||
int count_added, count_deleted;
|
||||
|
||||
/* list keys added or redefined */
|
||||
count_added = 0;
|
||||
for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
|
||||
for (ptr_key = gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key)
|
||||
{
|
||||
ptr_default_key = gui_keyboard_search (gui_default_keys,
|
||||
ptr_key->key);
|
||||
ptr_default_key = gui_key_search (gui_default_keys[context],
|
||||
ptr_key->key);
|
||||
if (!ptr_default_key
|
||||
|| (strcmp (ptr_default_key->command, ptr_key->command) != 0))
|
||||
{
|
||||
@@ -2299,12 +2310,15 @@ command_key_display_listdiff ()
|
||||
if (count_added > 0)
|
||||
{
|
||||
gui_chat_printf (NULL, "");
|
||||
gui_chat_printf (NULL, _("Key bindings added or redefined (%d):"),
|
||||
count_added);
|
||||
for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
|
||||
gui_chat_printf (NULL,
|
||||
_("Key bindings added or redefined (%d) for "
|
||||
"context \"%s\":"),
|
||||
count_added,
|
||||
_(gui_key_context_string[context]));
|
||||
for (ptr_key = gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key)
|
||||
{
|
||||
ptr_default_key = gui_keyboard_search (gui_default_keys,
|
||||
ptr_key->key);
|
||||
ptr_default_key = gui_key_search (gui_default_keys[context],
|
||||
ptr_key->key);
|
||||
if (!ptr_default_key
|
||||
|| (strcmp (ptr_default_key->command, ptr_key->command) != 0))
|
||||
{
|
||||
@@ -2315,21 +2329,24 @@ command_key_display_listdiff ()
|
||||
|
||||
/* list keys deleted */
|
||||
count_deleted = 0;
|
||||
for (ptr_default_key = gui_default_keys; ptr_default_key;
|
||||
for (ptr_default_key = gui_default_keys[context]; ptr_default_key;
|
||||
ptr_default_key = ptr_default_key->next_key)
|
||||
{
|
||||
ptr_key = gui_keyboard_search (gui_keys, ptr_default_key->key);
|
||||
ptr_key = gui_key_search (gui_keys[context], ptr_default_key->key);
|
||||
if (!ptr_key)
|
||||
count_deleted++;
|
||||
}
|
||||
}
|
||||
if (count_deleted > 0)
|
||||
{
|
||||
gui_chat_printf (NULL, "");
|
||||
gui_chat_printf (NULL, _("Key bindings deleted (%d):"), count_deleted);
|
||||
for (ptr_default_key = gui_default_keys; ptr_default_key;
|
||||
gui_chat_printf (NULL,
|
||||
_("Key bindings deleted (%d) for context \"%s\":"),
|
||||
count_deleted,
|
||||
_(gui_key_context_string[context]));
|
||||
for (ptr_default_key = gui_default_keys[context]; ptr_default_key;
|
||||
ptr_default_key = ptr_default_key->next_key)
|
||||
{
|
||||
ptr_key = gui_keyboard_search (gui_keys, ptr_default_key->key);
|
||||
ptr_key = gui_key_search (gui_keys[context], ptr_default_key->key);
|
||||
if (!ptr_key)
|
||||
{
|
||||
command_key_display (ptr_default_key, NULL);
|
||||
@@ -2341,10 +2358,104 @@ command_key_display_listdiff ()
|
||||
if ((count_added == 0) && (count_deleted == 0))
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("No key binding added, redefined or removed"));
|
||||
_("No key binding added, redefined or removed "
|
||||
"for context \"%s\""),
|
||||
_(gui_key_context_string[context]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* command_key_reset: reset a key for a given context
|
||||
*/
|
||||
|
||||
int
|
||||
command_key_reset (int context, const char *key)
|
||||
{
|
||||
char *internal_code;
|
||||
struct t_gui_key *ptr_key, *ptr_default_key, *ptr_new_key;
|
||||
|
||||
internal_code = gui_key_get_internal_code (key);
|
||||
if (!internal_code)
|
||||
return WEECHAT_RC_ERROR;
|
||||
|
||||
ptr_key = gui_key_search (gui_keys[context],
|
||||
internal_code);
|
||||
ptr_default_key = gui_key_search (gui_default_keys[context],
|
||||
internal_code);
|
||||
free (internal_code);
|
||||
|
||||
if (ptr_key || ptr_default_key)
|
||||
{
|
||||
if (ptr_key && ptr_default_key)
|
||||
{
|
||||
if (strcmp (ptr_key->command, ptr_default_key->command) != 0)
|
||||
{
|
||||
gui_key_verbose = 1;
|
||||
ptr_new_key = gui_key_bind (NULL, context, key,
|
||||
ptr_default_key->command);
|
||||
gui_key_verbose = 0;
|
||||
if (!ptr_new_key)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to bind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
key);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("Key \"%s\" has already default "
|
||||
"value"),
|
||||
key);
|
||||
}
|
||||
}
|
||||
else if (ptr_key)
|
||||
{
|
||||
/* no default key, so just unbind key */
|
||||
if (gui_key_unbind (NULL, context, key, 1))
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("Key \"%s\" unbound (context: \"%s\")"),
|
||||
key,
|
||||
gui_key_context_string[context]);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to unbind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
key);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no key, but default key exists */
|
||||
gui_key_verbose = 1;
|
||||
ptr_new_key = gui_key_bind (NULL, context, key,
|
||||
ptr_default_key->command);
|
||||
gui_key_verbose = 0;
|
||||
if (!ptr_new_key)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to bind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
key);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL, _("%sKey \"%s\" not found"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
key);
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* command_key: bind/unbind keys
|
||||
*/
|
||||
@@ -2352,8 +2463,8 @@ command_key_display_listdiff ()
|
||||
COMMAND_CALLBACK(key)
|
||||
{
|
||||
char *internal_code;
|
||||
struct t_gui_key *ptr_key, *ptr_default_key, *ptr_new_key;
|
||||
int old_keys_count, keys_added;
|
||||
struct t_gui_key *ptr_new_key;
|
||||
int old_keys_count, keys_added, i, context;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -2362,39 +2473,68 @@ COMMAND_CALLBACK(key)
|
||||
/* display all key bindings (current keys) */
|
||||
if ((argc == 1) || (string_strcasecmp (argv[1], "list") == 0))
|
||||
{
|
||||
command_key_display_list (_("No key binding defined"),
|
||||
_("Key bindings (%d):"),
|
||||
gui_keys,
|
||||
gui_keys_count);
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
if ((argc < 3)
|
||||
|| (string_strcasecmp (argv[2], gui_key_context_string[i]) == 0))
|
||||
{
|
||||
command_key_display_list (_("No key binding defined for "
|
||||
"context \"%s\""),
|
||||
_("Key bindings (%d) for "
|
||||
"context \"%s\":"),
|
||||
i, gui_keys[i], gui_keys_count[i]);
|
||||
}
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* display redefined or key bindings added */
|
||||
if (string_strcasecmp (argv[1], "listdiff") == 0)
|
||||
{
|
||||
command_key_display_listdiff ();
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
if ((argc < 3)
|
||||
|| (string_strcasecmp (argv[2], gui_key_context_string[i]) == 0))
|
||||
{
|
||||
command_key_display_listdiff (i);
|
||||
}
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* display default key bindings */
|
||||
if (string_strcasecmp (argv[1], "listdefault") == 0)
|
||||
{
|
||||
command_key_display_list (_("No default key binding"),
|
||||
_("Default key bindings (%d):"),
|
||||
gui_default_keys,
|
||||
gui_default_keys_count);
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
if ((argc < 3)
|
||||
|| (string_strcasecmp (argv[2], gui_key_context_string[i]) == 0))
|
||||
{
|
||||
command_key_display_list (_("No default key binding for "
|
||||
"context \"%s\""),
|
||||
_("Default key bindings (%d) for "
|
||||
"context \"%s\":"),
|
||||
i,
|
||||
gui_default_keys[i],
|
||||
gui_default_keys_count[i]);
|
||||
}
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* bind a key (or display binding) */
|
||||
if (string_strcasecmp (argv[1], "bind") == 0)
|
||||
{
|
||||
COMMAND_MIN_ARGS(3, "key bind");
|
||||
|
||||
/* display a key binding */
|
||||
if (argc == 3)
|
||||
{
|
||||
ptr_new_key = NULL;
|
||||
internal_code = gui_keyboard_get_internal_code (argv[2]);
|
||||
internal_code = gui_key_get_internal_code (argv[2]);
|
||||
if (internal_code)
|
||||
ptr_new_key = gui_keyboard_search (gui_keys, internal_code);
|
||||
ptr_new_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT],
|
||||
internal_code);
|
||||
if (ptr_new_key)
|
||||
{
|
||||
gui_chat_printf (NULL, "");
|
||||
@@ -2411,12 +2551,11 @@ COMMAND_CALLBACK(key)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
COMMAND_MIN_ARGS(4, "key bind");
|
||||
|
||||
/* bind new key */
|
||||
gui_keyboard_verbose = 1;
|
||||
ptr_new_key = gui_keyboard_bind (NULL, argv[2], argv_eol[3]);
|
||||
gui_keyboard_verbose = 0;
|
||||
gui_key_verbose = 1;
|
||||
ptr_new_key = gui_key_bind (NULL, GUI_KEY_CONTEXT_DEFAULT,
|
||||
argv[2], argv_eol[3]);
|
||||
gui_key_verbose = 0;
|
||||
if (!ptr_new_key)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
@@ -2428,25 +2567,115 @@ COMMAND_CALLBACK(key)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* unbind a key */
|
||||
if (string_strcasecmp (argv[1], "unbind") == 0)
|
||||
/* bind a key for given context (or display binding) */
|
||||
if (string_strcasecmp (argv[1], "bindctxt") == 0)
|
||||
{
|
||||
if (argc >= 3)
|
||||
COMMAND_MIN_ARGS(4, "key bindctxt");
|
||||
|
||||
/* search context */
|
||||
context = gui_key_search_context (argv[2]);
|
||||
if (context < 0)
|
||||
{
|
||||
if (gui_keyboard_unbind (NULL, argv[2], 1))
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: context \"%s\" not found"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* display a key binding */
|
||||
if (argc == 4)
|
||||
{
|
||||
ptr_new_key = NULL;
|
||||
internal_code = gui_key_get_internal_code (argv[2]);
|
||||
if (internal_code)
|
||||
ptr_new_key = gui_key_search (gui_keys[context],
|
||||
internal_code);
|
||||
if (ptr_new_key)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("Key \"%s\" unbound"),
|
||||
argv[2]);
|
||||
gui_chat_printf (NULL, "");
|
||||
gui_chat_printf (NULL, _("Key:"));
|
||||
command_key_display (ptr_new_key, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to unbind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
_("No key found"));
|
||||
}
|
||||
if (internal_code)
|
||||
free (internal_code);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* bind new key */
|
||||
gui_key_verbose = 1;
|
||||
ptr_new_key = gui_key_bind (NULL, context,
|
||||
argv[3], argv_eol[4]);
|
||||
gui_key_verbose = 0;
|
||||
if (!ptr_new_key)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to bind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[3]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* unbind a key */
|
||||
if (string_strcasecmp (argv[1], "unbind") == 0)
|
||||
{
|
||||
COMMAND_MIN_ARGS(3, "key unbind");
|
||||
|
||||
if (gui_key_unbind (NULL, GUI_KEY_CONTEXT_DEFAULT, argv[2], 1))
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("Key \"%s\" unbound (context: \"%s\")"),
|
||||
argv[2],
|
||||
gui_key_context_string[GUI_KEY_CONTEXT_DEFAULT]);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to unbind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* unbind a key for a given context */
|
||||
if (string_strcasecmp (argv[1], "unbindctxt") == 0)
|
||||
{
|
||||
COMMAND_MIN_ARGS(4, "key unbindctxt");
|
||||
|
||||
/* search context */
|
||||
context = gui_key_search_context (argv[2]);
|
||||
if (context < 0)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: context \"%s\" not found"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
if (gui_key_unbind (NULL, context, argv[3], 1))
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("Key \"%s\" unbound (context: \"%s\")"),
|
||||
argv[3],
|
||||
gui_key_context_string[context]);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to unbind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[3]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
@@ -2454,86 +2683,28 @@ COMMAND_CALLBACK(key)
|
||||
/* reset a key to default binding */
|
||||
if (string_strcasecmp (argv[1], "reset") == 0)
|
||||
{
|
||||
if (argc >= 3)
|
||||
COMMAND_MIN_ARGS(3, "key reset");
|
||||
|
||||
return command_key_reset (GUI_KEY_CONTEXT_DEFAULT, argv[2]);
|
||||
}
|
||||
|
||||
/* reset a key to default binding for a given context */
|
||||
if (string_strcasecmp (argv[1], "resetctxt") == 0)
|
||||
{
|
||||
COMMAND_MIN_ARGS(4, "key reset");
|
||||
|
||||
/* search context */
|
||||
context = gui_key_search_context (argv[2]);
|
||||
if (context < 0)
|
||||
{
|
||||
internal_code = gui_keyboard_get_internal_code (argv[2]);
|
||||
if (!internal_code)
|
||||
return WEECHAT_RC_ERROR;
|
||||
|
||||
ptr_key = gui_keyboard_search (gui_keys, internal_code);
|
||||
ptr_default_key = gui_keyboard_search (gui_default_keys, internal_code);
|
||||
free (internal_code);
|
||||
|
||||
if (ptr_key || ptr_default_key)
|
||||
{
|
||||
if (ptr_key && ptr_default_key)
|
||||
{
|
||||
if (strcmp (ptr_key->command, ptr_default_key->command) != 0)
|
||||
{
|
||||
gui_keyboard_verbose = 1;
|
||||
ptr_new_key = gui_keyboard_bind (NULL, argv[2],
|
||||
ptr_default_key->command);
|
||||
gui_keyboard_verbose = 0;
|
||||
if (!ptr_new_key)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to bind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("Key \"%s\" has already default "
|
||||
"value"),
|
||||
argv[2]);
|
||||
}
|
||||
}
|
||||
else if (ptr_key)
|
||||
{
|
||||
/* no default key, so just unbind key */
|
||||
if (gui_keyboard_unbind (NULL, argv[2], 1))
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("Key \"%s\" unbound"),
|
||||
argv[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to unbind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no key, but default key exists */
|
||||
gui_keyboard_verbose = 1;
|
||||
ptr_new_key = gui_keyboard_bind (NULL, argv[2],
|
||||
ptr_default_key->command);
|
||||
gui_keyboard_verbose = 0;
|
||||
if (!ptr_new_key)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unable to bind key \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL, _("%sKey \"%s\" not found"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
}
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: context \"%s\" not found"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
return command_key_reset (context, argv[3]);
|
||||
}
|
||||
|
||||
/* reset ALL keys (only with "-yes", for security reason) */
|
||||
@@ -2541,10 +2712,20 @@ COMMAND_CALLBACK(key)
|
||||
{
|
||||
if ((argc >= 3) && (string_strcasecmp (argv[2], "-yes") == 0))
|
||||
{
|
||||
gui_keyboard_free_all (&gui_keys, &last_gui_key, &gui_keys_count);
|
||||
gui_keyboard_default_bindings ();
|
||||
gui_chat_printf (NULL,
|
||||
_("Default key bindings restored"));
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
if ((argc < 4)
|
||||
|| (string_strcasecmp (argv[3], gui_key_context_string[i]) == 0))
|
||||
{
|
||||
gui_key_free_all (&gui_keys[i], &last_gui_key[i],
|
||||
&gui_keys_count[i]);
|
||||
gui_key_default_bindings (i);
|
||||
gui_chat_printf (NULL,
|
||||
_("Default key bindings restored for "
|
||||
"context \"%s\""),
|
||||
gui_key_context_string[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2560,15 +2741,24 @@ COMMAND_CALLBACK(key)
|
||||
/* add missing keys */
|
||||
if (string_strcasecmp (argv[1], "missing") == 0)
|
||||
{
|
||||
old_keys_count = gui_keys_count;
|
||||
gui_keyboard_verbose = 1;
|
||||
gui_keyboard_default_bindings ();
|
||||
gui_keyboard_verbose = 0;
|
||||
keys_added = (gui_keys_count > old_keys_count) ?
|
||||
gui_keys_count - old_keys_count : 0;
|
||||
gui_chat_printf (NULL,
|
||||
NG_("%d new key added", "%d new keys added", keys_added),
|
||||
keys_added);
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
if ((argc < 3)
|
||||
|| (string_strcasecmp (argv[2], gui_key_context_string[i]) == 0))
|
||||
{
|
||||
old_keys_count = gui_keys_count[i];
|
||||
gui_key_verbose = 1;
|
||||
gui_key_default_bindings (i);
|
||||
gui_key_verbose = 0;
|
||||
keys_added = (gui_keys_count[i] > old_keys_count) ?
|
||||
gui_keys_count[i] - old_keys_count : 0;
|
||||
gui_chat_printf (NULL,
|
||||
NG_("%d new key added", "%d new keys added "
|
||||
"(context: \"%s\")", keys_added),
|
||||
keys_added,
|
||||
gui_key_context_string[i]);
|
||||
}
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -4980,6 +5170,10 @@ command_init ()
|
||||
" complete_previous: complete word with previous "
|
||||
"completion\n"
|
||||
" search_text: search text in buffer\n"
|
||||
" search_switch_case: switch exact case for search\n"
|
||||
" search_previous: search previous line\n"
|
||||
" search_next: search next line\n"
|
||||
" search_stop: stop search\n"
|
||||
" delete_previous_char: delete previous char\n"
|
||||
" delete_next_char: delete next char\n"
|
||||
" delete_previous_word: delete previous word\n"
|
||||
@@ -5027,6 +5221,7 @@ command_init ()
|
||||
" insert: insert text in command line\n\n"
|
||||
"This command is used by key bindings or plugins."),
|
||||
"return|complete_next|complete_previous|search_text|"
|
||||
"search_switch_case|search_previous|search_next|search_stop|"
|
||||
"delete_previous_char|delete_next_char|"
|
||||
"delete_previous_word|delete_next_word|"
|
||||
"delete_beginning_of_line|delete_end_of_line|"
|
||||
@@ -5043,21 +5238,33 @@ command_init ()
|
||||
&command_input, NULL);
|
||||
hook_command (NULL, "key",
|
||||
N_("bind/unbind keys"),
|
||||
N_("list|listdefault|listdiff"
|
||||
N_("list|listdefault|listdiff [<context>]"
|
||||
" || bind <key> [<command> [<args>]]"
|
||||
" || bindctxt <context> <key> [<command> [<args>]]"
|
||||
" || unbind <key>"
|
||||
" || unbindctxt <context> <key>"
|
||||
" || reset <key>"
|
||||
" || resetall -yes"
|
||||
" || missing"),
|
||||
" || resetctxt <context> <key>"
|
||||
" || resetall -yes [<context>]"
|
||||
" || missing [<context>]"),
|
||||
N_(" list: list all current keys (without argument, "
|
||||
"this list is displayed)\n"
|
||||
"listdefault: list default keys\n"
|
||||
" listdiff: list differences between current and "
|
||||
"default keys (keys added, redefined or deleted)\n"
|
||||
"default keys (keys added, redefined or deleted)\n"
|
||||
" context: name of context (\"default\" or "
|
||||
"\"search\")\n"
|
||||
" bind: bind a command to a key or display command "
|
||||
"bound to key\n"
|
||||
" unbind: remove a key binding\n"
|
||||
" reset: reset a key to default binding\n"
|
||||
"bound to key (for context \"default\")\n"
|
||||
" bindctxt: bind a command to a key or display command "
|
||||
"bound to key, for given context\n"
|
||||
" unbind: remove a key binding (for context "
|
||||
"\"default\")\n"
|
||||
" unbindctxt: remove a key binding for given context\n"
|
||||
" reset: reset a key to default binding (for "
|
||||
"context \"default\")\n"
|
||||
" resetctxt: reset a key to default binding, for given "
|
||||
"context\n"
|
||||
" resetall: restore bindings to the default values and "
|
||||
"delete ALL personal bindings (use carefully!)\n"
|
||||
" missing: add missing keys (using default bindings), "
|
||||
@@ -5071,15 +5278,20 @@ command_init ()
|
||||
" key alt-r to jump to #weechat IRC channel:\n"
|
||||
" /key bind meta-r /buffer #weechat\n"
|
||||
" restore default binding for key alt-r:\n"
|
||||
" /key reset meta-r"),
|
||||
"list"
|
||||
" || listdefault"
|
||||
" || listdiff"
|
||||
" /key reset meta-r\n"
|
||||
" key \"tab\" to stop search in buffer:\n"
|
||||
" /key bindctxt search ctrl-I /input search_stop"),
|
||||
"list %(keys_contexts)"
|
||||
" || listdefault %(keys_contexts)"
|
||||
" || listdiff %(keys_contexts)"
|
||||
" || bind %(keys_codes) %(commands)"
|
||||
" || bindctxt %(keys_contexts) %(keys_codes) %(commands)"
|
||||
" || unbind %(keys_codes)"
|
||||
" || unbindctxt %(keys_contexts) %(keys_codes)"
|
||||
" || reset %(keys_codes_for_reset)"
|
||||
" || resetctxt %(keys_contexts) %(keys_codes_for_reset)"
|
||||
" || resetall"
|
||||
" || missing",
|
||||
" || missing %(keys_contexts)",
|
||||
&command_key, NULL);
|
||||
hook_command (NULL, "layout",
|
||||
N_("save/apply/reset layout for buffers and windows"),
|
||||
|
||||
+75
-35
@@ -48,7 +48,7 @@
|
||||
#include "../gui/gui-buffer.h"
|
||||
#include "../gui/gui-color.h"
|
||||
#include "../gui/gui-filter.h"
|
||||
#include "../gui/gui-keyboard.h"
|
||||
#include "../gui/gui-key.h"
|
||||
#include "../gui/gui-nicklist.h"
|
||||
|
||||
|
||||
@@ -1105,6 +1105,32 @@ completion_list_add_proxies_options_cb (void *data,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* completion_list_add_keys_contexts_cb: add keys contexts to completion list
|
||||
*/
|
||||
|
||||
int
|
||||
completion_list_add_keys_contexts_cb (void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
gui_completion_list_add (completion, gui_key_context_string[i],
|
||||
0, WEECHAT_LIST_POS_END);
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* completion_list_add_keys_codes_cb: add keys to completion list
|
||||
*/
|
||||
@@ -1115,6 +1141,7 @@ completion_list_add_keys_codes_cb (void *data,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
int i;
|
||||
struct t_gui_key *ptr_key;
|
||||
char *expanded_name;
|
||||
|
||||
@@ -1122,15 +1149,18 @@ completion_list_add_keys_codes_cb (void *data,
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
|
||||
for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
|
||||
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
expanded_name = gui_keyboard_get_expanded_name (ptr_key->key);
|
||||
gui_completion_list_add (completion,
|
||||
(expanded_name) ? expanded_name : ptr_key->key,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
if (expanded_name)
|
||||
free (expanded_name);
|
||||
for (ptr_key = gui_keys[i]; ptr_key; ptr_key = ptr_key->next_key)
|
||||
{
|
||||
expanded_name = gui_key_get_expanded_name (ptr_key->key);
|
||||
gui_completion_list_add (completion,
|
||||
(expanded_name) ? expanded_name : ptr_key->key,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
if (expanded_name)
|
||||
free (expanded_name);
|
||||
}
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
@@ -1148,6 +1178,7 @@ completion_list_add_keys_codes_for_reset_cb (void *data,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
int i;
|
||||
struct t_gui_key *ptr_key, *ptr_default_key;
|
||||
char *expanded_name;
|
||||
|
||||
@@ -1155,36 +1186,39 @@ completion_list_add_keys_codes_for_reset_cb (void *data,
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
|
||||
/* keys added or redefined */
|
||||
for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
|
||||
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
ptr_default_key = gui_keyboard_search (gui_default_keys, ptr_key->key);
|
||||
if (!ptr_default_key
|
||||
|| (strcmp (ptr_default_key->command, ptr_key->command) != 0))
|
||||
/* keys added or redefined */
|
||||
for (ptr_key = gui_keys[i]; ptr_key; ptr_key = ptr_key->next_key)
|
||||
{
|
||||
expanded_name = gui_keyboard_get_expanded_name (ptr_key->key);
|
||||
gui_completion_list_add (completion,
|
||||
(expanded_name) ? expanded_name : ptr_key->key,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
if (expanded_name)
|
||||
free (expanded_name);
|
||||
ptr_default_key = gui_key_search (gui_default_keys[i], ptr_key->key);
|
||||
if (!ptr_default_key
|
||||
|| (strcmp (ptr_default_key->command, ptr_key->command) != 0))
|
||||
{
|
||||
expanded_name = gui_key_get_expanded_name (ptr_key->key);
|
||||
gui_completion_list_add (completion,
|
||||
(expanded_name) ? expanded_name : ptr_key->key,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
if (expanded_name)
|
||||
free (expanded_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* keys deleted */
|
||||
for (ptr_default_key = gui_default_keys; ptr_default_key;
|
||||
ptr_default_key = ptr_default_key->next_key)
|
||||
{
|
||||
ptr_key = gui_keyboard_search (gui_keys, ptr_default_key->key);
|
||||
if (!ptr_key)
|
||||
|
||||
/* keys deleted */
|
||||
for (ptr_default_key = gui_default_keys[i]; ptr_default_key;
|
||||
ptr_default_key = ptr_default_key->next_key)
|
||||
{
|
||||
expanded_name = gui_keyboard_get_expanded_name (ptr_default_key->key);
|
||||
gui_completion_list_add (completion,
|
||||
(expanded_name) ? expanded_name : ptr_default_key->key,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
if (expanded_name)
|
||||
free (expanded_name);
|
||||
ptr_key = gui_key_search (gui_keys[i], ptr_default_key->key);
|
||||
if (!ptr_key)
|
||||
{
|
||||
expanded_name = gui_key_get_expanded_name (ptr_default_key->key);
|
||||
gui_completion_list_add (completion,
|
||||
(expanded_name) ? expanded_name : ptr_default_key->key,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
if (expanded_name)
|
||||
free (expanded_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1264,10 +1298,16 @@ completion_init ()
|
||||
hook_completion (NULL, "bars_options",
|
||||
N_("options for bars"),
|
||||
&completion_list_add_bars_options_cb, NULL);
|
||||
hook_completion (NULL, "keys_contexts",
|
||||
/* TRANSLATORS: "key" means "key on the keyboard" */
|
||||
N_("key contexts"),
|
||||
&completion_list_add_keys_contexts_cb, NULL);
|
||||
hook_completion (NULL, "keys_codes",
|
||||
/* TRANSLATORS: "key" means "key on the keyboard" */
|
||||
N_("key codes"),
|
||||
&completion_list_add_keys_codes_cb, NULL);
|
||||
hook_completion (NULL, "keys_codes_for_reset",
|
||||
/* TRANSLATORS: "key" means "key on the keyboard" */
|
||||
N_("key codes that can be reset (keys added, redefined "
|
||||
"or removed)"),
|
||||
&completion_list_add_keys_codes_for_reset_cb, NULL);
|
||||
|
||||
+59
-22
@@ -52,7 +52,7 @@
|
||||
#include "../gui/gui-color.h"
|
||||
#include "../gui/gui-filter.h"
|
||||
#include "../gui/gui-hotlist.h"
|
||||
#include "../gui/gui-keyboard.h"
|
||||
#include "../gui/gui-key.h"
|
||||
#include "../gui/gui-layout.h"
|
||||
#include "../gui/gui-line.h"
|
||||
#include "../gui/gui-main.h"
|
||||
@@ -581,6 +581,8 @@ config_day_change_timer_cb (void *data, int remaining_calls)
|
||||
void
|
||||
config_weechat_init_after_read ()
|
||||
{
|
||||
int i;
|
||||
|
||||
gui_buffer_notify_set_all ();
|
||||
|
||||
proxy_use_temp_proxies ();
|
||||
@@ -601,8 +603,11 @@ config_weechat_init_after_read ()
|
||||
}
|
||||
|
||||
/* if no key was found config file, then we use default bindings */
|
||||
if (!gui_keys)
|
||||
gui_keyboard_default_bindings ();
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
if (!gui_keys[i])
|
||||
gui_key_default_bindings (i);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -616,13 +621,17 @@ config_weechat_init_after_read ()
|
||||
int
|
||||
config_weechat_reload_cb (void *data, struct t_config_file *config_file)
|
||||
{
|
||||
int rc;
|
||||
int i, rc;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
/* remove all keys */
|
||||
gui_keyboard_free_all (&gui_keys, &last_gui_key, &gui_keys_count);
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
gui_key_free_all (&gui_keys[i], &last_gui_key[i],
|
||||
&gui_keys_count[i]);
|
||||
}
|
||||
|
||||
/* remove all proxies */
|
||||
proxy_free_all ();
|
||||
@@ -1425,22 +1434,33 @@ config_weechat_key_read_cb (void *data, struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
const char *option_name, const char *value)
|
||||
{
|
||||
int context;
|
||||
char *pos;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) config_file;
|
||||
(void) section;
|
||||
|
||||
if (option_name)
|
||||
{
|
||||
context = GUI_KEY_CONTEXT_DEFAULT;
|
||||
pos = strchr (section->name, '_');
|
||||
if (pos)
|
||||
{
|
||||
context = gui_key_search_context (pos + 1);
|
||||
if (context < 0)
|
||||
context = GUI_KEY_CONTEXT_DEFAULT;
|
||||
}
|
||||
|
||||
if (value && value[0])
|
||||
{
|
||||
/* bind key (overwrite any binding with same key) */
|
||||
gui_keyboard_bind (NULL, option_name, value);
|
||||
gui_key_bind (NULL, context, option_name, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* unbind key if no value given */
|
||||
gui_keyboard_unbind (NULL, option_name, 1);
|
||||
gui_key_unbind (NULL, context, option_name, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1456,18 +1476,26 @@ config_weechat_key_write_cb (void *data, struct t_config_file *config_file,
|
||||
const char *section_name)
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
char *expanded_name;
|
||||
int rc;
|
||||
char *pos, *expanded_name;
|
||||
int rc, context;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
if (!config_file_write_line (config_file, section_name, NULL))
|
||||
return WEECHAT_CONFIG_WRITE_ERROR;
|
||||
|
||||
for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
|
||||
|
||||
context = GUI_KEY_CONTEXT_DEFAULT;
|
||||
pos = strchr (section_name, '_');
|
||||
if (pos)
|
||||
{
|
||||
expanded_name = gui_keyboard_get_expanded_name (ptr_key->key);
|
||||
context = gui_key_search_context (pos + 1);
|
||||
if (context < 0)
|
||||
context = GUI_KEY_CONTEXT_DEFAULT;
|
||||
}
|
||||
for (ptr_key = gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key)
|
||||
{
|
||||
expanded_name = gui_key_get_expanded_name (ptr_key->key);
|
||||
if (expanded_name)
|
||||
{
|
||||
rc = config_file_write_line (config_file,
|
||||
@@ -1493,6 +1521,8 @@ int
|
||||
config_weechat_init_options ()
|
||||
{
|
||||
struct t_config_section *ptr_section;
|
||||
int i;
|
||||
char section_name[128];
|
||||
|
||||
weechat_config_file = config_file_new (NULL, WEECHAT_CONFIG_NAME,
|
||||
&config_weechat_reload_cb, NULL);
|
||||
@@ -2507,16 +2537,23 @@ config_weechat_init_options ()
|
||||
}
|
||||
|
||||
/* keys */
|
||||
ptr_section = config_file_new_section (weechat_config_file, "key",
|
||||
0, 0,
|
||||
&config_weechat_key_read_cb, NULL,
|
||||
&config_weechat_key_write_cb, NULL,
|
||||
&config_weechat_key_write_cb, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
if (!ptr_section)
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
config_file_free (weechat_config_file);
|
||||
return 0;
|
||||
snprintf (section_name, sizeof (section_name),
|
||||
"key%s%s",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
|
||||
ptr_section = config_file_new_section (weechat_config_file, section_name,
|
||||
0, 0,
|
||||
&config_weechat_key_read_cb, NULL,
|
||||
&config_weechat_key_write_cb, NULL,
|
||||
&config_weechat_key_write_cb, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
if (!ptr_section)
|
||||
{
|
||||
config_file_free (weechat_config_file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
#include "../gui/gui-chat.h"
|
||||
#include "../gui/gui-filter.h"
|
||||
#include "../gui/gui-hotlist.h"
|
||||
#include "../gui/gui-keyboard.h"
|
||||
#include "../gui/gui-key.h"
|
||||
#include "../gui/gui-layout.h"
|
||||
#include "../gui/gui-main.h"
|
||||
#include "../gui/gui-window.h"
|
||||
@@ -92,7 +92,7 @@ debug_dump (int crash)
|
||||
gui_window_print_log ();
|
||||
gui_buffer_print_log ();
|
||||
gui_layout_print_log ();
|
||||
gui_keyboard_print_log (NULL);
|
||||
gui_key_print_log (NULL);
|
||||
gui_filter_print_log ();
|
||||
gui_bar_print_log ();
|
||||
gui_bar_item_print_log ();
|
||||
|
||||
+23
-17
@@ -72,7 +72,7 @@
|
||||
#include "../gui/gui-completion.h"
|
||||
#include "../gui/gui-layout.h"
|
||||
#include "../gui/gui-main.h"
|
||||
#include "../gui/gui-keyboard.h"
|
||||
#include "../gui/gui-key.h"
|
||||
#include "../plugins/plugin.h"
|
||||
|
||||
|
||||
@@ -164,22 +164,28 @@ weechat_display_keys ()
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
char *expanded_name;
|
||||
|
||||
gui_keyboard_default_bindings ();
|
||||
string_iconv_fprintf (stdout,
|
||||
/* TRANSLATORS: "%s" is "weechat" */
|
||||
_("%s default keys:\n"),
|
||||
PACKAGE_NAME);
|
||||
string_iconv_fprintf (stdout, "\n");
|
||||
for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
expanded_name = gui_keyboard_get_expanded_name (ptr_key->key);
|
||||
gui_key_default_bindings (i);
|
||||
string_iconv_fprintf (stdout,
|
||||
"* %s => %s\n",
|
||||
(expanded_name) ? expanded_name : ptr_key->key,
|
||||
ptr_key->command);
|
||||
if (expanded_name)
|
||||
free (expanded_name);
|
||||
/* TRANSLATORS: first "%s" is "weechat" */
|
||||
_("%s default keys (context: \"%s\"):\n"),
|
||||
(gui_key_context_string[i] && gui_key_context_string[i][0]) ?
|
||||
_(gui_key_context_string[i]) : "",
|
||||
PACKAGE_NAME);
|
||||
string_iconv_fprintf (stdout, "\n");
|
||||
for (ptr_key = gui_keys[i]; ptr_key; ptr_key = ptr_key->next_key)
|
||||
{
|
||||
expanded_name = gui_key_get_expanded_name (ptr_key->key);
|
||||
string_iconv_fprintf (stdout,
|
||||
"* %s => %s\n",
|
||||
(expanded_name) ? expanded_name : ptr_key->key,
|
||||
ptr_key->command);
|
||||
if (expanded_name)
|
||||
free (expanded_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +424,7 @@ main (int argc, char *argv[])
|
||||
gui_main_pre_init (&argc, &argv); /* pre-initiliaze interface */
|
||||
command_init (); /* initialize WeeChat commands */
|
||||
completion_init (); /* add core completion hooks */
|
||||
gui_keyboard_init (); /* init keyboard */
|
||||
gui_key_init (); /* init keys */
|
||||
if (!config_weechat_init ()) /* init options with default values */
|
||||
exit (EXIT_FAILURE);
|
||||
weechat_parse_args (argc, argv); /* parse command line args */
|
||||
@@ -451,7 +457,7 @@ main (int argc, char *argv[])
|
||||
gui_main_end (1); /* shut down WeeChat GUI */
|
||||
proxy_free_all (); /* free all proxies */
|
||||
config_file_free_all (); /* free all configuration files */
|
||||
gui_keyboard_end (); /* end keyboard */
|
||||
gui_key_end (); /* remove all keys */
|
||||
unhook_all (); /* remove all hooks */
|
||||
hdata_end (); /* end hdata */
|
||||
weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */
|
||||
|
||||
@@ -29,7 +29,7 @@ gui-completion.c gui-completion.h
|
||||
gui-history.c gui-history.h
|
||||
gui-hotlist.c gui-hotlist.h
|
||||
gui-input.c gui-input.h
|
||||
gui-keyboard.c gui-keyboard.h
|
||||
gui-key.c gui-key.h
|
||||
gui-layout.c gui-layout.h
|
||||
gui-line.c gui-line.h
|
||||
gui-main.h
|
||||
|
||||
+2
-2
@@ -43,8 +43,8 @@ lib_weechat_gui_common_a_SOURCES = gui-bar.c \
|
||||
gui-hotlist.h \
|
||||
gui-input.c \
|
||||
gui-input.h \
|
||||
gui-keyboard.c \
|
||||
gui-keyboard.h \
|
||||
gui-key.c \
|
||||
gui-key.h \
|
||||
gui-layout.c \
|
||||
gui-layout.h \
|
||||
gui-line.c \
|
||||
|
||||
@@ -28,7 +28,7 @@ gui-curses.h
|
||||
gui-curses-bar-window.c
|
||||
gui-curses-chat.c
|
||||
gui-curses-color.c
|
||||
gui-curses-keyboard.c
|
||||
gui-curses-key.c
|
||||
gui-curses-main.c
|
||||
gui-curses-term.c
|
||||
gui-curses-window.c)
|
||||
|
||||
@@ -35,7 +35,7 @@ weechat_curses_LDADD = ./../../core/lib_weechat_core.a \
|
||||
weechat_curses_SOURCES = gui-curses-bar-window.c \
|
||||
gui-curses-chat.c \
|
||||
gui-curses-color.c \
|
||||
gui-curses-keyboard.c \
|
||||
gui-curses-key.c \
|
||||
gui-curses-main.c \
|
||||
gui-curses-term.c \
|
||||
gui-curses-window.c \
|
||||
|
||||
@@ -0,0 +1,508 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* gui-curses-key.c: keyboard functions for Curses GUI
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../../core/weechat.h"
|
||||
#include "../../core/wee-config.h"
|
||||
#include "../../core/wee-hook.h"
|
||||
#include "../../core/wee-log.h"
|
||||
#include "../../core/wee-utf8.h"
|
||||
#include "../../core/wee-string.h"
|
||||
#include "../../plugins/plugin.h"
|
||||
#include "../gui-key.h"
|
||||
#include "../gui-buffer.h"
|
||||
#include "../gui-color.h"
|
||||
#include "../gui-input.h"
|
||||
#include "../gui-completion.h"
|
||||
#include "../gui-window.h"
|
||||
#include "gui-curses.h"
|
||||
|
||||
#define BIND(key, command) gui_key_default_bind(context, key, command)
|
||||
|
||||
|
||||
/*
|
||||
* gui_key_default_bind: create key bind, only if it does not exist yet
|
||||
*/
|
||||
|
||||
void
|
||||
gui_key_default_bind (int context, const char *key, const char *command)
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
char *internal_code;
|
||||
|
||||
internal_code = gui_key_get_internal_code (key);
|
||||
|
||||
ptr_key = gui_key_search (gui_keys[context],
|
||||
(internal_code) ? internal_code : key);
|
||||
if (!ptr_key)
|
||||
gui_key_new (NULL, context, key, command);
|
||||
|
||||
if (internal_code)
|
||||
free (internal_code);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_default_bindings: create default key bindings for context given
|
||||
*/
|
||||
|
||||
void
|
||||
gui_key_default_bindings (int context)
|
||||
{
|
||||
int i;
|
||||
char key_str[32], command[32];
|
||||
|
||||
switch (context)
|
||||
{
|
||||
case GUI_KEY_CONTEXT_DEFAULT:
|
||||
BIND(/* RC */ "ctrl-M", "/input return");
|
||||
BIND(/* RC */ "ctrl-J", "/input return");
|
||||
BIND(/* tab */ "ctrl-I", "/input complete_next");
|
||||
BIND(/* s-tab */ "meta2-Z", "/input complete_previous");
|
||||
BIND(/* ^R */ "ctrl-R", "/input search_text");
|
||||
BIND(/* basckpace */ "ctrl-H", "/input delete_previous_char");
|
||||
BIND(/* basckpace */ "ctrl-?", "/input delete_previous_char");
|
||||
BIND(/* ^_ */ "ctrl-_", "/input undo");
|
||||
BIND(/* m-_ */ "meta-_", "/input redo");
|
||||
BIND(/* del */ "meta2-3~", "/input delete_next_char");
|
||||
BIND(/* ^D */ "ctrl-D", "/input delete_next_char");
|
||||
BIND(/* ^W */ "ctrl-W", "/input delete_previous_word");
|
||||
BIND(/* ^X */ "ctrl-X", "/input switch_active_buffer");
|
||||
BIND(/* m-d */ "meta-d", "/input delete_next_word");
|
||||
BIND(/* ^K */ "ctrl-K", "/input delete_end_of_line");
|
||||
BIND(/* m-r */ "meta-r", "/input delete_line");
|
||||
BIND(/* ^T */ "ctrl-T", "/input transpose_chars");
|
||||
BIND(/* ^U */ "ctrl-U", "/input delete_beginning_of_line");
|
||||
BIND(/* ^Y */ "ctrl-Y", "/input clipboard_paste");
|
||||
BIND(/* home */ "meta2-1~", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta2-H", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta2-7~", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta-OH", "/input move_beginning_of_line");
|
||||
BIND(/* ^A */ "ctrl-A", "/input move_beginning_of_line");
|
||||
BIND(/* end */ "meta2-4~", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta2-F", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta2-8~", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta-OF", "/input move_end_of_line");
|
||||
BIND(/* ^E */ "ctrl-E", "/input move_end_of_line");
|
||||
BIND(/* left */ "meta2-D", "/input move_previous_char");
|
||||
BIND(/* ^B */ "ctrl-B", "/input move_previous_char");
|
||||
BIND(/* right */ "meta2-C", "/input move_next_char");
|
||||
BIND(/* ^F */ "ctrl-F", "/input move_next_char");
|
||||
BIND(/* m-b */ "meta-b", "/input move_previous_word");
|
||||
BIND(/* ^left */ "meta-Od", "/input move_previous_word");
|
||||
BIND(/* ^left */ "meta-OD", "/input move_previous_word");
|
||||
BIND(/* m-f */ "meta-f", "/input move_next_word");
|
||||
BIND(/* ^right */ "meta-Oc", "/input move_next_word");
|
||||
BIND(/* ^right */ "meta-OC", "/input move_next_word");
|
||||
BIND(/* up */ "meta2-A", "/input history_previous");
|
||||
BIND(/* down */ "meta2-B", "/input history_next");
|
||||
BIND(/* ^up */ "meta-Oa", "/input history_global_previous");
|
||||
BIND(/* ^up */ "meta-OA", "/input history_global_previous");
|
||||
BIND(/* ^up */ "meta2-1;5A", "/input history_global_previous");
|
||||
BIND(/* ^down */ "meta-Ob", "/input history_global_next");
|
||||
BIND(/* ^down */ "meta-OB", "/input history_global_next");
|
||||
BIND(/* ^down */ "meta2-1;5B", "/input history_global_next");
|
||||
BIND(/* m-a */ "meta-a", "/input jump_smart");
|
||||
BIND(/* m-j,m-l */ "meta-jmeta-l", "/input jump_last_buffer");
|
||||
BIND(/* m-j,m-r */ "meta-jmeta-r", "/server raw");
|
||||
BIND(/* m-j,m-s */ "meta-jmeta-s", "/server jump");
|
||||
BIND(/* m-h */ "meta-h", "/input hotlist_clear");
|
||||
BIND(/* m-k */ "meta-k", "/input grab_key_command");
|
||||
BIND(/* m-u */ "meta-u", "/input scroll_unread");
|
||||
BIND(/* ^S^U */ "ctrl-Sctrl-U", "/input set_unread");
|
||||
BIND(/* ^Cb */ "ctrl-Cb", "/input insert \\x02");
|
||||
BIND(/* ^Cc */ "ctrl-Cc", "/input insert \\x03");
|
||||
BIND(/* ^Ci */ "ctrl-Ci", "/input insert \\x1D");
|
||||
BIND(/* ^Co */ "ctrl-Co", "/input insert \\x0F");
|
||||
BIND(/* ^Cr */ "ctrl-Cr", "/input insert \\x12");
|
||||
BIND(/* ^Cu */ "ctrl-Cu", "/input insert \\x15");
|
||||
BIND(/* m-right */ "meta-meta2-C", "/buffer +1");
|
||||
BIND(/* m-right */ "meta2-1;3C", "/buffer +1");
|
||||
BIND(/* m-down */ "meta-meta2-B", "/buffer +1");
|
||||
BIND(/* m-down */ "meta2-1;3B", "/buffer +1");
|
||||
BIND(/* F6 */ "meta2-17~", "/buffer +1");
|
||||
BIND(/* ^N */ "ctrl-N", "/buffer +1");
|
||||
BIND(/* m-left */ "meta-meta2-D", "/buffer -1");
|
||||
BIND(/* m-left */ "meta2-1;3D", "/buffer -1");
|
||||
BIND(/* m-up */ "meta-meta2-A", "/buffer -1");
|
||||
BIND(/* m-up */ "meta2-1;3A", "/buffer -1");
|
||||
BIND(/* F5 */ "meta2-15~", "/buffer -1");
|
||||
BIND(/* ^P */ "ctrl-P", "/buffer -1");
|
||||
BIND(/* pgup */ "meta2-5~", "/window page_up");
|
||||
BIND(/* pgup */ "meta2-I", "/window page_up");
|
||||
BIND(/* pgdn */ "meta2-6~", "/window page_down");
|
||||
BIND(/* pgdn */ "meta2-G", "/window page_down");
|
||||
BIND(/* m-pgup */ "meta-meta2-5~", "/window scroll_up");
|
||||
BIND(/* m-pgup */ "meta2-5;3~", "/window scroll_up");
|
||||
BIND(/* m-pgdn */ "meta-meta2-6~", "/window scroll_down");
|
||||
BIND(/* m-pgdn */ "meta2-6;3~", "/window scroll_down");
|
||||
BIND(/* m-home */ "meta-meta2-1~", "/window scroll_top");
|
||||
BIND(/* m-home */ "meta-meta2-7~", "/window scroll_top");
|
||||
BIND(/* m-end */ "meta-meta2-4~", "/window scroll_bottom");
|
||||
BIND(/* m-end */ "meta-meta2-8~", "/window scroll_bottom");
|
||||
BIND(/* m-n */ "meta-n", "/window scroll_next_highlight");
|
||||
BIND(/* m-p */ "meta-p", "/window scroll_previous_highlight");
|
||||
BIND(/* F9 */ "meta2-20~", "/bar scroll title * x-50%");
|
||||
BIND(/* F10 */ "meta2-21~", "/bar scroll title * x+50%");
|
||||
BIND(/* F11 */ "meta2-23~", "/bar scroll nicklist * y-100%");
|
||||
BIND(/* F12 */ "meta2-24~", "/bar scroll nicklist * y+100%");
|
||||
BIND(/* m-F11 */ "meta-meta2-23~", "/bar scroll nicklist * yb");
|
||||
BIND(/* m-F12 */ "meta-meta2-24~", "/bar scroll nicklist * ye");
|
||||
BIND(/* ^L */ "ctrl-L", "/window refresh");
|
||||
BIND(/* F7 */ "meta2-18~", "/window -1");
|
||||
BIND(/* F8 */ "meta2-19~", "/window +1");
|
||||
BIND(/* m-w,m-up */ "meta-wmeta-meta2-A", "/window up");
|
||||
BIND(/* m-w,m-up */ "meta-wmeta2-1;3A", "/window up");
|
||||
BIND(/* m-w,m-down */ "meta-wmeta-meta2-B", "/window down");
|
||||
BIND(/* m-w,m-down */ "meta-wmeta2-1;3B", "/window down");
|
||||
BIND(/* m-w,m-right */ "meta-wmeta-meta2-C", "/window right");
|
||||
BIND(/* m-w,m-right */ "meta-wmeta2-1;3C", "/window right");
|
||||
BIND(/* m-w,m-left */ "meta-wmeta-meta2-D", "/window left");
|
||||
BIND(/* m-w,m-left */ "meta-wmeta2-1;3D", "/window left");
|
||||
BIND(/* m-w,m-b */ "meta-wmeta-b", "/window balance");
|
||||
BIND(/* m-w,m-s */ "meta-wmeta-s", "/window swap");
|
||||
BIND(/* m-z */ "meta-z", "/window zoom");
|
||||
BIND(/* m-= */ "meta-=", "/filter toggle");
|
||||
BIND(/* m-0 */ "meta-0", "/buffer *10");
|
||||
BIND(/* m-1 */ "meta-1", "/buffer *1");
|
||||
BIND(/* m-2 */ "meta-2", "/buffer *2");
|
||||
BIND(/* m-3 */ "meta-3", "/buffer *3");
|
||||
BIND(/* m-4 */ "meta-4", "/buffer *4");
|
||||
BIND(/* m-5 */ "meta-5", "/buffer *5");
|
||||
BIND(/* m-6 */ "meta-6", "/buffer *6");
|
||||
BIND(/* m-7 */ "meta-7", "/buffer *7");
|
||||
BIND(/* m-8 */ "meta-8", "/buffer *8");
|
||||
BIND(/* m-9 */ "meta-9", "/buffer *9");
|
||||
BIND(/* m-< */ "meta-<", "/input jump_previously_visited_buffer");
|
||||
BIND(/* m-> */ "meta->", "/input jump_next_visited_buffer");
|
||||
|
||||
/* 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);
|
||||
BIND(key_str, command);
|
||||
}
|
||||
break;
|
||||
case GUI_KEY_CONTEXT_SEARCH:
|
||||
BIND(/* RC */ "ctrl-M", "/input search_stop");
|
||||
BIND(/* RC */ "ctrl-J", "/input search_stop");
|
||||
BIND(/* ^R */ "ctrl-R", "/input search_switch_case");
|
||||
BIND(/* up */ "meta2-A", "/input search_previous");
|
||||
BIND(/* down */ "meta2-B", "/input search_next");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_flush: flush keyboard buffer
|
||||
*/
|
||||
|
||||
void
|
||||
gui_key_flush ()
|
||||
{
|
||||
int i, key, insert_ok;
|
||||
char key_str[32], *key_utf, *input_old;
|
||||
|
||||
/*
|
||||
* if there's no paste pending, then we use buffer and do actions
|
||||
* according to keys
|
||||
*/
|
||||
if (!gui_key_paste_pending)
|
||||
{
|
||||
if (gui_key_buffer_size > 0)
|
||||
gui_key_last_activity_time = time (NULL);
|
||||
|
||||
for (i = 0; i < gui_key_buffer_size; i++)
|
||||
{
|
||||
key = gui_key_buffer[i];
|
||||
|
||||
insert_ok = 1;
|
||||
|
||||
if (key < 32)
|
||||
{
|
||||
insert_ok = 0;
|
||||
key_str[0] = '^';
|
||||
key_str[1] = (char) key + '@';
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else if (key == 127)
|
||||
{
|
||||
key_str[0] = '^';
|
||||
key_str[1] = '?';
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (local_utf8)
|
||||
{
|
||||
/* 1 char: 0vvvvvvv */
|
||||
if (key < 0x80)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
/* 2 chars: 110vvvvv 10vvvvvv */
|
||||
else if ((key & 0xE0) == 0xC0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
if (i < gui_key_buffer_size - 1)
|
||||
{
|
||||
key_str[1] = (char) (gui_key_buffer[++i]);
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
/* 3 chars: 1110vvvv 10vvvvvv 10vvvvvv */
|
||||
else if ((key & 0xF0) == 0xE0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
if (i < gui_key_buffer_size - 1)
|
||||
{
|
||||
key_str[1] = (char) (gui_key_buffer[++i]);
|
||||
if (i < gui_key_buffer_size - 1)
|
||||
{
|
||||
key_str[2] = (char) (gui_key_buffer[++i]);
|
||||
key_str[3] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
/* 4 chars: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */
|
||||
else if ((key & 0xF8) == 0xF0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
if (i < gui_key_buffer_size - 1)
|
||||
{
|
||||
key_str[1] = (char) (gui_key_buffer[++i]);
|
||||
if (i < gui_key_buffer_size - 1)
|
||||
{
|
||||
key_str[2] = (char) (gui_key_buffer[++i]);
|
||||
if (i < gui_key_buffer_size - 1)
|
||||
{
|
||||
key_str[3] = (char) (gui_key_buffer[++i]);
|
||||
key_str[4] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[3] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = '\0';
|
||||
|
||||
/* convert input to UTF-8 is user is not using UTF-8 as locale */
|
||||
if (!local_utf8)
|
||||
{
|
||||
key_utf = string_iconv_to_internal (NULL, key_str);
|
||||
strncpy (key_str, key_utf, sizeof (key_str));
|
||||
key_str[sizeof (key_str) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp (key_str, "^") == 0)
|
||||
{
|
||||
key_str[1] = '^';
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
|
||||
hook_signal_send ("key_pressed",
|
||||
WEECHAT_HOOK_SIGNAL_STRING, key_str);
|
||||
|
||||
if (gui_current_window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED)
|
||||
input_old = (gui_current_window->buffer->input_buffer) ?
|
||||
strdup (gui_current_window->buffer->input_buffer) : strdup ("");
|
||||
else
|
||||
input_old = NULL;
|
||||
|
||||
if ((gui_key_pressed (key_str) != 0) && (insert_ok))
|
||||
{
|
||||
if (strcmp (key_str, "^^") == 0)
|
||||
key_str[1] = '\0';
|
||||
|
||||
gui_buffer_undo_snap (gui_current_window->buffer);
|
||||
gui_input_insert_string (gui_current_window->buffer,
|
||||
key_str, -1);
|
||||
if (gui_current_window->buffer->completion)
|
||||
gui_completion_stop (gui_current_window->buffer->completion, 0);
|
||||
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer, 1);
|
||||
}
|
||||
|
||||
/* incremental text search in buffer */
|
||||
if ((gui_current_window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED)
|
||||
&& ((input_old == NULL)
|
||||
|| (gui_current_window->buffer->input_buffer == NULL)
|
||||
|| (strcmp (input_old, gui_current_window->buffer->input_buffer) != 0)))
|
||||
{
|
||||
/*
|
||||
* if current input is longer than old input, and that
|
||||
* beginning of current input is exactly equal to old input,
|
||||
* then do nothing (search will not find any result and can
|
||||
* take some time on buffer with many lines..)
|
||||
*/
|
||||
if (!gui_current_window->buffer->text_search_found
|
||||
&& (input_old != NULL)
|
||||
&& (input_old[0])
|
||||
&& (gui_current_window->buffer->input_buffer != NULL)
|
||||
&& (gui_current_window->buffer->input_buffer[0])
|
||||
&& (strlen (gui_current_window->buffer->input_buffer) > strlen (input_old))
|
||||
&& (strncmp (gui_current_window->buffer->input_buffer, input_old,
|
||||
strlen (input_old)) == 0))
|
||||
{
|
||||
/*
|
||||
* do not search text in buffer, just alert about text not
|
||||
* found
|
||||
*/
|
||||
if (CONFIG_BOOLEAN(config_look_search_text_not_found_alert))
|
||||
printf ("\a");
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_window_search_restart (gui_current_window);
|
||||
}
|
||||
}
|
||||
|
||||
if (input_old)
|
||||
free (input_old);
|
||||
}
|
||||
|
||||
if (gui_key_grab && (gui_key_grab_count > 0))
|
||||
gui_key_grab_end ();
|
||||
|
||||
gui_key_buffer_reset ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_read_cb: read keyboard chars
|
||||
*/
|
||||
|
||||
int
|
||||
gui_key_read_cb (void *data, int fd)
|
||||
{
|
||||
int ret, i, accept_paste, cancel_paste, text_added_to_buffer, paste_lines;
|
||||
unsigned char buffer[4096];
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) fd;
|
||||
|
||||
accept_paste = 0;
|
||||
cancel_paste = 0;
|
||||
text_added_to_buffer = 0;
|
||||
|
||||
if (gui_key_paste_pending)
|
||||
{
|
||||
ret = read (STDIN_FILENO, buffer, 1);
|
||||
if (ret == 0)
|
||||
{
|
||||
/* no data on stdin, terminal lost */
|
||||
log_printf (_("Terminal lost, exiting WeeChat..."));
|
||||
hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
weechat_quit = 1;
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
if (ret <= 0)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
/* ctrl-Y: accept paste */
|
||||
if (buffer[0] == 25)
|
||||
accept_paste = 1;
|
||||
|
||||
/* ctrl-N: cancel paste */
|
||||
if (buffer[0] == 14)
|
||||
cancel_paste = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = read (STDIN_FILENO, buffer, sizeof (buffer));
|
||||
if (ret == 0)
|
||||
{
|
||||
/* no data on stdin, terminal lost */
|
||||
log_printf (_("Terminal lost, exiting WeeChat..."));
|
||||
hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
weechat_quit = 1;
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
if (ret < 0)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
for (i = 0; i < ret; i++)
|
||||
{
|
||||
gui_key_buffer_add (buffer[i]);
|
||||
}
|
||||
|
||||
text_added_to_buffer = 1;
|
||||
}
|
||||
|
||||
if (gui_key_paste_pending)
|
||||
{
|
||||
/* user is ok for pasting text, let's paste! */
|
||||
if (accept_paste)
|
||||
gui_key_paste_accept ();
|
||||
/* user doesn't want to paste text: clear whole buffer! */
|
||||
else if (cancel_paste)
|
||||
gui_key_paste_cancel ();
|
||||
else if (text_added_to_buffer)
|
||||
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* detect user paste or large amount of text
|
||||
* if so, ask user what to do
|
||||
*/
|
||||
if (CONFIG_INTEGER(config_look_paste_max_lines) > 0)
|
||||
{
|
||||
paste_lines = gui_key_get_paste_lines ();
|
||||
if (paste_lines > CONFIG_INTEGER(config_look_paste_max_lines))
|
||||
{
|
||||
gui_key_paste_pending = 1;
|
||||
gui_input_paste_pending_signal ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gui_key_flush ();
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
@@ -1,501 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* gui-curses-keyboard.c: keyboard functions for Curses GUI
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../../core/weechat.h"
|
||||
#include "../../core/wee-config.h"
|
||||
#include "../../core/wee-hook.h"
|
||||
#include "../../core/wee-log.h"
|
||||
#include "../../core/wee-utf8.h"
|
||||
#include "../../core/wee-string.h"
|
||||
#include "../../plugins/plugin.h"
|
||||
#include "../gui-keyboard.h"
|
||||
#include "../gui-buffer.h"
|
||||
#include "../gui-color.h"
|
||||
#include "../gui-input.h"
|
||||
#include "../gui-completion.h"
|
||||
#include "../gui-window.h"
|
||||
#include "gui-curses.h"
|
||||
|
||||
#define BIND(key, command) gui_keyboard_default_bind(key, command)
|
||||
|
||||
|
||||
/*
|
||||
* gui_keyboard_default_bind: create key bind, only if it does not exist yet
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_default_bind (const char *key, const char *command)
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
char *internal_code;
|
||||
|
||||
internal_code = gui_keyboard_get_internal_code (key);
|
||||
|
||||
ptr_key = gui_keyboard_search (gui_keys,
|
||||
(internal_code) ? internal_code : key);
|
||||
if (!ptr_key)
|
||||
{
|
||||
gui_keyboard_new (NULL, key, command);
|
||||
}
|
||||
|
||||
if (internal_code)
|
||||
free (internal_code);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_default_bindings: create default key bindings
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_default_bindings ()
|
||||
{
|
||||
int i;
|
||||
char key_str[32], command[32];
|
||||
|
||||
BIND(/* RC */ "ctrl-M", "/input return");
|
||||
BIND(/* RC */ "ctrl-J", "/input return");
|
||||
BIND(/* tab */ "ctrl-I", "/input complete_next");
|
||||
BIND(/* s-tab */ "meta2-Z", "/input complete_previous");
|
||||
BIND(/* ^R */ "ctrl-R", "/input search_text");
|
||||
BIND(/* basckpace */ "ctrl-H", "/input delete_previous_char");
|
||||
BIND(/* basckpace */ "ctrl-?", "/input delete_previous_char");
|
||||
BIND(/* ^_ */ "ctrl-_", "/input undo");
|
||||
BIND(/* m-_ */ "meta-_", "/input redo");
|
||||
BIND(/* del */ "meta2-3~", "/input delete_next_char");
|
||||
BIND(/* ^D */ "ctrl-D", "/input delete_next_char");
|
||||
BIND(/* ^W */ "ctrl-W", "/input delete_previous_word");
|
||||
BIND(/* ^X */ "ctrl-X", "/input switch_active_buffer");
|
||||
BIND(/* m-d */ "meta-d", "/input delete_next_word");
|
||||
BIND(/* ^K */ "ctrl-K", "/input delete_end_of_line");
|
||||
BIND(/* m-r */ "meta-r", "/input delete_line");
|
||||
BIND(/* ^T */ "ctrl-T", "/input transpose_chars");
|
||||
BIND(/* ^U */ "ctrl-U", "/input delete_beginning_of_line");
|
||||
BIND(/* ^Y */ "ctrl-Y", "/input clipboard_paste");
|
||||
BIND(/* home */ "meta2-1~", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta2-H", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta2-7~", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta-OH", "/input move_beginning_of_line");
|
||||
BIND(/* ^A */ "ctrl-A", "/input move_beginning_of_line");
|
||||
BIND(/* end */ "meta2-4~", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta2-F", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta2-8~", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta-OF", "/input move_end_of_line");
|
||||
BIND(/* ^E */ "ctrl-E", "/input move_end_of_line");
|
||||
BIND(/* left */ "meta2-D", "/input move_previous_char");
|
||||
BIND(/* ^B */ "ctrl-B", "/input move_previous_char");
|
||||
BIND(/* right */ "meta2-C", "/input move_next_char");
|
||||
BIND(/* ^F */ "ctrl-F", "/input move_next_char");
|
||||
BIND(/* m-b */ "meta-b", "/input move_previous_word");
|
||||
BIND(/* ^left */ "meta-Od", "/input move_previous_word");
|
||||
BIND(/* ^left */ "meta-OD", "/input move_previous_word");
|
||||
BIND(/* m-f */ "meta-f", "/input move_next_word");
|
||||
BIND(/* ^right */ "meta-Oc", "/input move_next_word");
|
||||
BIND(/* ^right */ "meta-OC", "/input move_next_word");
|
||||
BIND(/* up */ "meta2-A", "/input history_previous");
|
||||
BIND(/* down */ "meta2-B", "/input history_next");
|
||||
BIND(/* ^up */ "meta-Oa", "/input history_global_previous");
|
||||
BIND(/* ^up */ "meta-OA", "/input history_global_previous");
|
||||
BIND(/* ^up */ "meta2-1;5A", "/input history_global_previous");
|
||||
BIND(/* ^down */ "meta-Ob", "/input history_global_next");
|
||||
BIND(/* ^down */ "meta-OB", "/input history_global_next");
|
||||
BIND(/* ^down */ "meta2-1;5B", "/input history_global_next");
|
||||
BIND(/* m-a */ "meta-a", "/input jump_smart");
|
||||
BIND(/* m-j,m-l */ "meta-jmeta-l", "/input jump_last_buffer");
|
||||
BIND(/* m-j,m-r */ "meta-jmeta-r", "/server raw");
|
||||
BIND(/* m-j,m-s */ "meta-jmeta-s", "/server jump");
|
||||
BIND(/* m-h */ "meta-h", "/input hotlist_clear");
|
||||
BIND(/* m-k */ "meta-k", "/input grab_key_command");
|
||||
BIND(/* m-u */ "meta-u", "/input scroll_unread");
|
||||
BIND(/* ^S^U */ "ctrl-Sctrl-U", "/input set_unread");
|
||||
BIND(/* ^Cb */ "ctrl-Cb", "/input insert \\x02");
|
||||
BIND(/* ^Cc */ "ctrl-Cc", "/input insert \\x03");
|
||||
BIND(/* ^Ci */ "ctrl-Ci", "/input insert \\x1D");
|
||||
BIND(/* ^Co */ "ctrl-Co", "/input insert \\x0F");
|
||||
BIND(/* ^Cr */ "ctrl-Cr", "/input insert \\x12");
|
||||
BIND(/* ^Cu */ "ctrl-Cu", "/input insert \\x15");
|
||||
BIND(/* m-right */ "meta-meta2-C", "/buffer +1");
|
||||
BIND(/* m-right */ "meta2-1;3C", "/buffer +1");
|
||||
BIND(/* m-down */ "meta-meta2-B", "/buffer +1");
|
||||
BIND(/* m-down */ "meta2-1;3B", "/buffer +1");
|
||||
BIND(/* F6 */ "meta2-17~", "/buffer +1");
|
||||
BIND(/* ^N */ "ctrl-N", "/buffer +1");
|
||||
BIND(/* m-left */ "meta-meta2-D", "/buffer -1");
|
||||
BIND(/* m-left */ "meta2-1;3D", "/buffer -1");
|
||||
BIND(/* m-up */ "meta-meta2-A", "/buffer -1");
|
||||
BIND(/* m-up */ "meta2-1;3A", "/buffer -1");
|
||||
BIND(/* F5 */ "meta2-15~", "/buffer -1");
|
||||
BIND(/* ^P */ "ctrl-P", "/buffer -1");
|
||||
BIND(/* pgup */ "meta2-5~", "/window page_up");
|
||||
BIND(/* pgup */ "meta2-I", "/window page_up");
|
||||
BIND(/* pgdn */ "meta2-6~", "/window page_down");
|
||||
BIND(/* pgdn */ "meta2-G", "/window page_down");
|
||||
BIND(/* m-pgup */ "meta-meta2-5~", "/window scroll_up");
|
||||
BIND(/* m-pgup */ "meta2-5;3~", "/window scroll_up");
|
||||
BIND(/* m-pgdn */ "meta-meta2-6~", "/window scroll_down");
|
||||
BIND(/* m-pgdn */ "meta2-6;3~", "/window scroll_down");
|
||||
BIND(/* m-home */ "meta-meta2-1~", "/window scroll_top");
|
||||
BIND(/* m-home */ "meta-meta2-7~", "/window scroll_top");
|
||||
BIND(/* m-end */ "meta-meta2-4~", "/window scroll_bottom");
|
||||
BIND(/* m-end */ "meta-meta2-8~", "/window scroll_bottom");
|
||||
BIND(/* m-n */ "meta-n", "/window scroll_next_highlight");
|
||||
BIND(/* m-p */ "meta-p", "/window scroll_previous_highlight");
|
||||
BIND(/* F9 */ "meta2-20~", "/bar scroll title * x-50%");
|
||||
BIND(/* F10 */ "meta2-21~", "/bar scroll title * x+50%");
|
||||
BIND(/* F11 */ "meta2-23~", "/bar scroll nicklist * y-100%");
|
||||
BIND(/* F12 */ "meta2-24~", "/bar scroll nicklist * y+100%");
|
||||
BIND(/* m-F11 */ "meta-meta2-23~", "/bar scroll nicklist * yb");
|
||||
BIND(/* m-F12 */ "meta-meta2-24~", "/bar scroll nicklist * ye");
|
||||
BIND(/* ^L */ "ctrl-L", "/window refresh");
|
||||
BIND(/* F7 */ "meta2-18~", "/window -1");
|
||||
BIND(/* F8 */ "meta2-19~", "/window +1");
|
||||
BIND(/* m-w,m-up */ "meta-wmeta-meta2-A", "/window up");
|
||||
BIND(/* m-w,m-up */ "meta-wmeta2-1;3A", "/window up");
|
||||
BIND(/* m-w,m-down */ "meta-wmeta-meta2-B", "/window down");
|
||||
BIND(/* m-w,m-down */ "meta-wmeta2-1;3B", "/window down");
|
||||
BIND(/* m-w,m-right */ "meta-wmeta-meta2-C", "/window right");
|
||||
BIND(/* m-w,m-right */ "meta-wmeta2-1;3C", "/window right");
|
||||
BIND(/* m-w,m-left */ "meta-wmeta-meta2-D", "/window left");
|
||||
BIND(/* m-w,m-left */ "meta-wmeta2-1;3D", "/window left");
|
||||
BIND(/* m-w,m-b */ "meta-wmeta-b", "/window balance");
|
||||
BIND(/* m-w,m-s */ "meta-wmeta-s", "/window swap");
|
||||
BIND(/* m-z */ "meta-z", "/window zoom");
|
||||
BIND(/* m-= */ "meta-=", "/filter toggle");
|
||||
BIND(/* m-0 */ "meta-0", "/buffer *10");
|
||||
BIND(/* m-1 */ "meta-1", "/buffer *1");
|
||||
BIND(/* m-2 */ "meta-2", "/buffer *2");
|
||||
BIND(/* m-3 */ "meta-3", "/buffer *3");
|
||||
BIND(/* m-4 */ "meta-4", "/buffer *4");
|
||||
BIND(/* m-5 */ "meta-5", "/buffer *5");
|
||||
BIND(/* m-6 */ "meta-6", "/buffer *6");
|
||||
BIND(/* m-7 */ "meta-7", "/buffer *7");
|
||||
BIND(/* m-8 */ "meta-8", "/buffer *8");
|
||||
BIND(/* m-9 */ "meta-9", "/buffer *9");
|
||||
BIND(/* m-< */ "meta-<", "/input jump_previously_visited_buffer");
|
||||
BIND(/* m-> */ "meta->", "/input jump_next_visited_buffer");
|
||||
|
||||
/* 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);
|
||||
BIND(key_str, command);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_flush: flush keyboard buffer
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_flush ()
|
||||
{
|
||||
int i, key, insert_ok;
|
||||
char key_str[32], *key_utf, *input_old;
|
||||
|
||||
/*
|
||||
* if there's no paste pending, then we use buffer and do actions
|
||||
* according to keys
|
||||
*/
|
||||
if (!gui_keyboard_paste_pending)
|
||||
{
|
||||
if (gui_keyboard_buffer_size > 0)
|
||||
gui_keyboard_last_activity_time = time (NULL);
|
||||
|
||||
for (i = 0; i < gui_keyboard_buffer_size; i++)
|
||||
{
|
||||
key = gui_keyboard_buffer[i];
|
||||
|
||||
insert_ok = 1;
|
||||
|
||||
if (key < 32)
|
||||
{
|
||||
insert_ok = 0;
|
||||
key_str[0] = '^';
|
||||
key_str[1] = (char) key + '@';
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else if (key == 127)
|
||||
{
|
||||
key_str[0] = '^';
|
||||
key_str[1] = '?';
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (local_utf8)
|
||||
{
|
||||
/* 1 char: 0vvvvvvv */
|
||||
if (key < 0x80)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
/* 2 chars: 110vvvvv 10vvvvvv */
|
||||
else if ((key & 0xE0) == 0xC0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
if (i < gui_keyboard_buffer_size - 1)
|
||||
{
|
||||
key_str[1] = (char) (gui_keyboard_buffer[++i]);
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
/* 3 chars: 1110vvvv 10vvvvvv 10vvvvvv */
|
||||
else if ((key & 0xF0) == 0xE0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
if (i < gui_keyboard_buffer_size - 1)
|
||||
{
|
||||
key_str[1] = (char) (gui_keyboard_buffer[++i]);
|
||||
if (i < gui_keyboard_buffer_size - 1)
|
||||
{
|
||||
key_str[2] = (char) (gui_keyboard_buffer[++i]);
|
||||
key_str[3] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
/* 4 chars: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */
|
||||
else if ((key & 0xF8) == 0xF0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
if (i < gui_keyboard_buffer_size - 1)
|
||||
{
|
||||
key_str[1] = (char) (gui_keyboard_buffer[++i]);
|
||||
if (i < gui_keyboard_buffer_size - 1)
|
||||
{
|
||||
key_str[2] = (char) (gui_keyboard_buffer[++i]);
|
||||
if (i < gui_keyboard_buffer_size - 1)
|
||||
{
|
||||
key_str[3] = (char) (gui_keyboard_buffer[++i]);
|
||||
key_str[4] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[3] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = '\0';
|
||||
|
||||
/* convert input to UTF-8 is user is not using UTF-8 as locale */
|
||||
if (!local_utf8)
|
||||
{
|
||||
key_utf = string_iconv_to_internal (NULL, key_str);
|
||||
strncpy (key_str, key_utf, sizeof (key_str));
|
||||
key_str[sizeof (key_str) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp (key_str, "^") == 0)
|
||||
{
|
||||
key_str[1] = '^';
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
|
||||
/*gui_printf (gui_current_window->buffer,
|
||||
"gui_input_read: key = %s (%d)\n", key_str, key);*/
|
||||
|
||||
hook_signal_send ("key_pressed",
|
||||
WEECHAT_HOOK_SIGNAL_STRING, key_str);
|
||||
|
||||
if (gui_current_window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED)
|
||||
input_old = (gui_current_window->buffer->input_buffer) ?
|
||||
strdup (gui_current_window->buffer->input_buffer) : strdup ("");
|
||||
else
|
||||
input_old = NULL;
|
||||
|
||||
if ((gui_keyboard_pressed (key_str) != 0) && (insert_ok))
|
||||
{
|
||||
if (strcmp (key_str, "^^") == 0)
|
||||
key_str[1] = '\0';
|
||||
|
||||
gui_buffer_undo_snap (gui_current_window->buffer);
|
||||
gui_input_insert_string (gui_current_window->buffer,
|
||||
key_str, -1);
|
||||
if (gui_current_window->buffer->completion)
|
||||
gui_completion_stop (gui_current_window->buffer->completion, 0);
|
||||
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer, 1);
|
||||
}
|
||||
|
||||
/* incremental text search in buffer */
|
||||
if ((gui_current_window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED)
|
||||
&& ((input_old == NULL)
|
||||
|| (gui_current_window->buffer->input_buffer == NULL)
|
||||
|| (strcmp (input_old, gui_current_window->buffer->input_buffer) != 0)))
|
||||
{
|
||||
/*
|
||||
* if current input is longer than old input, and that
|
||||
* beginning of current input is exactly equal to old input,
|
||||
* then do nothing (search will not find any result and can
|
||||
* take some time on buffer with many lines..)
|
||||
*/
|
||||
if (!gui_current_window->buffer->text_search_found
|
||||
&& (input_old != NULL)
|
||||
&& (input_old[0])
|
||||
&& (gui_current_window->buffer->input_buffer != NULL)
|
||||
&& (gui_current_window->buffer->input_buffer[0])
|
||||
&& (strlen (gui_current_window->buffer->input_buffer) > strlen (input_old))
|
||||
&& (strncmp (gui_current_window->buffer->input_buffer, input_old,
|
||||
strlen (input_old)) == 0))
|
||||
{
|
||||
/*
|
||||
* do not search text in buffer, just alert about text not
|
||||
* found
|
||||
*/
|
||||
if (CONFIG_BOOLEAN(config_look_search_text_not_found_alert))
|
||||
printf ("\a");
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_window_search_restart (gui_current_window);
|
||||
}
|
||||
}
|
||||
|
||||
if (input_old)
|
||||
free (input_old);
|
||||
}
|
||||
|
||||
if (gui_key_grab && (gui_key_grab_count > 0))
|
||||
gui_keyboard_grab_end ();
|
||||
|
||||
gui_keyboard_buffer_reset ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_read_cb: read keyboard chars
|
||||
*/
|
||||
|
||||
int
|
||||
gui_keyboard_read_cb (void *data, int fd)
|
||||
{
|
||||
int ret, i, accept_paste, cancel_paste, text_added_to_buffer, paste_lines;
|
||||
unsigned char buffer[4096];
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) fd;
|
||||
|
||||
accept_paste = 0;
|
||||
cancel_paste = 0;
|
||||
text_added_to_buffer = 0;
|
||||
|
||||
if (gui_keyboard_paste_pending)
|
||||
{
|
||||
ret = read (STDIN_FILENO, buffer, 1);
|
||||
if (ret == 0)
|
||||
{
|
||||
/* no data on stdin, terminal lost */
|
||||
log_printf (_("Terminal lost, exiting WeeChat..."));
|
||||
hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
weechat_quit = 1;
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
if (ret <= 0)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
/* ctrl-Y: accept paste */
|
||||
if (buffer[0] == 25)
|
||||
accept_paste = 1;
|
||||
|
||||
/* ctrl-N: cancel paste */
|
||||
if (buffer[0] == 14)
|
||||
cancel_paste = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = read (STDIN_FILENO, buffer, sizeof (buffer));
|
||||
if (ret == 0)
|
||||
{
|
||||
/* no data on stdin, terminal lost */
|
||||
log_printf (_("Terminal lost, exiting WeeChat..."));
|
||||
hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
weechat_quit = 1;
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
if (ret < 0)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
for (i = 0; i < ret; i++)
|
||||
{
|
||||
gui_keyboard_buffer_add (buffer[i]);
|
||||
}
|
||||
|
||||
text_added_to_buffer = 1;
|
||||
}
|
||||
|
||||
if (gui_keyboard_paste_pending)
|
||||
{
|
||||
/* user is ok for pasting text, let's paste! */
|
||||
if (accept_paste)
|
||||
gui_keyboard_paste_accept ();
|
||||
/* user doesn't want to paste text: clear whole buffer! */
|
||||
else if (cancel_paste)
|
||||
gui_keyboard_paste_cancel ();
|
||||
else if (text_added_to_buffer)
|
||||
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* detect user paste or large amount of text
|
||||
* if so, ask user what to do
|
||||
*/
|
||||
if (CONFIG_INTEGER(config_look_paste_max_lines) > 0)
|
||||
{
|
||||
paste_lines = gui_keyboard_get_paste_lines ();
|
||||
if (paste_lines > CONFIG_INTEGER(config_look_paste_max_lines))
|
||||
{
|
||||
gui_keyboard_paste_pending = 1;
|
||||
gui_input_paste_pending_signal ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gui_keyboard_flush ();
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ gui_main_loop ()
|
||||
|
||||
/* hook stdin (read keyboard) */
|
||||
hook_fd_keyboard = hook_fd (NULL, STDIN_FILENO, 1, 0, 0,
|
||||
&gui_keyboard_read_cb, NULL);
|
||||
&gui_key_read_cb, NULL);
|
||||
|
||||
gui_window_ask_refresh (1);
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "../gui-color.h"
|
||||
#include "../gui-hotlist.h"
|
||||
#include "../gui-input.h"
|
||||
#include "../gui-key.h"
|
||||
#include "../gui-main.h"
|
||||
#include "../gui-line.h"
|
||||
#include "../gui-nicklist.h"
|
||||
|
||||
@@ -78,9 +78,9 @@ extern void gui_chat_calculate_line_diff (struct t_gui_window *window,
|
||||
struct t_gui_line **line,
|
||||
int *line_pos, int difference);
|
||||
|
||||
/* keyboard functions */
|
||||
extern void gui_keyboard_default_bindings ();
|
||||
extern int gui_keyboard_read_cb (void *data, int fd);
|
||||
/* key functions */
|
||||
extern void gui_key_default_bindings (int context);
|
||||
extern int gui_key_read_cb (void *data, int fd);
|
||||
|
||||
/* window functions */
|
||||
extern void gui_window_read_terminal_size ();
|
||||
|
||||
@@ -23,7 +23,7 @@ gui-gtk.h
|
||||
gui-gtk-bar-window.c
|
||||
gui-gtk-chat.c
|
||||
gui-gtk-color.c
|
||||
gui-gtk-keyboard.c
|
||||
gui-gtk-key.c
|
||||
gui-gtk-main.c
|
||||
gui-gtk-term.c
|
||||
gui-gtk-window.c)
|
||||
|
||||
@@ -35,7 +35,7 @@ weechat_gtk_LDADD = ./../../core/lib_weechat_core.a \
|
||||
weechat_gtk_SOURCES = gui-gtk-bar-window.c \
|
||||
gui-gtk-chat.c \
|
||||
gui-gtk-color.c \
|
||||
gui-gtk-keyboard.c \
|
||||
gui-gtk-key.c \
|
||||
gui-gtk-main.c \
|
||||
gui-gtk-term.c \
|
||||
gui-gtk-window.c \
|
||||
|
||||
@@ -31,27 +31,28 @@
|
||||
#include "../../core/weechat.h"
|
||||
#include "../../core/wee-utf8.h"
|
||||
#include "../../plugins/plugin.h"
|
||||
#include "../gui-keyboard.h"
|
||||
#include "../gui-key.h"
|
||||
#include "../gui-buffer.h"
|
||||
#include "gui-gtk.h"
|
||||
|
||||
|
||||
/*
|
||||
* gui_keyboard_default_bindings: create default key bindings
|
||||
* gui_key_default_bindings: create default key bindings
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_default_bindings ()
|
||||
gui_key_default_bindings (int context)
|
||||
{
|
||||
/* TODO: write this function for Gtk */
|
||||
(void) context;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_read: read keyboard chars
|
||||
* gui_key_read: read keyboard chars
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_read ()
|
||||
gui_key_read ()
|
||||
{
|
||||
/* TODO: write this function for Gtk */
|
||||
}
|
||||
@@ -98,10 +98,10 @@ extern void gui_chat_calculate_line_diff (struct t_gui_window *window,
|
||||
struct t_gui_line **line,
|
||||
int *line_pos, int difference);
|
||||
|
||||
/* keyboard functions */
|
||||
extern void gui_keyboard_default_bindings ();
|
||||
extern void gui_keyboard_read ();
|
||||
extern void gui_keyboard_flush ();
|
||||
/* key functions */
|
||||
extern void gui_key_default_bindings (int context);
|
||||
extern void gui_key_read ();
|
||||
extern void gui_key_flush ();
|
||||
|
||||
/* window functions */
|
||||
extern void gui_window_redraw_buffer (struct t_gui_buffer *buffer);
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
#include "gui-completion.h"
|
||||
#include "gui-filter.h"
|
||||
#include "gui-hotlist.h"
|
||||
#include "gui-keyboard.h"
|
||||
#include "gui-key.h"
|
||||
#include "gui-line.h"
|
||||
#include "gui-nicklist.h"
|
||||
#include "gui-window.h"
|
||||
@@ -628,7 +628,7 @@ gui_bar_item_default_input_paste (void *data, struct t_gui_bar_item *item,
|
||||
if (window != gui_current_window)
|
||||
return NULL;
|
||||
|
||||
if (!gui_keyboard_paste_pending)
|
||||
if (!gui_key_paste_pending)
|
||||
return NULL;
|
||||
|
||||
ptr_message = _(text_paste_pending);
|
||||
@@ -637,7 +637,7 @@ gui_bar_item_default_input_paste (void *data, struct t_gui_bar_item *item,
|
||||
if (buf)
|
||||
snprintf (buf, length, ptr_message,
|
||||
gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_input_actions))),
|
||||
gui_keyboard_get_paste_lines ());
|
||||
gui_key_get_paste_lines ());
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
#include "gui-history.h"
|
||||
#include "gui-hotlist.h"
|
||||
#include "gui-input.h"
|
||||
#include "gui-keyboard.h"
|
||||
#include "gui-key.h"
|
||||
#include "gui-layout.h"
|
||||
#include "gui-line.h"
|
||||
#include "gui-main.h"
|
||||
@@ -1532,17 +1532,17 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
|
||||
}
|
||||
else if (string_strncasecmp (property, "key_bind_", 9) == 0)
|
||||
{
|
||||
gui_keyboard_bind (buffer, property + 9, value);
|
||||
gui_key_bind (buffer, 0, 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,
|
||||
&buffer->keys_count);
|
||||
gui_key_free_all (&buffer->keys, &buffer->last_key,
|
||||
&buffer->keys_count);
|
||||
}
|
||||
else
|
||||
gui_keyboard_unbind (buffer, property + 11, 1);
|
||||
gui_key_unbind (buffer, 0, property + 11, 1);
|
||||
}
|
||||
else if (string_strcasecmp (property, "input") == 0)
|
||||
{
|
||||
@@ -2138,8 +2138,8 @@ gui_buffer_close (struct t_gui_buffer *buffer)
|
||||
string_free_split (buffer->highlight_tags_array);
|
||||
if (buffer->hotlist_max_level_nicks)
|
||||
hashtable_free (buffer->hotlist_max_level_nicks);
|
||||
gui_keyboard_free_all (&buffer->keys, &buffer->last_key,
|
||||
&buffer->keys_count);
|
||||
gui_key_free_all (&buffer->keys, &buffer->last_key,
|
||||
&buffer->keys_count);
|
||||
gui_buffer_local_var_remove_all (buffer);
|
||||
hashtable_free (buffer->local_variables);
|
||||
|
||||
@@ -3365,7 +3365,7 @@ gui_buffer_print_log ()
|
||||
{
|
||||
log_printf ("");
|
||||
log_printf (" => keys:");
|
||||
gui_keyboard_print_log (ptr_buffer);
|
||||
gui_key_print_log (ptr_buffer);
|
||||
}
|
||||
|
||||
if (ptr_buffer->local_variables)
|
||||
|
||||
+175
-130
@@ -40,7 +40,7 @@
|
||||
#include "gui-completion.h"
|
||||
#include "gui-history.h"
|
||||
#include "gui-hotlist.h"
|
||||
#include "gui-keyboard.h"
|
||||
#include "gui-key.h"
|
||||
#include "gui-line.h"
|
||||
#include "gui-window.h"
|
||||
|
||||
@@ -341,35 +341,28 @@ gui_input_return (struct t_gui_buffer *buffer)
|
||||
char *command;
|
||||
|
||||
window = gui_window_search_with_buffer (buffer);
|
||||
if (window && window->buffer->input)
|
||||
if (window && window->buffer->input
|
||||
&& (window->buffer->input_buffer_size > 0))
|
||||
{
|
||||
if (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED)
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
command = strdup (window->buffer->input_buffer);
|
||||
if (command)
|
||||
{
|
||||
gui_window_search_stop (window);
|
||||
gui_input_search_signal ();
|
||||
}
|
||||
else if (window->buffer->input_buffer_size > 0)
|
||||
{
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
command = strdup (window->buffer->input_buffer);
|
||||
if (command)
|
||||
{
|
||||
gui_history_add (window->buffer,
|
||||
window->buffer->input_buffer);
|
||||
window->buffer->input_buffer[0] = '\0';
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
gui_completion_stop (window->buffer->completion, 1);
|
||||
gui_buffer_undo_free_all (window->buffer);
|
||||
window->buffer->ptr_history = NULL;
|
||||
history_global_ptr = NULL;
|
||||
gui_input_optimize_size (window->buffer);
|
||||
gui_input_text_changed_modifier_and_signal (window->buffer, 0);
|
||||
input_data (window->buffer, command);
|
||||
free (command);
|
||||
}
|
||||
gui_history_add (window->buffer,
|
||||
window->buffer->input_buffer);
|
||||
window->buffer->input_buffer[0] = '\0';
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
gui_completion_stop (window->buffer->completion, 1);
|
||||
gui_buffer_undo_free_all (window->buffer);
|
||||
window->buffer->ptr_history = NULL;
|
||||
history_global_ptr = NULL;
|
||||
gui_input_optimize_size (window->buffer);
|
||||
gui_input_text_changed_modifier_and_signal (window->buffer, 0);
|
||||
input_data (window->buffer, command);
|
||||
free (command);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -498,7 +491,7 @@ gui_input_complete_previous (struct t_gui_buffer *buffer)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_search_text: search text in buffer history (default key: ctrl-r)
|
||||
* gui_input_search_text: search text in buffer (default key: ctrl-r)
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -507,16 +500,86 @@ gui_input_search_text (struct t_gui_buffer *buffer)
|
||||
struct t_gui_window *window;
|
||||
|
||||
window = gui_window_search_with_buffer (buffer);
|
||||
if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED))
|
||||
if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
|
||||
&& (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED))
|
||||
{
|
||||
/* toggle search */
|
||||
if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)
|
||||
gui_window_search_start (window);
|
||||
else
|
||||
{
|
||||
window->buffer->text_search_exact ^= 1;
|
||||
gui_window_search_restart (window);
|
||||
}
|
||||
gui_window_search_start (window);
|
||||
gui_input_search_signal ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_search_previous: search backward in buffer (default key: up during
|
||||
* search)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_search_previous (struct t_gui_buffer *buffer)
|
||||
{
|
||||
struct t_gui_window *window;
|
||||
|
||||
window = gui_window_search_with_buffer (buffer);
|
||||
if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
|
||||
&& (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
|
||||
{
|
||||
window->buffer->text_search = GUI_TEXT_SEARCH_BACKWARD;
|
||||
(void) gui_window_search_text (window);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_search_next: search forward in buffer (default key: down during
|
||||
* search)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_search_next (struct t_gui_buffer *buffer)
|
||||
{
|
||||
struct t_gui_window *window;
|
||||
|
||||
window = gui_window_search_with_buffer (buffer);
|
||||
if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
|
||||
&& (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
|
||||
{
|
||||
window->buffer->text_search = GUI_TEXT_SEARCH_FORWARD;
|
||||
(void) gui_window_search_text (window);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_search_switch_case: switch case for search in buffer (default key:
|
||||
* ctrl-r during search)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_search_switch_case (struct t_gui_buffer *buffer)
|
||||
{
|
||||
struct t_gui_window *window;
|
||||
|
||||
window = gui_window_search_with_buffer (buffer);
|
||||
if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
|
||||
&& (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
|
||||
{
|
||||
window->buffer->text_search_exact ^= 1;
|
||||
gui_window_search_restart (window);
|
||||
gui_input_search_signal ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_search_stop: stop text search (default key: return during search)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_search_stop (struct t_gui_buffer *buffer)
|
||||
{
|
||||
struct t_gui_window *window;
|
||||
|
||||
window = gui_window_search_with_buffer (buffer);
|
||||
if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
|
||||
&& (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
|
||||
{
|
||||
gui_window_search_stop (window);
|
||||
gui_input_search_signal ();
|
||||
}
|
||||
}
|
||||
@@ -948,57 +1011,48 @@ gui_input_history_previous (struct t_gui_window *window,
|
||||
if (!window->buffer->input)
|
||||
return;
|
||||
|
||||
if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)
|
||||
if (*ptr_history)
|
||||
{
|
||||
if (*ptr_history)
|
||||
{
|
||||
if (!(*ptr_history)->next_history)
|
||||
return;
|
||||
*ptr_history = (*ptr_history)->next_history;
|
||||
}
|
||||
if (!(*ptr_history))
|
||||
*ptr_history = history;
|
||||
|
||||
if (!(*ptr_history))
|
||||
if (!(*ptr_history)->next_history)
|
||||
return;
|
||||
|
||||
/* bash/readline like use of history */
|
||||
if (window->buffer->input_buffer_size > 0)
|
||||
{
|
||||
if ((*ptr_history)->prev_history)
|
||||
{
|
||||
/* replace text in history with current input */
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
if ((*ptr_history)->prev_history->text)
|
||||
free ((*ptr_history)->prev_history->text);
|
||||
(*ptr_history)->prev_history->text =
|
||||
strdup (window->buffer->input_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add current input in history */
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_history_add (window->buffer,
|
||||
window->buffer->input_buffer);
|
||||
}
|
||||
}
|
||||
window->buffer->input_buffer_size =
|
||||
strlen ((*ptr_history)->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen ((*ptr_history)->text);
|
||||
gui_input_optimize_size (window->buffer);
|
||||
window->buffer->input_buffer_pos = window->buffer->input_buffer_length;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
strcpy (window->buffer->input_buffer, (*ptr_history)->text);
|
||||
gui_input_text_changed_modifier_and_signal (window->buffer, 0);
|
||||
gui_buffer_undo_free_all (window->buffer);
|
||||
*ptr_history = (*ptr_history)->next_history;
|
||||
}
|
||||
else
|
||||
if (!(*ptr_history))
|
||||
*ptr_history = history;
|
||||
|
||||
if (!(*ptr_history))
|
||||
return;
|
||||
|
||||
/* bash/readline like use of history */
|
||||
if (window->buffer->input_buffer_size > 0)
|
||||
{
|
||||
/* search backward in buffer history */
|
||||
window->buffer->text_search = GUI_TEXT_SEARCH_BACKWARD;
|
||||
(void) gui_window_search_text (window);
|
||||
if ((*ptr_history)->prev_history)
|
||||
{
|
||||
/* replace text in history with current input */
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
if ((*ptr_history)->prev_history->text)
|
||||
free ((*ptr_history)->prev_history->text);
|
||||
(*ptr_history)->prev_history->text =
|
||||
strdup (window->buffer->input_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add current input in history */
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_history_add (window->buffer,
|
||||
window->buffer->input_buffer);
|
||||
}
|
||||
}
|
||||
window->buffer->input_buffer_size =
|
||||
strlen ((*ptr_history)->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen ((*ptr_history)->text);
|
||||
gui_input_optimize_size (window->buffer);
|
||||
window->buffer->input_buffer_pos = window->buffer->input_buffer_length;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
strcpy (window->buffer->input_buffer, (*ptr_history)->text);
|
||||
gui_input_text_changed_modifier_and_signal (window->buffer, 0);
|
||||
gui_buffer_undo_free_all (window->buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1020,62 +1074,53 @@ gui_input_history_next (struct t_gui_window *window,
|
||||
if (!window->buffer->input)
|
||||
return;
|
||||
|
||||
if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)
|
||||
if (*ptr_history)
|
||||
{
|
||||
*ptr_history = (*ptr_history)->prev_history;
|
||||
if (*ptr_history)
|
||||
{
|
||||
*ptr_history = (*ptr_history)->prev_history;
|
||||
if (*ptr_history)
|
||||
{
|
||||
window->buffer->input_buffer_size =
|
||||
strlen ((*ptr_history)->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen ((*ptr_history)->text);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->buffer->input_buffer[0] = '\0';
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
}
|
||||
gui_input_optimize_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_length;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
if (*ptr_history)
|
||||
{
|
||||
strcpy (window->buffer->input_buffer, (*ptr_history)->text);
|
||||
}
|
||||
input_changed = 1;
|
||||
window->buffer->input_buffer_size =
|
||||
strlen ((*ptr_history)->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen ((*ptr_history)->text);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add line to history then clear input */
|
||||
if (window->buffer->input_buffer_size > 0)
|
||||
{
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_history_add (window->buffer,
|
||||
window->buffer->input_buffer);
|
||||
window->buffer->input_buffer[0] = '\0';
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
gui_input_optimize_size (window->buffer);
|
||||
input_changed = 1;
|
||||
}
|
||||
window->buffer->input_buffer[0] = '\0';
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
}
|
||||
if (input_changed)
|
||||
gui_input_optimize_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_length;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
if (*ptr_history)
|
||||
{
|
||||
gui_input_text_changed_modifier_and_signal (window->buffer, 0);
|
||||
gui_buffer_undo_free_all (window->buffer);
|
||||
strcpy (window->buffer->input_buffer, (*ptr_history)->text);
|
||||
}
|
||||
input_changed = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* search forward in buffer history */
|
||||
window->buffer->text_search = GUI_TEXT_SEARCH_FORWARD;
|
||||
(void) gui_window_search_text (window);
|
||||
/* add line to history then clear input */
|
||||
if (window->buffer->input_buffer_size > 0)
|
||||
{
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_history_add (window->buffer,
|
||||
window->buffer->input_buffer);
|
||||
window->buffer->input_buffer[0] = '\0';
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
gui_input_optimize_size (window->buffer);
|
||||
input_changed = 1;
|
||||
}
|
||||
}
|
||||
if (input_changed)
|
||||
{
|
||||
gui_input_text_changed_modifier_and_signal (window->buffer, 0);
|
||||
gui_buffer_undo_free_all (window->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1297,7 +1342,7 @@ void
|
||||
gui_input_grab_key (struct t_gui_buffer *buffer)
|
||||
{
|
||||
if (buffer->input)
|
||||
gui_keyboard_grab_init (0);
|
||||
gui_key_grab_init (0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1309,7 +1354,7 @@ void
|
||||
gui_input_grab_key_command (struct t_gui_buffer *buffer)
|
||||
{
|
||||
if (buffer->input)
|
||||
gui_keyboard_grab_init (1);
|
||||
gui_key_grab_init (1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -43,6 +43,10 @@ extern void gui_input_return (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_complete_next (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_complete_previous (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_search_text (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_search_previous (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_search_next (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_search_switch_case (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_search_stop (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_delete_previous_char (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_delete_next_char (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_delete_previous_word (struct t_gui_buffer *buffer);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* gui-keyboard: keyboard functions (used by all GUI)
|
||||
* gui-key.c: keyboard functions (used by all GUI)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@@ -40,7 +40,7 @@
|
||||
#include "../core/wee-string.h"
|
||||
#include "../core/wee-utf8.h"
|
||||
#include "../plugins/plugin.h"
|
||||
#include "gui-keyboard.h"
|
||||
#include "gui-key.h"
|
||||
#include "gui-buffer.h"
|
||||
#include "gui-chat.h"
|
||||
#include "gui-color.h"
|
||||
@@ -49,60 +49,106 @@
|
||||
#include "gui-window.h"
|
||||
|
||||
|
||||
struct t_gui_key *gui_keys = NULL; /* key bindings */
|
||||
struct t_gui_key *last_gui_key = NULL; /* last key binding */
|
||||
struct t_gui_key *gui_default_keys = NULL; /* default key bindings */
|
||||
struct t_gui_key *last_gui_default_key = NULL; /* last default key binding */
|
||||
struct t_gui_key *gui_keys[GUI_KEY_NUM_CONTEXTS]; /* keys by context */
|
||||
struct t_gui_key *last_gui_key[GUI_KEY_NUM_CONTEXTS]; /* last key */
|
||||
struct t_gui_key *gui_default_keys[GUI_KEY_NUM_CONTEXTS]; /* default keys */
|
||||
struct t_gui_key *last_gui_default_key[GUI_KEY_NUM_CONTEXTS];
|
||||
int gui_keys_count[GUI_KEY_NUM_CONTEXTS]; /* keys number */
|
||||
int gui_default_keys_count[GUI_KEY_NUM_CONTEXTS]; /* default keys number */
|
||||
|
||||
int gui_keys_count = 0; /* number of defined keys */
|
||||
int gui_default_keys_count = 0; /* number of default keys */
|
||||
char *gui_key_context_string[GUI_KEY_NUM_CONTEXTS] =
|
||||
{ "default", "search" };
|
||||
|
||||
int gui_keyboard_verbose = 0; /* 1 to see some messages */
|
||||
int gui_key_verbose = 0; /* 1 to see some messages */
|
||||
|
||||
char gui_key_combo_buffer[128]; /* 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? */
|
||||
|
||||
int *gui_keyboard_buffer = NULL; /* input buffer (for paste detection) */
|
||||
int gui_keyboard_buffer_alloc = 0; /* input buffer allocated size */
|
||||
int gui_keyboard_buffer_size = 0; /* input buffer size in bytes */
|
||||
int *gui_key_buffer = NULL; /* input buffer (for paste detection) */
|
||||
int gui_key_buffer_alloc = 0; /* input buffer allocated size */
|
||||
int gui_key_buffer_size = 0; /* input buffer size in bytes */
|
||||
|
||||
int gui_keyboard_paste_pending = 0; /* 1 is big paste was detected and */
|
||||
int gui_key_paste_pending = 0; /* 1 is big paste was detected and */
|
||||
/* WeeChat is asking user what to do */
|
||||
int gui_keyboard_paste_lines = 0; /* number of lines for pending paste */
|
||||
int gui_key_paste_lines = 0; /* number of lines for pending paste */
|
||||
|
||||
time_t gui_keyboard_last_activity_time = 0; /* last activity time (key) */
|
||||
time_t gui_key_last_activity_time = 0; /* last activity time (key) */
|
||||
|
||||
|
||||
/*
|
||||
* gui_keyboard_init: init keyboard
|
||||
* gui_key_init: init keyboard
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_init ()
|
||||
gui_key_init ()
|
||||
{
|
||||
int i;
|
||||
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
gui_key_grab = 0;
|
||||
gui_key_grab_count = 0;
|
||||
gui_keyboard_last_activity_time = time (NULL);
|
||||
gui_key_last_activity_time = time (NULL);
|
||||
|
||||
/* create default keys and save them in a separate list */
|
||||
gui_keyboard_default_bindings ();
|
||||
gui_default_keys = gui_keys;
|
||||
last_gui_default_key = last_gui_key;
|
||||
gui_default_keys_count = gui_keys_count;
|
||||
gui_keys = NULL;
|
||||
last_gui_key = NULL;
|
||||
gui_keys_count = 0;
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
gui_keys[i] = NULL;
|
||||
last_gui_key[i] = NULL;
|
||||
gui_default_keys[i] = NULL;
|
||||
last_gui_default_key[i] = NULL;
|
||||
gui_keys_count[i] = 0;
|
||||
gui_default_keys_count[i] = 0;
|
||||
gui_key_default_bindings (i);
|
||||
gui_default_keys[i] = gui_keys[i];
|
||||
last_gui_default_key[i] = last_gui_key[i];
|
||||
gui_default_keys_count[i] = gui_keys_count[i];
|
||||
gui_keys[i] = NULL;
|
||||
last_gui_key[i] = NULL;
|
||||
gui_keys_count[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_grab_init: init "grab" mode
|
||||
* gui_key_search_context: search context by name
|
||||
*/
|
||||
|
||||
int
|
||||
gui_key_search_context (const char *context)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
if (string_strcasecmp (gui_key_context_string[i], context) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
/* context not found */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_get_current_context: get current context
|
||||
*/
|
||||
|
||||
int
|
||||
gui_key_get_current_context ()
|
||||
{
|
||||
if (gui_current_window
|
||||
&& (gui_current_window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
|
||||
return GUI_KEY_CONTEXT_SEARCH;
|
||||
|
||||
return GUI_KEY_CONTEXT_DEFAULT;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_grab_init: init "grab" mode
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_grab_init (int grab_command)
|
||||
gui_key_grab_init (int grab_command)
|
||||
{
|
||||
gui_key_grab = 1;
|
||||
gui_key_grab_count = 0;
|
||||
@@ -110,17 +156,17 @@ gui_keyboard_grab_init (int grab_command)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_grab_end: insert grabbed key in input buffer
|
||||
* gui_key_grab_end: insert grabbed key in input buffer
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_grab_end ()
|
||||
gui_key_grab_end ()
|
||||
{
|
||||
char *expanded_key;
|
||||
struct t_gui_key *ptr_key;
|
||||
|
||||
/* get expanded name (for example: ^U => ctrl-u) */
|
||||
expanded_key = gui_keyboard_get_expanded_name (gui_key_combo_buffer);
|
||||
expanded_key = gui_key_get_expanded_name (gui_key_combo_buffer);
|
||||
|
||||
if (expanded_key)
|
||||
{
|
||||
@@ -129,7 +175,8 @@ gui_keyboard_grab_end ()
|
||||
gui_input_insert_string (gui_current_window->buffer, expanded_key, -1);
|
||||
if (gui_key_grab_command)
|
||||
{
|
||||
ptr_key = gui_keyboard_search (gui_keys, gui_key_combo_buffer);
|
||||
ptr_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT],
|
||||
gui_key_combo_buffer);
|
||||
if (ptr_key)
|
||||
{
|
||||
gui_input_insert_string (gui_current_window->buffer, " ", -1);
|
||||
@@ -151,12 +198,12 @@ gui_keyboard_grab_end ()
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_get_internal_code: get internal code from user key name
|
||||
* for example: return "^R" for "ctrl-R"
|
||||
* gui_key_get_internal_code: get internal code from user key name
|
||||
* for example: return "^R" for "ctrl-R"
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_keyboard_get_internal_code (const char *key)
|
||||
gui_key_get_internal_code (const char *key)
|
||||
{
|
||||
char *result;
|
||||
|
||||
@@ -194,12 +241,12 @@ gui_keyboard_get_internal_code (const char *key)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_get_expanded_name: get expanded name from internal key code
|
||||
* for example: return "ctrl-R" for "^R"
|
||||
* gui_key_get_expanded_name: get expanded name from internal key code
|
||||
* for example: return "ctrl-R" for "^R"
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_keyboard_get_expanded_name (const char *key)
|
||||
gui_key_get_expanded_name (const char *key)
|
||||
{
|
||||
char *result;
|
||||
|
||||
@@ -239,11 +286,11 @@ gui_keyboard_get_expanded_name (const char *key)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_find_pos: find position for a key (for sorting keys list)
|
||||
* gui_key_find_pos: find position for a key (for sorting keys list)
|
||||
*/
|
||||
|
||||
struct t_gui_key *
|
||||
gui_keyboard_find_pos (struct t_gui_key *keys, struct t_gui_key *key)
|
||||
gui_key_find_pos (struct t_gui_key *keys, struct t_gui_key *key)
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
|
||||
@@ -256,20 +303,20 @@ gui_keyboard_find_pos (struct t_gui_key *keys, struct t_gui_key *key)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_insert_sorted: insert key into sorted list
|
||||
* gui_key_insert_sorted: insert key into sorted list
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_insert_sorted (struct t_gui_key **keys,
|
||||
struct t_gui_key **last_key,
|
||||
int *keys_count,
|
||||
struct t_gui_key *key)
|
||||
gui_key_insert_sorted (struct t_gui_key **keys,
|
||||
struct t_gui_key **last_key,
|
||||
int *keys_count,
|
||||
struct t_gui_key *key)
|
||||
{
|
||||
struct t_gui_key *pos_key;
|
||||
|
||||
if (*keys)
|
||||
{
|
||||
pos_key = gui_keyboard_find_pos (*keys, key);
|
||||
pos_key = gui_key_find_pos (*keys, key);
|
||||
|
||||
if (pos_key)
|
||||
{
|
||||
@@ -304,14 +351,14 @@ gui_keyboard_insert_sorted (struct t_gui_key **keys,
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
* gui_key_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 (struct t_gui_buffer *buffer, const char *key,
|
||||
const char *command)
|
||||
gui_key_new (struct t_gui_buffer *buffer, int context, const char *key,
|
||||
const char *command)
|
||||
{
|
||||
struct t_gui_key *new_key;
|
||||
char *expanded_name;
|
||||
@@ -321,7 +368,7 @@ gui_keyboard_new (struct t_gui_buffer *buffer, const char *key,
|
||||
|
||||
if ((new_key = malloc (sizeof (*new_key))))
|
||||
{
|
||||
new_key->key = gui_keyboard_get_internal_code (key);
|
||||
new_key->key = gui_key_get_internal_code (key);
|
||||
if (!new_key->key)
|
||||
new_key->key = strdup (key);
|
||||
if (!new_key->key)
|
||||
@@ -339,21 +386,22 @@ gui_keyboard_new (struct t_gui_buffer *buffer, const char *key,
|
||||
|
||||
if (buffer)
|
||||
{
|
||||
gui_keyboard_insert_sorted (&buffer->keys, &buffer->last_key,
|
||||
&buffer->keys_count, new_key);
|
||||
gui_key_insert_sorted (&buffer->keys, &buffer->last_key,
|
||||
&buffer->keys_count, new_key);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_keyboard_insert_sorted (&gui_keys, &last_gui_key,
|
||||
&gui_keys_count, new_key);
|
||||
gui_key_insert_sorted (&gui_keys[context],
|
||||
&last_gui_key[context],
|
||||
&gui_keys_count[context], new_key);
|
||||
}
|
||||
|
||||
expanded_name = gui_keyboard_get_expanded_name (new_key->key);
|
||||
expanded_name = gui_key_get_expanded_name (new_key->key);
|
||||
|
||||
hook_signal_send ("key_bind",
|
||||
WEECHAT_HOOK_SIGNAL_STRING, expanded_name);
|
||||
|
||||
if (gui_keyboard_verbose)
|
||||
if (gui_key_verbose)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("New key binding: %s%s => %s%s"),
|
||||
@@ -372,11 +420,11 @@ gui_keyboard_new (struct t_gui_buffer *buffer, const char *key,
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_search: search a key
|
||||
* gui_key_search: search a key
|
||||
*/
|
||||
|
||||
struct t_gui_key *
|
||||
gui_keyboard_search (struct t_gui_key *keys, const char *key)
|
||||
gui_key_search (struct t_gui_key *keys, const char *key)
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
|
||||
@@ -391,11 +439,11 @@ gui_keyboard_search (struct t_gui_key *keys, const char *key)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_cmp: compares 2 keys
|
||||
* gui_key_cmp: compares 2 keys
|
||||
*/
|
||||
|
||||
int
|
||||
gui_keyboard_cmp (const char *key, const char *search)
|
||||
gui_key_cmp (const char *key, const char *search)
|
||||
{
|
||||
int diff;
|
||||
|
||||
@@ -412,18 +460,19 @@ gui_keyboard_cmp (const char *key, const char *search)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_search_part: search a key (maybe part of string)
|
||||
* gui_key_search_part: search a key (maybe part of string)
|
||||
*/
|
||||
|
||||
struct t_gui_key *
|
||||
gui_keyboard_search_part (struct t_gui_buffer *buffer, const char *key)
|
||||
gui_key_search_part (struct t_gui_buffer *buffer, int context,
|
||||
const char *key)
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
|
||||
for (ptr_key = (buffer) ? buffer->keys : gui_keys; ptr_key;
|
||||
for (ptr_key = (buffer) ? buffer->keys : gui_keys[context]; ptr_key;
|
||||
ptr_key = ptr_key->next_key)
|
||||
{
|
||||
if (ptr_key->key && (gui_keyboard_cmp (ptr_key->key, key) == 0))
|
||||
if (ptr_key->key && (gui_key_cmp (ptr_key->key, key) == 0))
|
||||
return ptr_key;
|
||||
}
|
||||
|
||||
@@ -432,13 +481,14 @@ gui_keyboard_search_part (struct t_gui_buffer *buffer, const char *key)
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
* gui_key_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 (struct t_gui_buffer *buffer, const char *key, const char *command)
|
||||
gui_key_bind (struct t_gui_buffer *buffer, int context, const char *key,
|
||||
const char *command)
|
||||
{
|
||||
struct t_gui_key *new_key;
|
||||
|
||||
@@ -448,9 +498,9 @@ gui_keyboard_bind (struct t_gui_buffer *buffer, const char *key, const char *com
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gui_keyboard_unbind (buffer, key, 0);
|
||||
gui_key_unbind (buffer, context, key, 0);
|
||||
|
||||
new_key = gui_keyboard_new (buffer, key, command);
|
||||
new_key = gui_key_new (buffer, context, key, command);
|
||||
if (!new_key)
|
||||
{
|
||||
log_printf (_("Error: not enough memory for key binding"));
|
||||
@@ -461,31 +511,31 @@ gui_keyboard_bind (struct t_gui_buffer *buffer, const char *key, const char *com
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_unbind: remove a key binding
|
||||
* gui_key_unbind: remove a key binding
|
||||
*/
|
||||
|
||||
int
|
||||
gui_keyboard_unbind (struct t_gui_buffer *buffer, const char *key,
|
||||
int send_signal)
|
||||
gui_key_unbind (struct t_gui_buffer *buffer, int context, const char *key,
|
||||
int send_signal)
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
char *internal_code;
|
||||
|
||||
internal_code = gui_keyboard_get_internal_code (key);
|
||||
internal_code = gui_key_get_internal_code (key);
|
||||
|
||||
ptr_key = gui_keyboard_search ((buffer) ? buffer->keys : gui_keys,
|
||||
(internal_code) ? internal_code : key);
|
||||
ptr_key = gui_key_search ((buffer) ? buffer->keys : gui_keys[context],
|
||||
(internal_code) ? internal_code : key);
|
||||
if (ptr_key)
|
||||
{
|
||||
if (buffer)
|
||||
{
|
||||
gui_keyboard_free (&buffer->keys, &buffer->last_key,
|
||||
&buffer->keys_count, ptr_key);
|
||||
gui_key_free (&buffer->keys, &buffer->last_key,
|
||||
&buffer->keys_count, ptr_key);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_keyboard_free (&gui_keys, &last_gui_key,
|
||||
&gui_keys_count, ptr_key);
|
||||
gui_key_free (&gui_keys[context], &last_gui_key[context],
|
||||
&gui_keys_count[context], ptr_key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,15 +552,15 @@ gui_keyboard_unbind (struct t_gui_buffer *buffer, const char *key,
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_pressed: treat new key pressed
|
||||
* return: 1 if key should be added to input buffer
|
||||
* 0 otherwise
|
||||
* gui_key_pressed: treat new key pressed
|
||||
* return: 1 if key should be added to input buffer
|
||||
* 0 otherwise
|
||||
*/
|
||||
|
||||
int
|
||||
gui_keyboard_pressed (const char *key_str)
|
||||
gui_key_pressed (const char *key_str)
|
||||
{
|
||||
int first_key;
|
||||
int first_key, context;
|
||||
struct t_gui_key *ptr_key;
|
||||
char *buffer_before_key;
|
||||
char **commands, **ptr_cmd;
|
||||
@@ -526,12 +576,32 @@ gui_keyboard_pressed (const char *key_str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
context = gui_key_get_current_context ();
|
||||
switch (context)
|
||||
{
|
||||
case GUI_KEY_CONTEXT_DEFAULT:
|
||||
/* look for key combo in key table for current buffer */
|
||||
ptr_key = gui_key_search_part (gui_current_window->buffer,
|
||||
GUI_KEY_CONTEXT_DEFAULT,
|
||||
gui_key_combo_buffer);
|
||||
/* if key is not found for buffer, then look in general table */
|
||||
if (!ptr_key)
|
||||
ptr_key = gui_key_search_part (NULL,
|
||||
GUI_KEY_CONTEXT_DEFAULT,
|
||||
gui_key_combo_buffer);
|
||||
break;
|
||||
case GUI_KEY_CONTEXT_SEARCH:
|
||||
ptr_key = gui_key_search_part (NULL,
|
||||
GUI_KEY_CONTEXT_SEARCH,
|
||||
gui_key_combo_buffer);
|
||||
if (!ptr_key)
|
||||
{
|
||||
ptr_key = gui_key_search_part (NULL,
|
||||
GUI_KEY_CONTEXT_DEFAULT,
|
||||
gui_key_combo_buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* if key is found, then execute action */
|
||||
if (ptr_key)
|
||||
@@ -573,12 +643,12 @@ gui_keyboard_pressed (const char *key_str)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_free: delete a key binding
|
||||
* gui_key_free: delete a key binding
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_free (struct t_gui_key **keys, struct t_gui_key **last_key,
|
||||
int *keys_count, struct t_gui_key *key)
|
||||
gui_key_free (struct t_gui_key **keys, struct t_gui_key **last_key,
|
||||
int *keys_count, struct t_gui_key *key)
|
||||
{
|
||||
/* free memory */
|
||||
if (key->key)
|
||||
@@ -602,157 +672,161 @@ gui_keyboard_free (struct t_gui_key **keys, struct t_gui_key **last_key,
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_free_all: delete all key bindings
|
||||
* gui_key_free_all: delete all key bindings
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_free_all (struct t_gui_key **keys, struct t_gui_key **last_key,
|
||||
gui_key_free_all (struct t_gui_key **keys, struct t_gui_key **last_key,
|
||||
int *keys_count)
|
||||
{
|
||||
while (*keys)
|
||||
{
|
||||
gui_keyboard_free (keys, last_key, keys_count, *keys);
|
||||
gui_key_free (keys, last_key, keys_count, *keys);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_buffer_optimize: optimize keyboard buffer size
|
||||
* gui_key_buffer_optimize: optimize keyboard buffer size
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_buffer_optimize ()
|
||||
gui_key_buffer_optimize ()
|
||||
{
|
||||
int optimal_size;
|
||||
|
||||
optimal_size = (((gui_keyboard_buffer_size * sizeof (int)) /
|
||||
GUI_KEYBOARD_BUFFER_BLOCK_SIZE) *
|
||||
GUI_KEYBOARD_BUFFER_BLOCK_SIZE) +
|
||||
GUI_KEYBOARD_BUFFER_BLOCK_SIZE;
|
||||
optimal_size = (((gui_key_buffer_size * sizeof (int)) /
|
||||
GUI_KEY_BUFFER_BLOCK_SIZE) *
|
||||
GUI_KEY_BUFFER_BLOCK_SIZE) +
|
||||
GUI_KEY_BUFFER_BLOCK_SIZE;
|
||||
|
||||
if (gui_keyboard_buffer_alloc != optimal_size)
|
||||
if (gui_key_buffer_alloc != optimal_size)
|
||||
{
|
||||
gui_keyboard_buffer_alloc = optimal_size;
|
||||
gui_keyboard_buffer = realloc (gui_keyboard_buffer, optimal_size);
|
||||
gui_key_buffer_alloc = optimal_size;
|
||||
gui_key_buffer = realloc (gui_key_buffer, optimal_size);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_buffer_reset: reset keyboard buffer
|
||||
* (create empty if never created before)
|
||||
* gui_key_buffer_reset: reset keyboard buffer
|
||||
* (create empty if never created before)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_buffer_reset ()
|
||||
gui_key_buffer_reset ()
|
||||
{
|
||||
if (!gui_keyboard_buffer)
|
||||
if (!gui_key_buffer)
|
||||
{
|
||||
gui_keyboard_buffer_alloc = GUI_KEYBOARD_BUFFER_BLOCK_SIZE;
|
||||
gui_keyboard_buffer_size = 0;
|
||||
gui_keyboard_buffer = malloc (gui_keyboard_buffer_alloc);
|
||||
gui_key_buffer_alloc = GUI_KEY_BUFFER_BLOCK_SIZE;
|
||||
gui_key_buffer_size = 0;
|
||||
gui_key_buffer = malloc (gui_key_buffer_alloc);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_keyboard_buffer_size = 0;
|
||||
gui_keyboard_buffer_optimize ();
|
||||
gui_key_buffer_size = 0;
|
||||
gui_key_buffer_optimize ();
|
||||
}
|
||||
gui_keyboard_paste_lines = 0;
|
||||
gui_key_paste_lines = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_buffer_add: add a key to keyboard buffer
|
||||
* gui_key_buffer_add: add a key to keyboard buffer
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_buffer_add (unsigned char key)
|
||||
gui_key_buffer_add (unsigned char key)
|
||||
{
|
||||
if (!gui_keyboard_buffer)
|
||||
gui_keyboard_buffer_reset ();
|
||||
if (!gui_key_buffer)
|
||||
gui_key_buffer_reset ();
|
||||
|
||||
gui_keyboard_buffer_size++;
|
||||
gui_key_buffer_size++;
|
||||
|
||||
gui_keyboard_buffer_optimize ();
|
||||
gui_key_buffer_optimize ();
|
||||
|
||||
if (gui_keyboard_buffer)
|
||||
if (gui_key_buffer)
|
||||
{
|
||||
gui_keyboard_buffer[gui_keyboard_buffer_size - 1] = key;
|
||||
gui_key_buffer[gui_key_buffer_size - 1] = key;
|
||||
if ((key == 13)
|
||||
&& (gui_keyboard_buffer_size > 1)
|
||||
&& (gui_keyboard_buffer[gui_keyboard_buffer_size - 2] != 13))
|
||||
gui_keyboard_paste_lines++;
|
||||
&& (gui_key_buffer_size > 1)
|
||||
&& (gui_key_buffer[gui_key_buffer_size - 2] != 13))
|
||||
gui_key_paste_lines++;
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_keyboard_buffer_alloc = 0;
|
||||
gui_keyboard_buffer_size = 0;
|
||||
gui_keyboard_paste_lines = 0;
|
||||
gui_key_buffer_alloc = 0;
|
||||
gui_key_buffer_size = 0;
|
||||
gui_key_paste_lines = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_get_paste_lines: return real number of lines in buffer
|
||||
* if last key is not Return, then this is lines + 1
|
||||
* else it's lines
|
||||
* gui_key_get_paste_lines: return real number of lines in buffer
|
||||
* if last key is not Return, then this is lines + 1
|
||||
* else it's lines
|
||||
*/
|
||||
|
||||
int
|
||||
gui_keyboard_get_paste_lines ()
|
||||
gui_key_get_paste_lines ()
|
||||
{
|
||||
if ((gui_keyboard_buffer_size > 0)
|
||||
&& (gui_keyboard_buffer[gui_keyboard_buffer_size - 1] != 13))
|
||||
return gui_keyboard_paste_lines + 1;
|
||||
if ((gui_key_buffer_size > 0)
|
||||
&& (gui_key_buffer[gui_key_buffer_size - 1] != 13))
|
||||
return gui_key_paste_lines + 1;
|
||||
|
||||
return gui_keyboard_paste_lines;
|
||||
return gui_key_paste_lines;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_paste_accept: accept paste from user
|
||||
* gui_key_paste_accept: accept paste from user
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_paste_accept ()
|
||||
gui_key_paste_accept ()
|
||||
{
|
||||
gui_keyboard_paste_pending = 0;
|
||||
gui_input_paste_pending_signal ();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* gui_keyboard_paste_cancel: cancel paste from user (reset buffer)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_paste_cancel ()
|
||||
{
|
||||
gui_keyboard_buffer_reset ();
|
||||
gui_keyboard_paste_pending = 0;
|
||||
gui_key_paste_pending = 0;
|
||||
gui_input_paste_pending_signal ();
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_end: end keyboard (free some data)
|
||||
* gui_key_paste_cancel: cancel paste from user (reset buffer)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_end ()
|
||||
gui_key_paste_cancel ()
|
||||
{
|
||||
/* free keyboard buffer */
|
||||
if (gui_keyboard_buffer)
|
||||
free (gui_keyboard_buffer);
|
||||
|
||||
/* free all keys */
|
||||
gui_keyboard_free_all (&gui_keys, &last_gui_key, &gui_keys_count);
|
||||
|
||||
/* free all default keys */
|
||||
gui_keyboard_free_all (&gui_default_keys, &last_gui_default_key,
|
||||
&gui_default_keys_count);
|
||||
gui_key_buffer_reset ();
|
||||
gui_key_paste_pending = 0;
|
||||
gui_input_paste_pending_signal ();
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_hdata_key_cb: return hdata for key
|
||||
* gui_key_end: end keyboard (free some data)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_key_end ()
|
||||
{
|
||||
int i;
|
||||
|
||||
/* free key buffer */
|
||||
if (gui_key_buffer)
|
||||
free (gui_key_buffer);
|
||||
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
/* free keys */
|
||||
gui_key_free_all (&gui_keys[i], &last_gui_key[i],
|
||||
&gui_keys_count[i]);
|
||||
/* free default keys */
|
||||
gui_key_free_all (&gui_default_keys[i], &last_gui_default_key[i],
|
||||
&gui_default_keys_count[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_hdata_key_cb: return hdata for key
|
||||
*/
|
||||
|
||||
struct t_hdata *
|
||||
gui_keyboard_hdata_key_cb (void *data, const char *hdata_name)
|
||||
gui_key_hdata_key_cb (void *data, const char *hdata_name)
|
||||
{
|
||||
struct t_hdata *hdata;
|
||||
|
||||
@@ -775,13 +849,12 @@ gui_keyboard_hdata_key_cb (void *data, const char *hdata_name)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_add_to_infolist: add a key in an infolist
|
||||
* return 1 if ok, 0 if error
|
||||
* gui_key_add_to_infolist: add a key in an infolist
|
||||
* return 1 if ok, 0 if error
|
||||
*/
|
||||
|
||||
int
|
||||
gui_keyboard_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_gui_key *key)
|
||||
gui_key_add_to_infolist (struct t_infolist *infolist, struct t_gui_key *key)
|
||||
{
|
||||
struct t_infolist_item *ptr_item;
|
||||
char *expanded_key;
|
||||
@@ -795,7 +868,7 @@ gui_keyboard_add_to_infolist (struct t_infolist *infolist,
|
||||
|
||||
if (!infolist_new_var_string (ptr_item, "key_internal", key->key))
|
||||
return 0;
|
||||
expanded_key = gui_keyboard_get_expanded_name (key->key);
|
||||
expanded_key = gui_key_get_expanded_name (key->key);
|
||||
if (expanded_key)
|
||||
{
|
||||
if (!infolist_new_var_string (ptr_item, "key", expanded_key))
|
||||
@@ -809,34 +882,49 @@ gui_keyboard_add_to_infolist (struct t_infolist *infolist,
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_keyboard_print_log: print key infos in log (usually for crash dump)
|
||||
* gui_key_print_log: print key infos in log (usually for crash dump)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_keyboard_print_log (struct t_gui_buffer *buffer)
|
||||
gui_key_print_log (struct t_gui_buffer *buffer)
|
||||
{
|
||||
struct t_gui_key *ptr_keys, *ptr_last_key, *ptr_key;
|
||||
int keys_count;
|
||||
char prefix[32];
|
||||
struct t_gui_key *ptr_key;
|
||||
int i;
|
||||
|
||||
ptr_keys = (buffer) ? buffer->keys : gui_keys;
|
||||
ptr_last_key = (buffer) ? buffer->last_key : last_gui_key;
|
||||
keys_count = (buffer) ? buffer->keys_count : gui_keys_count;
|
||||
|
||||
snprintf (prefix, sizeof (prefix), "%s", (buffer) ? " " : "");
|
||||
|
||||
log_printf ("%skeys . . . . . . . . : 0x%lx", prefix, ptr_keys);
|
||||
log_printf ("%slast_key . . . . . . : 0x%lx", prefix, ptr_last_key);
|
||||
log_printf ("%skeys_count . . . . . : %d", prefix, keys_count);
|
||||
|
||||
for (ptr_key = (buffer) ? buffer->keys : gui_keys; ptr_key;
|
||||
ptr_key = ptr_key->next_key)
|
||||
if (buffer)
|
||||
{
|
||||
log_printf ("");
|
||||
log_printf ("%s[key (addr:0x%lx)]", prefix, ptr_key);
|
||||
log_printf ("%s key. . . . . . . . : '%s'", prefix, ptr_key->key);
|
||||
log_printf ("%s command. . . . . . : '%s'", prefix, ptr_key->command);
|
||||
log_printf ("%s prev_key . . . . . : 0x%lx", prefix, ptr_key->prev_key);
|
||||
log_printf ("%s next_key . . . . . : 0x%lx", prefix, ptr_key->next_key);
|
||||
log_printf (" keys . . . . . . . . : 0x%lx", buffer->keys);
|
||||
log_printf (" last_key . . . . . . : 0x%lx", buffer->last_key);
|
||||
log_printf (" keys_count . . . . . : %d", buffer->keys_count);
|
||||
for (ptr_key = buffer->keys; ptr_key; ptr_key = ptr_key->next_key)
|
||||
{
|
||||
log_printf ("");
|
||||
log_printf (" [key (addr:0x%lx)]", ptr_key);
|
||||
log_printf (" key. . . . . . . . : '%s'", ptr_key->key);
|
||||
log_printf (" command. . . . . . : '%s'", ptr_key->command);
|
||||
log_printf (" prev_key . . . . . : 0x%lx", ptr_key->prev_key);
|
||||
log_printf (" next_key . . . . . : 0x%lx", ptr_key->next_key);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
log_printf ("[keys for context: %s]", gui_key_context_string[i]);
|
||||
log_printf ("");
|
||||
log_printf (" keys . . . . . . . . : 0x%lx", gui_keys[i]);
|
||||
log_printf (" last_key . . . . . . : 0x%lx", last_gui_key[i]);
|
||||
log_printf (" keys_count . . . . . : %d", gui_keys_count[i]);
|
||||
|
||||
for (ptr_key = gui_keys[i]; ptr_key; ptr_key = ptr_key->next_key)
|
||||
{
|
||||
log_printf ("");
|
||||
log_printf ("[key (addr:0x%lx)]", ptr_key);
|
||||
log_printf (" key. . . . . . . . : '%s'", ptr_key->key);
|
||||
log_printf (" command. . . . . . : '%s'", ptr_key->command);
|
||||
log_printf (" prev_key . . . . . : 0x%lx", ptr_key->prev_key);
|
||||
log_printf (" next_key . . . . . : 0x%lx", ptr_key->next_key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __WEECHAT_GUI_KEY_H
|
||||
#define __WEECHAT_GUI_KEY_H 1
|
||||
|
||||
#define GUI_KEY_BUFFER_BLOCK_SIZE 256
|
||||
|
||||
enum t_gui_key_context
|
||||
{
|
||||
GUI_KEY_CONTEXT_DEFAULT = 0,
|
||||
GUI_KEY_CONTEXT_SEARCH,
|
||||
/* number of key contexts */
|
||||
GUI_KEY_NUM_CONTEXTS,
|
||||
};
|
||||
|
||||
/* key structures */
|
||||
|
||||
struct t_gui_key
|
||||
{
|
||||
char *key; /* key combo (ex: a, ^W, ^W^C, meta-a) */
|
||||
char *command; /* associated command (may be NULL) */
|
||||
struct t_gui_key *prev_key; /* link to previous key */
|
||||
struct t_gui_key *next_key; /* link to next key */
|
||||
};
|
||||
|
||||
/* key variables */
|
||||
|
||||
extern struct t_gui_key *gui_keys[GUI_KEY_NUM_CONTEXTS];
|
||||
extern struct t_gui_key *last_gui_key[GUI_KEY_NUM_CONTEXTS];
|
||||
extern struct t_gui_key *gui_default_keys[GUI_KEY_NUM_CONTEXTS];
|
||||
extern struct t_gui_key *last_gui_default_key[GUI_KEY_NUM_CONTEXTS];
|
||||
extern int gui_keys_count[GUI_KEY_NUM_CONTEXTS];
|
||||
extern int gui_default_keys_count[GUI_KEY_NUM_CONTEXTS];
|
||||
extern char *gui_key_context_string[GUI_KEY_NUM_CONTEXTS];
|
||||
extern int gui_key_verbose;
|
||||
extern char gui_key_combo_buffer[];
|
||||
extern int gui_key_grab;
|
||||
extern int gui_key_grab_count;
|
||||
extern int *gui_key_buffer;
|
||||
extern int gui_key_buffer_size;
|
||||
extern int gui_key_paste_pending;
|
||||
extern time_t gui_key_last_activity_time;
|
||||
|
||||
/* key functions */
|
||||
|
||||
extern void gui_key_init ();
|
||||
extern int gui_key_search_context (const char *context);
|
||||
extern void gui_key_grab_init (int grab_command);
|
||||
extern void gui_key_grab_end ();
|
||||
extern char *gui_key_get_internal_code (const char *key);
|
||||
extern char *gui_key_get_expanded_name (const char *key);
|
||||
extern struct t_gui_key *gui_key_new (struct t_gui_buffer *buffer,
|
||||
int context,
|
||||
const char *key,
|
||||
const char *command);
|
||||
extern struct t_gui_key *gui_key_search (struct t_gui_key *keys,
|
||||
const char *key);
|
||||
extern struct t_gui_key *gui_key_bind (struct t_gui_buffer *buffer,
|
||||
int context,
|
||||
const char *key,
|
||||
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_pressed (const char *key_str);
|
||||
extern void gui_key_free (struct t_gui_key **keys,
|
||||
struct t_gui_key **last_key,
|
||||
int *keys_count,
|
||||
struct t_gui_key *key);
|
||||
extern void gui_key_free_all (struct t_gui_key **keys,
|
||||
struct t_gui_key **last_key,
|
||||
int *keys_count);
|
||||
extern void gui_key_buffer_reset ();
|
||||
extern void gui_key_buffer_add (unsigned char key);
|
||||
extern int gui_key_get_paste_lines ();
|
||||
extern void gui_key_paste_accept ();
|
||||
extern void gui_key_paste_cancel ();
|
||||
extern void gui_key_end ();
|
||||
extern struct t_hdata *gui_key_hdata_key_cb (void *data,
|
||||
const char *hdata_name);
|
||||
extern int gui_key_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_gui_key *key);
|
||||
extern void gui_key_print_log (struct t_gui_buffer *buffer);
|
||||
|
||||
/* key functions (GUI dependent) */
|
||||
|
||||
extern void gui_key_default_bindings ();
|
||||
|
||||
#endif /* __WEECHAT_GUI_KEY_H */
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __WEECHAT_GUI_KEYBOARD_H
|
||||
#define __WEECHAT_GUI_KEYBOARD_H 1
|
||||
|
||||
#define GUI_KEYBOARD_BUFFER_BLOCK_SIZE 256
|
||||
|
||||
/* keyboard structures */
|
||||
|
||||
struct t_gui_key
|
||||
{
|
||||
char *key; /* key combo (ex: a, ^W, ^W^C, meta-a) */
|
||||
char *command; /* associated command (may be NULL) */
|
||||
struct t_gui_key *prev_key; /* link to previous key */
|
||||
struct t_gui_key *next_key; /* link to next key */
|
||||
};
|
||||
|
||||
/* keyboard variables */
|
||||
|
||||
extern struct t_gui_key *gui_keys;
|
||||
extern struct t_gui_key *last_gui_key;
|
||||
extern struct t_gui_key *gui_default_keys;
|
||||
extern struct t_gui_key *last_gui_default_key;
|
||||
extern int gui_keys_count;
|
||||
extern int gui_default_keys_count;
|
||||
extern int gui_keyboard_verbose;
|
||||
extern char gui_key_combo_buffer[];
|
||||
extern int gui_key_grab;
|
||||
extern int gui_key_grab_count;
|
||||
extern int *gui_keyboard_buffer;
|
||||
extern int gui_keyboard_buffer_size;
|
||||
extern int gui_keyboard_paste_pending;
|
||||
extern time_t gui_keyboard_last_activity_time;
|
||||
|
||||
/* keyboard functions */
|
||||
|
||||
extern void gui_keyboard_init ();
|
||||
extern void gui_keyboard_grab_init (int grab_command);
|
||||
extern void gui_keyboard_grab_end ();
|
||||
extern char *gui_keyboard_get_internal_code (const char *key);
|
||||
extern char *gui_keyboard_get_expanded_name (const char *key);
|
||||
extern struct t_gui_key *gui_keyboard_new (struct t_gui_buffer *buffer,
|
||||
const char *key,
|
||||
const char *command);
|
||||
extern struct t_gui_key *gui_keyboard_search (struct t_gui_key *keys,
|
||||
const char *key);
|
||||
extern struct t_gui_key *gui_keyboard_bind (struct t_gui_buffer *buffer,
|
||||
const char *key,
|
||||
const char *command);
|
||||
extern int gui_keyboard_unbind (struct t_gui_buffer *buffer, const char *key,
|
||||
int send_signal);
|
||||
extern int gui_keyboard_pressed (const char *key_str);
|
||||
extern void gui_keyboard_free (struct t_gui_key **keys,
|
||||
struct t_gui_key **last_key,
|
||||
int *keys_count,
|
||||
struct t_gui_key *key);
|
||||
extern void gui_keyboard_free_all (struct t_gui_key **keys,
|
||||
struct t_gui_key **last_key,
|
||||
int *keys_count);
|
||||
extern void gui_keyboard_buffer_reset ();
|
||||
extern void gui_keyboard_buffer_add (unsigned char 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 struct t_hdata *gui_keyboard_hdata_key_cb (void *data,
|
||||
const char *hdata_name);
|
||||
extern int gui_keyboard_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_gui_key *key);
|
||||
extern void gui_keyboard_print_log (struct t_gui_buffer *buffer);
|
||||
|
||||
/* keyboard functions (GUI dependent) */
|
||||
|
||||
extern void gui_keyboard_default_bindings ();
|
||||
|
||||
#endif /* __WEECHAT_GUI_KEYBOARD_H */
|
||||
@@ -1099,6 +1099,7 @@ gui_window_scroll_next_highlight (struct t_gui_window *window)
|
||||
|
||||
/*
|
||||
* gui_window_search_text: search text in a buffer
|
||||
* return 1 if line has been found with text, otherwise 0
|
||||
*/
|
||||
|
||||
int
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
#include "../gui/gui-filter.h"
|
||||
#include "../gui/gui-history.h"
|
||||
#include "../gui/gui-hotlist.h"
|
||||
#include "../gui/gui-keyboard.h"
|
||||
#include "../gui/gui-key.h"
|
||||
#include "../gui/gui-line.h"
|
||||
#include "../gui/gui-nicklist.h"
|
||||
#include "../gui/gui-window.h"
|
||||
@@ -353,10 +353,10 @@ plugin_api_info_get_internal (void *data, const char *info_name,
|
||||
}
|
||||
else if (string_strcasecmp (info_name, "inactivity") == 0)
|
||||
{
|
||||
if (gui_keyboard_last_activity_time == 0)
|
||||
if (gui_key_last_activity_time == 0)
|
||||
inactivity = 0;
|
||||
else
|
||||
inactivity = time (NULL) - gui_keyboard_last_activity_time;
|
||||
inactivity = time (NULL) - gui_key_last_activity_time;
|
||||
snprintf (value, sizeof (value), "%ld", (long int)inactivity);
|
||||
return value;
|
||||
}
|
||||
@@ -394,6 +394,7 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name,
|
||||
struct t_gui_key *ptr_key;
|
||||
struct t_weechat_plugin *ptr_plugin;
|
||||
char buffer_full_name[1024];
|
||||
int context;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -678,12 +679,17 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name,
|
||||
ptr_infolist = infolist_new ();
|
||||
if (ptr_infolist)
|
||||
{
|
||||
for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
|
||||
context = gui_key_search_context (arguments);
|
||||
if (context >= 0)
|
||||
{
|
||||
if (!gui_keyboard_add_to_infolist (ptr_infolist, ptr_key))
|
||||
for (ptr_key = gui_keys[context]; ptr_key;
|
||||
ptr_key = ptr_key->next_key)
|
||||
{
|
||||
infolist_free (ptr_infolist);
|
||||
return NULL;
|
||||
if (!gui_key_add_to_infolist (ptr_infolist, ptr_key))
|
||||
{
|
||||
infolist_free (ptr_infolist);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ptr_infolist;
|
||||
@@ -1074,7 +1080,7 @@ plugin_api_init ()
|
||||
hook_hdata (NULL, "input_undo", N_("structure with undo for input line"),
|
||||
&gui_buffer_hdata_input_undo_cb, NULL);
|
||||
hook_hdata (NULL, "key", N_("a key (keyboard shortcut)"),
|
||||
&gui_keyboard_hdata_key_cb, NULL);
|
||||
&gui_key_hdata_key_cb, NULL);
|
||||
hook_hdata (NULL, "lines", N_("structure with lines"),
|
||||
&gui_line_hdata_lines_cb, NULL);
|
||||
hook_hdata (NULL, "line", N_("structure with one line"),
|
||||
|
||||
Reference in New Issue
Block a user