X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 02 Nov 2012 15:22:37 -0400
changeset 66383d221da309d3
parent 6637 31e3f5b04120
child 6639 c7e81fae23c4
X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11video.h
src/video/x11/SDL_x11window.c
     1.1 --- a/src/video/x11/SDL_x11events.c	Fri Nov 02 14:15:21 2012 -0400
     1.2 +++ b/src/video/x11/SDL_x11events.c	Fri Nov 02 15:22:37 2012 -0400
     1.3 @@ -388,9 +388,33 @@
     1.4      case ClientMessage:{
     1.5              if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
     1.6                  (xevent.xclient.format == 32) &&
     1.7 +                (xevent.xclient.data.l[0] == videodata->_NET_WM_PING)) {
     1.8 +
     1.9 +                SDL_DisplayData *dpydata;
    1.10 +                Window root;
    1.11 +
    1.12 +#ifdef DEBUG_XEVENTS
    1.13 +                printf("window %p: _NET_WM_PING\n", data);
    1.14 +#endif
    1.15 +
    1.16 +                dpydata = (SDL_DisplayData *)
    1.17 +                    SDL_GetDisplayForWindow(data->window);
    1.18 +                root = RootWindow(display, dpydata->screen);
    1.19 +                xevent.xclient.window = root;
    1.20 +                XSendEvent(display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xevent);
    1.21 +                break;
    1.22 +            }
    1.23 +
    1.24 +            else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
    1.25 +                (xevent.xclient.format == 32) &&
    1.26                  (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) {
    1.27  
    1.28 +#ifdef DEBUG_XEVENTS
    1.29 +                printf("window %p: WM_DELETE_WINDOW\n", data);
    1.30 +#endif
    1.31 +
    1.32                  SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
    1.33 +                break;
    1.34              }
    1.35          }
    1.36          break;
     2.1 --- a/src/video/x11/SDL_x11video.c	Fri Nov 02 14:15:21 2012 -0400
     2.2 +++ b/src/video/x11/SDL_x11video.c	Fri Nov 02 15:22:37 2012 -0400
     2.3 @@ -383,6 +383,7 @@
     2.4      GET_ATOM(_NET_WM_NAME);
     2.5      GET_ATOM(_NET_WM_ICON_NAME);
     2.6      GET_ATOM(_NET_WM_ICON);
     2.7 +    GET_ATOM(_NET_WM_PING);
     2.8      GET_ATOM(UTF8_STRING);
     2.9  
    2.10      /* Detect the window manager */
     3.1 --- a/src/video/x11/SDL_x11video.h	Fri Nov 02 14:15:21 2012 -0400
     3.2 +++ b/src/video/x11/SDL_x11video.h	Fri Nov 02 15:22:37 2012 -0400
     3.3 @@ -93,6 +93,7 @@
     3.4      Atom _NET_WM_NAME;
     3.5      Atom _NET_WM_ICON_NAME;
     3.6      Atom _NET_WM_ICON;
     3.7 +    Atom _NET_WM_PING;
     3.8      Atom UTF8_STRING;
     3.9  
    3.10      SDL_Scancode key_layout[256];
     4.1 --- a/src/video/x11/SDL_x11window.c	Fri Nov 02 14:15:21 2012 -0400
     4.2 +++ b/src/video/x11/SDL_x11window.c	Fri Nov 02 15:22:37 2012 -0400
     4.3 @@ -536,8 +536,14 @@
     4.4                      PropModeReplace,
     4.5                      (unsigned char *)&_NET_WM_WINDOW_TYPE_NORMAL, 1);
     4.6  
     4.7 -    /* Allow the window to be deleted by the window manager */
     4.8 -    XSetWMProtocols(display, w, &data->WM_DELETE_WINDOW, 1);
     4.9 +    
    4.10 +    {
    4.11 +        Atom protocols[] = {
    4.12 +            data->WM_DELETE_WINDOW, /* Allow window to be deleted by the WM */
    4.13 +            data->_NET_WM_PING, /* Respond so WM knows we're alive */
    4.14 +        };
    4.15 +        XSetWMProtocols(display, w, protocols, sizeof (protocols) / sizeof (protocols[0]));
    4.16 +    }
    4.17  
    4.18      if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
    4.19          XDestroyWindow(display, w);