1 ///////////////////////////////////////////////////////////////////////// 
   2 // File:        src/gtk/taskbar.cpp 
   3 // Purpose:     wxTaskBarIcon (src/unix/taskbarx11.cpp) helper for GTK2 
   4 // Author:      Vaclav Slavik 
   8 // Copyright:   (c) Vaclav Slavik, 2004 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 #include "wx/gtk/taskbarpriv.h" 
  26 #include <gtk/gtkversion.h> 
  27 #if GTK_CHECK_VERSION(2, 1, 0) 
  31 #include "eggtrayicon.h" 
  33 wxTaskBarIconAreaBase::wxTaskBarIconAreaBase() 
  35     if (IsProtocolSupported()) 
  37         m_widget 
= GTK_WIDGET(egg_tray_icon_new("systray icon")); 
  38         gtk_window_set_resizable(GTK_WINDOW(m_widget
), false); 
  40         wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec")); 
  43     wxTopLevelWindow::Create( 
  44             NULL
, wxID_ANY
, _T("systray icon"), 
  45             wxDefaultPosition
, wxDefaultSize
, 
  46             wxDEFAULT_FRAME_STYLE 
| wxFRAME_NO_TASKBAR 
| wxSIMPLE_BORDER 
| 
  48             wxEmptyString 
/*eggtray doesn't like setting wmclass*/); 
  50     m_invokingWindow 
= NULL
; 
  53 bool wxTaskBarIconAreaBase::IsProtocolSupported() 
  55     static int s_supported 
= -1; 
  56     if (s_supported 
== -1) 
  58         Display 
*display 
= GDK_DISPLAY(); 
  59         Screen 
*screen 
= DefaultScreenOfDisplay(display
); 
  62         name
.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen
)); 
  63         Atom atom 
= XInternAtom(display
, name
.ToAscii(), False
); 
  65         Window manager 
= XGetSelectionOwner(display
, atom
); 
  67         s_supported 
= (manager 
!= None
); 
  70     return (bool)s_supported
; 
  73 //----------------------------------------------------------------------------- 
  75 //----------------------------------------------------------------------------- 
  77 extern "C" WXDLLIMPEXP_CORE 
void gtk_pop_hide_callback( GtkWidget 
*widget
, bool* is_waiting  
); 
  79 extern WXDLLIMPEXP_CORE 
void SetInvokingWindow( wxMenu 
*menu
, wxWindow
* win 
); 
  81 extern "C" WXDLLIMPEXP_CORE
 
  82     void wxPopupMenuPositionCallback( GtkMenu 
*menu
, 
  84                                       gboolean 
* WXUNUSED(whatever
), 
  87 #if wxUSE_MENUS_NATIVE 
  88 bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu 
*menu
, int x
, int y 
) 
  90     wxCHECK_MSG( m_widget 
!= NULL
, false, wxT("invalid window") ); 
  92     wxCHECK_MSG( menu 
!= NULL
, false, wxT("invalid popup-menu") ); 
  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, 
  98     SetInvokingWindow( menu
, this ); 
 100     menu
->UpdateUI( m_invokingWindow 
); 
 102     bool is_waiting 
= true; 
 104     gulong handler 
= g_signal_connect (menu
->m_menu
, "hide", 
 105                                        G_CALLBACK (gtk_pop_hide_callback
), 
 110     GtkMenuPositionFunc posfunc
; 
 111     if ( x 
== -1 && y 
== -1 ) 
 113         // use GTK's default positioning algorithm 
 119         pos 
= ClientToScreen(wxPoint(x
, y
)); 
 121         posfunc 
= wxPopupMenuPositionCallback
; 
 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() 
 136         gtk_main_iteration(); 
 139     g_signal_handler_disconnect (menu
->m_menu
, handler
); 
 143 #endif // wxUSE_MENUS_NATIVE 
 145 #endif // __WXGTK20__ 
 146 #endif // GTK_CHECK_VERSION(2, 1, 0)