[banshee/stable-1.8] X11NotificationArea: Enhance check for RGBA visual (bgo#638477)



commit 75a5e306659d3f7bc57d867edb0d2169af30397a
Author: Christian Krause <chkr plauener de>
Date:   Sun Jan 2 01:43:29 2011 +0100

    X11NotificationArea: Enhance check for RGBA visual (bgo#638477)
    
    Compare the sum of the precisions of all colors with the depth of the
    visual.
    
    This uses functions that are only available in gdk-x11 >= 2.22,
    so we only do it in this case. Users with an older version of gdk-x11
    will still have the bug, but it improves the situation quite a bit.
    
    Signed-off-by: Bertrand Lorentz <bertrand lorentz gmail com>

 configure.ac                                       |    4 ++
 .../X11NotificationArea.cs                         |   31 ++++++++++++++++++-
 .../Banshee.NotificationArea/Makefile.am           |    4 ++
 3 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 57d50f3..0e87990 100644
--- a/configure.ac
+++ b/configure.ac
@@ -99,6 +99,10 @@ else
 fi
 AC_SUBST(BANSHEE_DESKTOP_NAME)
 
+dnl Check for gdk-x11 >= 2.22 for NotificationArea extension, bgo#638477
+PKG_CHECK_MODULES(GDK_2_22, gdk-x11-2.0 >= 2.22, have_gdk_2_22=yes, have_gdk_2_22=no)
+AM_CONDITIONAL(HAVE_GDK_2_22, test "x$have_gdk_2_22" = "xyes")
+
 dnl NDesk DBus libraries
 BANSHEE_CHECK_NDESK_DBUS
 
diff --git a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/X11NotificationArea.cs b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/X11NotificationArea.cs
index cf13447..57edd92 100644
--- a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/X11NotificationArea.cs
+++ b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/X11NotificationArea.cs
@@ -421,9 +421,22 @@ public class X11NotificationArea : Plug
             visual = GLib.Object.GetObject (raw_ret) as Gdk.Visual;
         }
 
-        // TODO the proper check is (visual->red_prec + visual->blue_prec + visual->green_prec < visual->depth)
-        // but this seems to work
+#if HAVE_GDK_2_22
+        IntPtr r_mask, r_shift, r_precision;
+        IntPtr g_mask, g_shift, g_precision;
+        IntPtr b_mask, b_shift, b_precision;
+
+        if (visual == null) {
+            visual_is_rgba = false;
+        } else {
+            gdk_visual_get_red_pixel_details(visual.Handle, out r_mask, out r_shift, out  r_precision);
+            gdk_visual_get_green_pixel_details(visual.Handle, out g_mask, out g_shift, out  g_precision);
+            gdk_visual_get_blue_pixel_details(visual.Handle, out b_mask, out b_shift, out  b_precision);
+            visual_is_rgba = ((int)r_precision + (int)g_precision + (int)b_precision) < gdk_visual_get_depth(visual.Handle);
+        }
+#else
         visual_is_rgba = visual != null && visual == Screen.RgbaVisual;
+#endif
 
         // we can't be double-buffered when we aren't using a real RGBA visual
         DoubleBuffered = visual_is_rgba;
@@ -433,6 +446,20 @@ public class X11NotificationArea : Plug
         }
     }
 
+#if HAVE_GDK_2_22
+    [DllImport ("libgdk-x11-2.0.so.0")]
+    private static extern int gdk_visual_get_depth(IntPtr visual);
+
+    [DllImport ("libgdk-x11-2.0.so.0")]
+    private static extern void gdk_visual_get_red_pixel_details(IntPtr visual, out IntPtr mask, out IntPtr shift, out IntPtr precision);
+
+    [DllImport ("libgdk-x11-2.0.so.0")]
+    private static extern void gdk_visual_get_green_pixel_details(IntPtr visual, out IntPtr mask, out IntPtr shift, out IntPtr precision);
+
+    [DllImport ("libgdk-x11-2.0.so.0")]
+    private static extern void gdk_visual_get_blue_pixel_details(IntPtr visual, out IntPtr mask, out IntPtr shift, out IntPtr precision);
+#endif
+
     [DllImport ("libgdk-x11-2.0.so.0")]
     private static extern IntPtr gdk_x11_screen_lookup_visual (IntPtr screen, int visual_id);
 
diff --git a/src/Extensions/Banshee.NotificationArea/Makefile.am b/src/Extensions/Banshee.NotificationArea/Makefile.am
index 819e587..b499244 100644
--- a/src/Extensions/Banshee.NotificationArea/Makefile.am
+++ b/src/Extensions/Banshee.NotificationArea/Makefile.am
@@ -5,6 +5,10 @@ GMCS_FLAGS+="-define:INTERNAL_NOTIFY_SHARP"
 NOTIFY_SHARP_LIBS = 
 endif
 
+if HAVE_GDK_2_22
+GMCS_FLAGS+= "-define:HAVE_GDK_2_22"
+endif
+
 ASSEMBLY = Banshee.NotificationArea
 TARGET = library
 LINK = $(REF_EXTENSION_NOTIFICATIONAREA) $(NOTIFY_SHARP_LIBS)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]