[Xfce4-commits] <xfce4-panel:master> Move some systray code around without functionality changes.

Nick Schermer noreply at xfce.org
Sun Jan 23 12:10:01 CET 2011


Updating branch refs/heads/master
         to ccf4636bb379b8a0d49032fd032b3b29dd1e7528 (commit)
       from 2a004cc07a36f9a738b04ff3ca03730f8900e13e (commit)

commit ccf4636bb379b8a0d49032fd032b3b29dd1e7528
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Jan 22 13:13:59 2011 +0100

    Move some systray code around without functionality changes.
    
    - Remove from socket hashtable before telling others the
      icon will be removed, this to make sure the window
      still exists.
    - Move composited detection to socket init, no need to do this
      during realize, since we restart the tray on compositing
      changes anyway.

 plugins/systray/systray-manager.c |   12 +++-------
 plugins/systray/systray-socket.c  |   41 ++++++++++++++++++++++++------------
 2 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/plugins/systray/systray-manager.c b/plugins/systray/systray-manager.c
index 6a18f9e..d485bfa 100644
--- a/plugins/systray/systray-manager.c
+++ b/plugins/systray/systray-manager.c
@@ -214,8 +214,6 @@ systray_manager_init (SystrayManager *manager)
   manager->invisible = NULL;
   manager->orientation = GTK_ORIENTATION_HORIZONTAL;
   manager->messages = NULL;
-
-  /* create new sockets table */
   manager->sockets = g_hash_table_new (NULL, NULL);
 }
 
@@ -738,15 +736,13 @@ systray_manager_handle_undock_request (GtkSocket *socket,
 
   panel_return_val_if_fail (XFCE_IS_SYSTRAY_MANAGER (manager), FALSE);
 
-  /* emit signal that the socket will be removed */
-  g_signal_emit (manager, systray_manager_signals[ICON_REMOVED], 0, socket);
-
-  /* get the xwindow */
-  window = systray_socket_get_window (XFCE_SYSTRAY_SOCKET (socket));
-
   /* remove the socket from the list */
+  window = systray_socket_get_window (XFCE_SYSTRAY_SOCKET (socket));
   g_hash_table_remove (manager->sockets, GUINT_TO_POINTER (*window));
 
+  /* emit signal that the socket will be removed */
+  g_signal_emit (manager, systray_manager_signals[ICON_REMOVED], 0, socket);
+
   /* destroy the socket */
   return FALSE;
 }
diff --git a/plugins/systray/systray-socket.c b/plugins/systray/systray-socket.c
index 70496b3..3e5e67b 100644
--- a/plugins/systray/systray-socket.c
+++ b/plugins/systray/systray-socket.c
@@ -122,35 +122,34 @@ static void
 systray_socket_realize (GtkWidget *widget)
 {
   SystraySocket *socket = XFCE_SYSTRAY_SOCKET (widget);
-  GdkVisual     *visual;
   GdkColor       transparent = { 0, 0, 0, 0 };
+  GdkWindow     *window;
 
   GTK_WIDGET_CLASS (systray_socket_parent_class)->realize (widget);
 
-  visual = gtk_widget_get_visual (widget);
-  if (visual->red_prec + visual->blue_prec + visual->green_prec < visual->depth
-      && gdk_display_supports_composite (gtk_widget_get_display (widget)))
+  window = gtk_widget_get_window (widget);
+
+  if (socket->is_composited)
     {
-      gdk_window_set_background (widget->window, &transparent);
-      gdk_window_set_composited (widget->window, TRUE);
+      gdk_window_set_background (window, &transparent);
+      gdk_window_set_composited (window, TRUE);
 
-      socket->is_composited = TRUE;
       socket->parent_relative_bg = FALSE;
     }
-  else if (visual == gdk_drawable_get_visual (
-               GDK_DRAWABLE (gdk_window_get_parent (widget->window))))
+  else if (gtk_widget_get_visual (widget) ==
+           gdk_drawable_get_visual (GDK_DRAWABLE (gdk_window_get_parent (window))))
     {
-      gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
+      gdk_window_set_back_pixmap (window, NULL, TRUE);
 
-      socket->is_composited = FALSE;
       socket->parent_relative_bg = TRUE;
     }
   else
     {
-      socket->is_composited = FALSE;
       socket->parent_relative_bg = FALSE;
     }
 
+  gdk_window_set_composited (window, socket->is_composited);
+
   gtk_widget_set_app_paintable (widget,
       socket->parent_relative_bg || socket->is_composited);
 
@@ -197,6 +196,7 @@ systray_socket_size_allocate (GtkWidget     *widget,
 }
 
 
+
 static gboolean
 systray_socket_expose_event (GtkWidget      *widget,
                              GdkEventExpose *event)
@@ -248,6 +248,7 @@ systray_socket_new (GdkScreen       *screen,
   GdkVisual         *visual;
   GdkColormap       *colormap;
   gboolean           release_colormap = FALSE;
+  gint               red_prec, green_prec, blue_prec, depth;
 
   panel_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
 
@@ -257,12 +258,13 @@ systray_socket_new (GdkScreen       *screen,
   result = XGetWindowAttributes (GDK_DISPLAY_XDISPLAY (display),
                                  window, &attr);
 
-  /* leave on an error or is the window does not exist */
+  /* leave on an error or if the window does not exist */
   if (gdk_error_trap_pop () != 0 || result == 0)
     return NULL;
 
   /* get the windows visual */
   visual = gdk_x11_screen_lookup_visual (screen, attr.visual->visualid);
+  panel_return_val_if_fail (visual == NULL || GDK_IS_VISUAL (visual), NULL);
   if (G_UNLIKELY (visual == NULL))
     return NULL;
 
@@ -282,13 +284,24 @@ systray_socket_new (GdkScreen       *screen,
 
   /* create a new socket */
   socket = g_object_new (XFCE_TYPE_SYSTRAY_SOCKET, NULL);
-  gtk_widget_set_colormap (GTK_WIDGET (socket), colormap);
   socket->window = window;
+  socket->is_composited = FALSE;
+  gtk_widget_set_colormap (GTK_WIDGET (socket), colormap);
 
   /* release the custom colormap */
   if (release_colormap)
     g_object_unref (G_OBJECT (colormap));
 
+  /* check if there is an alpha channel in the visual */
+  gdk_visual_get_red_pixel_details (visual, NULL, NULL, &red_prec);
+  gdk_visual_get_green_pixel_details (visual, NULL, NULL, &green_prec);
+  gdk_visual_get_blue_pixel_details (visual, NULL, NULL, &blue_prec);
+  depth = gdk_visual_get_depth (visual);
+
+  if (red_prec + blue_prec + green_prec < depth
+      && gdk_display_supports_composite (gdk_screen_get_display (screen)))
+    socket->is_composited = TRUE;
+
   return GTK_WIDGET (socket);
 }
 



More information about the Xfce4-commits mailing list