1 /////////////////////////////////////////////////////////////////////////
2 // File: src/gtk/taskbar.cpp
3 // Purpose: wxTaskBarIcon (src/unix/taskbarx11.cpp) helper for GTK2
4 // Author: Vaclav Slavik
8 // Copyright: (c) Vaclav Slavik, 2004
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
17 #include "wx/gtk/taskbarpriv.h"
28 #include <gtk/gtkversion.h>
29 #if GTK_CHECK_VERSION(2, 1, 0)
33 #include "eggtrayicon.h"
35 wxTaskBarIconAreaBase::wxTaskBarIconAreaBase()
37 if (IsProtocolSupported())
39 m_widget
= GTK_WIDGET(egg_tray_icon_new("systray icon"));
40 gtk_window_set_resizable(GTK_WINDOW(m_widget
), false);
42 wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));
45 wxTopLevelWindow::Create(
46 NULL
, wxID_ANY
, _T("systray icon"),
47 wxDefaultPosition
, wxDefaultSize
,
48 wxDEFAULT_FRAME_STYLE
| wxFRAME_NO_TASKBAR
| wxSIMPLE_BORDER
|
50 wxEmptyString
/*eggtray doesn't like setting wmclass*/);
52 m_invokingWindow
= NULL
;
55 bool wxTaskBarIconAreaBase::IsProtocolSupported()
57 static int s_supported
= -1;
58 if (s_supported
== -1)
60 Display
*display
= GDK_DISPLAY();
61 Screen
*screen
= DefaultScreenOfDisplay(display
);
64 g_snprintf(name
, sizeof(name
), "_NET_SYSTEM_TRAY_S%d",
65 XScreenNumberOfScreen(screen
));
66 Atom atom
= XInternAtom(display
, name
, False
);
68 Window manager
= XGetSelectionOwner(display
, atom
);
70 s_supported
= (manager
!= None
);
73 return (bool)s_supported
;
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
80 extern "C" WXDLLIMPEXP_CORE
void gtk_pop_hide_callback( GtkWidget
*widget
, bool* is_waiting
);
82 extern WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
);
84 extern "C" WXDLLIMPEXP_CORE
85 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
87 gboolean
* WXUNUSED(whatever
),
90 #if wxUSE_MENUS_NATIVE
91 bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
93 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
95 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
97 // NOTE: if you change this code, you need to update
98 // the same code in window.cpp as well. This
99 // is ugly code duplication, I know,
101 SetInvokingWindow( menu
, this );
103 menu
->UpdateUI( m_invokingWindow
);
105 bool is_waiting
= true;
107 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
108 G_CALLBACK (gtk_pop_hide_callback
),
113 GtkMenuPositionFunc posfunc
;
114 if ( x
== -1 && y
== -1 )
116 // use GTK's default positioning algorithm
122 pos
= ClientToScreen(wxPoint(x
, y
));
124 posfunc
= wxPopupMenuPositionCallback
;
128 GTK_MENU(menu
->m_menu
),
129 (GtkWidget
*) NULL
, // parent menu shell
130 (GtkWidget
*) NULL
, // parent menu item
131 posfunc
, // function to position it
132 userdata
, // client data
133 0, // button used to activate it
134 gtk_get_current_event_time()
139 gtk_main_iteration();
142 g_signal_handler_disconnect (menu
->m_menu
, handler
);
146 #endif // wxUSE_MENUS_NATIVE
148 #endif // __WXGTK20__
149 #endif // GTK_CHECK_VERSION(2, 1, 0)
151 #endif // wxUSE_TASKBARICON