Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
authorSam Lantinga <slouken@libsdl.org>
Tue, 27 Oct 2015 11:18:04 -0700
changeset 989925d1e99080ce
parent 9898 0da384bef562
child 9901 c9cae280468f
Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
_NET_WM_PING protocol handling in CreateWindow if
desired.
include/SDL_hints.h
src/video/x11/SDL_x11window.c
     1.1 --- a/include/SDL_hints.h	Tue Oct 27 11:17:32 2015 -0700
     1.2 +++ b/include/SDL_hints.h	Tue Oct 27 11:18:04 2015 -0700
     1.3 @@ -186,6 +186,20 @@
     1.4  #define SDL_HINT_VIDEO_X11_XRANDR           "SDL_VIDEO_X11_XRANDR"
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable controlling whether the X11 _NET_WM_PING protocol should be supported.
     1.8 + *
     1.9 + *  This variable can be set to the following values:
    1.10 + *    "0"       - Disable _NET_WM_PING
    1.11 + *    "1"       - Enable _NET_WM_PING
    1.12 + *
    1.13 + *  By default SDL will use _NET_WM_PING, but for applications that know they
    1.14 + *  will not always be able to respond to ping requests in a timely manner they can
    1.15 + *  turn it off to avoid the window manager thinking the app is hung.
    1.16 + *  The hint is checked in CreateWindow.
    1.17 + */
    1.18 +#define SDL_HINT_VIDEO_X11_NET_WM_PING      "SDL_VIDEO_X11_NET_WM_PING"
    1.19 +
    1.20 +/**
    1.21   *  \brief  A variable controlling whether the window frame and title bar are interactive when the cursor is hidden 
    1.22   *
    1.23   *  This variable can be set to the following values:
     2.1 --- a/src/video/x11/SDL_x11window.c	Tue Oct 27 11:17:32 2015 -0700
     2.2 +++ b/src/video/x11/SDL_x11window.c	Tue Oct 27 11:18:04 2015 -0700
     2.3 @@ -542,11 +542,23 @@
     2.4                      (unsigned char *)&_NET_WM_BYPASS_COMPOSITOR_HINT_ON, 1);
     2.5  
     2.6      {
     2.7 -        Atom protocols[] = {
     2.8 -            data->WM_DELETE_WINDOW, /* Allow window to be deleted by the WM */
     2.9 -            data->_NET_WM_PING, /* Respond so WM knows we're alive */
    2.10 -        };
    2.11 -        X11_XSetWMProtocols(display, w, protocols, sizeof (protocols) / sizeof (protocols[0]));
    2.12 +        Atom protocols[2];
    2.13 +        int proto_count = 0;
    2.14 +        const char *ping_hint;
    2.15 +
    2.16 +        protocols[proto_count] = data->WM_DELETE_WINDOW; /* Allow window to be deleted by the WM */
    2.17 +        proto_count++;
    2.18 +        
    2.19 +        ping_hint = SDL_GetHint(SDL_HINT_VIDEO_X11_NET_WM_PING);
    2.20 +        /* Default to using ping if there is no hint */
    2.21 +        if (!ping_hint || SDL_atoi(ping_hint)) {
    2.22 +            protocols[proto_count] = data->_NET_WM_PING; /* Respond so WM knows we're alive */
    2.23 +            proto_count++;
    2.24 +        }
    2.25 +
    2.26 +        SDL_assert(proto_count <= sizeof(protocols) / sizeof(protocols[0]));
    2.27 +
    2.28 +        X11_XSetWMProtocols(display, w, protocols, proto_count);
    2.29      }
    2.30  
    2.31      if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {