From 2c2396a7d09a6c7ea3f381f575686b84cd97b63a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 31 May 2023 03:27:50 +0300 Subject: [PATCH 32/32] gtk4: Fix chat are autoscrolling on resize See osdn #48117 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/gui_main.c | 31 +++++++++++++++++-------------- client/gui-gtk-4.0/gui_main.h | 2 ++ client/gui-gtk-4.0/pages.c | 3 ++- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index f525d6aeb4..6a9d507557 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -359,16 +359,21 @@ static void toplevel_focus(GtkWidget *w, GtkDirectionType arg, prevents users from accidentally missing messages when the chatline gets scrolled up a small amount and stops scrolling down automatically. **************************************************************************/ -static void main_message_area_resize(GtkWidget *widget, int width, int height, - gpointer data) -{ - static int old_width = 0, old_height = 0; +void main_message_area_resize(void *data) +{ + if (get_current_client_page() == PAGE_GAME) { + static int old_width = 0, old_height = 0; + int width = gtk_widget_get_width(GTK_WIDGET(main_message_area)); + int height = gtk_widget_get_height(GTK_WIDGET(main_message_area)); + + if (width != old_width + || height != old_height) { + chatline_scroll_to_bottom(TRUE); + old_width = width; + old_height = height; + } - if (width != old_width - || height != old_height) { - chatline_scroll_to_bottom(TRUE); - old_width = width; - old_height = height; + add_idle_callback(main_message_area_resize, NULL); } } @@ -1589,8 +1594,6 @@ static void setup_widgets(void) set_message_buffer_view_link_handlers(text); gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), text); - g_signal_connect(text, "resize", - G_CALLBACK(main_message_area_resize), NULL); gtk_widget_set_name(text, "chatline"); @@ -1605,7 +1608,7 @@ static void setup_widgets(void) chat_welcome_message(TRUE); - /* the chat line */ + /* The chat line */ view = inputline_toolkit_view_new(); gtk_grid_attach(GTK_GRID(vgrid), view, 0, grid_row++, 1, 1); gtk_widget_set_margin_bottom(view, 3); @@ -2403,7 +2406,7 @@ struct callback { }; /**********************************************************************//** - A wrapper for the callback called through add_idle_callback. + A wrapper for the callback called through add_idle_callback(). **************************************************************************/ static gboolean idle_callback_wrapper(gpointer data) { @@ -2416,7 +2419,7 @@ static gboolean idle_callback_wrapper(gpointer data) } /**********************************************************************//** - Enqueue a callback to be called during an idle moment. The 'callback' + Enqueue a callback to be called during an idle moment. The 'callback' function should be called sometimes soon, and passed the 'data' pointer as its data. **************************************************************************/ diff --git a/client/gui-gtk-4.0/gui_main.h b/client/gui-gtk-4.0/gui_main.h index 8effb44db1..ab27c5ab15 100644 --- a/client/gui-gtk-4.0/gui_main.h +++ b/client/gui-gtk-4.0/gui_main.h @@ -22,6 +22,8 @@ #define GUI_GTK_OPTION_STR(optname) "gui_gtk4_" #optname #define GUI_GTK_DEFAULT_THEME_NAME FC_GTK4_DEFAULT_THEME_NAME +void main_message_area_resize(void *data); + /* Network string charset conversion */ gchar *ntoh_str(const gchar *netstr); diff --git a/client/gui-gtk-4.0/pages.c b/client/gui-gtk-4.0/pages.c index e30b93dd9e..07e92d58ee 100644 --- a/client/gui-gtk-4.0/pages.c +++ b/client/gui-gtk-4.0/pages.c @@ -3478,7 +3478,7 @@ enum client_pages get_current_client_page(void) } /**********************************************************************//** - Changes the current page. The action is delayed. + Changes the current page. The action is delayed. **************************************************************************/ void real_set_client_page(enum client_pages new_page) { @@ -3585,6 +3585,7 @@ void real_set_client_page(enum client_pages new_page) refresh_chat_buttons(); center_on_something(); mapview_thaw(); + add_idle_callback(main_message_area_resize, NULL); break; case PAGE_NETWORK: update_network_lists(); -- 2.39.2