GTK4: button-press-event deprecated
authorColin Clark <colin.clark@cclark.uk>
Tue, 28 Mar 2023 17:26:44 +0000 (18:26 +0100)
committerColin Clark <colin.clark@cclark.uk>
Tue, 28 Mar 2023 17:26:44 +0000 (18:26 +0100)
GTK4 migration
- replace button-press-event with gtk_gesture_click
- include the mechanism for HAVE_GTK4 (but this is not for users)

config.h.in
meson.build
meson_options.txt
src/bar-histogram.cc

index 5f7186d..de5fc44 100644 (file)
 
 /* Define to 1 if you have the <execinfo.h> header file. */
 #mesondefine HAVE_EXECINFO_H
+
+/* Do not use */
+#mesondefine HAVE_GTK4
+
 #endif
index c2a58ce..9680f90 100644 (file)
@@ -155,7 +155,13 @@ conf_data = configuration_data()
 conf_data.set_quoted('VERSION', meson.project_version())
 conf_data.set('DEBUG', debug)
 
-gtk_dep = dependency('gtk+-3.0', version : '>=3.22', required: true)
+option = get_option('gtk4')
+if option.enabled()
+    gtk_dep = dependency('gtk4', required: true)
+    conf_data.set('HAVE_GTK4', 1)
+else
+    gtk_dep = dependency('gtk+-3.0', version : '>=3.24', required: true)
+endif
 glib_dep = dependency('glib-2.0', version : '>=2.52', required: true)
 
 # Required only when backward-cpp is used
index a0ad63a..82b08ef 100644 (file)
@@ -33,6 +33,7 @@ option('execinfo', type : 'feature', value : 'auto', description : 'execinfo.h')
 option('exiv2', type : 'feature', value : 'auto', description : 'exiv2')
 option('git', type : 'feature', value : 'auto', description : 'lua-api and changelog.html')
 option('gps-map', type : 'feature', value : 'auto', description : 'gps map')
+option('gtk4', type : 'feature', value : 'disabled', description : 'gtk4 - do not use')
 option('heif', type : 'feature', value : 'auto', description : 'heif')
 option('j2k', type : 'feature', value : 'auto', description : 'j2k')
 option('jpeg', type : 'feature', value : 'auto', description : 'jpeg')
index 10a98fc..8870704 100644 (file)
@@ -243,26 +243,22 @@ static GtkWidget *bar_pane_histogram_menu(PaneHistogramData *phd)
        return menu;
 }
 
-static gboolean bar_pane_histogram_press_cb(GtkWidget *UNUSED(widget), GdkEventButton *bevent, gpointer data)
+static gboolean bar_pane_histogram_press_cb(GtkGesture *UNUSED(gesture), gint UNUSED(n_press), gdouble UNUSED(x), gdouble UNUSED(y), gpointer data)
 {
        PaneHistogramData *phd = data;
+       GtkWidget *menu;
 
-       if (bevent->button == MOUSE_BUTTON_RIGHT)
-               {
-               GtkWidget *menu;
-
-               menu = bar_pane_histogram_menu(phd);
-               gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL);
-               return TRUE;
-       }
+       menu = bar_pane_histogram_menu(phd);
+       gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL);
 
-       return FALSE;
+       return TRUE;
 }
 
 
 static GtkWidget *bar_pane_histogram_new(const gchar *id, const gchar *title, gint height, gboolean expanded, gint histogram_channel, gint histogram_mode)
 {
        PaneHistogramData *phd;
+       GtkGesture *gesture;
 
        phd = g_new0(PaneHistogramData, 1);
 
@@ -299,7 +295,15 @@ static GtkWidget *bar_pane_histogram_new(const gchar *id, const gchar *title, gi
        gtk_widget_show(phd->drawing_area);
        gtk_widget_add_events(phd->drawing_area, GDK_BUTTON_PRESS_MASK);
 
-       g_signal_connect(G_OBJECT(phd->drawing_area), "button_press_event", G_CALLBACK(bar_pane_histogram_press_cb), phd);
+
+#ifdef HAVE_GTK4
+       gesture = gtk_gesture_click_new();
+       gtk_widget_add_controller(phd->drawing_area, GTK_EVENT_CONTROLLER(gesture));
+#else
+       gesture = gtk_gesture_multi_press_new(phd->drawing_area);
+#endif
+       gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), MOUSE_BUTTON_RIGHT);
+       g_signal_connect(gesture, "pressed", G_CALLBACK(bar_pane_histogram_press_cb), phd);
 
        gtk_widget_show(phd->widget);