]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/taskbar.cpp
vertically centered miniframe close button
[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
e1bf3ad3 15#include "wx/gtk/taskbarpriv.h"
e4db172a
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/log.h"
76b49cf4 19 #include "wx/frame.h"
3b3dc801 20 #include "wx/menu.h"
e4db172a
WS
21#endif
22
5dc22463 23#include <gdk/gdkx.h>
5dc22463 24
6376cdc3
RD
25#ifdef __WXGTK20__
26#include <gtk/gtkversion.h>
27#if GTK_CHECK_VERSION(2, 1, 0)
33d4eef0 28
0bd3b8ec
RR
29#include "gtk/gtk.h"
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
33d4eef0
VS
61 wxString name;
62 name.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen));
63 Atom atom = XInternAtom(display, name.ToAscii(), False);
3d257b8d 64
33d4eef0 65 Window manager = XGetSelectionOwner(display, atom);
3d257b8d 66
33d4eef0
VS
67 s_supported = (manager != None);
68 }
3d257b8d 69
33d4eef0
VS
70 return (bool)s_supported;
71}
72
0bd3b8ec
RR
73//-----------------------------------------------------------------------------
74// Pop-up menu stuff
75//-----------------------------------------------------------------------------
76
20123d49 77extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *widget, bool* is_waiting );
0bd3b8ec 78
20123d49 79extern WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win );
0bd3b8ec 80
20123d49
MW
81extern "C" WXDLLIMPEXP_CORE
82 void wxPopupMenuPositionCallback( GtkMenu *menu,
83 gint *x, gint *y,
84 gboolean * WXUNUSED(whatever),
85 gpointer user_data );
0bd3b8ec 86
065f010f 87#if wxUSE_MENUS_NATIVE
0bd3b8ec
RR
88bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu *menu, int x, int y )
89{
90 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
91
92 wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
93
94 // NOTE: if you change this code, you need to update
95 // the same code in window.cpp as well. This
96 // is ugly code duplication, I know,
97
98 SetInvokingWindow( menu, this );
99
100 menu->UpdateUI( m_invokingWindow );
101
102 bool is_waiting = true;
103
9fa72bd2
MR
104 gulong handler = g_signal_connect (menu->m_menu, "hide",
105 G_CALLBACK (gtk_pop_hide_callback),
106 &is_waiting);
0bd3b8ec
RR
107
108 wxPoint pos;
109 gpointer userdata;
110 GtkMenuPositionFunc posfunc;
111 if ( x == -1 && y == -1 )
112 {
113 // use GTK's default positioning algorithm
114 userdata = NULL;
115 posfunc = NULL;
116 }
117 else
118 {
119 pos = ClientToScreen(wxPoint(x, y));
120 userdata = &pos;
121 posfunc = wxPopupMenuPositionCallback;
122 }
123
124 gtk_menu_popup(
125 GTK_MENU(menu->m_menu),
126 (GtkWidget *) NULL, // parent menu shell
127 (GtkWidget *) NULL, // parent menu item
128 posfunc, // function to position it
129 userdata, // client data
130 0, // button used to activate it
131 gtk_get_current_event_time()
132 );
133
134 while (is_waiting)
135 {
136 gtk_main_iteration();
137 }
138
9fa72bd2 139 g_signal_handler_disconnect (menu->m_menu, handler);
0bd3b8ec
RR
140
141 return true;
142}
065f010f 143#endif // wxUSE_MENUS_NATIVE
0bd3b8ec 144
33d4eef0 145#endif // __WXGTK20__
6376cdc3 146#endif // GTK_CHECK_VERSION(2, 1, 0)