Is there a way to find whether theuser is using Wayland instead of X11, WITHOUT enviroment variables? (C)

876 views Asked by At

I am currently working with C and SDL2, and I need to know whether Wayland is currently used as the windowing system (Obviously because I want to use Wayland, but SDL2 defaults to Xwayland). While SDL_VIDEODRIVER=wayland does work, it won't work if you are in X11, saying that the video driver is unavailable. So, what I am looking for, is a low-level way of getting the current windowing system (Possibly by asking the compositor?) on GNU/Linux. It also needs to be unmodifiable, that is, no application or user will be able to change it unless the session ends.

1

There are 1 answers

5
genpfault On BEST ANSWER

Initialize SDL with no subsystem via SDL_Init(0) then ask SDL to connect to whatever Wayland session is running via SDL_VideoInit("wayland"); if that call succeeds you're good to go with the usual SDL_Init(SDL_INIT_EVERYTHING) & window creation.

Though for more robustness you should iterate over the SDL_GetNumVideoDrivers()/SDL_GetVideoDriver() string list to verify the SDL install in use was even built with Wayland support.

See the test program here for video driver enumeration & testing.