[vlc-devel] [PATCH] notify: don't depend on any GTK version

RĂ©mi Denis-Courmont remi at remlab.net
Tue May 5 17:50:59 CEST 2020


If there's one in the process use it. If there's none fallback to
default VLC icon with the old code.

This not only avoids VLC builds depending on GTK, but this should
prevent crashes if GTK 2 is present in the process (e.g. through Qt plugin).
---
 configure.ac            |  2 +-
 modules/notify/notify.c | 33 ++++++++++++++++++++-------------
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4fd1240d09..76788dac53 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4413,7 +4413,7 @@ AS_IF([test "${enable_osx_notifications}" != "no"], [
 dnl
 dnl Libnotify notification plugin
 dnl
-PKG_ENABLE_MODULES_VLC([NOTIFY], [], [libnotify gtk+-3.0], [libnotify notification], [auto])
+PKG_ENABLE_MODULES_VLC([NOTIFY], [], [libnotify], [libnotify notification], [auto])
 
 PKG_ENABLE_MODULES_VLC([MEDIALIBRARY], [medialibrary], [medialibrary >= 0.7.1], (medialibrary support), [auto])
 
diff --git a/modules/notify/notify.c b/modules/notify/notify.c
index d2d2c110ca..138ec8225e 100644
--- a/modules/notify/notify.c
+++ b/modules/notify/notify.c
@@ -35,10 +35,16 @@
 #include <vlc_playlist.h>
 #include <vlc_url.h>
 
-#include <gtk/gtk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <libnotify/notify.h>
 
+typedef struct GtkIconTheme GtkIconTheme;
+enum GtkIconLookupFlags { dummy = 0x7fffffff };
+
+VLC_WEAK GtkIconTheme *gtk_icon_theme_get_default(void);
+VLC_WEAK GdkPixbuf *gtk_icon_theme_load_icon(GtkIconTheme *,
+    const char *icon_name, int size, enum GtkIconLookupFlags, GError **);
+
 #ifndef NOTIFY_CHECK_VERSION
 # define NOTIFY_CHECK_VERSION(x,y,z) 0
 #endif
@@ -241,23 +247,24 @@ static void on_current_media_changed(vlc_player_t *player,
                                                  72, 72, TRUE, &p_error );
         free( psz_arturl );
     }
-    else /* else we show state-of-the art logo */
+    else
+    /* else we show state-of-the art logo */
+    if( gtk_icon_theme_get_default != NULL
+     && gtk_icon_theme_load_icon != NULL )
     {
         /* First try to get an icon from the current theme. */
         GtkIconTheme* p_theme = gtk_icon_theme_get_default();
         pix = gtk_icon_theme_load_icon( p_theme, "vlc", 72, 0, NULL);
-
-        if( !pix )
-        {
-        /* Load icon from share/ */
-            GError *p_error = NULL;
-            char *psz_pixbuf = config_GetSysPath(VLC_SYSDATA_DIR,
+    }
+    else
+    {   /* Load icon from share/ */
+        GError *p_error = NULL;
+        char *psz_pixbuf = config_GetSysPath(VLC_SYSDATA_DIR,
                                      "icons/hicolor/48x48/"PACKAGE_NAME".png");
-            if (psz_pixbuf != NULL)
-            {
-                pix = gdk_pixbuf_new_from_file( psz_pixbuf, &p_error );
-                free( psz_pixbuf );
-            }
+        if (psz_pixbuf != NULL)
+        {
+            pix = gdk_pixbuf_new_from_file( psz_pixbuf, &p_error );
+            free( psz_pixbuf );
         }
     }
 
-- 
2.26.2



More information about the vlc-devel mailing list