SDL

SDL (Simple DirectMedia Layer) is a cross-platform multimedia framework. It has suport fro Wayland since version 2.0.2.

Resources

Installing

Writing SDL applications requires the RPM package SDL2-devel under Fedora and libsdl2-dev under Ubuntu.

A simple SDL application

To demonstrate SDL and Wayland we don't need a complex application, just a simple window will do. The following application draws a window and exits after 10 seconds window.c:


      

It can be built using the Makefile


      

Running under X or Wayland

The default is to run under X:

        
          ./window
        
      
runs as an X application with an X window. To run under Wayland, set the environment variable SDL_VIDEODRIVER:
        
          SDL_VIDEODRIVER=wayland ./window
        
      
This runs as a Wayland application, native on Fedora, in Weston on Ubuntu.

Getting a wayland surface

If you need to get a Wayland surface this is done by getting the system structure SDL_GetWindowWMInfo. This contains a union of information for different backends. For Wayland, the relevant calls are given in the program wayland_info.c


      

Conclusion

Building SDL applications for Wayland is straightforward: without any changes to the source code, run the executable with the environment variable SDL_VIDEODRIVER set to wayland. Access to the Wayland display and applications's Wayland surface is straightforward.