From 51f265a1690d6da7fce988f5322e6563efa769cd Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 7 Aug 2022 00:25:42 +0300 Subject: [PATCH 50/50] gtk4: Implement popup for the info label See osdn #45313 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/gui_main.c | 51 ++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index d0c287f977..a300d58b0c 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -186,7 +186,8 @@ static struct video_mode vmode = { -1, -1 }; static void set_g_log_callbacks(void); -static gboolean show_info_popup(GtkWidget *w, GdkEvent *ev, gpointer data); +static gboolean show_info_popup(GtkGestureClick *gesture, int n_press, + double x, double y, gpointer data); static void end_turn_callback(GtkWidget *w, gpointer data); static gboolean get_net_input(GIOChannel *source, GIOCondition condition, @@ -1279,8 +1280,11 @@ static void setup_widgets(void) gtk_widget_set_margin_end(label, 2); gtk_widget_set_margin_top(label, 2); gtk_widget_set_margin_bottom(label, 2); - g_signal_connect(label, "button_press_event", - G_CALLBACK(show_info_popup), NULL); + + mc_controller = GTK_EVENT_CONTROLLER(gtk_gesture_click_new()); + g_signal_connect(mc_controller, "pressed", + G_CALLBACK(show_info_popup), frame); + gtk_widget_add_controller(label, mc_controller); gtk_grid_attach(GTK_GRID(vgrid), label, 0, grid_row++, 1, 1); main_label_info = label; @@ -2258,28 +2262,31 @@ static gboolean select_more_arrow_callback(GtkGestureClick *gesture, int n_press } /**********************************************************************//** - Popup info box + On close of the info popup **************************************************************************/ -static gboolean show_info_popup(GtkWidget *w, GdkEvent *ev, gpointer data) +static void info_popup_closed(GtkWidget *self, gpointer data) { - guint button; + gtk_widget_unparent(self); +} - button = gdk_button_event_get_button(ev); - if (button == 1) { - GtkWidget *p; - GtkWidget *child; +/**********************************************************************//** + Popup info box +**************************************************************************/ +static gboolean show_info_popup(GtkGestureClick *gesture, int n_press, + double x, double y, gpointer data) +{ + GtkWidget *p; + GtkWidget *child; + GtkWidget *frame = GTK_WIDGET(data); - p = gtk_window_new(); - gtk_widget_set_margin_start(p, 4); - gtk_widget_set_margin_end(p, 4); - gtk_widget_set_margin_top(p, 4); - gtk_widget_set_margin_bottom(p, 4); - gtk_window_set_transient_for(GTK_WINDOW(p), GTK_WINDOW(toplevel)); + p = gtk_popover_new(); - child = gtk_label_new(get_info_label_text_popup()); - gtk_window_set_child(GTK_WINDOW(p), child); - gtk_widget_show(p); - } + gtk_widget_set_parent(p, frame); + child = gtk_label_new(get_info_label_text_popup()); + gtk_popover_set_child(GTK_POPOVER(p), child); + g_signal_connect(p, "closed", + G_CALLBACK(info_popup_closed), NULL); + gtk_popover_popup(GTK_POPOVER(p)); return TRUE; } @@ -2289,8 +2296,8 @@ static gboolean show_info_popup(GtkWidget *w, GdkEvent *ev, gpointer data) **************************************************************************/ static void end_turn_callback(GtkWidget *w, gpointer data) { - gtk_widget_set_sensitive(turn_done_button, FALSE); - user_ended_turn(); + gtk_widget_set_sensitive(turn_done_button, FALSE); + user_ended_turn(); } /**********************************************************************//** -- 2.35.1