Screen capture troubles

Bram Biesbrouck b at beligum.org
Wed Sep 28 16:17:38 PDT 2005


Hi,

First of all, I would like to introduce myself to this list. My name is Bram 
from Belgium and I'm in the middle of developing a(nother) screen capturing 
program for GNU/Linux.

I'm quite new to using Xlib and therefore, I'm having some beginner problems 
and I hope someone here could help me out with one of them. Maybe this isn't 
the right list for that kind of questions, but I couldn't find an 
alternative, so please accept my apologies if so.

On the bottom is the code for a routine that should select a window on the 
screen, make a pixmap of it and write that pixmap toa XPM file.

When I try to run this code, sometimes I get a correct dump of the window and 
at other times, the colors are a mess. I think it has something to do with 
colormaps (I have read the tutorials and docs, but I couldn't figure out all 
of it), but I'm stuck.

Please help me out.

Bram

-------START CODE----------
display = XOpenDisplay(DEFAULT_DISPLAY);
if (display==NULL)
	fatalError("Error while fetching display.");
screen = DefaultScreen(display);
rootWin = XRootWindow(display, screen);
if (!XGetWindowAttributes(display, rootWin, &rootAttr))
	fatalError("Couldn't retrieve rootwindow information.");
    
targetWindow = SelectWindow(display);

if (!XGetWindowAttributes(display, targetWindow, &targetAttr))
	fatalError("Couldn't retrieve window information.");
    
targetWindow = rootWin;
    
gcValuemask = GCFunction | GCSubwindowMode;
gcValues.function = GXcopy;
gcValues.subwindow_mode = IncludeInferiors;
winGc = XCreateGC(display, targetWindow, gcValuemask, &gcValues);
    
dumpPixmap = XCreatePixmap(display, targetWindow, targetAttr.width, 
targetAttr.height, targetAttr.depth);
    
XCopyArea(display, targetWindow, dumpPixmap, winGc, targetAttr.x, 
targetAttr.y, targetAttr.width, targetAttr.height, 0, 0);

XpmWriteFileFromPixmap(display, DUMP_FILENAME, dumpPixmap, (Pixmap)0, NULL);
    
XCloseDisplay(display);
-------END CODE---------



More information about the xorg mailing list