]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/taskbar.cpp
corrected version in the libraries names: it's only 2 digits even in development...
[wxWidgets.git] / src / gtk / taskbar.cpp
1 /////////////////////////////////////////////////////////////////////////
2 // File: src/gtk/taskbar.cpp
3 // Purpose: wxTaskBarIcon (src/unix/taskbarx11.cpp) helper for GTK2
4 // Author: Vaclav Slavik
5 // Modified by:
6 // Created: 2004/05/29
7 // RCS-ID: $Id$
8 // Copyright: (c) Vaclav Slavik, 2004
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/gtk/taskbarpriv.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/log.h"
19 #include "wx/frame.h"
20 #include "wx/menu.h"
21 #endif
22
23 #include <gdk/gdkx.h>
24
25 #ifdef __WXGTK20__
26 #include <gtk/gtkversion.h>
27 #if GTK_CHECK_VERSION(2, 1, 0)
28
29 #include "gtk/gtk.h"
30
31 #include "eggtrayicon.h"
32
33 wxTaskBarIconAreaBase::wxTaskBarIconAreaBase()
34 {
35 if (IsProtocolSupported())
36 {
37 m_widget = GTK_WIDGET(egg_tray_icon_new("systray icon"));
38 gtk_window_set_resizable(GTK_WINDOW(m_widget), false);
39
40 wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));
41 }
42
43 wxTopLevelWindow::Create(
44 NULL, wxID_ANY, _T("systray icon"),
45 wxDefaultPosition, wxDefaultSize,
46 wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR | wxSIMPLE_BORDER |
47 wxFRAME_SHAPED,
48 wxEmptyString /*eggtray doesn't like setting wmclass*/);
49
50 m_invokingWindow = NULL;
51 }
52
53 bool wxTaskBarIconAreaBase::IsProtocolSupported()
54 {
55 static int s_supported = -1;
56 if (s_supported == -1)
57 {
58 Display *display = GDK_DISPLAY();
59 Screen *screen = DefaultScreenOfDisplay(display);
60
61 wxString name;
62 name.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen));
63 Atom atom = XInternAtom(display, name.ToAscii(), False);
64
65 Window manager = XGetSelectionOwner(display, atom);
66
67 s_supported = (manager != None);
68 }
69
70 return (bool)s_supported;
71 }
72
73 //-----------------------------------------------------------------------------
74 // Pop-up menu stuff
75 //-----------------------------------------------------------------------------
76
77 extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *widget, bool* is_waiting );
78
79 extern WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win );
80
81 extern "C" WXDLLIMPEXP_CORE
82 void wxPopupMenuPositionCallback( GtkMenu *menu,
83 gint *x, gint *y,
84 gboolean * WXUNUSED(whatever),
85 gpointer user_data );
86
87 #if wxUSE_MENUS_NATIVE
88 bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu *menu, int x, int y )
89 {
90 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
91
92 wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
93
94 // NOTE: if you change this code, you need to update
95 // the same code in window.cpp as well. This
96 // is ugly code duplication, I know,
97
98 SetInvokingWindow( menu, this );
99
100 menu->UpdateUI( m_invokingWindow );
101
102 bool is_waiting = true;
103
104 gulong handler = g_signal_connect (menu->m_menu, "hide",
105 G_CALLBACK (gtk_pop_hide_callback),
106 &is_waiting);
107
108 wxPoint pos;
109 gpointer userdata;
110 GtkMenuPositionFunc posfunc;
111 if ( x == -1 && y == -1 )
112 {
113 // use GTK's default positioning algorithm
114 userdata = NULL;
115 posfunc = NULL;
116 }
117 else
118 {
119 pos = ClientToScreen(wxPoint(x, y));
120 userdata = &pos;
121 posfunc = wxPopupMenuPositionCallback;
122 }
123
124 gtk_menu_popup(
125 GTK_MENU(menu->m_menu),
126 (GtkWidget *) NULL, // parent menu shell
127 (GtkWidget *) NULL, // parent menu item
128 posfunc, // function to position it
129 userdata, // client data
130 0, // button used to activate it
131 gtk_get_current_event_time()
132 );
133
134 while (is_waiting)
135 {
136 gtk_main_iteration();
137 }
138
139 g_signal_handler_disconnect (menu->m_menu, handler);
140
141 return true;
142 }
143 #endif // wxUSE_MENUS_NATIVE
144
145 #endif // __WXGTK20__
146 #endif // GTK_CHECK_VERSION(2, 1, 0)