I want to display the contents of a window in a QWidget (or QPixmap) using XComposite and XRender. The problem I am facing is that I cannot get the image in a QWidget. The code below was written using the following tutorial: http://ktown.kde.org/~fredrik/composite_howto.html
The window identifier is hardcoded, so any other window identifier can be used. The QWidget window that opens does not display the contents of the original window, but simply shows an empty gray rectangle. The same, if I use QPixmap, it contains only a black rectangle and nothing else. XRender support is included.
What am I missing here?
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
Display *dpy = XOpenDisplay( getenv("DISPLAY") );
Window window = 2097154;
XCompositeRedirectWindow( dpy, window, CompositeRedirectManual );
XWindowAttributes attr;
XGetWindowAttributes( dpy, window, &attr );
XRenderPictFormat *format = XRenderFindVisualFormat( dpy, attr.visual );
bool hasAlpha = ( format->type == PictTypeDirect && format->direct.alphaMask );
int x = attr.x;
int y = attr.y;
int width = attr.width;
int height = attr.height;
qDebug() << hasAlpha << x << y << width << height;
XRenderPictureAttributes pa;
pa.subwindow_mode = IncludeInferiors; // Don't clip child widgets
QWidget widget;
widget.setGeometry( 100, 100, 500, 500 );
widget.show();
Picture picture = XRenderCreatePicture( dpy, window, format, CPSubwindowMode, &pa );
XRenderComposite( dpy, PictOpSrc, picture, None,
widget.x11PictureHandle(), 0, 0, 0, 0, 0, 0, 500, 500 );
XRenderFreePicture( dpy, picture );
return app.exec();
}