From 221a95b7b4358dfacadfea8d5c75812a09ceb221 Mon Sep 17 00:00:00 2001 From: "jabber.developer2" Date: Wed, 29 Oct 2025 17:45:43 +0300 Subject: [PATCH] refactor(ui,window): post-review cleanups in window module Apply code style and structure simplifications suggested during review; no functional changes. --- src/ui/window.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index dd08c29a..cc76bf02 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -701,9 +701,11 @@ void win_page_down(ProfWin* window, int scroll_size) { int total_rows = getcury(window->layout->win); + int total_rows_with_unreaded = total_rows + window->layout->unread_msg; int* page_start = &(window->layout->y_pos); int page_space = getmaxy(stdscr) - 4; int page_start_initial = *page_start; + if (scroll_size == 0) scroll_size = page_space; win_scroll_state_t* scroll_state = &window->scroll_state; @@ -712,7 +714,11 @@ win_page_down(ProfWin* window, int scroll_size) *page_start += scroll_size; // Scrolled down after reaching the bottom of the page - if (((*page_start > total_rows + window->layout->unread_msg - page_space) || ((*page_start == page_space + window->layout->unread_msg) && *page_start >= (total_rows + window->layout->unread_msg))) && window->type == WIN_CHAT) { + gboolean past_bottom = *page_start > total_rows_with_unreaded - page_space; + gboolean at_page_space_and_past_unread = (*page_start == page_space && *page_start >= total_rows_with_unreaded); + gboolean is_chat = window->type == WIN_CHAT; + + if ((past_bottom || at_page_space_and_past_unread) && is_chat) { int bf_size = buffer_size(window->layout->buffer); if (bf_size > 0 && *scroll_state != WIN_SCROLL_REACHED_BOTTOM) { // How many lines are left until end of the screen @@ -746,7 +752,7 @@ win_page_down(ProfWin* window, int scroll_size) window->layout->paged = 1; // update only if position has changed - if ((page_start_initial != *page_start) || (window->layout->unread_msg)) { + if ((page_start_initial != *page_start) || window->layout->unread_msg) { win_update_virtual(window); } @@ -1706,7 +1712,7 @@ _win_printf(ProfWin* window, const char* show_char, int pad_indent, GDateTime* t { /* Prevent printing and buffer update when user is viewing message history [SCROLLING]*/ - if ((window->layout->paged) && wins_is_current(window)) { + if (window->layout->paged && wins_is_current(window)) { window->layout->unread_msg++; return; }