SDL and Xshape

I’ve tried to port the sdl/gtk-demo with the xshape-hole (
http://www.libsdl.org/projects/gtk-demo/ ) to plain SDL but I cant get it to
work. I just get a wandering black hole, any suggestions? Some additional
layer that needs punching through when not using GTK or something?

Here’s the code:

// ------------------------------------------------------------------------
// apabepa.c
//
// Build with (?):
// gcc apabepa.c -o test -lXi -lXext -lX11 -lm -lSDL -lpthread && ./test
// ------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>

#include <X11/Xlib.h>
#include <X11/extensions/shape.h>
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>

#define WIDTH 400
#define HEIGHT 500

Pixmap shape_mask = 0; // Shape mask
GC shape_gc; // Graphics context
int use_shape = 1;
int shape_x = 0; // X-coord
int shape_y = 0; // Y-coord
int shape_dx = 0; // Left/Right?
int shape_dy = 0; // Up/down?

SDL_SysWMinfo info;
SDL_Surface *screen;
SDL_Event event;

void ResizeShape()
{
Display *dpy;
XGCValues GCvalue;

if ( !use_shape )
	return;
//dpy = GDK_WINDOW_XDISPLAY(mainwin->window);
dpy = info.info.x11.display;
if ( shape_mask ) {
            XFreePixmap(dpy, shape_mask);
            XFreeGC(dpy, shape_gc);
}

shape_mask = XCreatePixmap(dpy, DefaultRootWindow(dpy), screen->w, 

screen->h, 1);
GCvalue.function = GXcopy;
shape_gc = XCreateGC(dpy, shape_mask, GCFunction, &GCvalue);
XSync(dpy, False);
}

void ShapeWindow(void)
{
#define RADIUS 24
Display *dpy;
Window win;
int x, y, i;
void (*set_bit)(XImage *image, int x, int y);
int (*get_bit)(XImage *image, int x, int y);

if ( !use_shape )
	return;

// Only move the shape every 100'th time through
{ static int step = 0;
  if ( (step++)%100 != 0 )
	return;
}

// Set the window and display
//dpy = GDK_WINDOW_XDISPLAY(mainwin->window);
//win = GDK_WINDOW_XWINDOW(mainwin->window);
dpy = info.info.x11.display;
win = info.info.x11.window;

// Bounce the hole when it hits the edge
if ( shape_x == 0 ) {
	shape_dx = 1;
}
if ( shape_x >= (screen->w-(2*RADIUS)) ) {
	shape_x = (screen->w-(2*RADIUS));
	shape_dx = -1;
}
if ( shape_y == 0 ) {
	shape_dy = 1;
}
if ( shape_y >= (screen->h-(2*RADIUS)) ) {
	shape_y = (screen->h-(2*RADIUS));
	shape_dy = -1;
}

// Move the hole around
shape_x += shape_dx;
shape_y += shape_dy;

// Now put the hole in the mask
//dpy = GDK_WINDOW_XDISPLAY(mainwin->window);
dpy = info.info.x11.display;
XSetForeground(dpy, shape_gc, ~0);
XFillRectangle(dpy, shape_mask, shape_gc, 0, 0, screen->w, screen->h);
XSetForeground(dpy, shape_gc, 0);

//#ifdef SQUARE_HOLE
// XFillRectangle(dpy, shape_mask, shape_gc, shape_x, shape_y, 2RADIUS,
2
RADIUS);
//#else
XFillArc(dpy, shape_mask, shape_gc, shape_x, shape_y, 2RADIUS, 2RADIUS,
0, 360*64);
//#endif

// Set the mask on the window
XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, shape_mask, ShapeSet);

// Update the whole screen
SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);

}

// ------------------------------------------------------------------------
// int main( int argc, char argv[] )
//
// ------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
// initialize SDL
SDL_Init( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO );
screen = SDL_SetVideoMode( WIDTH, HEIGHT, 0, 0 );

printf("Set %dx%d at %d bpp mode\n", screen->w, screen->h, 

screen->format->BitsPerPixel);

SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
SDL_VERSION(&info.version);
SDL_GetWMInfo(&info);
ResizeShape();

while(1) {
	ShapeWindow();

	while( SDL_PollEvent(&event)) {
		switch(event.type) {
			case SDL_QUIT:
				SDL_Quit();
				exit(0);
				break;
			default:
				break;
		}
	}
}

return 0;

}_________________________________________________________________
Kommer solen att skina imorgon? http://www.msn.se/weather/