How to move an SDL window (X11)

This has been asked so many times, I’ve added it to the FAQ:
Q: How do I move the SDL window in my program?

#include “SDL_syswm.h”

static void gtv_center_window(SDL_Surface *screen)
{
SDL_SysWMinfo info;

SDL_VERSION(&info.version);
if ( SDL_GetWMInfo(&info) > 0 ) {
    int x, y;
    int w, h;

#ifdef unix
if ( info.subsystem == SDL_SYSWM_X11 ) {
info.info.x11.lock_func();
w = DisplayWidth(info.info.x11.display,
DefaultScreen(info.info.x11.display));
h = DisplayHeight(info.info.x11.display,
DefaultScreen(info.info.x11.display));
x = (w - screen->w)/2;
y = (h - screen->h)/2;
XMoveWindow(info.info.x11.display, info.info.x11.wmwindow, x, y);
info.info.x11.unlock_func();
}
#else
#warning Need to implement these functions for other systems
#endif // unix
}
}

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

-= * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =-
To debug, or not to debug, that is the question! Whether
tis nobler in mind to suffer the slings and arrows of outrageous QA
testers, or take arms against a sea of user issues, and by compiling,
end them? To code, to sleep, no more, and by code to say we end the
heartache and thousand natural crashes players are heir to…A: Here is some code used by SMPEG’s gtv to center the window: