]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/taskbar.cpp
Patch from Bo for recent API changes
[wxWidgets.git] / src / gtk / taskbar.cpp
CommitLineData
33d4eef0 1/////////////////////////////////////////////////////////////////////////
e4db172a 2// File: src/gtk/taskbar.cpp
33d4eef0
VS
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
33d4eef0
VS
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
4f167b46
VZ
15#if wxUSE_TASKBARICON
16
e1bf3ad3 17#include "wx/gtk/taskbarpriv.h"
e4db172a
WS
18
19#ifndef WX_PRECOMP
20 #include "wx/log.h"
76b49cf4 21 #include "wx/frame.h"
3b3dc801 22 #include "wx/menu.h"
e4db172a
WS
23#endif
24
5dc22463 25#include <gdk/gdkx.h>
5dc22463 26
6376cdc3
RD
27#ifdef __WXGTK20__
28#include <gtk/gtkversion.h>
29#if GTK_CHECK_VERSION(2, 1, 0)
33d4eef0 30
0bd3b8ec
RR
31#include "gtk/gtk.h"
32
33d4eef0
VS
33#include "eggtrayicon.h"
34
35wxTaskBarIconAreaBase::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);
3d257b8d 41
33d4eef0
VS
42 wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));
43 }
3d257b8d 44
33d4eef0
VS
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*/);
3d257b8d 51
0bd3b8ec 52 m_invokingWindow = NULL;
33d4eef0
VS
53}
54
55bool 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);
3d257b8d 62
33d4eef0
VS
63 wxString name;
64 name.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen));
65 Atom atom = XInternAtom(display, name.ToAscii(), False);
3d257b8d 66
33d4eef0 67 Window manager = XGetSelectionOwner(display, atom);
3d257b8d 68
33d4eef0
VS
69 s_supported = (manager != None);
70 }
3d257b8d 71
33d4eef0
VS
72 return (bool)s_supported;
73}
74
0bd3b8ec
RR
75//-----------------------------------------------------------------------------
76// Pop-up menu stuff
77//-----------------------------------------------------------------------------
78
20123d49 79extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *widget, bool* is_waiting );
0bd3b8ec 80
20123d49 81extern WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win );
0bd3b8ec 82
20123d49
MW
83extern "C" WXDLLIMPEXP_CORE
84 void wxPopupMenuPositionCallback( GtkMenu *menu,
85 gint *x, gint *y,
86 gboolean * WXUNUSED(whatever),
87 gpointer user_data );
0bd3b8ec 88
065f010f 89#if wxUSE_MENUS_NATIVE
0bd3b8ec
RR
90bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu *menu, int x, int y )
91{
92 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
93
94 wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
95
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,
99
100 SetInvokingWindow( menu, this );
101
102 menu->UpdateUI( m_invokingWindow );
103
104 bool is_waiting = true;
105
9fa72bd2
MR
106 gulong handler = g_signal_connect (menu->m_menu, "hide",
107 G_CALLBACK (gtk_pop_hide_callback),
108 &is_waiting);
0bd3b8ec
RR
109
110 wxPoint pos;
111 gpointer userdata;
112 GtkMenuPositionFunc posfunc;
113 if ( x == -1 && y == -1 )
114 {
115 // use GTK's default positioning algorithm
116 userdata = NULL;
117 posfunc = NULL;
118 }
119 else
120 {
121 pos = ClientToScreen(wxPoint(x, y));
122 userdata = &pos;
123 posfunc = wxPopupMenuPositionCallback;
124 }
125
126 gtk_menu_popup(
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()
134 );
135
136 while (is_waiting)
137 {
138 gtk_main_iteration();
139 }
140
9fa72bd2 141 g_signal_handler_disconnect (menu->m_menu, handler);
0bd3b8ec
RR
142
143 return true;
144}
065f010f 145#endif // wxUSE_MENUS_NATIVE
0bd3b8ec 146
33d4eef0 147#endif // __WXGTK20__
6376cdc3 148#endif // GTK_CHECK_VERSION(2, 1, 0)
4f167b46
VZ
149
150#endif // wxUSE_TASKBARICON