I’m currently working on a project and, for learning, I want to write myself the windowing system with platform specific code.
So, I use the preprocessor to know at compile time which platform I’m on but I don’t know how to identify the windowing system on Linux. I really need this because X11 and Wayland applications are not compatible; therefore, I’ll have to write different files.
Here is my file with the preprocessor options that I found on this site:
// Windows OS
#if defined(_WIN32) || defined(_WIN64)
#define PLATFORM_WINDOWS 1
// Linux OS
#elif defined(__linux__)
#define PLATFORM_LINUX 1
#if defined(WAYLAND)
#define LINUX_ON_WAYLAND
#elif defined(X11)
#define LINUX_ON_X11
#endif
// Unix OS
#elif defined(__unix) || defined(__unix__)
#define PLATFORM_UNIX 1
// Mac OS
#elif defined(__APPLE__) || defined(__MACH__)
#define PLATFORM_MACOS
// Unknown OS
#else
#error "Unknown platform."
#endif
As you can see, I’ve put placeholders for WAYLAND and X11 but, is there a way to have a system like this working?
2