SDL and GTK+ together?

This is a bit of an odd one.
I’ve ported an editor for my game from DOS to SDL in Linux, using GTK+
for popup messages and dialog entries, but using SDL and some graphics
primitives for everything else.

The problem is this:

When the user clicks on OK for a GTK popup, something peculiar happens
to the SDL mouse routines, and the release of the mouse button is
never reported.

The functions affected are:

void IG_WaitForRelease()
{
int x,y,z,timeout;

z=1; // Kickstart the loop
timeout = 254;

while(z && timeout > 0)
{
I32_GetMouse(&x,&y,&z); // Defined below.
usleep(50000);
timeout–;
}

if(timeout < 1)
fprintf(DEBUGIO,“Timed out waiting for mouse, reports %d\n”,z);
}

void I32_GetMouse(int *x, int *y, int *z)
{
Uint8 sz;

sz = SDL_GetMouseState(x,y);
*z = 0;

// Translate mouse button to DOS format

if(sz & SDL_BUTTON(1))
*z |= 1;
if(sz & SDL_BUTTON(3))
*z |= 2;
if(sz & SDL_BUTTON(2))
*z |= 3;
}

Now using GTK+ seems like an odd way to do the interface, but the
real reason is because it allows the user to type in strings, with
the OS handling the keyboard map.

SDL’s keyboard interface is designed for games and other software
requiring multiple simultaneous keypresses. It makes life
difficult if you want to allow both cases of letters and punctuation,
because you’d have to do the keyboard mapping yourself for various
different countries.–
JP Morris - aka DOUG the Eagle (Dragon) -=UDIC=- DOUG-15 at bigfoot.com
Fun things to do with the Ultima games (http://ithe.cjb.net)
Developing a U6/U7 clone (http://fly.to/ire)
d+++ e+ N+ T++ Om U123456!7’!8!KA u++ uC+++ uF+++ uG---- uLB----
uA— nC+ nR---- nH+++ nP++ nI nPT nS nT wM- wC- y a(YEAR - 1976)

Now using GTK+ seems like an odd way to do the interface, but the
real reason is because it allows the user to type in strings, with
the OS handling the keyboard map.

SDL’s keyboard interface is designed for games and other software
requiring multiple simultaneous keypresses. It makes life
difficult if you want to allow both cases of letters and punctuation,
because you’d have to do the keyboard mapping yourself for various
different countries.

If you use SDL_EnableUNICODE() at the beginning of your program, you
get the normal SDL keyboard input, with the addition that the 'unicode’
member of the key event has the UNICODE translation of the key.

This has been used very successfully with no changes on international
keyboards, because the keyboard translation is done by the OS.

See ya!
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec