darbyjohnston / tlRender

tlRender is an open source library for building playback and review applications for visual effects, film, and animation.
BSD 3-Clause "New" or "Revised" License
193 stars 22 forks source link

Can glfw3 be compiled with both wayland and x11 support? #125

Closed ggarra13 closed 1 year ago

ggarra13 commented 1 year ago

Currently glfw3 is compiled with X11 support only. It can be compiled with Wayland support with the cmake setting -D GLFW_USE_WAYLAND=ON.

But it seems it cannot be compiled with support for both and switched at runtime with an environment variable like FLTK can.

This is problematic.

darbyjohnston commented 1 year ago

Feel free to raise this issue with the GLFW project.

ggarra13 commented 1 year ago

I did. It seems it has been requested in the past.

ggarra13 commented 1 year ago

I got this answer back:

PR https://github.com/glfw/glfw/pull/1958 added support for runtime platform selection, and this has been merged into main so you can select the platform using the GLFW_PLATFORM init hint with either GLFW_PLATFORM_X11 or GLFW_PLATFORM_WAYLAND in your case. Also see glfwPlatformSupported.

It seems we may need to upgrade glfw and add the GLFW_PLATFORM hint by checking an environment variable, like:


#ifdef __linux__
    char* platform = getenv("GLFW_PLATFORM");
    if (!platform)
           platform = getenv("XDG_SESSION_TYPE");

    int platform_hint = GLFW_PLATFORM_X11;
    if (platform && strcmp(platform, "wayland") == 0)
    {
          platform_hint = GLFW_PLATFORM_WAYLAND;
    }

    if (glfwPlatformSupported(platform_hint) == GLFW_TRUE)
         glfwWindowHint(GLFW_PLATFORM, platform_hint);
#endif
ggarra13 commented 1 year ago

See PR #130 for an implementation.