Skip to content

Commit

Permalink
Merge pull request #399 from MatusGuy/autoscroll
Browse files Browse the repository at this point in the history
Scroll down when new message even if window is inactive
  • Loading branch information
SilverRainZ authored Dec 3, 2023
2 parents ef336d3 + fdb8c63 commit 2d3c15c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions data/builtin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exit-on-close = false # Bool; Exit program on main window closed
auto-connect = [] # String array; Servers that are auto connected
# after startup
server-visibility = true # Bool; Whether the server buffer is visible
scroll-on-new-message = false # Auto scroll when a new message is recieved

# If you want to report/fix a bug, terminal log will be helpful.
log =
Expand Down
2 changes: 2 additions & 0 deletions src/config/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ static SrnRet read_application_config_from_cfg(config_t *cfg,
&app_cfg->ui->window.exit_on_close);
config_lookup_bool_ex(cfg, "server-visibility",
&app_cfg->ui->window.server_visibility);
config_lookup_bool_ex(cfg, "scroll-on-new-message",
&app_cfg->ui->window.scroll_on_new_message);

/* Read auto connect server list */
config_setting_t *auto_connect;
Expand Down
1 change: 1 addition & 0 deletions src/inc/sui/sui_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct _SuiWindowConfig {
bool send_on_ctrl_enter;
bool exit_on_close;
bool server_visibility;
bool scroll_on_new_message;
};

struct _SuiApplicationConfig {
Expand Down
7 changes: 5 additions & 2 deletions src/sui/sui_message_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ static gboolean scroll_to_bottom_timeout(gpointer user_data){
*
* This function called when a message added to ``SuiMessageList``.
* If:
* - The top-level window is active;
* - The top-level window is active
* (Can be changed with the "scroll_on_new_message" config option)
* - And the SuiMessageList itself is child of current ``SuiBuffer``;
* - The scroll bar is near the bottom of the list box
* (If not, the user may be browsing previous messages).
Expand All @@ -312,7 +313,9 @@ static void smart_scroll(SuiMessageList *self){
buf = sui_window_get_cur_buffer(win);
g_return_if_fail(SUI_IS_BUFFER(buf));

if (!sui_window_is_active(win)) {
if (!sui_window_get_config(win)->scroll_on_new_message &&
!sui_window_is_active(win))
{
return;
}
if (sui_buffer_get_message_list(buf) != self){
Expand Down

0 comments on commit 2d3c15c

Please sign in to comment.