summaryrefslogtreecommitdiff
path: root/applets/notification_area/status-notifier/sn-item.c
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2017-01-23 10:18:44 +0100
committerlukefromdc <[email protected]>2017-01-23 13:49:34 -0500
commit352600f12126c2f974a2510dfb744ba4f562da3f (patch)
tree5c9cba8df8c5e5802887971896bbfad4df9d20e4 /applets/notification_area/status-notifier/sn-item.c
parent290a5d6fcdeed499cd6220c62d3e55b51c558a43 (diff)
downloadmate-panel-352600f12126c2f974a2510dfb744ba4f562da3f.tar.bz2
mate-panel-352600f12126c2f974a2510dfb744ba4f562da3f.tar.xz
status-notifier: Move GTK compatibility code inline
Diffstat (limited to 'applets/notification_area/status-notifier/sn-item.c')
-rw-r--r--applets/notification_area/status-notifier/sn-item.c67
1 files changed, 65 insertions, 2 deletions
diff --git a/applets/notification_area/status-notifier/sn-item.c b/applets/notification_area/status-notifier/sn-item.c
index 3a849f91..654bb291 100644
--- a/applets/notification_area/status-notifier/sn-item.c
+++ b/applets/notification_area/status-notifier/sn-item.c
@@ -17,8 +17,6 @@
#include "config.h"
-#include "sn-compat-gtk.h"
-
#include "sn-dbus-menu.h"
#include "sn-item.h"
@@ -184,6 +182,49 @@ sn_item_get_action_coordinates (SnItem *item,
*x += width;
}
+#if ! GTK_CHECK_VERSION (3, 22, 0)
+static void
+sn_item_popup_menu_position_func (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer widget)
+{
+ GtkAllocation widget_alloc;
+ GtkRequisition menu_req;
+ GdkWindow *window;
+ GdkScreen *screen;
+ gint monitor_num;
+ GdkRectangle monitor;
+
+ gtk_widget_get_allocation (widget, &widget_alloc);
+ gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_req, NULL);
+
+ window = gtk_widget_get_window (widget);
+ gdk_window_get_origin (window, x, y);
+
+ *x += widget_alloc.x;
+ *y += widget_alloc.y;
+
+ screen = gtk_widget_get_screen (widget);
+ monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
+ gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+ /* put the menu on the left if we can't put it on the right */
+ if (*x + menu_req.width > monitor.x + monitor.width)
+ *x -= menu_req.width - widget_alloc.width;
+ /* and push it back in if all else failed */
+ if (*x < monitor.x)
+ *x = monitor.x;
+
+ /* put the menu above if we can't put it below */
+ if (*y + widget_alloc.height + menu_req.height > monitor.y + monitor.height)
+ *y -= menu_req.height;
+ else
+ *y += widget_alloc.height;
+}
+#endif
+
static gboolean
sn_item_button_press_event (GtkWidget *widget,
GdkEventButton *event)
@@ -214,10 +255,16 @@ sn_item_button_press_event (GtkWidget *widget,
{
if (priv->menu != NULL)
{
+#if GTK_CHECK_VERSION (3, 22, 0)
gtk_menu_popup_at_widget (priv->menu, widget,
GDK_GRAVITY_SOUTH_WEST,
GDK_GRAVITY_NORTH_WEST,
(GdkEvent *) event);
+#else
+ gtk_menu_popup (priv->menu, NULL, NULL,
+ sn_item_popup_menu_position_func, widget,
+ event->button, event->time);
+#endif
}
else
{
@@ -248,10 +295,26 @@ sn_item_popup_menu (GtkWidget *widget)
if (priv->menu != NULL)
{
+#if GTK_CHECK_VERSION (3, 22, 0)
gtk_menu_popup_at_widget (priv->menu, widget,
GDK_GRAVITY_SOUTH_WEST,
GDK_GRAVITY_NORTH_WEST,
NULL);
+#else
+ guint button = 0;
+ guint32 active_time = GDK_CURRENT_TIME;
+ GdkEvent *event = gtk_get_current_event ();
+
+ if (event)
+ {
+ gdk_event_get_button (event, &button);
+ active_time = gdk_event_get_time (event);
+ }
+
+ gtk_menu_popup (priv->menu, NULL, NULL,
+ sn_item_popup_menu_position_func, widget,
+ button, active_time);
+#endif
}
else
{