1 /////////////////////////////////////////////////////////////////////////
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"
15 #include "wx/gtk/taskbarpriv.h"
23 #include <gtk/gtkversion.h>
24 #if GTK_CHECK_VERSION(2, 1, 0)
28 #include "eggtrayicon.h"
30 wxTaskBarIconAreaBase::wxTaskBarIconAreaBase()
32 if (IsProtocolSupported())
34 m_widget
= GTK_WIDGET(egg_tray_icon_new("systray icon"));
35 gtk_window_set_resizable(GTK_WINDOW(m_widget
), false);
37 wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));
40 wxTopLevelWindow::Create(
41 NULL
, wxID_ANY
, _T("systray icon"),
42 wxDefaultPosition
, wxDefaultSize
,
43 wxDEFAULT_FRAME_STYLE
| wxFRAME_NO_TASKBAR
| wxSIMPLE_BORDER
|
45 wxEmptyString
/*eggtray doesn't like setting wmclass*/);
47 m_invokingWindow
= NULL
;
50 bool wxTaskBarIconAreaBase::IsProtocolSupported()
52 static int s_supported
= -1;
53 if (s_supported
== -1)
55 Display
*display
= GDK_DISPLAY();
56 Screen
*screen
= DefaultScreenOfDisplay(display
);
59 name
.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen
));
60 Atom atom
= XInternAtom(display
, name
.ToAscii(), False
);
62 Window manager
= XGetSelectionOwner(display
, atom
);
64 s_supported
= (manager
!= None
);
67 return (bool)s_supported
;
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
74 extern "C" WXDLLIMPEXP_CORE
void gtk_pop_hide_callback( GtkWidget
*widget
, bool* is_waiting
);
76 extern WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
);
78 extern "C" WXDLLIMPEXP_CORE
79 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
81 gboolean
* WXUNUSED(whatever
),
84 #if wxUSE_MENUS_NATIVE
85 bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
87 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
89 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
91 // NOTE: if you change this code, you need to update
92 // the same code in window.cpp as well. This
93 // is ugly code duplication, I know,
95 SetInvokingWindow( menu
, this );
97 menu
->UpdateUI( m_invokingWindow
);
99 bool is_waiting
= true;
101 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
102 G_CALLBACK (gtk_pop_hide_callback
),
107 GtkMenuPositionFunc posfunc
;
108 if ( x
== -1 && y
== -1 )
110 // use GTK's default positioning algorithm
116 pos
= ClientToScreen(wxPoint(x
, y
));
118 posfunc
= wxPopupMenuPositionCallback
;
122 GTK_MENU(menu
->m_menu
),
123 (GtkWidget
*) NULL
, // parent menu shell
124 (GtkWidget
*) NULL
, // parent menu item
125 posfunc
, // function to position it
126 userdata
, // client data
127 0, // button used to activate it
128 gtk_get_current_event_time()
133 gtk_main_iteration();
136 g_signal_handler_disconnect (menu
->m_menu
, handler
);
140 #endif // wxUSE_MENUS_NATIVE
142 #endif // __WXGTK20__
143 #endif // GTK_CHECK_VERSION(2, 1, 0)