playground/base/plasma/applets/systray-refactor/core/fdo

Jason Stubbs jasonbstubbs at gmail.com
Sat Aug 16 18:57:51 CEST 2008


SVN commit 848034 by jstubbs:

This code doesn't serve it's purpose, but I'd like others to have a look at it
so I'm throwing it into subversion for the time being.

The purpose is to do ParentRelative background-pixmap manually. No X errors
are mentioned on the console and there's no crashes but nothing is actually
happening. When trying to set the background-pixmap attribute during window
creation however, the creation fails and crashes - but still with no visible
X errors.

By the way, this rewrite is pretty much ready, other than a severe lack of
comments. Will follow up later with a few questions, but if anybody would
like to take a look and let me know of issues in advance, I'd greatly
appreciate it.

CCMAIL: plasma-devel at kde.org


 M  +50 -0     x11embedcontainer.cpp  
 M  +3 -0      x11embedcontainer.h  


--- trunk/playground/base/plasma/applets/systray-refactor/core/fdo/x11embedcontainer.cpp #848033:848034
@@ -29,6 +29,7 @@
 #include <QX11Info>
 
 // Xlib
+#include <X11/Xutil.h>
 #include <X11/Xlib.h>
 
 
@@ -105,6 +106,55 @@
 }
 
 
+void
+X11EmbedContainer::paintEvent(QPaintEvent* event)
+{
+    QX11EmbedContainer::paintEvent(event);
+
+    if (clientWinId()) {
+        Display* display = QX11Info::display();
+
+        XWindowAttributes attr;
+        XGetWindowAttributes(display, clientWinId(), &attr);
+
+        QImage srcImage;
+        switch (attr.depth) {
+        case 32:
+            srcImage = QImage(size(), QImage::Format_ARGB32);
+            break;
+        case 24:
+            srcImage = QImage(size(), QImage::Format_RGB32);
+            break;
+        case 16:
+            srcImage = QImage(size(), QImage::Format_RGB16);
+            break;
+        default:
+            return;
+        }
+
+        parentWidget()->render(&srcImage, QPoint(0, 0), geometry(), QWidget::DrawWindowBackground);
+
+        char* data = (char*)malloc(srcImage.numBytes());
+        memcpy(data, srcImage.bits(), srcImage.numBytes());
+
+        XImage* bgImage = XCreateImage(display, attr.visual, attr.depth, ZPixmap, 0,
+                data, srcImage.width(), srcImage.height(), srcImage.depth(), srcImage.bytesPerLine());
+
+        Pixmap bg = XCreatePixmap(display, DefaultScreen(display), attr.depth, srcImage.width(), srcImage.height());
+
+        GC gc = XCreateGC(display, bg, 0, 0);
+        XPutImage(display, bg, gc, bgImage, 0, 0, 0, 0, srcImage.width(), srcImage.height());
+        XFreeGC(display, gc);
+
+        // This frees the malloc'd data above too
+        XDestroyImage(bgImage);
+
+        XSetWindowBackgroundPixmap(display, clientWinId(), bg);
+        XFreePixmap(display, bg);
+    }
+}
+
+
 };
 };
 
--- trunk/playground/base/plasma/applets/systray-refactor/core/fdo/x11embedcontainer.h #848033:848034
@@ -39,6 +39,9 @@
     X11EmbedContainer(QWidget* parent = 0);
 
     void embedClient(WId id);
+
+protected:
+    void paintEvent(QPaintEvent* event);
 };
 
 };


More information about the Plasma-devel mailing list