From b47af3c61e232300eb76e9b7c831f3c9bd6942f0 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Tue, 20 Aug 2013 11:42:12 +0200 Subject: [PATCH] core: fix buffer returned in focus info for bar items with a forced buffer --- src/gui/gui-bar-item.c | 23 +++++++++++++++++++---- src/gui/gui-bar-window.c | 8 +++++++- src/gui/gui-bar-window.h | 7 ++++--- src/gui/gui-cursor.c | 5 +++-- src/gui/gui-focus.c | 32 +++++++++++++++++++++++--------- src/gui/gui-focus.h | 1 + src/gui/gui-key.c | 25 +++++++++++++++++++++---- 7 files changed, 78 insertions(+), 23 deletions(-) diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index 33bfb61a9..8300e007c 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -1636,8 +1636,9 @@ gui_bar_item_focus_buffer_nicklist (void *data, struct t_gui_nick *ptr_nick; int i, rc, bar_item_line; unsigned long int value; - const char *str_window, *str_bar_item_line; + const char *str_window, *str_buffer, *str_bar_item_line; struct t_gui_window *window; + struct t_gui_buffer *buffer; char *error; /* make C compiler happy */ @@ -1647,6 +1648,7 @@ gui_bar_item_focus_buffer_nicklist (void *data, if (!str_bar_item_line || !str_bar_item_line[0]) return NULL; + /* get window */ str_window = hashtable_get (info, "_window"); if (str_window && str_window[0]) { @@ -1663,6 +1665,19 @@ gui_bar_item_focus_buffer_nicklist (void *data, if (!window) return NULL; + /* get buffer */ + buffer = window->buffer; + str_buffer = hashtable_get (info, "_buffer"); + if (str_buffer && str_buffer[0]) + { + rc = sscanf (str_buffer, "%lx", &value); + if ((rc == EOF) || (rc == 0)) + return NULL; + buffer = (struct t_gui_buffer *)value; + } + if (!buffer) + return NULL; + error = NULL; bar_item_line = (int) strtol (str_bar_item_line, &error, 10); if (!error || error[0]) @@ -1671,19 +1686,19 @@ gui_bar_item_focus_buffer_nicklist (void *data, i = 0; ptr_group = NULL; ptr_nick = NULL; - gui_nicklist_get_next_item (window->buffer, &ptr_group, &ptr_nick); + gui_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick); while (ptr_group || ptr_nick) { if ((ptr_nick && ptr_nick->visible) || (ptr_group && !ptr_nick - && window->buffer->nicklist_display_groups + && buffer->nicklist_display_groups && ptr_group->visible)) { if (i == bar_item_line) break; i++; } - gui_nicklist_get_next_item (window->buffer, &ptr_group, &ptr_nick); + gui_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick); } if (i != bar_item_line) diff --git a/src/gui/gui-bar-window.c b/src/gui/gui-bar-window.c index 001eacab5..d27021ba0 100644 --- a/src/gui/gui-bar-window.c +++ b/src/gui/gui-bar-window.c @@ -38,6 +38,7 @@ #include "gui-bar-window.h" #include "gui-bar.h" #include "gui-bar-item.h" +#include "gui-buffer.h" #include "gui-chat.h" #include "gui-color.h" #include "gui-window.h" @@ -117,7 +118,8 @@ void gui_bar_window_search_by_xy (struct t_gui_window *window, int x, int y, struct t_gui_bar_window **bar_window, char **bar_item, - int *bar_item_line, int *bar_item_col) + int *bar_item_line, int *bar_item_col, + struct t_gui_buffer **buffer) { struct t_gui_bar *ptr_bar; struct t_gui_bar_window *ptr_bar_window; @@ -231,6 +233,8 @@ gui_bar_window_search_by_xy (struct t_gui_window *window, int x, int y, *bar_item = (*bar_window)->bar->items_name[item][subitem]; *bar_item_line = (*bar_window)->coords[i]->line; *bar_item_col = x - (*bar_window)->coords[i]->x; + if ((*bar_window)->bar->items_buffer[item][subitem]) + *buffer = gui_buffer_search_by_full_name ((*bar_window)->bar->items_buffer[item][subitem]); break; } i++; @@ -249,6 +253,8 @@ gui_bar_window_search_by_xy (struct t_gui_window *window, int x, int y, if (*bar_item_line < lines) { *bar_item = (*bar_window)->bar->items_name[i][j]; + if ((*bar_window)->bar->items_buffer[i][j]) + *buffer = gui_buffer_search_by_full_name ((*bar_window)->bar->items_buffer[i][j]); break; } j++; diff --git a/src/gui/gui-bar-window.h b/src/gui/gui-bar-window.h index 6e1703440..ac431718b 100644 --- a/src/gui/gui-bar-window.h +++ b/src/gui/gui-bar-window.h @@ -21,6 +21,7 @@ #define __WEECHAT_GUI_BAR_WINDOW_H 1 struct t_infolist; +struct t_gui_buffer; struct t_gui_window; enum t_gui_bar_position; @@ -67,9 +68,9 @@ extern int gui_bar_window_valid (struct t_gui_bar_window *bar_window); extern void gui_bar_window_search_by_xy (struct t_gui_window *window, int x, int y, struct t_gui_bar_window **bar_window, - char **bar_item, - int *bar_item_line, - int *bar_item_col); + char **bar_item, int *bar_item_line, + int *bar_item_col, + struct t_gui_buffer **buffer); extern void gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window, struct t_gui_window *window); extern void gui_bar_window_content_build (struct t_gui_bar_window *bar_window, diff --git a/src/gui/gui-cursor.c b/src/gui/gui-cursor.c index 825a1ea9f..601202651 100644 --- a/src/gui/gui-cursor.c +++ b/src/gui/gui-cursor.c @@ -109,13 +109,14 @@ gui_cursor_display_debug_info () if (focus_info) { snprintf (str_info, sizeof (str_info), - "%s(%d,%d) window:0x%lx (buffer: %s), " + "%s(%d,%d) window:0x%lx, buffer:0x%lx (%s), " "bar_window:0x%lx (bar: %s, item: %s, line: %d, col: %d), " "chat: %d, word: \"%s\"", gui_color_get_custom ("yellow,red"), focus_info->x, focus_info->y, (long unsigned int)focus_info->window, - (focus_info->window) ? (focus_info->window)->buffer->name : "-", + (long unsigned int)focus_info->buffer, + (focus_info->buffer) ? (focus_info->buffer)->full_name : "-", (long unsigned int)focus_info->bar_window, (focus_info->bar_window) ? ((focus_info->bar_window)->bar)->name : "-", (focus_info->bar_item) ? focus_info->bar_item : "-", diff --git a/src/gui/gui-focus.c b/src/gui/gui-focus.c index 59b480bc3..aa24c6fa5 100644 --- a/src/gui/gui-focus.c +++ b/src/gui/gui-focus.c @@ -84,6 +84,7 @@ gui_focus_get_info (int x, int y) /* search window */ focus_info->window = gui_window_search_by_xy (x, y); + focus_info->buffer = (focus_info->window) ? (focus_info->window)->buffer : NULL; /* fill info about chat area */ gui_window_get_context_at_xy (focus_info->window, @@ -101,7 +102,12 @@ gui_focus_get_info (int x, int y) &focus_info->bar_window, &focus_info->bar_item, &focus_info->bar_item_line, - &focus_info->bar_item_col); + &focus_info->bar_item_col, + &focus_info->buffer); + + /* force current buffer if not buffer at all was found */ + if (!focus_info->buffer && gui_current_window) + focus_info->buffer = gui_current_window->buffer; return focus_info; } @@ -177,22 +183,30 @@ gui_focus_to_hashtable (struct t_gui_focus_info *focus_info, const char *key) FOCUS_INT("_x", focus_info->x); FOCUS_INT("_y", focus_info->y); - /* window/buffer */ + /* window */ FOCUS_PTR("_window", focus_info->window); if (focus_info->window) { FOCUS_INT("_window_number", (focus_info->window)->number); - FOCUS_PTR("_buffer", focus_info->window->buffer); - FOCUS_INT("_buffer_number", ((focus_info->window)->buffer)->number); - FOCUS_STR("_buffer_plugin", plugin_get_name (((focus_info->window)->buffer)->plugin)); - FOCUS_STR("_buffer_name", ((focus_info->window)->buffer)->name); - FOCUS_STR("_buffer_full_name", ((focus_info->window)->buffer)->full_name); - hashtable_map (focus_info->window->buffer->local_variables, - &gui_focus_buffer_localvar_map_cb, hashtable); } else { FOCUS_STR("_window_number", "*"); + } + + /* buffer */ + FOCUS_PTR("_buffer", focus_info->buffer); + if (focus_info->buffer) + { + FOCUS_INT("_buffer_number", (focus_info->buffer)->number); + FOCUS_STR("_buffer_plugin", plugin_get_name ((focus_info->buffer)->plugin)); + FOCUS_STR("_buffer_name", (focus_info->buffer)->name); + FOCUS_STR("_buffer_full_name", (focus_info->buffer)->full_name); + hashtable_map ((focus_info->buffer)->local_variables, + &gui_focus_buffer_localvar_map_cb, hashtable); + } + else + { FOCUS_PTR("_buffer", NULL); FOCUS_STR("_buffer_number", "-1"); FOCUS_STR("_buffer_plugin", ""); diff --git a/src/gui/gui-focus.h b/src/gui/gui-focus.h index f658c54f8..e12205954 100644 --- a/src/gui/gui-focus.h +++ b/src/gui/gui-focus.h @@ -26,6 +26,7 @@ struct t_gui_focus_info { int x, y; /* (x,y) on screen */ struct t_gui_window *window; /* window found */ + struct t_gui_buffer *buffer; /* buffer found */ int chat; /* 1 for chat area, otherwise 0 */ struct t_gui_line *chat_line; /* line in chat area */ int chat_line_x; /* x in line */ diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index 771f6135d..eef07c089 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -1040,11 +1040,14 @@ gui_key_focus_command (const char *key, int context, struct t_hashtable **hashtable_focus) { struct t_gui_key *ptr_key; - int i, errors, matching, debug; + int i, errors, matching, debug, rc; + long unsigned int value; char *command, **commands; + const char *str_buffer; struct t_hashtable *hashtable; struct t_weelist *list_keys; struct t_weelist_item *ptr_item; + struct t_gui_buffer *ptr_buffer; debug = 0; if (gui_cursor_debug && (context == GUI_KEY_CONTEXT_CURSOR)) @@ -1082,6 +1085,18 @@ gui_key_focus_command (const char *key, int context, if (!hashtable) continue; + /* get buffer */ + ptr_buffer = gui_current_window->buffer; + str_buffer = hashtable_get (hashtable, "_buffer"); + if (str_buffer && str_buffer[0]) + { + rc = sscanf (str_buffer, "%lx", &value); + if ((rc != EOF) && (rc != 0)) + ptr_buffer = (struct t_gui_buffer *)value; + } + if (!ptr_buffer) + continue; + if ((context == GUI_KEY_CONTEXT_CURSOR) && gui_cursor_debug) { gui_input_delete_line (gui_current_window->buffer); @@ -1136,10 +1151,12 @@ gui_key_focus_command (const char *key, int context, if (debug) { gui_chat_printf (NULL, - _("Executing command: \"%s\""), - command); + _("Executing command: \"%s\" " + "on buffer \"%s\""), + command, + ptr_buffer->full_name); } - input_data (gui_current_window->buffer, command); + input_data (ptr_buffer, command); } free (command); }