=== modified file 'src/appmenuplatformmenubar.cpp'
--- src/appmenuplatformmenubar.cpp	2014-12-13 15:38:51 +0000
+++ src/appmenuplatformmenubar.cpp	2016-11-24 02:19:42 +0000
@@ -35,6 +35,7 @@
 #include <QDebug>
 #include <QList>
 #include <QVariant>
+#include <QX11Info>
 
 #undef signals // Needed to make sure we can include gtk.h
 #include <gtk/gtk.h>
@@ -229,6 +230,10 @@
 /* Helper function, as copy-pasted from Qt 5.2.1 gtk2 platformthemeplugin */
 static QString gtkSetting(const gchar *propertyName)
 {
+    if (!QX11Info::isPlatformX11()) {
+        return QString();
+    }
+
     GtkSettings *settings = gtk_settings_get_default();
     gchararray value;
     g_object_get(settings, propertyName, &value, NULL);
@@ -261,13 +266,19 @@
 GnomeAppMenuPlatformTheme::GnomeAppMenuPlatformTheme()
     : QGnomeTheme()
 {
-    int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL);
-    gtk_init(0, 0);
-    XSetErrorHandler(oldErrorHandler);
+    if (QX11Info::isPlatformX11()) {
+        int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL);
+        gtk_init(0, 0);
+        XSetErrorHandler(oldErrorHandler);
+    }
 }
 
 QVariant GnomeAppMenuPlatformTheme::themeHint(QPlatformTheme::ThemeHint hint) const
 {
+    if (!QX11Info::isPlatformX11()) {
+        return QVariant(QVariant::String);
+    }
+
     switch (hint) {
         case QPlatformTheme::SystemIconThemeName:
             return QVariant(gtkSetting("gtk-icon-theme-name"));

=== modified file 'src/appmenuplatformsystemtrayicon.cpp'
--- src/appmenuplatformsystemtrayicon.cpp	2016-11-24 02:19:42 +0000
+++ src/appmenuplatformsystemtrayicon.cpp	2016-11-24 02:19:42 +0000
@@ -181,7 +181,7 @@
 
 QString AppMenuPlatformSystemTrayIcon::iconThemePath() const
 {
-    return iconCache.themePath();
+    return iconCache.themePath(m_icon);
 }
 
 QString AppMenuPlatformSystemTrayIcon::iconName() const

=== modified file 'src/iconcache.cpp'
--- src/iconcache.cpp	2014-12-13 15:38:51 +0000
+++ src/iconcache.cpp	2016-11-24 02:19:42 +0000
@@ -29,8 +29,7 @@
 
 IconCache::IconCache(QObject *parent):
     QObject(parent),
-    m_temporaryDir(Q_NULLPTR),
-    m_initialized(false)
+    m_temporaryDir(Q_NULLPTR)
 {
 }
 
@@ -41,13 +40,41 @@
     }
 }
 
-QString IconCache::themePath()
+QString IconCache::themePath(const QIcon &icon)
 {
-    if (!m_initialized) {
-        QString path = QDir::tempPath() + QStringLiteral("/iconcache-XXXXXX");
+    if (!m_temporaryDir) {
+        QString dir;
+
+        if (!getenv("SNAP")) {
+            dir = QDir::tempPath();
+        } else {
+            // Try to get the .cache from $XDG_CACHE_HOME, if it's not set,
+            // it has to be in ~/.cache as per XDG standard
+            dir = QString::fromUtf8(getenv("XDG_CACHE_HOME"));
+            if (dir.isEmpty()) {
+                dir = QDir::cleanPath(QDir::homePath() + QStringLiteral("/.cache"));
+            }
+
+            QDir d(dir);
+            if (!d.exists()) {
+                d.mkpath(".");
+            }
+        }
+
+        QString path = dir + QStringLiteral("/qt-tray-iconcache-XXXXXX");
         m_temporaryDir = new QTemporaryDir(path);
-        m_initialized = true;
-    }
+    }
+
+    if (!icon.isNull() && !icon.name().isEmpty() && QIcon::hasThemeIcon(icon.name())) {
+        QString dataHome = QString::fromUtf8(getenv("XDG_DATA_HOME"));
+
+        if (dataHome.isEmpty()) {
+            dataHome = QDir::homePath() + "/.local/share";
+        }
+
+        return QDir::cleanPath(dataHome + "/icons");
+    }
+
     return m_temporaryDir->path();
 }
 

=== modified file 'src/iconcache.h'
--- src/iconcache.h	2014-12-13 15:38:51 +0000
+++ src/iconcache.h	2016-11-24 02:19:42 +0000
@@ -39,13 +39,12 @@
 
     static const int MaxIconCount;
 
-    QString themePath();
+    QString themePath(const QIcon &icon = QIcon());
     QString nameForIcon(const QIcon &icon);
 
 private:
     QTemporaryDir *m_temporaryDir;
     mutable QList<qint64> m_cacheKeys;
-    bool m_initialized;
 
     void cacheIcon(qint64 key, const QIcon &);
     void trimCache();

