# SDL and GTK+ together?

**URL:** <https://discourse.libsdl.org/t/sdl-and-gtk-together/1337>\
**Category:** SDL Development\
**Created:** [December 8, 1999, 9:19pm UTC](https://discourse.libsdl.org/t/sdl-and-gtk-together/1337 "1999-12-08T21:19:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JP\_Morris](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@JP\_Morris](https://discourse.libsdl.org/u/JP_Morris)\
**Post date:** [December 8, 1999, 9:19pm UTC](https://discourse.libsdl.org/t/sdl-and-gtk-together/1337/1 "1999-12-08T21:19:22Z")

</div>

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](http://bigfoot.com)  
Fun things to do with the Ultima games ([http://ithe.cjb.net](http://ithe.cjb.net))  
Developing a U6/U7 clone ([http://fly.to/ire](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)

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [December 8, 1999, 9:44pm UTC](https://discourse.libsdl.org/t/sdl-and-gtk-together/1337/2 "1999-12-08T21:44:32Z")

</div>

> 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](http://devolution.com))

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