From af21583d4d60edf9782cdd803b3854f5c4b2a967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 25 Jul 2018 16:39:53 +0200 Subject: tests: Stop using legacy gtk_menu_popup API Use the new portable APIs, so that menus will be positioned properly on all backends. --- tests/testiconview.c | 3 +-- tests/testtoolbar.c | 48 ++++++++++++++++-------------------------------- 2 files changed, 17 insertions(+), 34 deletions(-) (limited to 'tests') diff --git a/tests/testiconview.c b/tests/testiconview.c index 7d52899301..b008dd1093 100644 --- a/tests/testiconview.c +++ b/tests/testiconview.c @@ -384,8 +384,7 @@ do_popup_menu (GtkWidget *icon_list, event_time = gtk_get_current_event_time (); } - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - button, event_time); + gtk_menu_popup_at_pointer (GTK_MENU (menu), event); } diff --git a/tests/testtoolbar.c b/tests/testtoolbar.c index 24d80b9d1e..c49b2cdb5f 100644 --- a/tests/testtoolbar.c +++ b/tests/testtoolbar.c @@ -320,34 +320,9 @@ rtl_toggled (GtkCheckButton *check) gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR); } -typedef struct -{ - int x; - int y; -} MenuPositionData; - -static void -position_function (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data) -{ - /* Do not do this in your own code */ - - MenuPositionData *position_data = user_data; - - if (x) - *x = position_data->x; - - if (y) - *y = position_data->y; - - if (push_in) - *push_in = FALSE; -} - static gboolean popup_context_menu (GtkToolbar *toolbar, gint x, gint y, gint button_number) { - MenuPositionData position_data; - GtkMenu *menu = GTK_MENU (gtk_menu_new ()); int i; @@ -358,18 +333,27 @@ popup_context_menu (GtkToolbar *toolbar, gint x, gint y, gint button_number) item = gtk_menu_item_new_with_mnemonic (label); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); } - gtk_widget_show (GTK_WIDGET (menu)); if (button_number != -1) { - position_data.x = x; - position_data.y = y; - - gtk_menu_popup (menu, NULL, NULL, position_function, - &position_data, button_number, gtk_get_current_event_time()); + gtk_menu_popup_at_pointer (menu, NULL); } else - gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); + { + GtkWindow *window; + GtkWidget *widget; + + window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (toolbar))); + widget = gtk_window_get_focus (window); + if (!widget) + widget = GTK_WIDGET (toolbar); + + gtk_menu_popup_at_widget (menu, + widget, + GDK_GRAVITY_SOUTH_EAST, + GDK_GRAVITY_NORTH_WEST, + NULL); + } return TRUE; } -- cgit v1.2.1