summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2011-03-21 18:45:20 -0400
committerAlberts Muktupāvels <alberts.muktupavels@gmail.com>2016-05-23 23:34:23 +0300
commita2250539217fba3ba906961901e6133b01189eea (patch)
tree684603b6a8bd9de72519a859ce6b08d5434e34fa
parente2ee54b388d9c3e7eaee45b07609b1e586159db6 (diff)
downloadmetacity-a2250539217fba3ba906961901e6133b01189eea.tar.gz
iconcache: Correctly interpret monochrome icons
Getting the contents of a depth-1 pixmap through cairo gives us an alpha pixmap. We need to convert to a monochrome pixmap as is expected by the ICCCM definition of WM_HINTS. https://bugzilla.gnome.org/show_bug.cgi?id=641975
-rw-r--r--src/core/iconcache.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/core/iconcache.c b/src/core/iconcache.c
index 2978d4d4..4647ca88 100644
--- a/src/core/iconcache.c
+++ b/src/core/iconcache.c
@@ -321,6 +321,40 @@ get_pixmap_geometry (MetaDisplay *display,
*d = depth;
}
+static void
+apply_foreground_background (GdkPixbuf *pixbuf)
+{
+ int w, h;
+ int i, j;
+ guchar *pixels;
+ int stride;
+
+ w = gdk_pixbuf_get_width (pixbuf);
+ h = gdk_pixbuf_get_height (pixbuf);
+ pixels = gdk_pixbuf_get_pixels (pixbuf);
+ stride = gdk_pixbuf_get_rowstride (pixbuf);
+
+ i = 0;
+ while (i < h)
+ {
+ j = 0;
+ while (j < w)
+ {
+ guchar *p = pixels + i * stride + j * 4;
+ if (p[3] == 0)
+ p[0] = p[1] = p[2] = 0xff; /* white background */
+ else
+ p[0] = p[1] = p[2] = 0x00; /* black foreground */
+
+ p[3] = 0xff;
+
+ ++j;
+ }
+
+ ++i;
+ }
+}
+
static GdkPixbuf*
apply_mask (GdkPixbuf *pixbuf,
GdkPixbuf *mask)
@@ -377,19 +411,25 @@ try_pixmap_and_mask (MetaDisplay *display,
{
GdkPixbuf *unscaled = NULL;
GdkPixbuf *mask = NULL;
- int w, h;
+ int w, h, d;
if (src_pixmap == None)
return FALSE;
meta_error_trap_push (display);
- get_pixmap_geometry (display, src_pixmap, &w, &h, NULL);
+ get_pixmap_geometry (display, src_pixmap, &w, &h, &d);
unscaled = meta_gdk_pixbuf_get_from_pixmap (src_pixmap,
0, 0,
w, h);
+ /* A depth 1 pixmap has 0 background, and 1 foreground, but
+ * cairo and meta_gdk_pixbuf_get_from_pixmap consider it
+ * to be 0 transparent, 1 opaque */
+ if (d == 1)
+ apply_foreground_background (unscaled);
+
if (unscaled && src_mask != None)
{
get_pixmap_geometry (display, src_mask, &w, &h, NULL);