]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/taskbar.cpp
remove checks for new dc code
[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
290cd301
PC
17#include <gtk/gtkversion.h>
18#if GTK_CHECK_VERSION(2, 1, 0)
19
e1bf3ad3 20#include "wx/gtk/taskbarpriv.h"
e4db172a
WS
21
22#ifndef WX_PRECOMP
23 #include "wx/log.h"
76b49cf4 24 #include "wx/frame.h"
3b3dc801 25 #include "wx/menu.h"
e4db172a
WS
26#endif
27
290cd301 28#include <gtk/gtk.h>
5dc22463 29#include <gdk/gdkx.h>
5dc22463 30
33d4eef0
VS
31#include "eggtrayicon.h"
32
33wxTaskBarIconAreaBase::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);
3d257b8d 39
33d4eef0
VS
40 wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));
41 }
3d257b8d 42
33d4eef0
VS
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*/);
3d257b8d 49
0bd3b8ec 50 m_invokingWindow = NULL;
33d4eef0
VS
51}
52
53bool 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);
3d257b8d 60
37fde106
PC
61 char name[32];
62 g_snprintf(name, sizeof(name), "_NET_SYSTEM_TRAY_S%d",
63 XScreenNumberOfScreen(screen));
64 Atom atom = XInternAtom(display, name, 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
290cd301
PC
74bool wxTaskBarIconAreaBase::IsDecorCacheable() const
75{
76 // Apparently, WM frame extents extend to full width of screen when window
77 // is in the tray. Don't cache, it's not useful for other windows.
78 return false;
79}
80
0bd3b8ec
RR
81//-----------------------------------------------------------------------------
82// Pop-up menu stuff
83//-----------------------------------------------------------------------------
84
20123d49 85extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *widget, bool* is_waiting );
0bd3b8ec 86
20123d49 87extern WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win );
0bd3b8ec 88
20123d49
MW
89extern "C" WXDLLIMPEXP_CORE
90 void wxPopupMenuPositionCallback( GtkMenu *menu,
91 gint *x, gint *y,
92 gboolean * WXUNUSED(whatever),
93 gpointer user_data );
0bd3b8ec 94
065f010f 95#if wxUSE_MENUS_NATIVE
0bd3b8ec
RR
96bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu *menu, int x, int y )
97{
98 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
99
100 wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
101
102 // NOTE: if you change this code, you need to update
103 // the same code in window.cpp as well. This
104 // is ugly code duplication, I know,
105
106 SetInvokingWindow( menu, this );
107
108 menu->UpdateUI( m_invokingWindow );
109
110 bool is_waiting = true;
111
9fa72bd2
MR
112 gulong handler = g_signal_connect (menu->m_menu, "hide",
113 G_CALLBACK (gtk_pop_hide_callback),
114 &is_waiting);
0bd3b8ec
RR
115
116 wxPoint pos;
117 gpointer userdata;
118 GtkMenuPositionFunc posfunc;
119 if ( x == -1 && y == -1 )
120 {
121 // use GTK's default positioning algorithm
122 userdata = NULL;
123 posfunc = NULL;
124 }
125 else
126 {
127 pos = ClientToScreen(wxPoint(x, y));
128 userdata = &pos;
129 posfunc = wxPopupMenuPositionCallback;
130 }
131
132 gtk_menu_popup(
133 GTK_MENU(menu->m_menu),
134 (GtkWidget *) NULL, // parent menu shell
135 (GtkWidget *) NULL, // parent menu item
136 posfunc, // function to position it
137 userdata, // client data
138 0, // button used to activate it
139 gtk_get_current_event_time()
140 );
141
142 while (is_waiting)
143 {
144 gtk_main_iteration();
145 }
146
9fa72bd2 147 g_signal_handler_disconnect (menu->m_menu, handler);
0bd3b8ec
RR
148
149 return true;
150}
151
290cd301 152#endif // wxUSE_MENUS_NATIVE
6376cdc3 153#endif // GTK_CHECK_VERSION(2, 1, 0)
4f167b46 154#endif // wxUSE_TASKBARICON