Don't link against a particular version of GTK+
Instead, open ourselves through GModule, and check whether we have all the GTK+ and GDK functions required for us to work correctly. This means that the front-end application cannot rely on libnotify linking against GTK+, which would only be a problem for edge-cases. https://bugzilla.gnome.org/show_bug.cgi?id=622550
This commit is contained in:
parent
1fb351b531
commit
0eb56b2fcf
17
configure.ac
17
configure.ac
|
@ -86,11 +86,22 @@ AM_PROG_LIBTOOL
|
|||
REQ_DBUS_VERSION=0.76
|
||||
REQ_GTK_VERSION=2.18
|
||||
REQ_GLIB_VERSION=2.6
|
||||
pkg_modules="gtk+-2.0 >= $REQ_GTK_VERSION, glib-2.0 >= $REQ_GLIB_VERSION, dbus-1 >= $REQ_DBUS_VERSION, dbus-glib-1 >= $REQ_DBUS_VERSION"
|
||||
AC_SUBST(pkg_modules)
|
||||
|
||||
pkg_modules="gtk+-2.0 >= $REQ_GTK_VERSION, glib-2.0 >= $REQ_GLIB_VERSION, dbus-1 >= $REQ_DBUS_VERSION, dbus-glib-1 >= $REQ_DBUS_VERSION gmodule-2.0"
|
||||
PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
|
||||
AC_SUBST(PACKAGE_CFLAGS)
|
||||
AC_SUBST(PACKAGE_LIBS)
|
||||
AC_SUBST(PACKAGE_CFLAGS)
|
||||
|
||||
dnl The libraries against which we'll actually link
|
||||
link_modules="glib-2.0 >= $REQ_GLIB_VERSION, dbus-1 >= $REQ_DBUS_VERSION, dbus-glib-1 >= $REQ_DBUS_VERSION, gmodule-2.0"
|
||||
AC_SUBST(link_modules)
|
||||
PKG_CHECK_MODULES(LINKS, [$link_modules])
|
||||
AC_SUBST(LINKS_LIBS)
|
||||
|
||||
dnl The libraries to compile the gtk3 test against
|
||||
PKG_CHECK_MODULES(GTK3, gtk+-3.0)
|
||||
AC_SUBST(GTK3_CFLAGS)
|
||||
AC_SUBST(GTK3_LIBS)
|
||||
|
||||
GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0`
|
||||
AC_SUBST(GLIB_GENMARSHAL)
|
||||
|
|
|
@ -6,7 +6,7 @@ includedir=@includedir@
|
|||
Name: libnotify
|
||||
Description: Notifications Library
|
||||
Version: @VERSION@
|
||||
Requires: @pkg_modules@
|
||||
Requires: @link_modules@
|
||||
Libs: -L${libdir} -lnotify
|
||||
Cflags: -I${includedir}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ libnotify_la_SOURCES = \
|
|||
notify-marshal.c
|
||||
|
||||
libnotify_la_LIBADD = \
|
||||
$(PACKAGE_LIBS)
|
||||
$(LINKS_LIBS)
|
||||
|
||||
libnotify_la_LDFLAGS = \
|
||||
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <gmodule.h>
|
||||
|
||||
#include "notify.h"
|
||||
#include "internal.h"
|
||||
|
@ -39,6 +40,25 @@ static GList *_active_notifications = NULL;
|
|||
static int _spec_version_major = 0;
|
||||
static int _spec_version_minor = 0;
|
||||
|
||||
/* For the GTK+ and gdk-pixbuf functions */
|
||||
static GModule *module = NULL;
|
||||
static struct GtkDlMapping {
|
||||
const char *function_name;
|
||||
gpointer function_ptr;
|
||||
} gtk_dl_mapping [] = {
|
||||
#define MAP(a) { #a, (gpointer *)&a }
|
||||
MAP(gdk_screen_make_display_name),
|
||||
MAP(gdk_window_get_origin),
|
||||
MAP(gtk_status_icon_get_geometry),
|
||||
MAP(gtk_status_icon_get_x11_window_id),
|
||||
MAP(gtk_widget_get_allocation),
|
||||
MAP(gtk_widget_get_has_window),
|
||||
MAP(gtk_widget_get_screen),
|
||||
MAP(gtk_widget_get_window)
|
||||
#undef MAP
|
||||
};
|
||||
|
||||
|
||||
gboolean
|
||||
_notify_check_spec_version (int major,
|
||||
int minor)
|
||||
|
@ -80,16 +100,39 @@ _notify_update_spec_version (void)
|
|||
gboolean
|
||||
notify_init (const char *app_name)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (app_name != NULL, FALSE);
|
||||
g_return_val_if_fail (*app_name != '\0', FALSE);
|
||||
|
||||
if (_initted)
|
||||
return TRUE;
|
||||
|
||||
g_free (_app_name);
|
||||
_app_name = g_strdup (app_name);
|
||||
|
||||
g_type_init ();
|
||||
|
||||
/* Look up the symbols for the GTK+ and GDK
|
||||
* functions we use */
|
||||
module = g_module_open (NULL, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
|
||||
if (module == NULL) {
|
||||
g_warning ("Failed to get our own symbols: '%s'",
|
||||
g_module_error ());
|
||||
return FALSE;
|
||||
}
|
||||
for (i = 0; i < G_N_ELEMENTS (gtk_dl_mapping); i++) {
|
||||
if (!g_module_symbol (module,
|
||||
gtk_dl_mapping[i].function_name,
|
||||
>k_dl_mapping[i].function_ptr)) {
|
||||
g_warning ("Missing symbol '%s'",
|
||||
gtk_dl_mapping[i].function_name);
|
||||
g_module_close (module);
|
||||
module = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
_initted = TRUE;
|
||||
|
||||
return TRUE;
|
||||
|
|
|
@ -13,12 +13,12 @@ noinst_PROGRAMS = \
|
|||
test-urgency \
|
||||
test-xy \
|
||||
test-xy-actions \
|
||||
test-xy-stress
|
||||
test-xy-stress \
|
||||
test-gtk3
|
||||
|
||||
common_ldflags = \
|
||||
$(top_builddir)/libnotify/libnotify.la \
|
||||
$(PACKAGE_LIBS) \
|
||||
$(GDK_LIBS)
|
||||
$(PACKAGE_LIBS)
|
||||
|
||||
test_replace_SOURCES = test-replace.c
|
||||
test_replace_LDADD = $(common_ldflags)
|
||||
|
@ -65,10 +65,13 @@ test_xy_stress_LDADD = $(common_ldflags)
|
|||
test_rtl_SOURCES = test-rtl.c
|
||||
test_rtl_LDADD = $(common_ldflags)
|
||||
|
||||
test_gtk3_SOURCES = test-gtk3.c
|
||||
test_gtk3_LDADD = $(top_builddir)/libnotify/libnotify.la $(GTK3_LIBS)
|
||||
|
||||
EXTRA_DIST = applet-critical.png
|
||||
|
||||
INCLUDES = $(PACKAGE_CFLAGS) \
|
||||
$(GDK_CFLAGS) \
|
||||
$(GTK3_CFLAGS) \
|
||||
-I$(top_srcdir)
|
||||
|
||||
-include $(top_srcdir)/git.mk
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||
*
|
||||
* @file tests/test-gtk3.c Unit test: gtk3 symbols
|
||||
*
|
||||
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <libnotify/notify.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
NotifyNotification *n;
|
||||
|
||||
notify_init ("Basics");
|
||||
|
||||
/* Long summary */
|
||||
n = notify_notification_new ("Summary that is very long 8374983278r32j4 rhjjfh dw8f 43jhf 8ds7 ur2389f jdbjkt h8924yf jkdbjkt 892hjfiHER98HEJIF BDSJHF hjdhF JKLH 890YRHEJHFU 89HRJKSHdd dddd ddddd dddd ddddd dddd ddddd dddd dddd ddd ddd dddd Fdd d ddddd dddddddd ddddddddhjkewdkjsjfjk sdhkjf hdkj dadasdadsa adsd asd sd saasd fadskfkhsjf hsdkhfkshfjkhsd kjfhsjdkhfj ksdhfkjshkjfsd sadhfjkhaskd jfhsdajkfhkjs dhfkjsdhfkjs adhjkfhasdkj fhdsakjhfjk asdhkjkfhd akfjshjfsk afhjkasdhf jkhsdaj hf kjsdfahkfh sakjhfksdah kfdashkjf ksdahfj shdjdh",
|
||||
"Content",
|
||||
NULL,
|
||||
NULL);
|
||||
notify_notification_set_timeout (n, 3000); //3 seconds
|
||||
|
||||
if (!notify_notification_show (n, NULL)) {
|
||||
fprintf (stderr, "failed to send notification\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_object_unref (G_OBJECT (n));
|
||||
|
||||
/* Long message */
|
||||
n = notify_notification_new ("Summary",
|
||||
"Content that is very long 8374983278r32j4 rhjjfh dw8f 43jhf 8ds7 ur2389f jdbjkt h8924yf jkdbjkt 892hjfiHER98HEJIF BDSJHF hjdhF JKLH 890YRHEJHFU 89HRJKSHdd dddd ddddd dddd ddddd dddd ddddd dddd dddd ddd ddd dddd Fdd d ddddd dddddddd ddddddddhjkewdkjsjfjk sdhkjf hdkj dadasdadsa adsd asd sd saasd fadskfkhsjf hsdkhfkshfjkhsd kjfhsjdkhfj ksdhfkjshkjfsd sadhfjkhaskd jfhsdajkfhkjs dhfkjsdhfkjs adhjkfhasdkj fhdsakjhfjk asdhkjkfhd akfjshjfsk afhjkasdhf jkhsdaj hf kjsdfahkfh sakjhfksdah kfdashkjf ksdahfj shdjdh",
|
||||
NULL,
|
||||
NULL);
|
||||
notify_notification_set_timeout (n, 3000); //3 seconds
|
||||
|
||||
if (!notify_notification_show (n, NULL)) {
|
||||
fprintf (stderr, "failed to send notification\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_object_unref (G_OBJECT (n));
|
||||
|
||||
/* Summary only */
|
||||
n = notify_notification_new ("Summary only there is no message content",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
notify_notification_set_timeout (n, 3000); //3 seconds
|
||||
|
||||
if (!notify_notification_show (n, NULL)) {
|
||||
fprintf (stderr, "failed to send notification\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_object_unref (G_OBJECT (n));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue