From e980c0380f96c0eea185e86a464f140b012e2818 Mon Sep 17 00:00:00 2001
From: Timothy Pearson <kb9vqf@pearsoncomputing.net>
Date: Thu, 2 May 2013 14:20:33 -0500
Subject: Automated update from Qt3

---
 src/kernel/qwidget_x11.cpp | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/kernel/qwidget_x11.cpp b/src/kernel/qwidget_x11.cpp
index 67463d0cf..1479342e9 100644
--- a/src/kernel/qwidget_x11.cpp
+++ b/src/kernel/qwidget_x11.cpp
@@ -44,6 +44,7 @@
 #include "ntqpaintdevicemetrics.h"
 #include "ntqpainter.h"
 #include "ntqbitmap.h"
+#include "ntqimage.h"
 #include "ntqobjectlist.h"
 #include "ntqlayout.h"
 #include "ntqtextcodec.h"
@@ -1310,14 +1311,47 @@ void TQWidget::setIcon( const TQPixmap &pixmap )
     }
     Pixmap icon_pixmap = 0;
     Pixmap mask_pixmap = 0;
+    TQPixmap* pm = NULL;
     if ( !pixmap.isNull() ) {
-	TQPixmap* pm = new TQPixmap( pixmap );
+	if (pixmap.depth() == 24) {
+	    pm = new TQPixmap( pixmap );
+	}
+	else {
+	    // With most window managers, only 24-bit icon pixmaps are allowed in the WM hints, otherwise corrupt icons will be displayed
+	    // Convert provided pixmaps to 24-bit here
+	    int w = pixmap.width();
+	    int h = pixmap.height();
+	    pm = new TQPixmap( pixmap.width(), pixmap.height(), 24 );
+	    TQImage iconImage = pixmap.convertToImage();
+
+	    // Load the new 24-bit RGB pixmap with data
+	    GC gc;
+	    pm->detach();
+	    TQt::HANDLE pmHandle = pm->handle();
+	    gc = XCreateGC(x11Display(), pmHandle, 0, 0);
+	    for (int y = 0; y < h; ++y) {
+		TQRgb *ls = (TQRgb *)iconImage.scanLine( y );
+		for (int x = 0; x < w; ++x) {
+		    TQRgb l = ls[x];
+		    int r = int( tqRed( l ) );
+		    int g = int( tqGreen( l ) );
+		    int b = int( tqBlue( l ) );
+		    ls[x] = tqRgb( r, g, b );
+		    XSetForeground(x11Display(), gc, (r << 16) | (g << 8) | b );
+		    XDrawPoint(x11Display(), pmHandle, gc, x, y);
+		}
+	    }
+	    XFreeGC(x11Display(), gc);
+	}
+
 	extra->topextra->icon = pm;
-	if ( !pm->mask() )
+	if ( !pm->mask() ) {
 	    pm->setMask( pm->createHeuristicMask() ); // may do detach()
+	}
 	icon_pixmap = pm->handle();
-	if ( pm->mask() )
+	if ( pm->mask() ) {
 	    mask_pixmap = pm->mask()->handle();
+	}
     }
     XWMHints *h = XGetWMHints( x11Display(), winId() );
     XWMHints  wm_hints;
-- 
cgit v1.2.3

