x11: add a hint to force the VisualID used when creating a window.
authorSam Lantinga <slouken@libsdl.org>
Wed, 04 Sep 2019 09:27:58 -0700
changeset 1305786d690b71e35
parent 13056 ed80f97ebe81
child 13058 97448bd2f819
x11: add a hint to force the VisualID used when creating a window.
Android.mk
include/SDL_hints.h
src/video/x11/SDL_x11window.c
     1.1 --- a/include/SDL_hints.h	Wed Sep 04 00:39:47 2019 -0400
     1.2 +++ b/include/SDL_hints.h	Wed Sep 04 09:27:58 2019 -0700
     1.3 @@ -198,6 +198,12 @@
     1.4  #define SDL_HINT_VIDEO_X11_XRANDR           "SDL_VIDEO_X11_XRANDR"
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable forcing the visual ID chosen for new X11 windows
     1.8 + *
     1.9 + */
    1.10 +#define SDL_HINT_VIDEO_X11_WINDOW_VISUALID      "SDL_VIDEO_X11_WINDOW_VISUALID"
    1.11 +
    1.12 +/**
    1.13   *  \brief  A variable controlling whether the X11 _NET_WM_PING protocol should be supported.
    1.14   *
    1.15   *  This variable can be set to the following values:
     2.1 --- a/src/video/x11/SDL_x11window.c	Wed Sep 04 00:39:47 2019 -0400
     2.2 +++ b/src/video/x11/SDL_x11window.c	Wed Sep 04 09:27:58 2019 -0700
     2.3 @@ -393,7 +393,27 @@
     2.4      long fevent = 0;
     2.5  
     2.6  #if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_EGL
     2.7 -    if ((window->flags & SDL_WINDOW_OPENGL) &&
     2.8 +    const char *forced_visual_id = SDL_GetHint(SDL_HINT_VIDEO_X11_WINDOW_VISUALID);
     2.9 +
    2.10 +    if (forced_visual_id != NULL && forced_visual_id[0] != '\0')
    2.11 +    {
    2.12 +        XVisualInfo *vi, template;
    2.13 +        int nvis;
    2.14 +
    2.15 +        SDL_zero(template);
    2.16 +        template.visualid = SDL_strtol(forced_visual_id, NULL, 0);
    2.17 +        vi = X11_XGetVisualInfo(display, VisualIDMask, &template, &nvis);
    2.18 +        if (vi) {
    2.19 +            visual = vi->visual;
    2.20 +            depth = vi->depth;
    2.21 +            X11_XFree(vi);
    2.22 +        }
    2.23 +        else
    2.24 +        {
    2.25 +            return -1;
    2.26 +        }
    2.27 +    }
    2.28 +    else if ((window->flags & SDL_WINDOW_OPENGL) &&
    2.29          !SDL_getenv("SDL_VIDEO_X11_VISUALID")) {
    2.30          XVisualInfo *vinfo = NULL;
    2.31