summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2011-08-01 18:33:13 +0200
committerSebastien Helleu <flashcode@flashtux.org>2011-08-01 18:33:13 +0200
commit217e9683d21c754a932407c7ddcafa4ca88f5649 (patch)
tree330e5b8eb8a570e40aa8e1d11b73d65a082acffb /src/core
parent95b179dd0801ccb4b0068d1c2e2c04aa2264e912 (diff)
downloadweechat-217e9683d21c754a932407c7ddcafa4ca88f5649.zip
core: add info about position where mouse button is released in hook_focus (for mouse gestures)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-command.c4
-rw-r--r--src/core/wee-hashtable.c116
-rw-r--r--src/core/wee-hook.c172
-rw-r--r--src/core/wee-hook.h6
4 files changed, 221 insertions, 77 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 7fa4f0898..43411d395 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -5537,7 +5537,9 @@ command_init ()
" bar(*): any bar\n"
" bar(xxx): bar \"xxx\"\n"
" item(*): any bar item\n"
- " item(xxx): bar item \"xxx\"\n\n"
+ " item(xxx): bar item \"xxx\"\n"
+ "The key can start or end with '*' to match many mouse "
+ "events.\n\n"
"Examples:\n"
" key alt-x to toggle nicklist bar:\n"
" /key bind meta-x /bar toggle nicklist\n"
diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c
index f33db8c25..b84b12272 100644
--- a/src/core/wee-hashtable.c
+++ b/src/core/wee-hashtable.c
@@ -32,6 +32,7 @@
#include "weechat.h"
#include "wee-hashtable.h"
#include "wee-infolist.h"
+#include "wee-list.h"
#include "wee-log.h"
#include "wee-string.h"
#include "../plugins/plugin.h"
@@ -454,6 +455,64 @@ hashtable_map (struct t_hashtable *hashtable,
}
/*
+ * hashtable_get_list_keys_map_cb: function called for each variable in hdata
+ * to build sorted list of keys
+ */
+
+void
+hashtable_get_list_keys_map_cb (void *data,
+ struct t_hashtable *hashtable,
+ const void *key, const void *value)
+{
+ struct t_weelist *list;
+ char str_key[128];
+
+ /* make C compiler happy */
+ (void) hashtable;
+ (void) value;
+
+ list = (struct t_weelist *)data;
+
+ switch (hashtable->type_keys)
+ {
+ case HASHTABLE_INTEGER:
+ snprintf (str_key, sizeof (str_key), "%d", *((int *)key));
+ weelist_add (list, str_key, WEECHAT_LIST_POS_SORT, NULL);
+ break;
+ case HASHTABLE_STRING:
+ weelist_add (list, (const char *)key, WEECHAT_LIST_POS_SORT, NULL);
+ break;
+ case HASHTABLE_POINTER:
+ case HASHTABLE_BUFFER:
+ snprintf (str_key, sizeof (str_key), "0x%lx", (long unsigned int)key);
+ weelist_add (list, str_key, WEECHAT_LIST_POS_SORT, NULL);
+ break;
+ case HASHTABLE_TIME:
+ snprintf (str_key, sizeof (str_key), "%ld", (long)(*((time_t *)key)));
+ weelist_add (list, str_key, WEECHAT_LIST_POS_SORT, NULL);
+ break;
+ case HASHTABLE_NUM_TYPES:
+ break;
+ }
+}
+
+/*
+ * hashtable_get_list_keys: get list with sorted keys of hashtable
+ * Note: list must be freed after use
+ */
+
+struct t_weelist *
+hashtable_get_list_keys (struct t_hashtable *hashtable)
+{
+ struct t_weelist *weelist;
+
+ weelist = weelist_new ();
+ if (weelist)
+ hashtable_map (hashtable, &hashtable_get_list_keys_map_cb, weelist);
+ return weelist;
+}
+
+/*
* hashtable_get_integer: get a hashtable property as integer
*/
@@ -741,14 +800,15 @@ hashtable_build_string_keys_values_cb (void *data,
* keys only: "key1,key2,key3"
* values only: "value1,value2,value3"
* keys + values: "key1:value1,key2:value2,key3:value3"
- * Note: this works only if keys have type "integer",
- * or "string"
*/
const char *
-hashtable_get_keys_values (struct t_hashtable *hashtable, int keys, int values)
+hashtable_get_keys_values (struct t_hashtable *hashtable,
+ int keys, int sort_keys, int values)
{
int length;
+ struct t_weelist *list_keys;
+ struct t_weelist_item *ptr_item;
if (hashtable->keys_values)
{
@@ -771,11 +831,41 @@ hashtable_get_keys_values (struct t_hashtable *hashtable, int keys, int values)
if (!hashtable->keys_values)
return NULL;
hashtable->keys_values[0] = '\0';
- hashtable_map (hashtable,
- (keys && values) ? &hashtable_build_string_keys_values_cb :
- ((keys) ? &hashtable_build_string_keys_cb :
- &hashtable_build_string_values_cb),
- hashtable->keys_values);
+ if (keys && sort_keys)
+ {
+ list_keys = hashtable_get_list_keys (hashtable);
+ if (list_keys)
+ {
+ for (ptr_item = list_keys->items; ptr_item;
+ ptr_item = ptr_item->next_item)
+ {
+ if (values)
+ {
+ hashtable_build_string_keys_values_cb (hashtable->keys_values,
+ hashtable,
+ ptr_item->data,
+ hashtable_get (hashtable,
+ ptr_item->data));
+ }
+ else
+ {
+ hashtable_build_string_keys_cb (hashtable->keys_values,
+ hashtable,
+ ptr_item->data,
+ NULL);
+ }
+ }
+ weelist_free (list_keys);
+ }
+ }
+ else
+ {
+ hashtable_map (hashtable,
+ (keys && values) ? &hashtable_build_string_keys_values_cb :
+ ((keys) ? &hashtable_build_string_keys_cb :
+ &hashtable_build_string_values_cb),
+ hashtable->keys_values);
+ }
return hashtable->keys_values;
}
@@ -794,11 +884,15 @@ hashtable_get_string (struct t_hashtable *hashtable, const char *property)
else if (string_strcasecmp (property, "type_values") == 0)
return hashtable_type_string[hashtable->type_values];
else if (string_strcasecmp (property, "keys") == 0)
- return hashtable_get_keys_values (hashtable, 1, 0);
+ return hashtable_get_keys_values (hashtable, 1, 0, 0);
+ else if (string_strcasecmp (property, "keys_sorted") == 0)
+ return hashtable_get_keys_values (hashtable, 1, 1, 0);
else if (string_strcasecmp (property, "values") == 0)
- return hashtable_get_keys_values (hashtable, 0, 1);
+ return hashtable_get_keys_values (hashtable, 0, 0, 1);
else if (string_strcasecmp (property, "keys_values") == 0)
- return hashtable_get_keys_values (hashtable, 1, 1);
+ return hashtable_get_keys_values (hashtable, 1, 0, 1);
+ else if (string_strcasecmp (property, "keys_values_sorted") == 0)
+ return hashtable_get_keys_values (hashtable, 1, 1, 1);
}
return NULL;
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index 03066abf0..5eeaa64d3 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -54,7 +54,7 @@
#include "../gui/gui-buffer.h"
#include "../gui/gui-color.h"
#include "../gui/gui-completion.h"
-#include "../gui/gui-cursor.h"
+#include "../gui/gui-focus.h"
#include "../gui/gui-line.h"
#include "../gui/gui-window.h"
#include "../plugins/plugin.h"
@@ -2810,63 +2810,55 @@ hook_focus_hashtable_map_cb (void *data, struct t_hashtable *hashtable,
}
/*
+ * hook_focus_hashtable_map2_cb: add keys of a hashtable into another
+ * (adding suffix "2" to keys)
+ */
+
+void
+hook_focus_hashtable_map2_cb (void *data, struct t_hashtable *hashtable,
+ const void *key, const void *value)
+{
+ struct t_hashtable *hashtable1;
+ int length;
+ char *key2;
+
+ /* make C compiler happy */
+ (void) hashtable;
+
+ hashtable1 = (struct t_hashtable *)data;
+
+ length = strlen ((const char *)key) + 1 + 1;
+ key2 = malloc (length);
+ if (key2)
+ {
+ snprintf (key2, length, "%s2", (const char *)key);
+ if (hashtable1 && key && value)
+ hashtable_set (hashtable1, key2, (const char *)value);
+ free (key2);
+ }
+}
+
+/*
* hook_focus_get_data: get data for focus on (x,y) on screen
+ * focus_info2 is not NULL only for a mouse gesture (it's
+ * for point where mouse button is released)
*/
struct t_hashtable *
-hook_focus_get_data (struct t_gui_cursor_info *cursor_info)
+hook_focus_get_data (struct t_gui_focus_info *focus_info1,
+ struct t_gui_focus_info *focus_info2,
+ const char *key)
{
struct t_hook *ptr_hook, *next_hook;
- struct t_hashtable *hash_info, *hash_info2;
- char str_value[64];
+ struct t_hashtable *hash_info1, *hash_info2, *hash_info_ret;
+ const char *keys;
+ char **list_keys, *new_key;
+ int num_keys, i, length;
hook_exec_start ();
- hash_info = hashtable_new (8,
- WEECHAT_HASHTABLE_STRING,
- WEECHAT_HASHTABLE_STRING,
- NULL,
- NULL);
- if (!hash_info)
- return NULL;
-
- /* fill hash_info with values from cursor_info */
- snprintf (str_value, sizeof (str_value), "%d", cursor_info->x);
- hashtable_set (hash_info, "_x", str_value);
- snprintf (str_value, sizeof (str_value), "%d", cursor_info->y);
- hashtable_set (hash_info, "_y", str_value);
- snprintf (str_value, sizeof (str_value),
- "0x%lx", (long unsigned int)cursor_info->window);
- hashtable_set (hash_info, "_window", str_value);
- snprintf (str_value, sizeof (str_value),
- "0x%lx",
- (cursor_info->window) ?
- (long unsigned int)((cursor_info->window)->buffer) : 0);
- hashtable_set (hash_info, "_buffer", str_value);
- if (cursor_info->window)
- {
- snprintf (str_value, sizeof (str_value), "%d",
- (cursor_info->window)->number);
- hashtable_set (hash_info, "_window_number", str_value);
- snprintf (str_value, sizeof (str_value), "%d",
- ((cursor_info->window)->buffer)->number);
- hashtable_set (hash_info, "_buffer_number", str_value);
- hashtable_set (hash_info, "_buffer_plugin",
- plugin_get_name (((cursor_info->window)->buffer)->plugin));
- hashtable_set (hash_info, "_buffer_name",
- ((cursor_info->window)->buffer)->name);
- }
- hashtable_set (hash_info, "_bar_name",
- (cursor_info->bar_window) ?
- ((cursor_info->bar_window)->bar)->name : NULL);
- hashtable_set (hash_info, "_bar_item_name",
- cursor_info->bar_item);
- snprintf (str_value, sizeof (str_value),
- "%d", cursor_info->item_line);
- hashtable_set (hash_info, "_item_line", str_value);
- snprintf (str_value, sizeof (str_value),
- "%d", cursor_info->item_col);
- hashtable_set (hash_info, "_item_col", str_value);
+ hash_info1 = gui_focus_to_hashtable (focus_info1, key);
+ hash_info2 = (focus_info2) ? gui_focus_to_hashtable (focus_info2, key) : NULL;
ptr_hook = weechat_hooks[HOOK_TYPE_FOCUS];
while (ptr_hook)
@@ -2875,27 +2867,51 @@ hook_focus_get_data (struct t_gui_cursor_info *cursor_info)
if (!ptr_hook->deleted
&& !ptr_hook->running
- && ((cursor_info->chat
+ && ((focus_info1->chat
&& (strcmp (HOOK_FOCUS(ptr_hook, area), "chat") == 0))
- || (cursor_info->bar_item
- && (strcmp (HOOK_FOCUS(ptr_hook, area), cursor_info->bar_item) == 0))))
+ || (focus_info1->bar_item
+ && (strcmp (HOOK_FOCUS(ptr_hook, area), focus_info1->bar_item) == 0))))
{
+ /* run callback for focus_info1 */
ptr_hook->running = 1;
- hash_info2 = (HOOK_FOCUS(ptr_hook, callback))
- (ptr_hook->callback_data, hash_info);
+ hash_info_ret = (HOOK_FOCUS(ptr_hook, callback))
+ (ptr_hook->callback_data, hash_info1);
ptr_hook->running = 0;
-
- if (hash_info2)
+ if (hash_info_ret)
{
- if (hash_info2 != hash_info)
+ if (hash_info_ret != hash_info1)
{
/*
- * add keys of hashtable2 into hashtable and destroy
- * hashtable2
+ * add keys of hash_info_ret into hash_info and destroy
+ * hash_info_ret
*/
- hashtable_map (hash_info2, &hook_focus_hashtable_map_cb,
- hash_info);
- hashtable_free (hash_info2);
+ hashtable_map (hash_info_ret,
+ &hook_focus_hashtable_map_cb,
+ hash_info1);
+ hashtable_free (hash_info_ret);
+ }
+ }
+
+ /* run callback for focus_info2 */
+ if (hash_info2)
+ {
+ ptr_hook->running = 1;
+ hash_info_ret = (HOOK_FOCUS(ptr_hook, callback))
+ (ptr_hook->callback_data, hash_info2);
+ ptr_hook->running = 0;
+ if (hash_info_ret)
+ {
+ if (hash_info_ret != hash_info2)
+ {
+ /*
+ * add keys of hash_info_ret into hash_info and destroy
+ * hash_info_ret
+ */
+ hashtable_map (hash_info_ret,
+ &hook_focus_hashtable_map_cb,
+ hash_info2);
+ hashtable_free (hash_info_ret);
+ }
}
}
}
@@ -2903,9 +2919,39 @@ hook_focus_get_data (struct t_gui_cursor_info *cursor_info)
ptr_hook = next_hook;
}
+ if (hash_info2)
+ {
+ hashtable_map (hash_info2, &hook_focus_hashtable_map2_cb, hash_info1);
+ hashtable_free (hash_info2);
+ }
+ else
+ {
+ keys = hashtable_get_string (hash_info1, "keys");
+ if (keys)
+ {
+ list_keys = string_split (keys, ",", 0, 0, &num_keys);
+ if (list_keys)
+ {
+ for (i = 0; i < num_keys; i++)
+ {
+ length = strlen (list_keys[i]) + 1 + 1;
+ new_key = malloc (length);
+ if (new_key)
+ {
+ snprintf (new_key, length, "%s2", list_keys[i]);
+ hashtable_set (hash_info1, new_key,
+ hashtable_get (hash_info1, list_keys[i]));
+ free (new_key);
+ }
+ }
+ string_free_split (list_keys);
+ }
+ }
+ }
+
hook_exec_end ();
- return hash_info;
+ return hash_info1;
}
/*
diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h
index 65df6e7d0..ae0c880f6 100644
--- a/src/core/wee-hook.h
+++ b/src/core/wee-hook.h
@@ -28,7 +28,7 @@ struct t_gui_bar;
struct t_gui_buffer;
struct t_gui_line;
struct t_gui_completion;
-struct t_gui_cursor_info;
+struct t_gui_focus_info;
struct t_gui_window;
struct t_weelist;
struct t_hashtable;
@@ -541,7 +541,9 @@ extern struct t_hook *hook_focus (struct t_weechat_plugin *plugin,
const char *area,
t_hook_callback_focus *callback,
void *callback_data);
-extern struct t_hashtable *hook_focus_get_data (struct t_gui_cursor_info *cursor_info);
+extern struct t_hashtable *hook_focus_get_data (struct t_gui_focus_info *focus_info1,
+ struct t_gui_focus_info *focus_info2,
+ const char *key);
extern void unhook (struct t_hook *hook);
extern void unhook_all_plugin (struct t_weechat_plugin *plugin);
extern void unhook_all ();