]>
Commit | Line | Data |
---|---|---|
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 | ||
e1bf3ad3 | 15 | #include "wx/gtk/taskbarpriv.h" |
e4db172a WS |
16 | |
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/log.h" | |
19 | #endif | |
20 | ||
33d4eef0 | 21 | #include "wx/frame.h" |
0bd3b8ec | 22 | #include "wx/menu.h" |
33d4eef0 | 23 | |
5dc22463 | 24 | #include <gdk/gdkx.h> |
5dc22463 | 25 | |
6376cdc3 RD |
26 | #ifdef __WXGTK20__ |
27 | #include <gtk/gtkversion.h> | |
28 | #if GTK_CHECK_VERSION(2, 1, 0) | |
33d4eef0 | 29 | |
0bd3b8ec RR |
30 | #include "gtk/gtk.h" |
31 | ||
33d4eef0 VS |
32 | #include "eggtrayicon.h" |
33 | ||
34 | wxTaskBarIconAreaBase::wxTaskBarIconAreaBase() | |
35 | { | |
36 | if (IsProtocolSupported()) | |
37 | { | |
38 | m_widget = GTK_WIDGET(egg_tray_icon_new("systray icon")); | |
39 | gtk_window_set_resizable(GTK_WINDOW(m_widget), false); | |
3d257b8d | 40 | |
33d4eef0 VS |
41 | wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec")); |
42 | } | |
3d257b8d | 43 | |
33d4eef0 VS |
44 | wxTopLevelWindow::Create( |
45 | NULL, wxID_ANY, _T("systray icon"), | |
46 | wxDefaultPosition, wxDefaultSize, | |
47 | wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR | wxSIMPLE_BORDER | | |
48 | wxFRAME_SHAPED, | |
49 | wxEmptyString /*eggtray doesn't like setting wmclass*/); | |
3d257b8d | 50 | |
0bd3b8ec | 51 | m_invokingWindow = NULL; |
33d4eef0 VS |
52 | } |
53 | ||
54 | bool wxTaskBarIconAreaBase::IsProtocolSupported() | |
55 | { | |
56 | static int s_supported = -1; | |
57 | if (s_supported == -1) | |
58 | { | |
59 | Display *display = GDK_DISPLAY(); | |
60 | Screen *screen = DefaultScreenOfDisplay(display); | |
3d257b8d | 61 | |
33d4eef0 VS |
62 | wxString name; |
63 | name.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen)); | |
64 | Atom atom = XInternAtom(display, name.ToAscii(), False); | |
3d257b8d | 65 | |
33d4eef0 | 66 | Window manager = XGetSelectionOwner(display, atom); |
3d257b8d | 67 | |
33d4eef0 VS |
68 | s_supported = (manager != None); |
69 | } | |
3d257b8d | 70 | |
33d4eef0 VS |
71 | return (bool)s_supported; |
72 | } | |
73 | ||
0bd3b8ec RR |
74 | //----------------------------------------------------------------------------- |
75 | // Pop-up menu stuff | |
76 | //----------------------------------------------------------------------------- | |
77 | ||
20123d49 | 78 | extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *widget, bool* is_waiting ); |
0bd3b8ec | 79 | |
20123d49 | 80 | extern WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win ); |
0bd3b8ec | 81 | |
20123d49 MW |
82 | extern "C" WXDLLIMPEXP_CORE |
83 | void wxPopupMenuPositionCallback( GtkMenu *menu, | |
84 | gint *x, gint *y, | |
85 | gboolean * WXUNUSED(whatever), | |
86 | gpointer user_data ); | |
0bd3b8ec | 87 | |
065f010f | 88 | #if wxUSE_MENUS_NATIVE |
0bd3b8ec RR |
89 | bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu *menu, int x, int y ) |
90 | { | |
91 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") ); | |
92 | ||
93 | wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") ); | |
94 | ||
95 | // NOTE: if you change this code, you need to update | |
96 | // the same code in window.cpp as well. This | |
97 | // is ugly code duplication, I know, | |
98 | ||
99 | SetInvokingWindow( menu, this ); | |
100 | ||
101 | menu->UpdateUI( m_invokingWindow ); | |
102 | ||
103 | bool is_waiting = true; | |
104 | ||
9fa72bd2 MR |
105 | gulong handler = g_signal_connect (menu->m_menu, "hide", |
106 | G_CALLBACK (gtk_pop_hide_callback), | |
107 | &is_waiting); | |
0bd3b8ec RR |
108 | |
109 | wxPoint pos; | |
110 | gpointer userdata; | |
111 | GtkMenuPositionFunc posfunc; | |
112 | if ( x == -1 && y == -1 ) | |
113 | { | |
114 | // use GTK's default positioning algorithm | |
115 | userdata = NULL; | |
116 | posfunc = NULL; | |
117 | } | |
118 | else | |
119 | { | |
120 | pos = ClientToScreen(wxPoint(x, y)); | |
121 | userdata = &pos; | |
122 | posfunc = wxPopupMenuPositionCallback; | |
123 | } | |
124 | ||
125 | gtk_menu_popup( | |
126 | GTK_MENU(menu->m_menu), | |
127 | (GtkWidget *) NULL, // parent menu shell | |
128 | (GtkWidget *) NULL, // parent menu item | |
129 | posfunc, // function to position it | |
130 | userdata, // client data | |
131 | 0, // button used to activate it | |
132 | gtk_get_current_event_time() | |
133 | ); | |
134 | ||
135 | while (is_waiting) | |
136 | { | |
137 | gtk_main_iteration(); | |
138 | } | |
139 | ||
9fa72bd2 | 140 | g_signal_handler_disconnect (menu->m_menu, handler); |
0bd3b8ec RR |
141 | |
142 | return true; | |
143 | } | |
065f010f | 144 | #endif // wxUSE_MENUS_NATIVE |
0bd3b8ec | 145 | |
33d4eef0 | 146 | #endif // __WXGTK20__ |
6376cdc3 | 147 | #endif // GTK_CHECK_VERSION(2, 1, 0) |