Compare commits

...

6 Commits

Author SHA1 Message Date
522db05090 style(ui,window): format code and tidy comments
All checks were successful
CI Code / Check spelling (pull_request) Successful in 21s
CI Code / Check coding style (pull_request) Successful in 54s
CI Code / Linux (arch) (pull_request) Successful in 10m34s
CI Code / Linux (debian) (pull_request) Successful in 13m28s
CI Code / Linux (ubuntu) (pull_request) Successful in 14m0s
Whitespace and comment formatting only; no functional changes.
2025-11-04 08:26:35 +03:00
221a95b7b4 refactor(ui,window): post-review cleanups in window module
Apply code style and structure simplifications suggested during review; no functional changes.
2025-11-04 08:26:21 +03:00
89f75575a5 docs(ui,window): update comments related to metrics handling
Adjust comments to better reflect metrics-related behavior; no functional changes.
2025-11-04 08:26:06 +03:00
ccb4bbac4a docs(ui,window): update comments around buffer handling
Clarify buffer-related behavior and notes in the window module comments; no functional changes.
2025-11-04 08:25:54 +03:00
6a47efa049 fix(ui,window): manage unread indicators and paging state accurately
Add logic to track unread message indicators and the paged state in the UI window component, ensuring correct clearing and display of unread markers while navigating.

Files: src/ui/window.c, src/ui/titlebar.c, src/ui/win_types.h
2025-11-04 08:25:31 +03:00
33543d2543 fix(ui,window): prevent buffer updates while viewing history to avoid scroll lock
When the user scrolls back to view message history, suppress printing and buffer writes to keep the viewport stable and prevent the scroll position from jumping or getting stuck.

Files: src/ui/window.c
2025-11-04 08:25:17 +03:00
3 changed files with 31 additions and 5 deletions

View File

@@ -268,7 +268,11 @@ _show_scrolled(ProfWin* current)
wattroff(win, bracket_attrs); wattroff(win, bracket_attrs);
wattron(win, scrolled_attrs); wattron(win, scrolled_attrs);
wprintw(win, "SCROLLED"); if (current->layout->unread_msg == 0) {
wprintw(win, "SCROLLED");
} else {
wprintw(win, "SCROLLED, NEW MESSAGES");
}
wattroff(win, scrolled_attrs); wattroff(win, scrolled_attrs);
wattron(win, bracket_attrs); wattron(win, bracket_attrs);

View File

@@ -120,6 +120,7 @@ typedef struct prof_layout_t
ProfBuff buffer; ProfBuff buffer;
int y_pos; int y_pos;
int paged; int paged;
int unread_msg;
} ProfLayout; } ProfLayout;
typedef struct prof_layout_simple_t typedef struct prof_layout_simple_t

View File

@@ -103,6 +103,7 @@ _win_create_simple_layout(void)
layout->base.buffer = buffer_create(); layout->base.buffer = buffer_create();
layout->base.y_pos = 0; layout->base.y_pos = 0;
layout->base.paged = 0; layout->base.paged = 0;
layout->base.unread_msg = 0;
scrollok(layout->base.win, TRUE); scrollok(layout->base.win, TRUE);
return &layout->base; return &layout->base;
@@ -120,6 +121,7 @@ _win_create_split_layout(void)
layout->base.buffer = buffer_create(); layout->base.buffer = buffer_create();
layout->base.y_pos = 0; layout->base.y_pos = 0;
layout->base.paged = 0; layout->base.paged = 0;
layout->base.unread_msg = 0;
scrollok(layout->base.win, TRUE); scrollok(layout->base.win, TRUE);
layout->subwin = NULL; layout->subwin = NULL;
layout->sub_y_pos = 0; layout->sub_y_pos = 0;
@@ -197,6 +199,7 @@ win_create_muc(const char* const roomjid)
layout->base.buffer = buffer_create(); layout->base.buffer = buffer_create();
layout->base.y_pos = 0; layout->base.y_pos = 0;
layout->base.paged = 0; layout->base.paged = 0;
layout->base.unread_msg = 0;
scrollok(layout->base.win, TRUE); scrollok(layout->base.win, TRUE);
new_win->window.layout = (ProfLayout*)layout; new_win->window.layout = (ProfLayout*)layout;
@@ -698,9 +701,11 @@ void
win_page_down(ProfWin* window, int scroll_size) win_page_down(ProfWin* window, int scroll_size)
{ {
int total_rows = getcury(window->layout->win); int total_rows = getcury(window->layout->win);
int total_rows_with_unread = total_rows + window->layout->unread_msg;
int* page_start = &(window->layout->y_pos); int* page_start = &(window->layout->y_pos);
int page_space = getmaxy(stdscr) - 4; int page_space = getmaxy(stdscr) - 4;
int page_start_initial = *page_start; int page_start_initial = *page_start;
if (scroll_size == 0) if (scroll_size == 0)
scroll_size = page_space; scroll_size = page_space;
win_scroll_state_t* scroll_state = &window->scroll_state; win_scroll_state_t* scroll_state = &window->scroll_state;
@@ -709,7 +714,11 @@ win_page_down(ProfWin* window, int scroll_size)
*page_start += scroll_size; *page_start += scroll_size;
// Scrolled down after reaching the bottom of the page // Scrolled down after reaching the bottom of the page
if ((*page_start > total_rows - page_space || (*page_start == page_space && *page_start >= total_rows)) && window->type == WIN_CHAT) { gboolean past_bottom = *page_start > total_rows_with_unread - page_space;
gboolean at_page_space_and_past_unread = (*page_start == page_space && *page_start >= total_rows_with_unread);
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); int bf_size = buffer_size(window->layout->buffer);
if (bf_size > 0 && *scroll_state != WIN_SCROLL_REACHED_BOTTOM) { if (bf_size > 0 && *scroll_state != WIN_SCROLL_REACHED_BOTTOM) {
// How many lines are left until end of the screen // How many lines are left until end of the screen
@@ -743,13 +752,16 @@ win_page_down(ProfWin* window, int scroll_size)
window->layout->paged = 1; window->layout->paged = 1;
// update only if position has changed // update only if position has changed
if (page_start_initial != *page_start) { if ((page_start_initial != *page_start) || window->layout->unread_msg) {
win_update_virtual(window); win_update_virtual(window);
} }
// switch off page if last line and space line visible /* Switch off page if no messages left to read.
if (total_rows - *page_start == page_space) { * TODO: update buffer end handling to check messages just after last entry.
*/
if (*scroll_state == WIN_SCROLL_REACHED_BOTTOM) {
window->layout->paged = 0; window->layout->paged = 0;
window->layout->unread_msg = 0;
} }
} }
@@ -810,6 +822,7 @@ win_clear(ProfWin* window)
int* page_start = &(window->layout->y_pos); int* page_start = &(window->layout->y_pos);
*page_start = y; *page_start = y;
window->layout->paged = 1; window->layout->paged = 1;
window->layout->unread_msg = 0;
win_update_virtual(window); win_update_virtual(window);
} }
@@ -914,6 +927,7 @@ void
win_move_to_end(ProfWin* window) win_move_to_end(ProfWin* window)
{ {
window->layout->paged = 0; window->layout->paged = 0;
window->layout->unread_msg = 0;
int rows = getmaxy(stdscr); int rows = getmaxy(stdscr);
int y = getcury(window->layout->win); int y = getcury(window->layout->win);
@@ -1696,6 +1710,13 @@ win_newline(ProfWin* window)
static void static void
_win_printf(ProfWin* window, const char* show_char, int pad_indent, GDateTime* timestamp, int flags, theme_item_t theme_item, const char* const display_from, const char* const from_jid, const char* const message_id, const char* const message, ...) _win_printf(ProfWin* window, const char* show_char, int pad_indent, GDateTime* timestamp, int flags, theme_item_t theme_item, const char* const display_from, const char* const from_jid, const char* const message_id, const char* const message, ...)
{ {
/* Prevent printing and buffer update when user is viewing message history [SCROLLING]*/
if (window->layout->paged && wins_is_current(window)) {
window->layout->unread_msg++;
return;
}
if (timestamp == NULL) { if (timestamp == NULL) {
timestamp = g_date_time_new_now_local(); timestamp = g_date_time_new_now_local();
} else { } else {