Shaped SDL window

Hi there,

I am trying to create a shaped SDL window using the X11 shape extension.
So far nothing happens … maybe someone has an idea what I am missing.
The code follows the xeyes demo that is part of the XFree sources.

Below is the code that I am using to enable the shape extension. The
input is a 8bit mask surface in black and white.

Ciao
Andreas----

void SetWindowShape (SDL_Surface *mask)
{
int x,y;
Uint8 *curpos;
GC shapeGC;
Pixmap shape_mask;
SDL_SysWMinfo wmi;
Display *display;
Window window;
XGCValues xgcv;

/* Get the X window handle */
SDL_VERSION(&wmi.version);
if (!SDL_GetWMInfo(&wmi)) {
return;
} else {
display=wmi.info.x11.display;
window=wmi.info.x11.window;
}

/* Create shape pixmap */
shape_mask = XCreatePixmap (display, window, mask->w, mask->h, 1);
shapeGC = XCreateGC (display, shape_mask, 0, &xgcv);
XSetForeground (display, shapeGC, 0);
XFillRectangle (display, shape_mask, shapeGC, 0, 0, mask->w, mask->h);
XSetForeground (display, shapeGC, 1);

/* Scan through the mask surface to create shape pixmap */
curpos=(Uint8 *)mask->pixels;
for (y=0; yh; y++) {
for (x=0; xw; x++) {
if (curpos!=0) {
XDrawPoint(display, shape_mask, shapeGC, x, y);
}
curpos++;
}
/
Apply pixmap */
XShapeCombineMask (display, window, ShapeBounding, 0, 0, shape_mask,
ShapeSet);
XFreePixmap (display, shape_mask);

}


| Andreas Schiffler aschiffler at home.com |
| Senior Systems Engineer - Deskplayer Inc., Buffalo |
| 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
| +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |

Hi there,

I am trying to create a shaped SDL window using the X11 shape extension.
So far nothing happens … maybe someone has an idea what I am missing.

Try shaping wmwindow instead of window. I haven’t tried it, so let me
know if it works.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sam Lantinga wrote:

I am trying to create a shaped SDL window using the X11 shape extension.
So far nothing happens … maybe someone has an idea what I am missing.

Try shaping wmwindow instead of window. I haven’t tried it, so let me
know if it works.

Yes, that worked! Thanks for the tip …

Except now it crashes the Xserver hard when I click on the windows menu bar.
So something is still missing … I am not sure if there is more code I need
to add (event handler for resizing maybe), or if it is a SDL or XFree issue.

What does SDL do when I drag the window?

Ciao
Andreas–
| Andreas Schiffler aschiffler at home.com |
| Senior Systems Engineer - Deskplayer Inc., Buffalo |
| 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
| +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |

Except now it crashes the Xserver hard when I click on the windows menu bar.
So something is still missing … I am not sure if there is more code I need
to add (event handler for resizing maybe), or if it is a SDL or XFree issue.

What does SDL do when I drag the window?

Nothing, unless you add SDL_RESIZABLE to the video flags.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software