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 name
.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen
));
65 Atom atom
= XInternAtom(display
, name
.ToAscii(), False
);
67 Window manager
= XGetSelectionOwner(display
, atom
);
69 s_supported
= (manager
!= None
);
72 return (bool)s_supported
;
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
79 extern "C" WXDLLIMPEXP_CORE
void gtk_pop_hide_callback( GtkWidget
*widget
, bool* is_waiting
);
81 extern WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
);
83 extern "C" WXDLLIMPEXP_CORE
84 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
86 gboolean
* WXUNUSED(whatever
),
89 #if wxUSE_MENUS_NATIVE
90 bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
92 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
94 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
96 // NOTE: if you change this code, you need to update
97 // the same code in window.cpp as well. This
98 // is ugly code duplication, I know,
100 SetInvokingWindow( menu
, this );
102 menu
->UpdateUI( m_invokingWindow
);
104 bool is_waiting
= true;
106 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
107 G_CALLBACK (gtk_pop_hide_callback
),
112 GtkMenuPositionFunc posfunc
;
113 if ( x
== -1 && y
== -1 )
115 // use GTK's default positioning algorithm
121 pos
= ClientToScreen(wxPoint(x
, y
));
123 posfunc
= wxPopupMenuPositionCallback
;
127 GTK_MENU(menu
->m_menu
),
128 (GtkWidget
*) NULL
, // parent menu shell
129 (GtkWidget
*) NULL
, // parent menu item
130 posfunc
, // function to position it
131 userdata
, // client data
132 0, // button used to activate it
133 gtk_get_current_event_time()
138 gtk_main_iteration();
141 g_signal_handler_disconnect (menu
->m_menu
, handler
);
145 #endif // wxUSE_MENUS_NATIVE
147 #endif // __WXGTK20__
148 #endif // GTK_CHECK_VERSION(2, 1, 0)
150 #endif // wxUSE_TASKBARICON