[fpc-pascal] Linux : Using SDL with GTK2 ?
T.Guilleminot
tom at guilleminot.org
Fri Nov 16 00:49:54 CET 2007
Thanks for your answer. I'm a newbie so I still have a few questions :o) :
1. I'm unsure of chronology of things to do in the program body. Is the
following correct :
a) Create GTK stuff
b) SDL Hack/SDL_WINDOWID
c) SDL_INIT
d) Show GTK widgets
2. You mentioned "this is for gtk1 only. gtk2 is similar but different".
What to do for GTK2 ?
3. Which kind of GTK Object "APanel" can be ?
4. FPC complains on "handle". What's wrong ?
Free Pascal Compiler version 2.2.0 [2007/08/30] for i386
Target OS: Linux for i386
Compiling test.pas
test.pas(45,77) Error: Illegal qualifier
test.pas(45,77) Fatal: Syntax error, ")" expected but "identifier
HANDLE" found
Fatal: Compilation aborted
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not
specify a source file to be compiled)
Thanks Again.
Tom
Andrew Haines wrote:
> Tom wrote:
>
>> Hi,
>>
>> I'm desperately trying to build a application mixing GTK with SDL for *Linux*.
>>
>> I know that's not always recommended as it involves 2 listening loops but it
>> should work. I found some *C* snippets/applications (eg making window hacks) but
>> I'm unable to translate them into Pascal.
>> My goal is to display Joystick events into a GTK2 window. Ideally I would like
>> to use Jedi-SDL with GTK2. Of course either GTK2 or SDL used alone works fine.
>> Does anyone have some example to achieve this ?
>>
>>
>>
>
> uses sdl, gtk, gdk, X;
>
> var
> SDLWindowHack: String
> X11Window: X.TWindow;
> begin
> ...
> // this is for gtk1 only. gtk2 is similar but different
> X11Window :=
> GDK_WINDOW_XWINDOW(PGdkWindowPrivate(GTK_WIDGET(APanel.Handle)^.window ) );
>
> SDLWindowHack := 'SDL_WINDOWID='+ IntToStr(PtrUint(X11Window));
> putenv (PChar(SDLWindowhack));
> end;
>
>
> You have to for sure set the environment variable SDL_WINDOWID before
> you create the window with sdl and maybe before sdl_init.
>
> IIRC using this method somehow makes sdl not listen for keyboard/mouse
> events because it is using a window you have made and expects you to
> already be processing those events in some way.
>
> The other way to embed a window is to create the window normally with
> sdl without setting SDL_WINDOWID and then accessing the PSurface record
> get the X11 window ID and use XReparentWindow to embed it into your app.
> unfortunatly the window is created outside your app and is briefly
> visible before you have stuck it inside your app. Sdl will behave as if
> the window is not embedded in your app. Setting keyboard focus and mouse
> focus in the window may have quirks.
>
> Overall I think the first method is best.
>
> Setting the SDL_WINDOWID works on windows too if you set it to the
> (hwnd)TWinControl.Handle of whatever component you want sdl to draw to.
>
> Andrew
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20071116/a4740ac7/attachment.html>
More information about the fpc-pascal
mailing list