Skip to content

Commit 0cd08ec

Browse files
gtkui: runtime check for availability of gtk_menu_popup_at_pointer / gtk3.22 (fixes #3269)
1 parent e4fb3c2 commit 0cd08ec

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

plugins/gtkui/support.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <sys/types.h>
1010
#include <sys/stat.h>
11+
#include <dlfcn.h>
1112
#include <unistd.h>
1213
#include <string.h>
1314
#include <stdio.h>
@@ -219,3 +220,28 @@ gtk_widget_set_window(GtkWidget *widget, GdkWindow *window) {
219220
widget->window = window;
220221
}
221222
#endif
223+
224+
#if !GTK_CHECK_VERSION(3,22,0)
225+
void
226+
gtk_menu_popup_at_pointer_fallback (GtkMenu *menu, const GdkEvent *trigger_event) {
227+
#if !GTK_CHECK_VERSION(3,0,0)
228+
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 3, gtk_get_current_event_time());
229+
#else
230+
static void (* gtk_menu_popup_at_pointer_fn)(GtkMenu *menu, const GdkEvent *trigger_event);
231+
static gboolean did_check = FALSE;
232+
if (!did_check) {
233+
did_check = TRUE;
234+
void *handle = dlopen (NULL, RTLD_LAZY);
235+
if (handle != NULL) {
236+
gtk_menu_popup_at_pointer_fn = dlsym (handle, "gtk_menu_popup_at_pointer");
237+
dlclose (handle);
238+
}
239+
}
240+
if (gtk_menu_popup_at_pointer_fn != NULL) {
241+
gtk_menu_popup_at_pointer_fn (menu, trigger_event);
242+
} else {
243+
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 3, gtk_get_current_event_time());
244+
}
245+
#endif
246+
}
247+
#endif

plugins/gtkui/support.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ void gtk_widget_get_allocation (GtkWidget *widget,
180180
#endif
181181

182182
#if !GTK_CHECK_VERSION(3,22,0)
183-
#define gtk_menu_popup_at_pointer(menu,trigger_event) gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 3, gtk_get_current_event_time())
183+
void
184+
gtk_menu_popup_at_pointer_fallback(GtkMenu *menu, const GdkEvent *trigger_event);
185+
#define gtk_menu_popup_at_pointer(menu,trigger_event) gtk_menu_popup_at_pointer_fallback(menu, trigger_event)
184186
#endif
185187

186188
#if GTK_CHECK_VERSION(3,2,0)

0 commit comments

Comments
 (0)