Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

menu: avoid deprecated gtk_menu_popup #709

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,20 +530,18 @@ meta_core_get_active_workspace (Screen *xscreen)
}

void
meta_core_show_window_menu (Display *xdisplay,
Window frame_xwindow,
int root_x,
int root_y,
int button,
guint32 timestamp)
meta_core_show_window_menu (Display *xdisplay,
Window frame_xwindow,
const GdkRectangle *rect,
guint32 timestamp)
{
MetaWindow *window = get_window (xdisplay, frame_xwindow);

if (meta_prefs_get_raise_on_click ())
meta_window_raise (window);
meta_window_focus (window, timestamp);

meta_window_show_menu (window, root_x, root_y, button, timestamp);
meta_window_show_menu (window, rect, timestamp);
}

void
Expand Down
14 changes: 9 additions & 5 deletions src/core/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -1998,13 +1998,17 @@ static gboolean event_callback(XEvent* event, gpointer data)
}
else if (event->xbutton.button == meta_prefs_get_mouse_button_menu())
{
GdkRectangle rect;

if (meta_prefs_get_raise_on_click ())
meta_window_raise (window);
meta_window_show_menu (window,
event->xbutton.x_root,
event->xbutton.y_root,
event->xbutton.button,
event->xbutton.time);

rect.x = event->xbutton.x_root;
rect.y = event->xbutton.y_root;
rect.width = 0;
rect.height = 0;

meta_window_show_menu (window, &rect, event->xbutton.time);
}

if (!frame_was_receiver && unmodified)
Expand Down
14 changes: 5 additions & 9 deletions src/core/keybindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -2955,18 +2955,14 @@ handle_activate_window_menu (MetaDisplay *display,
{
if (display->focus_window)
{
int x, y;
GdkRectangle rect;

meta_window_get_position (display->focus_window,
&x, &y);
&rect.x, &rect.y);
rect.width = display->focus_window->rect.width;
rect.height = 0;

if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
x += display->focus_window->rect.width;

meta_window_show_menu (display->focus_window,
x, y,
0,
event->xkey.time);
meta_window_show_menu (display->focus_window, &rect, event->xkey.time);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/core/window-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,9 @@ void meta_window_set_current_workspace_hint (MetaWindow *window);

unsigned long meta_window_get_net_wm_desktop (MetaWindow *window);

void meta_window_show_menu (MetaWindow *window,
int root_x,
int root_y,
int button,
guint32 timestamp);
void meta_window_show_menu (MetaWindow *window,
const GdkRectangle *rect,
guint32 timestamp);

gboolean meta_window_titlebar_is_onscreen (MetaWindow *window);
void meta_window_shove_titlebar_onscreen (MetaWindow *window);
Expand Down
28 changes: 11 additions & 17 deletions src/core/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -5561,23 +5561,19 @@ meta_window_client_message (MetaWindow *window,
else if (event->xclient.message_type ==
display->atom__GTK_SHOW_WINDOW_MENU)
{
gulong x_root, y_root;
GdkRectangle rect;
guint32 timestamp;
int button;

if (meta_prefs_get_raise_on_click ())
meta_window_raise (window);

timestamp = meta_display_get_current_time_roundtrip (display);
x_root = event->xclient.data.l[1];
y_root = event->xclient.data.l[2];
button = 3;
rect.x = event->xclient.data.l[1];
rect.y = event->xclient.data.l[2];
rect.width = 0;
rect.height = 0;

meta_window_show_menu (window,
x_root,
y_root,
button,
timestamp);
timestamp = meta_display_get_current_time_roundtrip (display);
meta_window_show_menu (window, &rect, timestamp);
}

return FALSE;
Expand Down Expand Up @@ -6995,11 +6991,9 @@ menu_callback (MetaWindowMenu *menu,
}

void
meta_window_show_menu (MetaWindow *window,
int root_x,
int root_y,
int button,
guint32 timestamp)
meta_window_show_menu (MetaWindow *window,
const GdkRectangle *rect,
guint32 timestamp)
{
MetaMenuOp ops;
MetaMenuOp insensitive;
Expand Down Expand Up @@ -7120,7 +7114,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, rect, timestamp);
}

void
Expand Down
10 changes: 4 additions & 6 deletions src/include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,10 @@ const char* meta_core_get_workspace_name_with_index (Display *xdisplay,
Window xroot,
int index);

void meta_core_show_window_menu (Display *xdisplay,
Window frame_xwindow,
int root_x,
int root_y,
int button,
guint32 timestamp);
void meta_core_show_window_menu (Display *xdisplay,
Window frame_xwindow,
const GdkRectangle *rect,
guint32 timestamp);

void meta_core_get_menu_accelerator (MetaMenuOp menu_op,
int workspace,
Expand Down
6 changes: 3 additions & 3 deletions src/include/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ MetaUI* meta_ui_new (Display *xdisplay,
Screen *screen);
void meta_ui_free (MetaUI *ui);

gint meta_ui_get_scale (MetaUI *ui);

void meta_ui_theme_get_frame_borders (MetaUI *ui,
MetaFrameType type,
MetaFrameFlags flags,
Expand Down Expand Up @@ -131,9 +133,7 @@ MetaWindowMenu* meta_ui_window_menu_new (MetaUI *ui,
MetaWindowMenuFunc func,
gpointer data);
void meta_ui_window_menu_popup (MetaWindowMenu *menu,
int root_x,
int root_y,
int button,
const GdkRectangle *rect,
guint32 timestamp);
void meta_ui_window_menu_free (MetaWindowMenu *menu);

Expand Down
27 changes: 11 additions & 16 deletions src/ui/frames.c
Original file line number Diff line number Diff line change
Expand Up @@ -1564,12 +1564,18 @@ meta_frame_titlebar_event (MetaUIFrame *frame,
break;

case META_ACTION_TITLEBAR_MENU:
meta_core_show_window_menu (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
{
GdkRectangle rect;

rect.x = event->x_root;
rect.y = event->y_root;
rect.width = 0;
rect.height = 0;
meta_core_show_window_menu (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
frame->xwindow,
event->x_root,
event->y_root,
event->button,
&rect,
event->time);
}
break;

case META_ACTION_TITLEBAR_LAST:
Expand Down Expand Up @@ -1738,25 +1744,14 @@ meta_frames_button_press_event (GtkWidget *widget,
{
MetaFrameGeometry fgeom;
GdkRectangle *rect;
int dx, dy;

meta_frames_calc_geometry (frames, frame, &fgeom);

rect = control_rect (META_FRAME_CONTROL_MENU, &fgeom);

/* get delta to convert to root coords */
dx = event->x_root - event->x;
dy = event->y_root - event->y;

/* Align to the right end of the menu rectangle if RTL */
if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
dx += rect->width;

meta_core_show_window_menu (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
frame->xwindow,
rect->x + dx,
rect->y + rect->height + dy,
event->button,
rect,
event->time);
}
}
Expand Down
45 changes: 15 additions & 30 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,18 +467,25 @@ 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)
void meta_window_menu_popup(MetaWindowMenu* menu, const GdkRectangle *rect, guint32 timestamp)
{
GdkPoint* pt = g_new(GdkPoint, 1);
gint scale;
GdkDisplay *display;
GdkEvent *event;
GdkWindow *window;
GdkDevice *device;

display = gdk_display_get_default ();

event = gdk_event_new (GDK_BUTTON_PRESS);
event->button.time = timestamp;

g_object_set_data_full(G_OBJECT(menu->menu), "destroy-point", pt, g_free);
window = gdk_screen_get_root_window (gdk_display_get_default_screen (display));
event->button.window = g_object_ref (window);

scale = gtk_widget_get_scale_factor (menu->menu);
pt->x = root_x / scale;
pt->y = root_y / scale;
device = gdk_seat_get_pointer (gdk_display_get_default_seat (display));
gdk_event_set_device (event, device);

gtk_menu_popup(GTK_MENU (menu->menu), NULL, NULL, popup_position_func, pt, button, timestamp);
gtk_menu_popup_at_rect(GTK_MENU (menu->menu), event->any.window, rect, GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_NORTH_WEST, event);

if (!gtk_widget_get_visible (menu->menu))
meta_warning("GtkMenu failed to grab the pointer\n");
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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_popup(MetaWindowMenu* menu, const GdkRectangle *rect, guint32 timestamp);
void meta_window_menu_free(MetaWindowMenu* menu);

#endif
Loading