void script_action_showdiff () { char str_command[64]; struct t_gui_window *window; int diff, start_line_y, chat_height; if (script_buffer && script_buffer_detail_script && (script_buffer_detail_script_line_diff >= 0)) { /* check if we are already on diff */ diff = 0; window = dogechat_window_search_with_buffer (script_buffer); if (window) { script_buffer_get_window_info (window, &start_line_y, &chat_height); diff = (start_line_y == script_buffer_detail_script_line_diff); } /* scroll to top of window */ dogechat_command (script_buffer, "/window scroll_top"); /* if not currently on diff, jump to it */ if (!diff) { snprintf (str_command, sizeof (str_command), "/window scroll %d", script_buffer_detail_script_line_diff); dogechat_command (script_buffer, str_command); } } }
void script_buffer_check_line_outside_window () { struct t_gui_window *window; int start_line_y, chat_height; char str_command[256]; window = weechat_window_search_with_buffer (script_buffer); if (!window) return; script_buffer_get_window_info (window, &start_line_y, &chat_height); if ((start_line_y > script_buffer_selected_line) || (start_line_y <= script_buffer_selected_line - chat_height)) { snprintf (str_command, sizeof (str_command), "/window scroll -window %d %s%d", weechat_window_get_integer (window, "number"), (start_line_y > script_buffer_selected_line) ? "-" : "+", (start_line_y > script_buffer_selected_line) ? start_line_y - script_buffer_selected_line : script_buffer_selected_line - start_line_y - chat_height + 1); weechat_command (script_buffer, str_command); } }
int script_buffer_window_scrolled_cb (const void *pointer, void *data, const char *signal, const char *type_data, void *signal_data) { int start_line_y, chat_height, line; /* make C compiler happy */ (void) pointer; (void) data; (void) signal; (void) type_data; /* scrolled another window/buffer? then just ignore */ if (weechat_window_get_pointer (signal_data, "buffer") != script_buffer) return WEECHAT_RC_OK; /* ignore if detail of a script is displayed */ if (script_buffer_detail_script) return WEECHAT_RC_OK; script_buffer_get_window_info (signal_data, &start_line_y, &chat_height); line = script_buffer_selected_line; while (line < start_line_y) { line += chat_height; } while (line >= start_line_y + chat_height) { line -= chat_height; } if (line < start_line_y) line = start_line_y; if (line >= script_repo_count_displayed) line = script_repo_count_displayed - 1; script_buffer_set_current_line (line); return WEECHAT_RC_OK; }