Author: nick
Date: 2007-10-19 21:17:11 +0000 (Fri, 19 Oct 2007)
New Revision: 26148

Modified:
   xfce4-panel/trunk/plugins/systray/xfce-tray-manager.c
   xfce4-panel/trunk/plugins/systray/xfce-tray-manager.h
   xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.c
   xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.h
   xfce4-panel/trunk/plugins/systray/xfce-tray-widget.c
   xfce4-panel/trunk/plugins/systray/xfce-tray-widget.h
Log:
* Fix issue with unmapped icons (which was 'fixed' by
  adding them delayed to the tray). We now enter
  the main loop until the remote window is mapped, then
  the icon is added to the tray.
* Fix crash when switching screens, the manager will
  now try to register to the new screen. and the style
  is properly applied.
* Destroy button on remap.


Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-manager.c
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-manager.c       2007-10-19 
21:16:25 UTC (rev 26147)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-manager.c       2007-10-19 
21:17:11 UTC (rev 26148)
@@ -59,7 +59,9 @@
 static void                 xfce_tray_manager_class_init                       
  (XfceTrayManagerClass *klass);
 static void                 xfce_tray_manager_init                             
  (XfceTrayManager      *manager);
 static void                 xfce_tray_manager_finalize                         
  (GObject              *object);
-static void                 xfce_tray_manager_unregister                       
  (XfceTrayManager      *manager);
+static void                 xfce_tray_manager_remove_socket                    
  (gpointer              key,
+                                                                               
   gpointer              value,
+                                                                               
   gpointer              user_data);
 static GdkFilterReturn      xfce_tray_manager_window_filter                    
  (GdkXEvent            *xev,
                                                                                
   GdkEvent             *event,
                                                                                
   gpointer              user_data);
@@ -96,6 +98,7 @@
 
 enum
 {
+  TRAY_ICON_SET_PARENT,
   TRAY_ICON_ADDED,
   TRAY_ICON_REMOVED,
 #if XFCE_TRAY_MANAGER_ENABLE_MESSAGES
@@ -195,6 +198,15 @@
     gobject_class = (GObjectClass *)klass;
     gobject_class->finalize = xfce_tray_manager_finalize;
 
+    xfce_tray_manager_signals[TRAY_ICON_SET_PARENT] =
+        g_signal_new (I_("tray-icon-set-parent"),
+                      G_OBJECT_CLASS_TYPE (klass),
+                      G_SIGNAL_RUN_LAST,
+                      0, NULL, NULL,
+                      g_cclosure_marshal_VOID__OBJECT,
+                      G_TYPE_NONE, 1,
+                      GTK_TYPE_SOCKET);
+
     xfce_tray_manager_signals[TRAY_ICON_ADDED] =
         g_signal_new (I_("tray-icon-added"),
                       G_OBJECT_CLASS_TYPE (klass),
@@ -329,7 +341,7 @@
     GdkDisplay *display;
     Atom        selection_atom;
 
-    g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
+    _panel_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
 
     /* get the display */
     display = gdk_screen_get_display (screen);
@@ -364,9 +376,9 @@
     XClientMessageEvent  xevent;
     Window               root_window;
 
-    g_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), FALSE);
-    g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
-    g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+    _panel_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), FALSE);
+    _panel_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
+    _panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     /* create invisible window */
     invisible = gtk_invisible_new_for_screen (screen);
@@ -455,18 +467,29 @@
 
 
 static void
+xfce_tray_manager_remove_socket (gpointer key,
+                                 gpointer value,
+                                 gpointer user_data)
+{
+    /* undock the socket */
+    xfce_tray_manager_handle_undock_request (value, user_data);
+}
+
+
+
+void
 xfce_tray_manager_unregister (XfceTrayManager *manager)
 {
     GdkDisplay *display;
     GtkWidget  *invisible = manager->invisible;
 
     /* leave when there is no invisible window */
-    if (G_UNLIKELY (invisible == NULL))
+    if (invisible == NULL)
         return;
 
-    g_return_if_fail (GTK_IS_INVISIBLE (invisible));
-    g_return_if_fail (GTK_WIDGET_REALIZED (invisible));
-    g_return_if_fail (GDK_IS_WINDOW (invisible->window));
+    _panel_return_if_fail (GTK_IS_INVISIBLE (invisible));
+    _panel_return_if_fail (GTK_WIDGET_REALIZED (invisible));
+    _panel_return_if_fail (GDK_IS_WINDOW (invisible->window));
 
     /* get the display of the invisible window */
     display = gtk_widget_get_display (invisible);
@@ -485,6 +508,9 @@
     /* remove window filter */
     gdk_window_remove_filter (invisible->window, 
xfce_tray_manager_window_filter, manager);
 
+    /* remove all sockets from the hash table */
+    g_hash_table_foreach (manager->sockets, xfce_tray_manager_remove_socket, 
manager);
+
     /* destroy and unref the invisible window */
     manager->invisible = NULL;
     gtk_widget_destroy (invisible);
@@ -535,7 +561,7 @@
     XClientMessageEvent *xev;
     XfceTrayManager     *manager = XFCE_TRAY_MANAGER (user_data);
 
-    g_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), GDK_FILTER_REMOVE);
+    _panel_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), 
GDK_FILTER_REMOVE);
 
     /* cast to x11 event */
     xev = (XClientMessageEvent *) xevent;
@@ -575,7 +601,7 @@
     glong                length;
     GtkSocket           *socket;
 
-    g_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), GDK_FILTER_REMOVE);
+    _panel_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), 
GDK_FILTER_REMOVE);
 
     /* try to find the pending message in the list */
     for (li = manager->messages; li != NULL; li = li->next)
@@ -691,7 +717,30 @@
 #endif
 
 
+
 static void
+xfce_tray_manager_handle_plug_added (GtkSocket       *socket,
+                                     XfceTrayManager *manager)
+{
+    /* this function works the same as gtk_widget_show_now, but waits
+     * until the remote window is mapped. this is needed to fix problems
+     * with empty icons in the tray when they are added. */
+
+    /* show the socket */
+    gtk_widget_show (GTK_WIDGET (socket));
+
+    /* enter the main loop until the socket is mapped */
+    while (GTK_SOCKET (socket)->is_mapped == FALSE)
+        gtk_main_iteration ();
+
+    /* add the icon to the tray */
+    g_signal_emit (manager, xfce_tray_manager_signals[TRAY_ICON_ADDED], 0, 
socket);
+}
+
+
+
+
+static void
 xfce_tray_manager_handle_dock_request (XfceTrayManager     *manager,
                                        XClientMessageEvent *xevent)
 {
@@ -718,14 +767,15 @@
     /* set the application on the socket */
     xfce_tray_manager_application_set_socket (manager, socket, *xwindow);
 
-    /* emit signal */
-    g_signal_emit (manager, xfce_tray_manager_signals[TRAY_ICON_ADDED], 0, 
socket);
+    /* set the parent of the icon */
+    g_signal_emit (manager, xfce_tray_manager_signals[TRAY_ICON_SET_PARENT], 
0, socket);
 
     /* check if the widget has been attached. if the widget has no
        toplevel window, we cannot set the socket id. */
     if (G_LIKELY (GTK_IS_WINDOW (gtk_widget_get_toplevel (socket))))
     {
         /* signal to monitor if the client is removed from the socket */
+        g_signal_connect (G_OBJECT (socket), "plug-added", G_CALLBACK 
(xfce_tray_manager_handle_plug_added), manager);
         g_signal_connect (G_OBJECT (socket), "plug-removed", G_CALLBACK 
(xfce_tray_manager_handle_undock_request), manager);
 
         /* register the xembed client window id for this socket */
@@ -733,9 +783,6 @@
 
         /* add the socket to the list of known sockets */
         g_hash_table_insert (manager->sockets, GUINT_TO_POINTER (*xwindow), 
socket);
-
-        /* show the socket */
-        gtk_widget_show (socket);
     }
     else
     {
@@ -753,7 +800,7 @@
     XfceTrayManager *manager = XFCE_TRAY_MANAGER (user_data);
     Window          *xwindow;
 
-    g_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), FALSE);
+    _panel_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), FALSE);
 
     /* emit signal that the socket will be removed */
     g_signal_emit (manager, xfce_tray_manager_signals[TRAY_ICON_REMOVED], 0, 
socket);
@@ -777,7 +824,7 @@
 GtkOrientation
 xfce_tray_manager_get_orientation (XfceTrayManager *manager)
 {
-    g_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), 
GTK_ORIENTATION_HORIZONTAL);
+    _panel_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), 
GTK_ORIENTATION_HORIZONTAL);
 
     return manager->orientation;
 }
@@ -792,8 +839,8 @@
     Atom        orientation_atom;
     gulong      data[1];
 
-    g_return_if_fail (XFCE_IS_TRAY_MANAGER (manager));
-    g_return_if_fail (GTK_IS_INVISIBLE (manager->invisible));
+    _panel_return_if_fail (XFCE_IS_TRAY_MANAGER (manager));
+    _panel_return_if_fail (GTK_IS_INVISIBLE (manager->invisible));
 
     if (G_LIKELY (manager->orientation != orientation))
     {
@@ -832,8 +879,8 @@
 {
     XfceTrayApplication *application;
 
-    g_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), NULL);
-    g_return_val_if_fail (name, NULL);
+    _panel_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), NULL);
+    _panel_return_val_if_fail (name, NULL);
 
     /* create structure */
     application = panel_slice_new0 (XfceTrayApplication);
@@ -859,8 +906,8 @@
     GSList              *li;
     XfceTrayApplication *application;
 
-    g_return_if_fail (XFCE_IS_TRAY_MANAGER (manager));
-    g_return_if_fail (name);
+    _panel_return_if_fail (XFCE_IS_TRAY_MANAGER (manager));
+    _panel_return_if_fail (name);
 
     /* walk through the known window names */
     for (li = manager->applications; li != NULL; li = li->next)
@@ -901,7 +948,7 @@
 xfce_tray_manager_application_list (XfceTrayManager *manager,
                                     gboolean         sorted)
 {
-    g_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), NULL);
+    _panel_return_val_if_fail (XFCE_IS_TRAY_MANAGER (manager), NULL);
 
     /* sort the list if requested */
     if (sorted)
@@ -932,7 +979,7 @@
     GSList              *li;
     XfceTrayApplication *application;
 
-    g_return_val_if_fail (name, NULL);
+    _panel_return_val_if_fail (name, NULL);
 
     /* walk through the known window names */
     for (li = manager->applications; li != NULL; li = li->next)

Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-manager.h
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-manager.h       2007-10-19 
21:16:25 UTC (rev 26147)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-manager.h       2007-10-19 
21:17:11 UTC (rev 26148)
@@ -66,6 +66,8 @@
                                                                GdkScreen       
 *screen,
                                                                GError          
**error) G_GNUC_INTERNAL;
 
+void                 xfce_tray_manager_unregister             (XfceTrayManager 
 *manager) G_GNUC_INTERNAL;
+
 GtkOrientation       xfce_tray_manager_get_orientation        (XfceTrayManager 
 *manager) G_GNUC_INTERNAL;
 
 void                 xfce_tray_manager_set_orientation        (XfceTrayManager 
 *manager,

Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.c
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.c        2007-10-19 
21:16:25 UTC (rev 26147)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.c        2007-10-19 
21:17:11 UTC (rev 26148)
@@ -36,9 +36,6 @@
 
 
 /* prototypes */
-static void            xfce_tray_plugin_message                 
(GtkMessageType      type,
-                                                                 GdkScreen     
     *screen,
-                                                                 const gchar   
     *message);
 static gboolean        xfce_tray_plugin_check                   (GdkScreen     
     *screen);
 static GtkArrowType    xfce_tray_plugin_button_position         
(XfcePanelPlugin    *panel_plugin);
 static XfceTrayPlugin *xfce_tray_plugin_new                     
(XfcePanelPlugin    *panel_plugin);
@@ -62,7 +59,7 @@
 
 
 
-static void
+void
 xfce_tray_plugin_message (GtkMessageType  type,
                           GdkScreen      *screen,
                           const gchar    *message)
@@ -111,7 +108,7 @@
     GdkRectangle        geom;
     gint                mon, x, y;
 
-    g_return_val_if_fail (GTK_WIDGET_REALIZED (panel_plugin), GTK_ARROW_LEFT);
+    _panel_return_val_if_fail (GTK_WIDGET_REALIZED (panel_plugin), 
GTK_ARROW_LEFT);
 
     /* get the plugin position */
     position = xfce_panel_plugin_get_screen_position (panel_plugin);
@@ -165,9 +162,7 @@
 xfce_tray_plugin_new (XfcePanelPlugin *panel_plugin)
 {
     XfceTrayPlugin *plugin;
-    GError         *error = NULL;
     GtkArrowType    position;
-    GdkScreen      *screen;
 
     /* create structure */
     plugin = panel_slice_new0 (XfceTrayPlugin);
@@ -177,45 +172,32 @@
     plugin->manager = NULL;
     plugin->show_frame = TRUE;
 
-    /* get the button position */
-    position = xfce_tray_plugin_button_position (panel_plugin);
-
-    /* get the screen of the plugin */
-    screen = gtk_widget_get_screen (GTK_WIDGET (panel_plugin));
-
     /* try to create the tray */
-    plugin->tray = xfce_tray_widget_new_for_screen (screen, position, &error);
+    plugin->tray = xfce_tray_widget_new ();
 
-    if (G_LIKELY (plugin->tray))
-    {
-        /* get the manager */
-        plugin->manager = xfce_tray_widget_get_manager (XFCE_TRAY_WIDGET 
(plugin->tray));
+    /* get the manager */
+    plugin->manager = xfce_tray_widget_get_manager (XFCE_TRAY_WIDGET 
(plugin->tray));
 
-        /* read the plugin settings */
-        xfce_tray_plugin_read (plugin);
+    /* set arrow postion */
+    position = xfce_tray_plugin_button_position (panel_plugin);
+    xfce_tray_widget_set_arrow_position (XFCE_TRAY_WIDGET (plugin->tray), 
position);
 
-        /* create the frame */
-        plugin->frame = gtk_frame_new (NULL);
-        gtk_frame_set_shadow_type (GTK_FRAME (plugin->frame), 
plugin->show_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE);
-        gtk_container_add (GTK_CONTAINER (panel_plugin), plugin->frame);
-        gtk_widget_show (plugin->frame);
+    /* read the plugin settings */
+    xfce_tray_plugin_read (plugin);
 
-        /* add the tray */
-        gtk_container_add (GTK_CONTAINER (plugin->frame), plugin->tray);
-        gtk_widget_show (plugin->tray);
+    /* create the frame */
+    plugin->frame = gtk_frame_new (NULL);
+    gtk_frame_set_shadow_type (GTK_FRAME (plugin->frame), plugin->show_frame ? 
GTK_SHADOW_IN : GTK_SHADOW_NONE);
+    gtk_container_add (GTK_CONTAINER (panel_plugin), plugin->frame);
+    gtk_widget_show (plugin->frame);
 
-        /* connect signal to handle the real plugin size */
-        g_signal_connect_swapped (G_OBJECT (plugin->tray), "tray-size-changed",
-                                  G_CALLBACK 
(xfce_tray_plugin_tray_size_changed), plugin);
-    }
-    else
-    {
-        /* show the message */
-        xfce_tray_plugin_message (GTK_MESSAGE_ERROR, screen, error->message);
+    /* add the tray */
+    gtk_container_add (GTK_CONTAINER (plugin->frame), plugin->tray);
+    gtk_widget_show (plugin->tray);
 
-        /* cleanup */
-        g_error_free (error);
-    }
+    /* connect signal to handle the real plugin size */
+    g_signal_connect_swapped (G_OBJECT (plugin->tray), "tray-size-changed",
+                              G_CALLBACK (xfce_tray_plugin_tray_size_changed), 
plugin);
 
     return plugin;
 }

Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.h
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.h        2007-10-19 
21:16:25 UTC (rev 26147)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.h        2007-10-19 
21:17:11 UTC (rev 26148)
@@ -38,5 +38,9 @@
     guint            show_frame : 1;
 };
 
+void xfce_tray_plugin_message (GtkMessageType  type,
+                               GdkScreen      *screen,
+                               const gchar    *message);
 
+
 #endif /* !__XFCE_TRAY_PLUGIN_H__ */

Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-widget.c
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-widget.c        2007-10-19 
21:16:25 UTC (rev 26147)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-widget.c        2007-10-19 
21:17:11 UTC (rev 26148)
@@ -28,9 +28,12 @@
 #include <gtk/gtk.h>
 #include <libxfce4panel/xfce-arrow-button.h>
 #include <libxfce4panel/xfce-panel-macros.h>
+#include <libxfce4panel/xfce-panel-plugin.h>
+#include <libxfce4util/libxfce4util.h>
 
 #include "xfce-tray-manager.h"
 #include "xfce-tray-widget.h"
+#include "xfce-tray-plugin.h"
 
 #define XFCE_TRAY_WIDGET_BUTTON_SIZE          (16)
 #define XFCE_TRAY_WIDGET_REDRAW_DELAY         (250)
@@ -52,6 +55,8 @@
 static void     xfce_tray_widget_style_set          (GtkWidget           
*widget,
                                                      GtkStyle            
*previous_style);
 static void     xfce_tray_widget_map                (GtkWidget           
*widget);
+static void     xfce_tray_widget_screen_changed     (GtkWidget           
*widget,
+                                                     GdkScreen           
*previous_screen);
 static gint     xfce_tray_widget_expose_event       (GtkWidget           
*widget,
                                                      GdkEventExpose      
*event);
 static void     xfce_tray_widget_button_set_arrow   (XfceTrayWidget      
*tray);
@@ -72,8 +77,7 @@
                                                      gint                 
size);
 static gboolean xfce_tray_widget_redraw_idle        (gpointer             
user_data);
 static void     xfce_tray_widget_redraw_destroyed   (gpointer             
user_data);
-static void     xfce_tray_widget_redraw             (XfceTrayWidget      *tray,
-                                                     gboolean             
delayed);
+static void     xfce_tray_widget_redraw             (XfceTrayWidget      
*tray);
 
 
 
@@ -160,6 +164,7 @@
     gtkwidget_class->style_set = xfce_tray_widget_style_set;
     gtkwidget_class->expose_event = xfce_tray_widget_expose_event;
     gtkwidget_class->map = xfce_tray_widget_map;
+    gtkwidget_class->screen_changed = xfce_tray_widget_screen_changed;
 
     gtkcontainer_class = GTK_CONTAINER_CLASS (klass);
     gtkcontainer_class->add = NULL;
@@ -237,15 +242,23 @@
 {
     XfceTrayWidget *tray = XFCE_TRAY_WIDGET (widget);
     GSList         *li;
+    GtkStyle       *style;
 
-    /* set the button style */
-    if (tray->button)
-        gtk_widget_set_style (tray->button, widget->style);
+    /* get the style */
+    style = gtk_widget_get_style (widget);
 
-    /* send the style to all the childeren */
-    for (li = tray->childeren; li != NULL; li = li->next)
-        gtk_widget_set_style (GTK_WIDGET (li->data), widget->style);
+    /* style must be attached an widget must be realized */
+    if (style && GTK_STYLE_ATTACHED (style) && GTK_WIDGET_REALIZED (widget))
+    {
+        /* set the button style */
+        if (tray->button)
+               gtk_widget_set_style (tray->button, style);
 
+           /* send the style to all the childeren */
+        for (li = tray->childeren; li != NULL; li = li->next)
+            gtk_widget_set_style (GTK_WIDGET (li->data), style);
+    }
+
     /* invoke the parent */
     GTK_WIDGET_CLASS (xfce_tray_widget_parent_class)->style_set (widget, 
previous_style);
 }
@@ -260,6 +273,10 @@
     /* we've been mapped */
     GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
 
+    /* destroy old button on remap (screen changed) */
+    if (G_UNLIKELY (tray->button))
+        gtk_widget_destroy (tray->button);
+
     /* create the arrow button (needs a mapped tray before the parent is set) 
*/
     tray->button = xfce_arrow_button_new (tray->arrow_position);
     GTK_WIDGET_UNSET_FLAGS (tray->button, GTK_CAN_DEFAULT | GTK_CAN_FOCUS);
@@ -273,6 +290,45 @@
 
 
 static void
+xfce_tray_widget_screen_changed (GtkWidget *widget,
+                                 GdkScreen *previous_screen)
+{
+    XfceTrayWidget *tray = XFCE_TRAY_WIDGET (widget);
+    gboolean        succeed;
+    GdkScreen      *screen;
+    gchar          *message;
+
+    /* unregister the manager */
+    xfce_tray_manager_unregister (tray->manager);
+
+    /* get screen */
+    screen = gtk_widget_get_screen (widget);
+
+    /* register the manager for this screen */
+    succeed = xfce_tray_manager_register (tray->manager, screen, NULL);
+
+    if (G_LIKELY (succeed))
+    {
+        /* set the orienation */
+        xfce_tray_manager_set_orientation (tray->manager, 
XFCE_TRAY_WIDGET_GET_ORIENTATION (tray));
+    }
+    else
+    {
+        /* create message */
+        message = g_strdup_printf (_("Failed to register the system tray for 
screen %d"),
+                                   gdk_screen_get_number (screen));
+
+        /* show message */
+        xfce_tray_plugin_message (GTK_MESSAGE_ERROR, screen, message);
+
+        /* cleanup */
+        g_free (message);
+    }
+}
+
+
+
+static void
 xfce_tray_widget_button_set_arrow (XfceTrayWidget *tray)
 {
     GtkArrowType arrow_type;
@@ -306,7 +362,7 @@
     xfce_tray_widget_button_set_arrow (tray);
 
     /* update the tray */
-    xfce_tray_widget_redraw (tray, FALSE);
+    xfce_tray_widget_redraw (tray);
 }
 
 
@@ -353,15 +409,30 @@
 
 
 static void
+xfce_tray_widget_icon_set_parent (XfceTrayManager *manager,
+                                  GtkWidget       *icon,
+                                  XfceTrayWidget  *tray)
+{
+    _panel_return_if_fail (XFCE_IS_TRAY_MANAGER (manager));
+    _panel_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
+    _panel_return_if_fail (GTK_IS_WIDGET (icon));
+
+    /* set the parent window */
+    gtk_widget_set_parent (icon, GTK_WIDGET (tray));
+}
+
+
+
+static void
 xfce_tray_widget_icon_added (XfceTrayManager *manager,
                              GtkWidget       *icon,
                              XfceTrayWidget  *tray)
 {
     gboolean hidden;
 
-    g_return_if_fail (XFCE_IS_TRAY_MANAGER (manager));
-    g_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
-    g_return_if_fail (GTK_IS_WIDGET (icon));
+    _panel_return_if_fail (XFCE_IS_TRAY_MANAGER (manager));
+    _panel_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
+    _panel_return_if_fail (GTK_IS_WIDGET (icon));
 
     /* add the icon to the list */
     tray->childeren = g_slist_insert_sorted (tray->childeren, icon, 
xfce_tray_widget_compare_function);
@@ -376,11 +447,8 @@
     if (hidden)
         tray->n_hidden_childeren++;
 
-    /* set the parent window */
-    gtk_widget_set_parent (icon, GTK_WIDGET (tray));
-
     /* update the tray */
-    xfce_tray_widget_redraw (tray, TRUE);
+    xfce_tray_widget_redraw (tray);
 }
 
 
@@ -390,9 +458,9 @@
                                GtkWidget       *icon,
                                XfceTrayWidget  *tray)
 {
-    g_return_if_fail (XFCE_IS_TRAY_MANAGER (manager));
-    g_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
-    g_return_if_fail (GTK_IS_WIDGET (icon));
+    _panel_return_if_fail (XFCE_IS_TRAY_MANAGER (manager));
+    _panel_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
+    _panel_return_if_fail (GTK_IS_WIDGET (icon));
 
     /* decrease counter */
     tray->n_childeren--;
@@ -412,51 +480,30 @@
     }
 
     /* update the tray */
-    xfce_tray_widget_redraw (tray, FALSE);
+    xfce_tray_widget_redraw (tray);
 }
 
 
 
 GtkWidget *
-xfce_tray_widget_new_for_screen (GdkScreen     *screen,
-                                 GtkArrowType   arrow_position,
-                                 GError       **error)
+xfce_tray_widget_new (void)
 {
-    XfceTrayWidget  *tray = NULL;
-    XfceTrayManager *manager;
+    XfceTrayWidget  *tray;
 
-    g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
-    g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+    /* create a tray */
+    tray = g_object_new (XFCE_TYPE_TRAY_WIDGET, NULL);
 
     /* new tray manager */
-    manager = xfce_tray_manager_new ();
+    tray->manager = xfce_tray_manager_new ();
 
-    /* register the manager for this screen */
-    if (G_LIKELY (xfce_tray_manager_register (manager, screen, error) == TRUE))
-    {
-        /* create a tray */
-        tray = g_object_new (XFCE_TYPE_TRAY_WIDGET, NULL);
+    /* manager signals */
+    g_signal_connect (G_OBJECT (tray->manager), "tray-icon-set-parent", 
G_CALLBACK (xfce_tray_widget_icon_set_parent), tray);
+    g_signal_connect (G_OBJECT (tray->manager), "tray-icon-added", G_CALLBACK 
(xfce_tray_widget_icon_added), tray);
+    g_signal_connect (G_OBJECT (tray->manager), "tray-icon-removed", 
G_CALLBACK (xfce_tray_widget_icon_removed), tray);
+    //g_signal_connect (G_OBJECT (tray->manager), "tray-message-sent", 
G_CALLBACK (xfce_tray_widget_message_sent), tray);
+    //g_signal_connect (G_OBJECT (tray->manager), "tray-message-cancelled", 
G_CALLBACK (xfce_tray_widget_message_cancelled), tray);
+    //g_signal_connect (G_OBJECT (tray->manager), "tray-lost-selection", 
G_CALLBACK (xfce_tray_widget_lost_selection), tray);
 
-        /* set the manager */
-        tray->manager = manager;
-
-        /* set the orientations */
-        tray->arrow_position = arrow_position;
-        xfce_tray_manager_set_orientation (manager, 
XFCE_TRAY_WIDGET_GET_ORIENTATION (tray));
-
-        /* manager signals */
-        g_signal_connect (G_OBJECT (manager), "tray-icon-added", G_CALLBACK 
(xfce_tray_widget_icon_added), tray);
-        g_signal_connect (G_OBJECT (manager), "tray-icon-removed", G_CALLBACK 
(xfce_tray_widget_icon_removed), tray);
-        //g_signal_connect (G_OBJECT (manager), "tray-message-sent", 
G_CALLBACK (xfce_tray_widget_message_sent), tray);
-        //g_signal_connect (G_OBJECT (manager), "tray-message-cancelled", 
G_CALLBACK (xfce_tray_widget_message_cancelled), tray);
-        //g_signal_connect (G_OBJECT (manager), "tray-lost-selection", 
G_CALLBACK (xfce_tray_widget_lost_selection), tray);
-    }
-    else
-    {
-        /* release the manager */
-        g_object_unref (G_OBJECT (manager));
-    }
-
     return GTK_WIDGET (tray);
 }
 
@@ -582,10 +629,8 @@
         /* get the child */
         child = li->data;
 
-        /* handle hidden icons */
         if (!tray->all_visible && i < tray->n_hidden_childeren)
         {
-            /* put the widget offscreen */
             child_allocation.x = child_allocation.y = 
XFCE_TRAY_WIDGET_OFFSCREEN;
         }
         else
@@ -635,23 +680,17 @@
 
 
 static void
-xfce_tray_widget_redraw (XfceTrayWidget *tray,
-                         gboolean        delayed)
+xfce_tray_widget_redraw (XfceTrayWidget *tray)
 {
-    g_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
+    _panel_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
 
     /* ignore if there is already a redraw scheduled */
     if (tray->idle_redraw_id != 0)
         return;
 
-    /* schedule an idle or delayed redraw */
-    if (delayed)
-        tray->idle_redraw_id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 
XFCE_TRAY_WIDGET_REDRAW_DELAY,
-                                                   
xfce_tray_widget_redraw_idle, tray,
-                                                   
xfce_tray_widget_redraw_destroyed);
-    else
-        tray->idle_redraw_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, 
xfce_tray_widget_redraw_idle,
-                                                tray, 
xfce_tray_widget_redraw_destroyed);
+    /* schedule an idle redraw */
+    tray->idle_redraw_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, 
xfce_tray_widget_redraw_idle,
+                                            tray, 
xfce_tray_widget_redraw_destroyed);
 }
 
 
@@ -662,7 +701,7 @@
     GSList *li;
     guint   n_hidden_childeren = 0;
 
-    g_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
+    _panel_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
 
     /* sort the list */
     tray->childeren = g_slist_sort (tray->childeren, 
xfce_tray_widget_compare_function);
@@ -688,7 +727,7 @@
         tray->n_hidden_childeren = n_hidden_childeren;
 
         /* update the tray */
-        xfce_tray_widget_redraw (tray, FALSE);
+        xfce_tray_widget_redraw (tray);
     }
 }
 
@@ -697,7 +736,7 @@
 XfceTrayManager *
 xfce_tray_widget_get_manager (XfceTrayWidget *tray)
 {
-    g_return_val_if_fail (XFCE_IS_TRAY_WIDGET (tray), NULL);
+    _panel_return_val_if_fail (XFCE_IS_TRAY_WIDGET (tray), NULL);
 
     return tray->manager;
 }
@@ -708,7 +747,7 @@
 xfce_tray_widget_set_arrow_position (XfceTrayWidget *tray,
                                      GtkArrowType    arrow_position)
 {
-    g_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
+    _panel_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
 
     if (G_LIKELY (tray->arrow_position != arrow_position))
     {
@@ -722,7 +761,7 @@
         xfce_tray_widget_button_set_arrow (tray);
 
         /* update the tray */
-        xfce_tray_widget_redraw (tray, FALSE);
+        xfce_tray_widget_redraw (tray);
     }
 }
 
@@ -732,7 +771,7 @@
 xfce_tray_widget_set_size_request (XfceTrayWidget *tray,
                                    gint            size)
 {
-    g_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
+    _panel_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
 
     if (G_LIKELY (tray->size != size))
     {
@@ -740,6 +779,6 @@
         tray->size = size;
 
         /* redraw the tray */
-        xfce_tray_widget_redraw (tray, FALSE);
+        xfce_tray_widget_redraw (tray);
     }
 }

Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-widget.h
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-widget.h        2007-10-19 
21:16:25 UTC (rev 26147)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-widget.h        2007-10-19 
21:17:11 UTC (rev 26148)
@@ -32,9 +32,7 @@
 
 GType            xfce_tray_widget_get_type           (void) G_GNUC_CONST 
G_GNUC_INTERNAL;
 
-GtkWidget       *xfce_tray_widget_new_for_screen     (GdkScreen       *screen,
-                                                      GtkArrowType     
arrow_position,
-                                                      GError         **error) 
G_GNUC_MALLOC G_GNUC_INTERNAL;
+GtkWidget       *xfce_tray_widget_new                (void) G_GNUC_MALLOC 
G_GNUC_INTERNAL;
 
 void             xfce_tray_widget_sort               (XfceTrayWidget   *tray) 
G_GNUC_INTERNAL;
 

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to