3

config: archlinux with awesome desktop environment

I just installed sdl2, and tried to run this sample code: https://github.com/xyproto/hello_sdl2/blob/master/c%2B%2B/main.cpp

The result is an empty window (I can see my console through it) in the middle of the screen. Even when I hit mod4+Enter, it doesn't tile up nicely with the others. Why is that?

(I updated my system, reinstalled sdl2. I also couldn't find any relevant hit browsing google.)

dyarob
  • 175
  • 1
  • 7
  • 1
    Try [this app](https://gitlab.com/sdl2test/sdl2test/). I wrote it some time ago. It does just the same as yours, but has `SDL_PollEvent()` ([here](https://gitlab.com/sdl2test/sdl2test/blob/master/src/window.c#L83)). – Sam Protsenko Mar 29 '15 at 17:48
  • @Sam Thanks, the window's content get displayed perfectly now! Awesome tiling doesn't, but that's another problem... – dyarob Mar 30 '15 at 04:30
  • 1
    I guess for your window to work nice with tiling WM, you should make it (your window) resize-able, not fixed-sized. – Sam Protsenko Mar 31 '15 at 20:42
  • Please consider making a pull request for the `hello_sdl2` project to fix this. – Alexander Oct 16 '15 at 13:27

1 Answers1

5

All windowing systems require you to handle messages by pumping a message queue. See this chapter for some SDL specific examples but the essence is call SDL_PollEvent or some other SDL function regularly to process any events. Your code just delays for some time. You can't put your main thread to sleep and expect a window system to be happy with that. They run on events. When the window gets mapped, there is an event, then another to tell the window to paint itself or for keyboard input. Pump the event queue while waiting.

patthoyts
  • 32,320
  • 3
  • 62
  • 93