[Xfce4-commits] <xfce4-panel:devel> Set the colormap of the socket to embed all remote windows.

Nick Schermer nick at xfce.org
Tue Aug 11 20:32:21 CEST 2009


Updating branch refs/heads/devel
         to 75da55c4abe7741125fb96d475f44f71909cff19 (commit)
       from af6d3e02b1614ce8b14a27a51e966fd1c7489663 (commit)

commit 75da55c4abe7741125fb96d475f44f71909cff19
Author: Nick Schermer <nick at xfce.org>
Date:   Thu May 21 18:31:28 2009 +0200

    Set the colormap of the socket to embed all remote windows.

 plugins/systray/systray-manager.c |   46 ++++++++++++++++++++++++++++++++++--
 wrapper/wrapper-plug.c            |    2 +-
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/plugins/systray/systray-manager.c b/plugins/systray/systray-manager.c
index 9be223b..f7f29c3 100644
--- a/plugins/systray/systray-manager.c
+++ b/plugins/systray/systray-manager.c
@@ -680,22 +680,63 @@ static void
 systray_manager_handle_dock_request (SystrayManager      *manager,
                                      XClientMessageEvent *xevent)
 {
-  GtkWidget *socket;
-  Window    *xwindow;
+  GtkWidget         *socket;
+  Window            *xwindow;
+  XWindowAttributes  attr;
+  GdkVisual         *visual;
+  GdkColormap       *colormap;
+  gint               result;
+  GdkScreen         *screen;
+  GdkDisplay        *display;
+  gboolean           release_colormap = FALSE;
 
   panel_return_if_fail (XFCE_IS_SYSTRAY_MANAGER (manager));
+  panel_return_if_fail (GTK_IS_INVISIBLE (manager->invisible));
 
   /* check if we already have this notification */
   if (g_hash_table_lookup (manager->sockets, GUINT_TO_POINTER (xevent->data.l[2])))
     return;
 
+  /* get the window attributes, leave if this fails */
+  display = gtk_widget_get_display (manager->invisible);
+  gdk_error_trap_push ();
+  result = XGetWindowAttributes (GDK_DISPLAY_XDISPLAY (display),
+                                 xevent->data.l[2], &attr);
+  if (gdk_error_trap_pop () != 0 || result == 0)
+    return;
+
+  /* get the windows visual */
+  screen = gtk_widget_get_screen (manager->invisible);
+  visual = gdk_x11_screen_lookup_visual (screen, attr.visual->visualid);
+  if (visual == NULL)
+    return;
+
+  /* get the correct colormap */
+  if (visual == gdk_screen_get_rgb_visual (screen))
+    colormap = gdk_screen_get_rgb_colormap (screen);
+  else if (visual == gdk_screen_get_rgba_visual (screen))
+    colormap = gdk_screen_get_rgba_colormap (screen);
+  else if (visual == gdk_screen_get_system_visual (screen))
+    colormap = gdk_screen_get_system_colormap (screen);
+  else
+    {
+      /* create custom colormap */
+      colormap = gdk_colormap_new (visual, FALSE);
+      release_colormap = TRUE;
+    }
+
   /* create a new socket */
   socket = gtk_socket_new ();
+  gtk_widget_set_colormap (GTK_WIDGET (socket), colormap);
 
   /* allocate and set the xwindow */
   xwindow = g_new (Window, 1);
   *xwindow = xevent->data.l[2];
 
+  /* release the custom colormap */
+  if (release_colormap)
+    g_object_unref (G_OBJECT (colormap));
+
   /* connect the xwindow data to the socket */
   g_object_set_qdata_full (G_OBJECT (socket), xwindow_quark, xwindow, g_free);
 
@@ -792,7 +833,6 @@ systray_manager_set_visual (SystrayManager *manager)
     }
 
   data[0] = XVisualIDFromVisual (xvisual);
-
   XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
                    GDK_WINDOW_XWINDOW (manager->invisible->window),
                    visual_atom,
diff --git a/wrapper/wrapper-plug.c b/wrapper/wrapper-plug.c
index 8311d45..416e9ca 100644
--- a/wrapper/wrapper-plug.c
+++ b/wrapper/wrapper-plug.c
@@ -86,7 +86,7 @@ wrapper_plug_init (WrapperPlug *plug)
 
   /* connect signal to monitor the compositor changes */
   g_signal_connect (G_OBJECT (plug), "composited-changed",
-                    G_CALLBACK (wrapper_plug_set_colormap), NULL);
+      G_CALLBACK (wrapper_plug_set_colormap), NULL);
 
   /* old versions of gtk don't support transparent tray icons, if we
    * set an argb colormap on the tray, the icons won't be embedded because



More information about the Xfce4-commits mailing list