[metacity] menu: avoid deprecated gtk_menu_popup
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] menu: avoid deprecated gtk_menu_popup
- Date: Sun, 16 Oct 2016 20:14:32 +0000 (UTC)
commit 37fa0d19f35a7fbff3638a6e6deb108500d41abf
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Oct 16 22:46:15 2016 +0300
menu: avoid deprecated gtk_menu_popup
src/core/core.c | 14 ++++-----
src/core/display.c | 68 +++++++++++++++++++++++++++++++++++++++++---
src/core/keybindings.c | 48 +++++++++++++++++++++++++------
src/core/window-private.h | 8 ++---
src/core/window.c | 10 ++----
src/include/core.h | 10 ++----
src/include/ui.h | 6 +--
src/ui/frames.c | 28 ++++++++----------
src/ui/menu.c | 53 ++++++-----------------------------
src/ui/menu.h | 6 +--
src/ui/ui.c | 8 ++---
11 files changed, 146 insertions(+), 113 deletions(-)
---
diff --git a/src/core/core.c b/src/core/core.c
index cae8999..d2bef21 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -533,20 +533,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,
+ const GdkEventButton *event)
{
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_focus (window, event->time);
- meta_window_show_menu (window, root_x, root_y, button, timestamp);
+ meta_window_show_menu (window, rect, (GdkEvent *) event);
}
void
diff --git a/src/core/display.c b/src/core/display.c
index 2519ede..4de0c15 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -46,6 +46,7 @@
#include "bell.h"
#include "effects.h"
#include "compositor.h"
+#include <gdk/gdkx.h>
#include <libmetacity/meta-frame-borders.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
@@ -1464,6 +1465,56 @@ meta_display_queue_autoraise_callback (MetaDisplay *display,
display->autoraise_window = window;
}
+static gint
+get_window_scaling_factor (void)
+{
+ GdkScreen *screen;
+ GValue value = G_VALUE_INIT;
+
+ screen = gdk_screen_get_default ();
+
+ g_value_init (&value, G_TYPE_INT);
+
+ if (gdk_screen_get_setting (screen, "gdk-window-scaling-factor", &value))
+ return g_value_get_int (&value);
+ else
+ return 1;
+}
+
+static GdkEvent *
+button_press_event_new (XEvent *xevent)
+{
+ GdkDisplay *display;
+ GdkSeat *seat;
+ gint scale;
+ GdkWindow *window;
+ GdkDevice *device;
+ GdkEvent *event;
+
+ display = gdk_display_get_default ();
+ seat = gdk_display_get_default_seat (display);
+ scale = get_window_scaling_factor ();
+
+ window = gdk_x11_window_lookup_for_display (display, xevent->xbutton.window);
+ device = gdk_seat_get_pointer (seat);
+
+ event = gdk_event_new (GDK_BUTTON_PRESS);
+
+ event->button.window = window ? g_object_ref (window) : NULL;
+ event->button.send_event = xevent->xbutton.send_event ? TRUE : FALSE;
+ event->button.time = xevent->xbutton.time;
+ event->button.x = xevent->xbutton.x / scale;
+ event->button.y = xevent->xbutton.y / scale;
+ event->button.state = (GdkModifierType) xevent->xbutton.state;
+ event->button.button = xevent->xbutton.button;
+ event->button.x_root = xevent->xbutton.x_root / scale;
+ event->button.y_root = xevent->xbutton.y_root / scale;
+
+ gdk_event_set_device (event, device);
+
+ return event;
+}
+
/**
* This is the most important function in the whole program. It is the heart,
* it is the nexus, it is the Grand Central Station of Metacity's world.
@@ -1786,13 +1837,20 @@ event_callback (XEvent *event,
}
else if (event->xbutton.button == meta_prefs_get_mouse_button_menu())
{
+ GdkRectangle rect;
+ GdkEvent *gdk_event;
+
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;
+ rect.y = event->xbutton.y;
+ rect.width = 0;
+ rect.height = 0;
+
+ gdk_event = button_press_event_new (event);
+ meta_window_show_menu (window, &rect, gdk_event);
+ gdk_event_free (gdk_event);
}
if (!frame_was_receiver && unmodified)
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index c673e12..4aba1ec 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -36,6 +36,7 @@
#include "effects.h"
#include "util.h"
+#include <gdk/gdkx.h>
#include <X11/keysym.h>
#include <string.h>
#include <stdio.h>
@@ -2784,6 +2785,34 @@ handle_panel (MetaDisplay *display,
meta_error_trap_pop (display);
}
+static GdkEvent *
+key_press_event_new (XEvent *xevent)
+{
+ GdkDisplay *display;
+ GdkSeat *seat;
+ GdkWindow *window;
+ GdkDevice *device;
+ GdkEvent *event;
+
+ display = gdk_display_get_default ();
+ seat = gdk_display_get_default_seat (display);
+
+ window = gdk_x11_window_lookup_for_display (display, xevent->xkey.window);
+ device = gdk_seat_get_keyboard (seat);
+
+ event = gdk_event_new (GDK_KEY_PRESS);
+
+ event->key.window = window ? g_object_ref (window) : NULL;
+ event->key.send_event = xevent->xkey.send_event ? TRUE : FALSE;
+ event->key.time = xevent->xkey.time;
+ event->key.state = (GdkModifierType) xevent->xkey.state;
+ event->key.hardware_keycode = xevent->xkey.keycode;
+
+ gdk_event_set_device (event, device);
+
+ return event;
+}
+
static void
handle_activate_window_menu (MetaDisplay *display,
MetaScreen *screen,
@@ -2793,18 +2822,17 @@ handle_activate_window_menu (MetaDisplay *display,
{
if (display->focus_window)
{
- int x, y;
-
- meta_window_get_position (display->focus_window,
- &x, &y);
+ GdkRectangle rect;
+ GdkEvent *gdk_event;
- if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
- x += display->focus_window->rect.width;
+ rect.x = display->focus_window->rect.x;
+ rect.y = display->focus_window->rect.y;
+ rect.width = display->focus_window->rect.width;
+ rect.height = 0;
- meta_window_show_menu (display->focus_window,
- x, y,
- 0,
- event->xkey.time);
+ gdk_event = key_press_event_new (event);
+ meta_window_show_menu (display->focus_window, &rect, gdk_event);
+ gdk_event_free (gdk_event);
}
}
diff --git a/src/core/window-private.h b/src/core/window-private.h
index 0d917b0..77867c9 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -572,11 +572,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,
+ const GdkEvent *event);
gboolean meta_window_titlebar_is_onscreen (MetaWindow *window);
void meta_window_shove_titlebar_onscreen (MetaWindow *window);
diff --git a/src/core/window.c b/src/core/window.c
index 499e362..fd24faa 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -6761,11 +6761,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,
+ const GdkEvent *event)
{
MetaMenuOp ops;
MetaMenuOp insensitive;
@@ -6886,7 +6884,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, event);
}
void
diff --git a/src/include/core.h b/src/include/core.h
index f88f6cf..8a38618 100644
--- a/src/include/core.h
+++ b/src/include/core.h
@@ -160,12 +160,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,
+ const GdkEventButton *event);
void meta_core_get_menu_accelerator (MetaMenuOp menu_op,
int workspace,
diff --git a/src/include/ui.h b/src/include/ui.h
index 03c6262..3607810 100644
--- a/src/include/ui.h
+++ b/src/include/ui.h
@@ -132,10 +132,8 @@ 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,
- guint32 timestamp);
+ const GdkRectangle *rect,
+ const GdkEvent *event);
void meta_ui_window_menu_free (MetaWindowMenu *menu);
diff --git a/src/ui/frames.c b/src/ui/frames.c
index 31fe269..7872028 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -1655,9 +1655,17 @@ meta_frame_titlebar_event (MetaFrames *frames,
break;
case G_DESKTOP_TITLEBAR_ACTION_MENU:
- meta_core_show_window_menu (frames->xdisplay, frame->xwindow,
- event->x_root, event->y_root,
- event->button, event->time);
+ {
+ GdkRectangle rect;
+
+ rect.x = event->x;
+ rect.y = event->y;
+ rect.width = 0;
+ rect.height = 0;
+
+ meta_core_show_window_menu (frames->xdisplay, frame->xwindow,
+ &rect, event);
+ }
break;
default:
@@ -1812,7 +1820,6 @@ meta_frames_button_press_event (GtkWidget *widget,
{
MetaFrameGeometry fgeom;
GdkRectangle rect;
- int dx, dy;
meta_frames_calc_geometry (frames, frame, &fgeom);
@@ -1822,21 +1829,10 @@ meta_frames_button_press_event (GtkWidget *widget,
return FALSE;
}
- /* 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;
-
frame->ignore_leave_notify = TRUE;
meta_core_show_window_menu (frames->xdisplay,
frame->xwindow,
- rect.x + dx,
- rect.y + rect.height + dy,
- event->button,
- event->time);
+ &rect, event);
}
}
else if (event->button == 1 &&
diff --git a/src/ui/menu.c b/src/ui/menu.c
index 52df466..e1bc016 100644
--- a/src/ui/menu.c
+++ b/src/ui/menu.c
@@ -101,31 +101,6 @@ static MenuItem menuitems[] = {
};
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, gdk_screen_width () - req.width));
- *y = CLAMP (*y, 0, MAX (0, gdk_screen_height () - req.height));
-}
-
-static void
menu_closed (GtkMenu *widget,
gpointer data)
{
@@ -477,28 +452,18 @@ meta_window_menu_new (MetaFrames *frames,
void
meta_window_menu_popup (MetaWindowMenu *menu,
- int root_x,
- int root_y,
- int button,
- guint32 timestamp)
+ const GdkRectangle *rect,
+ const GdkEvent *event)
{
- GdkPoint *pt;
-
- pt = g_new (GdkPoint, 1);
-
- g_object_set_data_full (G_OBJECT (menu->menu),
- "destroy-point",
- pt,
- g_free);
+ GdkEventAny *any;
- pt->x = root_x;
- pt->y = root_y;
+ any = (GdkEventAny *) event;
- gtk_menu_popup (GTK_MENU (menu->menu),
- NULL, NULL,
- popup_position_func, pt,
- button,
- timestamp);
+ gtk_menu_popup_at_rect (GTK_MENU (menu->menu),
+ 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");
diff --git a/src/ui/menu.h b/src/ui/menu.h
index aa8f622..183a0e2 100644
--- a/src/ui/menu.h
+++ b/src/ui/menu.h
@@ -45,10 +45,8 @@ MetaWindowMenu* meta_window_menu_new (MetaFrames *frames,
MetaWindowMenuFunc func,
gpointer data);
void meta_window_menu_popup (MetaWindowMenu *menu,
- int root_x,
- int root_y,
- int button,
- guint32 timestamp);
+ const GdkRectangle *rect,
+ const GdkEvent *event);
void meta_window_menu_free (MetaWindowMenu *menu);
diff --git a/src/ui/ui.c b/src/ui/ui.c
index 7381c27..42b5c03 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -538,12 +538,10 @@ 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)
+ const GdkRectangle *rect,
+ const GdkEvent *event)
{
- meta_window_menu_popup (menu, root_x, root_y, button, timestamp);
+ meta_window_menu_popup (menu, rect, event);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]