Implement SDL in GTK +

I have an application that uses GTK + to display some nice GUI, but I use SDL to display a small RGB frame buffer inside GTK +

I used the following code to get SDL in GTK +:

char SDL_windowhack[32]; sprintf(SDL_windowhack, "SDL_WINDOWID=%ld", GDK_WINDOW_XWINDOW(deviceWindow->window)); putenv(SDL_windowhack); 

Unfortunately, I also use SDL for keyboard and mouse events. The main thread that uses the SDL to update the image spawns the following stream:

 void *SDLEvent(void *arg) { SDL_Event event; while (1) { fprintf(stderr, "Test\n"); SDL_WaitEvent(&event); switch (event.type) { /* ... */ } } } 

I see that the print statement is executed twice, and then not. As soon as I complete the thread that uses the SDL to update the screen, the cycle in SDLEvent starts to run very fast again.

This code worked fine before I included SDL in GTK +, so I think GTK + might somehow block SDL?

Does anyone have any suggestions?

Thank you very much!

+4
source share
1 answer

Although I did not use SDL, but since you are looking for events, it seems that you are triggering two event loops. Gtk launches its own event loop, which handles events similar to those of the mouse and keyboard. I think you need to find a way to integrate both. Some searches led to the following link , where under the "Problem with Double event loop" section your problem was resolved (I think). Try adding the SDLEvent function as the SDLEvent function with g_idle_add as suggested in the link and see if it works.
Hope this helps!

+4
source

Source: https://habr.com/ru/post/1381413/


All Articles