+#if wxUSE_TASKBARICON
+
+#include "wx/taskbar.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/toplevel.h"
+ #include "wx/menu.h"
+ #include "wx/icon.h"
+#endif
+
+#include <gtk/gtk.h>
+#ifdef GDK_WINDOWING_X11
+ #include <gdk/gdkx.h>
+#endif
+#ifndef __WXGTK3__
+ #include "eggtrayicon.h"
+#endif
+
+#if !GTK_CHECK_VERSION(2,10,0)
+ typedef struct _GtkStatusIcon GtkStatusIcon;
+#endif
+
+class wxTaskBarIcon::Private
+{
+public:
+ Private(wxTaskBarIcon* taskBarIcon);
+ ~Private();
+ void SetIcon();
+ void size_allocate(int width, int height);
+
+ // owning wxTaskBarIcon
+ wxTaskBarIcon* m_taskBarIcon;
+ // used when GTK+ >= 2.10
+ GtkStatusIcon* m_statusIcon;
+ // for PopupMenu
+ wxWindow* m_win;
+ wxBitmap m_bitmap;
+ wxString m_tipText;
+#ifndef __WXGTK3__
+ // used when GTK+ < 2.10
+ GtkWidget* m_eggTrayIcon;
+ // for tooltip when GTK+ < 2.10
+ GtkTooltips* m_tooltips;
+ // width and height of available space, only used when GTK+ < 2.10
+ int m_size;
+#endif
+};
+//-----------------------------------------------------------------------------
+
+extern "C" {
+#ifndef __WXGTK3__
+static void
+icon_size_allocate(GtkWidget*, GtkAllocation* alloc, wxTaskBarIcon::Private* priv)
+{
+ priv->size_allocate(alloc->width, alloc->height);
+}
+
+static void
+icon_destroy(GtkWidget*, wxTaskBarIcon::Private* priv)
+{
+ // Icon window destroyed, probably because tray program has died.
+ // Recreate icon so it will appear if tray program is restarted.
+ priv->m_eggTrayIcon = NULL;
+ priv->SetIcon();
+}
+#endif
+
+static void
+icon_activate(void*, wxTaskBarIcon* taskBarIcon)
+{
+ // activate occurs from single click with GTK+
+ wxTaskBarIconEvent event(wxEVT_TASKBAR_LEFT_DOWN, taskBarIcon);
+ if (!taskBarIcon->SafelyProcessEvent(event))
+ {
+ // if single click not handled, send double click for compatibility
+ event.SetEventType(wxEVT_TASKBAR_LEFT_DCLICK);
+ taskBarIcon->SafelyProcessEvent(event);
+ }
+}
+
+static gboolean
+icon_popup_menu(GtkWidget*, wxTaskBarIcon* taskBarIcon)
+{
+ wxTaskBarIconEvent event(wxEVT_TASKBAR_CLICK, taskBarIcon);
+ taskBarIcon->SafelyProcessEvent(event);
+ return true;
+}
+
+#ifndef __WXGTK3__
+static gboolean
+icon_button_press_event(GtkWidget*, GdkEventButton* event, wxTaskBarIcon* taskBarIcon)
+{
+ if (event->type == GDK_BUTTON_PRESS)
+ {
+ if (event->button == 1)
+ icon_activate(NULL, taskBarIcon);
+ else if (event->button == 3)
+ icon_popup_menu(NULL, taskBarIcon);
+ }
+ return false;
+}
+#endif
+
+#if GTK_CHECK_VERSION(2,10,0)
+static void
+status_icon_popup_menu(GtkStatusIcon*, guint, guint, wxTaskBarIcon* taskBarIcon)
+{
+ icon_popup_menu(NULL, taskBarIcon);
+}
+#endif
+} // extern "C"
+//-----------------------------------------------------------------------------
+
+bool wxTaskBarIconBase::IsAvailable()
+{
+#ifdef GDK_WINDOWING_X11
+ char name[32];
+ g_snprintf(name, sizeof(name), "_NET_SYSTEM_TRAY_S%d",
+ gdk_x11_get_default_screen());
+ Atom atom = gdk_x11_get_xatom_by_name(name);
+
+ Window manager = XGetSelectionOwner(gdk_x11_get_default_xdisplay(), atom);
+
+ return manager != None;
+#else
+ return true;
+#endif
+}
+//-----------------------------------------------------------------------------
+
+wxTaskBarIcon::Private::Private(wxTaskBarIcon* taskBarIcon)
+{
+ m_taskBarIcon = taskBarIcon;
+ m_statusIcon = NULL;
+ m_win = NULL;
+#ifndef __WXGTK3__
+ m_eggTrayIcon = NULL;
+ m_tooltips = NULL;
+ m_size = 0;
+#endif
+}
+
+wxTaskBarIcon::Private::~Private()
+{
+ if (m_statusIcon)
+ g_object_unref(m_statusIcon);
+#ifndef __WXGTK3__
+ else if (m_eggTrayIcon)
+ {
+ g_signal_handlers_disconnect_by_func(m_eggTrayIcon, (void*)icon_destroy, this);
+ gtk_widget_destroy(m_eggTrayIcon);
+ }
+#endif
+ if (m_win)
+ {
+ m_win->PopEventHandler();
+ m_win->Destroy();
+ }
+#ifndef __WXGTK3__
+ if (m_tooltips)
+ {
+ gtk_object_destroy(GTK_OBJECT(m_tooltips));
+ g_object_unref(m_tooltips);
+ }
+#endif
+}