From b454ea065b237fc4ae191a6388bb3b8934a8182d Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 8 Oct 2022 04:26:25 +0300
Subject: [PATCH 39/39] gtk4: Detect option dialog mouse press as gesture

See osdn #45794

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-4.0/mapctrl.c   | 14 +++++++-------
 client/gui-gtk-4.0/mapctrl.h   | 14 +++++++-------
 client/gui-gtk-4.0/optiondlg.c | 24 +++++++++++-------------
 3 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/client/gui-gtk-4.0/mapctrl.c b/client/gui-gtk-4.0/mapctrl.c
index 1ecf080750..9e6065c2ed 100644
--- a/client/gui-gtk-4.0/mapctrl.c
+++ b/client/gui-gtk-4.0/mapctrl.c
@@ -159,7 +159,7 @@ void set_turn_done_button_state(bool state)
   the release of both left and right mousebutton can launch the goto.
 **************************************************************************/
 gboolean left_butt_up_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                double x, double y)
+                                double x, double y, gpointer data)
 {
   if (editor_is_active()) {
     return handle_edit_mouse_button_release(gesture, MOUSE_BUTTON_LEFT,
@@ -176,7 +176,7 @@ gboolean left_butt_up_mapcanvas(GtkGestureClick *gesture, int n_press,
   the release of both left and right mousebutton can launch the goto.
 **************************************************************************/
 gboolean right_butt_up_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                 double x, double y)
+                                 double x, double y, gpointer data)
 {
   if (editor_is_active()) {
     return handle_edit_mouse_button_release(gesture, MOUSE_BUTTON_RIGHT,
@@ -201,7 +201,7 @@ gboolean right_butt_up_mapcanvas(GtkGestureClick *gesture, int n_press,
   Future feature: User-configurable mouse clicks.
 **************************************************************************/
 gboolean left_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                  double x, double y)
+                                  double x, double y, gpointer data)
 {
   struct tile *ptile = NULL;
   GdkModifierType state;
@@ -256,7 +256,7 @@ gboolean left_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press,
   Future feature: User-configurable mouse clicks.
 **************************************************************************/
 gboolean right_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                   double x, double y)
+                                   double x, double y, gpointer data)
 {
   struct city *pcity = NULL;
   struct tile *ptile = NULL;
@@ -325,7 +325,7 @@ gboolean right_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press,
   Future feature: User-configurable mouse clicks.
 **************************************************************************/
 gboolean middle_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                    double x, double y)
+                                    double x, double y, gpointer data)
 {
   struct tile *ptile = NULL;
   GdkModifierType state;
@@ -469,7 +469,7 @@ gboolean move_overviewcanvas(GtkEventControllerMotion *controller,
   Left button pressed at overview
 **************************************************************************/
 gboolean left_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press,
-                                       double x, double y)
+                                       double x, double y, gpointer data)
 {
   int xtile, ytile;
 
@@ -494,7 +494,7 @@ gboolean left_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press,
   Right button pressed at overview
 **************************************************************************/
 gboolean right_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press,
-                                        double x, double y)
+                                        double x, double y, gpointer data)
 {
   int xtile, ytile;
 
diff --git a/client/gui-gtk-4.0/mapctrl.h b/client/gui-gtk-4.0/mapctrl.h
index f998085697..2c94085107 100644
--- a/client/gui-gtk-4.0/mapctrl.h
+++ b/client/gui-gtk-4.0/mapctrl.h
@@ -22,19 +22,19 @@
 #include "mapctrl_g.h"
 
 gboolean left_butt_up_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                double x, double y);
+                                double x, double y, gpointer data);
 gboolean right_butt_up_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                 double x, double y);
+                                 double x, double y, gpointer data);
 gboolean left_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                  double x, double y);
+                                  double x, double y, gpointer data);
 gboolean right_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                   double x, double y);
+                                   double x, double y, gpointer data);
 gboolean middle_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press,
-                                    double x, double y);
+                                    double x, double y, gpointer data);
 gboolean left_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press,
-                                       double x, double y);
+                                       double x, double y, gpointer data);
 gboolean right_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press,
-                                        double x, double y);
+                                        double x, double y, gpointer data);
 gboolean move_mapcanvas(GtkEventControllerMotion *controller,
                         gdouble x, gdouble y, gpointer data);
 gboolean leave_mapcanvas(GtkEventControllerMotion *controller,
diff --git a/client/gui-gtk-4.0/optiondlg.c b/client/gui-gtk-4.0/optiondlg.c
index 21839c648f..47e6f421e3 100644
--- a/client/gui-gtk-4.0/optiondlg.c
+++ b/client/gui-gtk-4.0/optiondlg.c
@@ -181,25 +181,17 @@ static void option_apply_callback(GtkMenuItem *menuitem, gpointer data)
 /************************************************************************//**
   Called when a button is pressed on an option.
 ****************************************************************************/
-static gboolean option_button_press_callback(GtkWidget *widget,
-                                             GdkEvent *ev,
+static gboolean option_button_press_callback(GtkGestureClick *gesture,
+                                             int n_press,
+                                             double x, double y,
                                              gpointer data)
 {
   struct option *poption = (struct option *) data;
 #ifdef MENUS_GTK3
   GtkWidget *menu, *item;
 #endif /* MENUS_GTK3 */
-  GdkEventType type;
-  guint button;
 
-  type = gdk_event_get_event_type(ev);
-  if (type != GDK_BUTTON_PRESS) {
-    return FALSE;
-  }
-
-  button = gdk_button_event_get_button(ev);
-  if (3 != button || !option_is_changeable(poption)) {
-    /* Only right button please! */
+  if (!option_is_changeable(poption)) {
     return FALSE;
   }
 
@@ -491,6 +483,8 @@ static void option_dialog_option_add(struct option_dialog *pdialog,
   const int category = option_category(poption);
   GtkWidget *main_hbox, *label, *w = NULL;
   int main_col = 0;
+  GtkGesture *gesture;
+  GtkEventController *controller;
 
   fc_assert(NULL == option_get_gui_data(poption));
 
@@ -532,8 +526,12 @@ static void option_dialog_option_add(struct option_dialog *pdialog,
   gtk_widget_set_margin_top(label, 2);
   gtk_grid_attach(GTK_GRID(main_hbox), label, main_col++, 0, 1, 1);
   gtk_widget_set_tooltip_text(main_hbox, option_help_text(poption));
-  g_signal_connect(main_hbox, "button_press_event",
+  gesture = gtk_gesture_click_new();
+  gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 3);
+  controller = GTK_EVENT_CONTROLLER(gesture);
+  g_signal_connect(controller, "pressed",
                    G_CALLBACK(option_button_press_callback), poption);
+  gtk_widget_add_controller(main_hbox, controller);
   gtk_box_append(GTK_BOX(pdialog->vboxes[category]), main_hbox);
 
   switch (option_type(poption)) {
-- 
2.35.1