diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-11-11 21:04:21 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-11-11 21:04:21 +0100 |
commit | 7b86f317643a496bb46322c9045a7e81f4b17ec3 (patch) | |
tree | 4218d332c6d9b5a4a20ee57581e29acfc6beec63 | |
parent | 5d38149578031b88fc582b3f119bf302137688ce (diff) | |
download | weechat-7b86f317643a496bb46322c9045a7e81f4b17ec3.zip |
buflist: jump to previous/next buffer displayed in buflist item with ctrl+wheel up/down on a buflist item (closes #1473)
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | src/plugins/buflist/buflist-bar-item.c | 3 | ||||
-rw-r--r-- | src/plugins/buflist/buflist-mouse.c | 108 |
3 files changed, 110 insertions, 2 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index cbc76b276..01c106e03 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -24,6 +24,7 @@ New features:: * core: display only version with command `/version`, add options `-o` and `-ol` in command `/upgrade` * core: add number of processes in command `/sys waitpid` * core, alias, trigger: allow wildcard in commands `/bar`, `/item`, `/proxy`, `/alias` and `/trigger` (issue #1956) + * buflist: jump to previous/next buffer displayed in buflist item with ctrl+wheel up/down on a buflist item (issue #1473) * irc: change default value of server option "tls_priorities" to `NORMAL` * irc: add support of RGB colors in messages, add option irc.color.term_remap (issue #2025) * irc: add tags "nick_xxx" and "host_xxx" in all messages, including self and server messages diff --git a/src/plugins/buflist/buflist-bar-item.c b/src/plugins/buflist/buflist-bar-item.c index e0e12483a..46c115b39 100644 --- a/src/plugins/buflist/buflist-bar-item.c +++ b/src/plugins/buflist/buflist-bar-item.c @@ -74,6 +74,9 @@ buflist_bar_item_get_index (const char *item_name) int i; const char *ptr_item_name; + if (!item_name) + return -1; + for (i = 0; i < BUFLIST_BAR_NUM_ITEMS; i++) { ptr_item_name = buflist_bar_item_get_name (i); diff --git a/src/plugins/buflist/buflist-mouse.c b/src/plugins/buflist/buflist-mouse.c index 352e0bd85..e8c1d0e68 100644 --- a/src/plugins/buflist/buflist-mouse.c +++ b/src/plugins/buflist/buflist-mouse.c @@ -214,6 +214,106 @@ buflist_mouse_move_buffer (const char *key, struct t_gui_buffer *buffer, } /* + * Switches to previous/next buffer displayed in an item, starting from + * current buffer. + */ + +void +buflist_mouse_move_current_buffer (const char *item_name, int direction) +{ + struct t_gui_buffer *ptr_current_buffer, *ptr_buffer, *gui_buffers; + char str_command[1024]; + int i, size, index_item, index_current, index2, number_current; + int number, number2; + + if (!item_name) + return; + + index_item = buflist_bar_item_get_index (item_name); + if (index_item < 0) + return; + + if (!buflist_list_buffers[index_item]) + return; + + size = weechat_arraylist_size (buflist_list_buffers[index_item]); + if (size <= 0) + return; + + ptr_current_buffer = weechat_current_buffer (); + if (!ptr_current_buffer) + return; + + index_current = -1; + for (i = 0; i < size; i++) + { + if ((struct t_gui_buffer *)weechat_arraylist_get ( + buflist_list_buffers[index_item], i) == ptr_current_buffer) + { + index_current = i; + break; + } + } + + if (index_current < 0) + return; + + number_current = weechat_buffer_get_integer (ptr_current_buffer, "number"); + + gui_buffers = weechat_hdata_get_list (buflist_hdata_buffer, "gui_buffers"); + + /* search previous/next buffer with a different number */ + index2 = index_current; + while (1) + { + if (direction < 0) + { + index2--; + if (index2 < 0) + index2 = size - 1; + } + else + { + index2++; + if (index2 >= size) + index2 = 0; + } + if (index2 == index_current) + return; + ptr_buffer = (struct t_gui_buffer *)weechat_arraylist_get ( + buflist_list_buffers[index_item], index2); + if (!ptr_buffer) + return; + if (!weechat_hdata_check_pointer (buflist_hdata_buffer, + gui_buffers, ptr_buffer)) + return; + number2 = weechat_buffer_get_integer (ptr_buffer, "number"); + if (number2 != number_current) + break; + } + + /* search first buffer with the number found */ + for (i = 0; i < size; i++) + { + ptr_buffer = (struct t_gui_buffer *)weechat_arraylist_get ( + buflist_list_buffers[index_item], i); + if (!ptr_buffer) + break; + number = weechat_buffer_get_integer (ptr_buffer, "number"); + if (number == number2) + break; + } + if (i >= size) + return; + + /* switch to the buffer found */ + snprintf (str_command, sizeof (str_command), + "/buffer %s", + weechat_buffer_get_string (ptr_buffer, "full_name")); + weechat_command (NULL, str_command); +} + +/* * Callback called when a mouse action occurs in buflist bar or bar item. */ @@ -300,14 +400,18 @@ buflist_hsignal_cb (const void *pointer, void *data, const char *signal, { if (weechat_config_boolean (buflist_config_look_mouse_wheel)) { - weechat_command (NULL, "/buffer -1"); + buflist_mouse_move_current_buffer ( + (const char *)weechat_hashtable_get (hashtable, "_bar_item_name"), + -1); /* previous buffer */ } } else if (weechat_string_match (ptr_key, "*wheeldown", 1)) { if (weechat_config_boolean (buflist_config_look_mouse_wheel)) { - weechat_command (NULL, "/buffer +1"); + buflist_mouse_move_current_buffer ( + (const char *)weechat_hashtable_get (hashtable, "_bar_item_name"), + +1); /* next buffer */ } } else |