[nautilus] toolbar: port from gtk_menu_popup()
- From: Ernestas Kulik <ernestask src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] toolbar: port from gtk_menu_popup()
- Date: Tue, 25 Oct 2016 14:58:22 +0000 (UTC)
commit 0782ed9f161ed236abe3ed27045cd50c581ae527
Author: Ernestas Kulik <ernestask src gnome org>
Date: Sat Oct 22 15:13:35 2016 +0300
toolbar: port from gtk_menu_popup()
gtk_menu_popup() was deprecated in GTK+ 3.22. By replacing the call with
one of the recommended ones, some code has also become redundant.
https://bugzilla.gnome.org/show_bug.cgi?id=773349
src/nautilus-toolbar.c | 108 +++++++++++-------------------------------------
1 files changed, 25 insertions(+), 83 deletions(-)
---
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index f6a26fd..215dc5a 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -184,78 +184,10 @@ fill_menu (NautilusWindow *window,
}
}
-/* adapted from gtk/gtkmenubutton.c */
-static void
-menu_position_func (GtkMenu *menu,
- gint *x,
- gint *y,
- gboolean *push_in,
- GtkWidget *widget)
-{
- GtkWidget *toplevel;
- GtkRequisition menu_req;
- GdkRectangle monitor;
- gint monitor_num;
- GdkScreen *screen;
- GdkWindow *window;
- GtkAllocation allocation;
-
- /* Set the dropdown menu hint on the toplevel, so the WM can omit the top side
- * of the shadows.
- */
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
- gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
-
- window = gtk_widget_get_window (widget);
- screen = gtk_widget_get_screen (GTK_WIDGET (menu));
- monitor_num = gdk_screen_get_monitor_at_window (screen, window);
- if (monitor_num < 0)
- {
- monitor_num = 0;
- }
-
- gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
- gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_req, NULL);
- gtk_widget_get_allocation (widget, &allocation);
- gdk_window_get_origin (window, x, y);
-
- *x += allocation.x;
- *y += allocation.y;
-
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- {
- *x -= MAX (menu_req.width - allocation.width, 0);
- }
- else
- {
- *x += MAX (allocation.width - menu_req.width, 0);
- }
-
- if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
- {
- *y += allocation.height;
- }
- else if ((*y - menu_req.height) >= monitor.y)
- {
- *y -= menu_req.height;
- }
- else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
- {
- *y += allocation.height;
- }
- else
- {
- *y -= menu_req.height;
- }
-
- *push_in = FALSE;
-}
-
static void
show_menu (NautilusToolbar *self,
GtkWidget *widget,
- guint button,
- guint32 event_time)
+ const GdkEvent *event)
{
NautilusWindow *window;
GtkWidget *menu;
@@ -289,9 +221,10 @@ show_menu (NautilusToolbar *self,
}
gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (window), NULL);
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
- (GtkMenuPositionFunc) menu_position_func, widget,
- button, event_time);
+ gtk_menu_popup_at_widget (GTK_MENU (menu), widget,
+ GDK_GRAVITY_SOUTH_WEST,
+ GDK_GRAVITY_NORTH_WEST,
+ event);
}
#define MENU_POPUP_TIMEOUT 1200
@@ -300,11 +233,13 @@ typedef struct
{
NautilusToolbar *self;
GtkWidget *widget;
+ GdkEvent *event;
} ScheduleMenuData;
static void
schedule_menu_data_free (ScheduleMenuData *data)
{
+ gdk_event_free (data->event);
g_slice_free (ScheduleMenuData, data);
}
@@ -313,10 +248,12 @@ popup_menu_timeout_cb (gpointer user_data)
{
ScheduleMenuData *data = user_data;
- show_menu (data->self, data->widget,
- 1, gtk_get_current_event_time ());
+ show_menu (data->self, data->widget, data->event);
- return FALSE;
+ /* Need to also reset the ID here. */
+ unschedule_menu_popup_timeout (data->self);
+
+ return G_SOURCE_REMOVE;
}
static void
@@ -331,7 +268,8 @@ unschedule_menu_popup_timeout (NautilusToolbar *self)
static void
schedule_menu_popup_timeout (NautilusToolbar *self,
- GtkWidget *widget)
+ GtkWidget *widget,
+ GdkEvent *event)
{
ScheduleMenuData *data;
@@ -341,28 +279,32 @@ schedule_menu_popup_timeout (NautilusToolbar *self,
data = g_slice_new0 (ScheduleMenuData);
data->self = self;
data->widget = widget;
+ data->event = gdk_event_copy (event);
self->popup_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, MENU_POPUP_TIMEOUT,
popup_menu_timeout_cb, data,
(GDestroyNotify) schedule_menu_data_free);
}
static gboolean
-navigation_button_press_cb (GtkButton *button,
- GdkEventButton *event,
- gpointer user_data)
+navigation_button_press_cb (GtkButton *button,
+ GdkEvent *event,
+ gpointer user_data)
{
NautilusToolbar *self = user_data;
+ GdkEventButton *button_event;
+
+ button_event = (GdkEventButton *)event;
- if (event->button == 3)
+ if (button_event->button == 3)
{
/* right click */
- show_menu (self, GTK_WIDGET (button), event->button, event->time);
+ show_menu (self, GTK_WIDGET (button), event);
return TRUE;
}
- if (event->button == 1)
+ if (button_event->button == 1)
{
- schedule_menu_popup_timeout (self, GTK_WIDGET (button));
+ schedule_menu_popup_timeout (self, GTK_WIDGET (button), event);
}
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]