]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/taskbar.cpp
Fixed wxAtomicInc/Dec() to not use asm/atomic.h header on Linux - it's kernel interna...
[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 #if wxUSE_TASKBARICON
16
17 #include "wx/gtk/taskbarpriv.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/log.h"
21 #include "wx/frame.h"
22 #include "wx/menu.h"
23 #endif
24
25 #include <gdk/gdkx.h>
26
27 #ifdef __WXGTK20__
28 #include <gtk/gtkversion.h>
29 #if GTK_CHECK_VERSION(2, 1, 0)
30
31 #include "gtk/gtk.h"
32
33 #include "eggtrayicon.h"
34
35 wxTaskBarIconAreaBase::wxTaskBarIconAreaBase()
36 {
37 if (IsProtocolSupported())
38 {
39 m_widget = GTK_WIDGET(egg_tray_icon_new("systray icon"));
40 gtk_window_set_resizable(GTK_WINDOW(m_widget), false);
41
42 wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));
43 }
44
45 wxTopLevelWindow::Create(
46 NULL, wxID_ANY, _T("systray icon"),
47 wxDefaultPosition, wxDefaultSize,
48 wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR | wxSIMPLE_BORDER |
49 wxFRAME_SHAPED,
50 wxEmptyString /*eggtray doesn't like setting wmclass*/);
51
52 m_invokingWindow = NULL;
53 }
54
55 bool wxTaskBarIconAreaBase::IsProtocolSupported()
56 {
57 static int s_supported = -1;
58 if (s_supported == -1)
59 {
60 Display *display = GDK_DISPLAY();
61 Screen *screen = DefaultScreenOfDisplay(display);
62
63 char name[32];
64 g_snprintf(name, sizeof(name), "_NET_SYSTEM_TRAY_S%d",
65 XScreenNumberOfScreen(screen));
66 Atom atom = XInternAtom(display, name, False);
67
68 Window manager = XGetSelectionOwner(display, atom);
69
70 s_supported = (manager != None);
71 }
72
73 return (bool)s_supported;
74 }
75
76 //-----------------------------------------------------------------------------
77 // Pop-up menu stuff
78 //-----------------------------------------------------------------------------
79
80 extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *widget, bool* is_waiting );
81
82 extern WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win );
83
84 extern "C" WXDLLIMPEXP_CORE
85 void wxPopupMenuPositionCallback( GtkMenu *menu,
86 gint *x, gint *y,
87 gboolean * WXUNUSED(whatever),
88 gpointer user_data );
89
90 #if wxUSE_MENUS_NATIVE
91 bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu *menu, int x, int y )
92 {
93 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
94
95 wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
96
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,
100
101 SetInvokingWindow( menu, this );
102
103 menu->UpdateUI( m_invokingWindow );
104
105 bool is_waiting = true;
106
107 gulong handler = g_signal_connect (menu->m_menu, "hide",
108 G_CALLBACK (gtk_pop_hide_callback),
109 &is_waiting);
110
111 wxPoint pos;
112 gpointer userdata;
113 GtkMenuPositionFunc posfunc;
114 if ( x == -1 && y == -1 )
115 {
116 // use GTK's default positioning algorithm
117 userdata = NULL;
118 posfunc = NULL;
119 }
120 else
121 {
122 pos = ClientToScreen(wxPoint(x, y));
123 userdata = &pos;
124 posfunc = wxPopupMenuPositionCallback;
125 }
126
127 gtk_menu_popup(
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()
135 );
136
137 while (is_waiting)
138 {
139 gtk_main_iteration();
140 }
141
142 g_signal_handler_disconnect (menu->m_menu, handler);
143
144 return true;
145 }
146 #endif // wxUSE_MENUS_NATIVE
147
148 #endif // __WXGTK20__
149 #endif // GTK_CHECK_VERSION(2, 1, 0)
150
151 #endif // wxUSE_TASKBARICON