]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/taskbar.cpp
Applied patch [ 1701723 ] wxAUI: Added event for doubleclicks on the tabbar bg
[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 wxString name;
64 name.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen));
65 Atom atom = XInternAtom(display, name.ToAscii(), False);
66
67 Window manager = XGetSelectionOwner(display, atom);
68
69 s_supported = (manager != None);
70 }
71
72 return (bool)s_supported;
73 }
74
75 //-----------------------------------------------------------------------------
76 // Pop-up menu stuff
77 //-----------------------------------------------------------------------------
78
79 extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *widget, bool* is_waiting );
80
81 extern WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win );
82
83 extern "C" WXDLLIMPEXP_CORE
84 void wxPopupMenuPositionCallback( GtkMenu *menu,
85 gint *x, gint *y,
86 gboolean * WXUNUSED(whatever),
87 gpointer user_data );
88
89 #if wxUSE_MENUS_NATIVE
90 bool 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
106 gulong handler = g_signal_connect (menu->m_menu, "hide",
107 G_CALLBACK (gtk_pop_hide_callback),
108 &is_waiting);
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
141 g_signal_handler_disconnect (menu->m_menu, handler);
142
143 return true;
144 }
145 #endif // wxUSE_MENUS_NATIVE
146
147 #endif // __WXGTK20__
148 #endif // GTK_CHECK_VERSION(2, 1, 0)
149
150 #endif // wxUSE_TASKBARICON