From ac43d3cb80e566dd10d8846923d361b6ffb31b48 Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Fri, 15 Oct 2021 09:53:34 +0200 Subject: [PATCH] Use gtk_menu_popup_at_pointer() instead of deprecated gtk_menu_popup() gtk_menu_popup_at_pointer() saves us the helper functions for positioning and scaling. gtk_menu_popup_at_pointer() was introduced in gtk 3.22 and gtk_menu_popup() was deprecated at the same time. Signed-off-by: Tormod Volden --- src/core/window.c | 2 +- src/include/ui.h | 6 +----- src/ui/menu.c | 39 --------------------------------------- src/ui/menu.h | 1 - src/ui/ui.c | 8 ++------ 5 files changed, 4 insertions(+), 52 deletions(-) diff --git a/src/core/window.c b/src/core/window.c index 55badf548..8b87f52d4 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -7120,7 +7120,7 @@ meta_window_show_menu (MetaWindow *window, meta_verbose ("Popping up window menu for %s\n", window->desc); - meta_ui_window_menu_popup (menu, root_x, root_y, button, timestamp); + meta_ui_window_menu_popup (menu); } void diff --git a/src/include/ui.h b/src/include/ui.h index c02e78a21..3319c8ae1 100644 --- a/src/include/ui.h +++ b/src/include/ui.h @@ -130,11 +130,7 @@ MetaWindowMenu* meta_ui_window_menu_new (MetaUI *ui, int n_workspaces, MetaWindowMenuFunc func, gpointer data); -void meta_ui_window_menu_popup (MetaWindowMenu *menu, - int root_x, - int root_y, - int button, - guint32 timestamp); +void meta_ui_window_menu_popup (MetaWindowMenu *menu); void meta_ui_window_menu_free (MetaWindowMenu *menu); GdkPixbuf* meta_gdk_pixbuf_get_from_pixmap (GdkPixbuf *dest, diff --git a/src/ui/menu.c b/src/ui/menu.c index 34e4b5d91..c46262fe2 100644 --- a/src/ui/menu.c +++ b/src/ui/menu.c @@ -101,28 +101,6 @@ static MenuItem menuitems[] = { {META_MENU_OP_DELETE, MENU_ITEM_IMAGE, MARCO_STOCK_DELETE, FALSE, N_("_Close")} }; -static void popup_position_func(GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer user_data) -{ - GtkRequisition req; - GdkPoint* pos; - - pos = user_data; - - gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL); - - *x = pos->x; - *y = pos->y; - - if (meta_ui_get_direction() == META_UI_DIRECTION_RTL) - { - *x = MAX (0, *x - req.width); - } - - /* Ensure onscreen */ - *x = CLAMP (*x, 0, MAX(0, WidthOfScreen (gdk_x11_screen_get_xscreen (gdk_screen_get_default ())) - req.width)); - *y = CLAMP (*y, 0, MAX(0, HeightOfScreen (gdk_x11_screen_get_xscreen (gdk_screen_get_default ())) - req.height)); -} - static void menu_closed(GtkMenu* widget, gpointer data) { MetaWindowMenu *menu; @@ -489,23 +467,6 @@ meta_window_menu_new (MetaFrames *frames, return menu; } -void meta_window_menu_popup(MetaWindowMenu* menu, int root_x, int root_y, int button, guint32 timestamp) -{ - GdkPoint* pt = g_new(GdkPoint, 1); - gint scale; - - g_object_set_data_full(G_OBJECT(menu->menu), "destroy-point", pt, g_free); - - scale = gtk_widget_get_scale_factor (menu->menu); - pt->x = root_x / scale; - pt->y = root_y / scale; - - gtk_menu_popup(GTK_MENU (menu->menu), NULL, NULL, popup_position_func, pt, button, timestamp); - - if (!gtk_widget_get_visible (menu->menu)) - meta_warning("GtkMenu failed to grab the pointer\n"); -} - void meta_window_menu_free(MetaWindowMenu* menu) { gtk_widget_destroy(menu->menu); diff --git a/src/ui/menu.h b/src/ui/menu.h index 7af4ad8ed..b5b23cc58 100644 --- a/src/ui/menu.h +++ b/src/ui/menu.h @@ -42,7 +42,6 @@ struct _MetaWindowMenu { }; MetaWindowMenu* meta_window_menu_new(MetaFrames* frames, MetaMenuOp ops, MetaMenuOp insensitive, Window client_xwindow, unsigned long active_workspace, int n_workspaces, MetaWindowMenuFunc func, gpointer data); -void meta_window_menu_popup(MetaWindowMenu* menu, int root_x, int root_y, int button, guint32 timestamp); void meta_window_menu_free(MetaWindowMenu* menu); #endif diff --git a/src/ui/ui.c b/src/ui/ui.c index 4d61094b7..4c30d715b 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -516,13 +516,9 @@ meta_ui_window_menu_new (MetaUI *ui, } void -meta_ui_window_menu_popup (MetaWindowMenu *menu, - int root_x, - int root_y, - int button, - guint32 timestamp) +meta_ui_window_menu_popup (MetaWindowMenu *menu) { - meta_window_menu_popup (menu, root_x, root_y, button, timestamp); + gtk_menu_popup_at_pointer (GTK_MENU (menu->menu), NULL); } void