Skip to content

Commit

Permalink
Use gtk_menu_popup_at_pointer() instead of deprecated gtk_menu_popup()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tormodvolden committed Oct 15, 2021
1 parent 3405681 commit ac43d3c
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/core/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/include/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
39 changes: 0 additions & 39 deletions src/ui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/ui/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 2 additions & 6 deletions src/ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac43d3c

Please sign in to comment.