summaryrefslogtreecommitdiff
path: root/applets/notification_area
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
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')
-rw-r--r--applets/notification_area/status-notifier/Makefile.am3
-rw-r--r--applets/notification_area/status-notifier/sn-compat-gtk-3.16.h40
-rw-r--r--applets/notification_area/status-notifier/sn-compat-gtk-3.22.h102
-rw-r--r--applets/notification_area/status-notifier/sn-compat-gtk.h24
-rw-r--r--applets/notification_area/status-notifier/sn-image-menu-item.c6
-rw-r--r--applets/notification_area/status-notifier/sn-item.c67
6 files changed, 69 insertions, 173 deletions
diff --git a/applets/notification_area/status-notifier/Makefile.am b/applets/notification_area/status-notifier/Makefile.am
index 0b273824..38585c5d 100644
--- a/applets/notification_area/status-notifier/Makefile.am
+++ b/applets/notification_area/status-notifier/Makefile.am
@@ -14,9 +14,6 @@ AM_CPPFLAGS = \
AM_CFLAGS = $(WARN_CFLAGS)
libstatus_notifier_la_SOURCES = \
- sn-compat-gtk.h \
- sn-compat-gtk-3.16.h \
- sn-compat-gtk-3.22.h \
sn-dbus-menu.c \
sn-dbus-menu.h \
sn-dbus-menu-item.c \
diff --git a/applets/notification_area/status-notifier/sn-compat-gtk-3.16.h b/applets/notification_area/status-notifier/sn-compat-gtk-3.16.h
deleted file mode 100644
index 6cf7c7b8..00000000
--- a/applets/notification_area/status-notifier/sn-compat-gtk-3.16.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2016 Colomban Wendling <[email protected]>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef SN_COMPAT_GTK_3_16_H
-#define SN_COMPAT_GTK_3_16_H
-
-#include <gtk/gtk.h>
-
-#if ! GTK_CHECK_VERSION (3, 16, 0)
-
-G_BEGIN_DECLS
-
-
-static inline void
-sn_compat_gtk_label_set_xalign (GtkLabel *label,
- gfloat xalign)
-{
- g_object_set (label, "xalign", xalign, NULL);
-}
-#define gtk_label_set_xalign sn_compat_gtk_label_set_xalign
-
-
-G_END_DECLS
-
-#endif /* GTK version */
-#endif
diff --git a/applets/notification_area/status-notifier/sn-compat-gtk-3.22.h b/applets/notification_area/status-notifier/sn-compat-gtk-3.22.h
deleted file mode 100644
index 1f05519b..00000000
--- a/applets/notification_area/status-notifier/sn-compat-gtk-3.22.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2016 Colomban Wendling <[email protected]>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef SN_COMPAT_GTK_3_22_H
-#define SN_COMPAT_GTK_3_22_H
-
-#include <gtk/gtk.h>
-
-#include "sn-compat-gtk.h"
-
-#if ! GTK_CHECK_VERSION (3, 22, 0)
-
-G_BEGIN_DECLS
-
-
-static inline void
-sn_compat_gtk_menu_popup_at_widget_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;
-}
-
-/* WARNING: Only supports anchoring the menu northwest to the widget
- * southwest. */
-static inline void
-sn_compat_gtk_menu_popup_at_widget (GtkMenu *menu,
- GtkWidget *widget,
- GdkGravity widget_anchor,
- GdkGravity menu_anchor,
- const GdkEvent *trigger_event)
-{
- guint button = 0;
-
- g_warn_if_fail (widget_anchor == GDK_GRAVITY_SOUTH_WEST);
- g_warn_if_fail (menu_anchor == GDK_GRAVITY_NORTH_WEST);
-
- if (! trigger_event)
- trigger_event = gtk_get_current_event ();
-
- g_return_if_fail (trigger_event != NULL);
-
- gdk_event_get_button (trigger_event, &button);
-
- gtk_menu_popup (menu, NULL, NULL,
- sn_compat_gtk_menu_popup_at_widget_position_func,
- widget, button, gdk_event_get_time (trigger_event));
-}
-#define gtk_menu_popup_at_widget sn_compat_gtk_menu_popup_at_widget
-
-
-G_END_DECLS
-
-#endif /* GTK version */
-#endif
diff --git a/applets/notification_area/status-notifier/sn-compat-gtk.h b/applets/notification_area/status-notifier/sn-compat-gtk.h
deleted file mode 100644
index b3640f12..00000000
--- a/applets/notification_area/status-notifier/sn-compat-gtk.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2016 Colomban Wendling <[email protected]>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef SN_COMPAT_GTK_H
-#define SN_COMPAT_GTK_H
-
-#include "sn-compat-gtk-3.16.h"
-#include "sn-compat-gtk-3.22.h"
-
-#endif
diff --git a/applets/notification_area/status-notifier/sn-image-menu-item.c b/applets/notification_area/status-notifier/sn-image-menu-item.c
index 117ba9c3..412ba11e 100644
--- a/applets/notification_area/status-notifier/sn-image-menu-item.c
+++ b/applets/notification_area/status-notifier/sn-image-menu-item.c
@@ -17,8 +17,6 @@
#include "config.h"
-#include "sn-compat-gtk.h"
-
#include "sn-image-menu-item.h"
#define SPACING 6
@@ -175,7 +173,11 @@ sn_image_menu_item_init (SnImageMenuItem *item)
item->accel_label = gtk_accel_label_new ("");
gtk_box_pack_end (GTK_BOX (item->box), item->accel_label, TRUE, TRUE, 0);
+#if GTK_CHECK_VERSION (3, 16, 0)
gtk_label_set_xalign (GTK_LABEL (item->accel_label), 0.0);
+#else
+ gtk_misc_set_alignment (GTK_MISC (item->accel_label), 0.0, 0.5);
+#endif
gtk_widget_show (item->accel_label);
accel_label = GTK_ACCEL_LABEL (item->accel_label);
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
{