From 3f17b22cced1027fdff42bafb7828f3bf8face93 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 16 Oct 2021 05:15:46 +0300 Subject: [PATCH 51/51] gtk3x: Replace GdkEventButton use with GtkGesture See osdn #43051 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/dialogs.c | 9 +++++++-- client/gui-gtk-4.0/dialogs.h | 3 ++- client/gui-gtk-4.0/editgui.c | 34 ++++++++++++++++++++++++---------- client/gui-gtk-4.0/gui_main.c | 10 ++++++++-- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/client/gui-gtk-4.0/dialogs.c b/client/gui-gtk-4.0/dialogs.c index 5350637f4e..7f4d49b3da 100644 --- a/client/gui-gtk-4.0/dialogs.c +++ b/client/gui-gtk-4.0/dialogs.c @@ -1428,9 +1428,14 @@ static void races_response(GtkWidget *w, gint response, gpointer data) /**********************************************************************//** Adjust tax rates from main window **************************************************************************/ -gboolean taxrates_callback(GtkWidget *w, GdkEventButton *ev, gpointer data) +gboolean taxrates_callback(GtkGestureClick *gesture, int n_press, + double x, double y) { - common_taxrates_callback((size_t) data); + GtkWidget *widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)); + + common_taxrates_callback(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(widget), + "rate_button"))); + return TRUE; } diff --git a/client/gui-gtk-4.0/dialogs.h b/client/gui-gtk-4.0/dialogs.h index 8b56510e46..a96dfda688 100644 --- a/client/gui-gtk-4.0/dialogs.h +++ b/client/gui-gtk-4.0/dialogs.h @@ -21,7 +21,8 @@ void popup_revolution_dialog(struct government *government); void message_dialog_button_set_sensitive(GtkWidget *shl, int button, gboolean state); -gboolean taxrates_callback(GtkWidget *w, GdkEventButton *ev, gpointer data); +gboolean taxrates_callback(GtkGestureClick *gesture, int n_press, + double x, double y); void nationset_sync_to_server(const char *nationset); #endif /* FC__DIALOGS_H */ diff --git a/client/gui-gtk-4.0/editgui.c b/client/gui-gtk-4.0/editgui.c index 98c3d3e8e1..ae46d9ad29 100644 --- a/client/gui-gtk-4.0/editgui.c +++ b/client/gui-gtk-4.0/editgui.c @@ -1101,20 +1101,23 @@ create_tool_value_selector(struct editbar *eb, /************************************************************************//** Handle a mouse click on the tool image area in the editor info box. ****************************************************************************/ -static gboolean editinfobox_handle_tool_image_button_press(GtkWidget *evbox, - GdkEventButton *ev, - gpointer data) +static gboolean editinfobox_handle_tool_image_button_press( + GtkGestureClick *gesture, + int n_press, + double x, double y) { editgui_run_tool_selection(editor_get_tool()); + return TRUE; } /************************************************************************//** Handle a mouse click on the mode image area in the editor info box. ****************************************************************************/ -static gboolean editinfobox_handle_mode_image_button_press(GtkWidget *evbox, - GdkEventButton *ev, - gpointer data) +static gboolean editinfobox_handle_mode_image_button_press( + GtkGestureClick *gesture, + int n_press, + double x, double y) { editor_tool_cycle_mode(editor_get_tool()); editgui_refresh(); @@ -1192,6 +1195,7 @@ static struct editinfobox *editinfobox_create(void) GtkWidget *spin, *combo; GtkListStore *store; GtkCellRenderer *cell; + GtkEventController *controller; struct editinfobox *ei; char buf[128]; @@ -1221,8 +1225,13 @@ static struct editinfobox *editinfobox_create(void) image = gtk_image_new(); gtk_widget_set_tooltip_text(image, _("Click to change value if applicable.")); - g_signal_connect(image, "button_press_event", - G_CALLBACK(editinfobox_handle_tool_image_button_press), NULL); + + controller = GTK_EVENT_CONTROLLER(gtk_gesture_click_new()); + g_signal_connect(controller, "pressed", + G_CALLBACK(editinfobox_handle_tool_image_button_press), + NULL); + gtk_widget_add_controller(image, controller); + gtk_container_add(GTK_CONTAINER(hbox), image); ei->tool_image = image; @@ -1251,8 +1260,13 @@ static struct editinfobox *editinfobox_create(void) image = gtk_image_new(); gtk_widget_set_tooltip_text(image, _("Click to change tool mode.")); - g_signal_connect(image, "button_press_event", - G_CALLBACK(editinfobox_handle_mode_image_button_press), NULL); + + controller = GTK_EVENT_CONTROLLER(gtk_gesture_click_new()); + g_signal_connect(controller, "pressed", + G_CALLBACK(editinfobox_handle_mode_image_button_press), + NULL); + gtk_widget_add_controller(image, controller); + gtk_container_add(GTK_CONTAINER(hbox), image); ei->mode_image = image; diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 6ef8da1f69..6dbabd87f5 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -1232,10 +1232,16 @@ static void setup_widgets(void) econ_widget = table2; for (i = 0; i < 10; i++) { + GtkEventController *controller; + spr = i < 5 ? get_tax_sprite(tileset, O_SCIENCE) : get_tax_sprite(tileset, O_GOLD); econ_label[i] = image_new_from_surface(spr->surface); - g_signal_connect(econ_label[i], "button_press_event", - G_CALLBACK(taxrates_callback), GINT_TO_POINTER(i)); + + g_object_set_data(G_OBJECT(econ_label[i]), "rate_button", GUINT_TO_POINTER(i)); + controller = GTK_EVENT_CONTROLLER(gtk_gesture_click_new()); + g_signal_connect(controller, "pressed", + G_CALLBACK(taxrates_callback), NULL); + gtk_widget_add_controller(econ_label[i], controller); gtk_grid_attach(GTK_GRID(table2), econ_label[i], i, 0, 1, 1); } -- 2.33.0