Skip to content

Commit

Permalink
buflist: jump to previous/next buffer displayed in buflist item with …
Browse files Browse the repository at this point in the history
…ctrl+wheel up/down on a buflist item (closes weechat#1473)
  • Loading branch information
flashcode committed Nov 11, 2023
1 parent 5d38149 commit 7b86f31
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/buflist/buflist-bar-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
108 changes: 106 additions & 2 deletions src/plugins/buflist/buflist-mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,106 @@ buflist_mouse_move_buffer (const char *key, struct t_gui_buffer *buffer,
weechat_command (buffer, str_command);
}

/*
* 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.
*/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7b86f31

Please sign in to comment.