Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
X11: Handle _NET_WM_PING protocol, so window manager knows when app i…
…s hung up.
  • Loading branch information
icculus committed Nov 2, 2012
1 parent 0659ddd commit 61c1035f748cf837fd76286dd580c90711bd857b
Showing with 34 additions and 2 deletions.
  1. +24 −0 src/video/x11/SDL_x11events.c
  2. +1 −0 src/video/x11/SDL_x11video.c
  3. +1 −0 src/video/x11/SDL_x11video.h
  4. +8 −2 src/video/x11/SDL_x11window.c
@@ -387,10 +387,34 @@ X11_DispatchEvent(_THIS)
/* Have we been requested to quit (or another client message?) */
case ClientMessage:{
if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
(xevent.xclient.format == 32) &&
(xevent.xclient.data.l[0] == videodata->_NET_WM_PING)) {

SDL_DisplayData *dpydata;
Window root;

#ifdef DEBUG_XEVENTS
printf("window %p: _NET_WM_PING\n", data);
#endif

dpydata = (SDL_DisplayData *)
SDL_GetDisplayForWindow(data->window);
root = RootWindow(display, dpydata->screen);
xevent.xclient.window = root;
XSendEvent(display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xevent);
break;
}

else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
(xevent.xclient.format == 32) &&
(xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) {

#ifdef DEBUG_XEVENTS
printf("window %p: WM_DELETE_WINDOW\n", data);
#endif

SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
break;
}
}
break;
@@ -383,6 +383,7 @@ X11_VideoInit(_THIS)
GET_ATOM(_NET_WM_NAME);
GET_ATOM(_NET_WM_ICON_NAME);
GET_ATOM(_NET_WM_ICON);
GET_ATOM(_NET_WM_PING);
GET_ATOM(UTF8_STRING);

/* Detect the window manager */
@@ -93,6 +93,7 @@ typedef struct SDL_VideoData
Atom _NET_WM_NAME;
Atom _NET_WM_ICON_NAME;
Atom _NET_WM_ICON;
Atom _NET_WM_PING;
Atom UTF8_STRING;

SDL_Scancode key_layout[256];
@@ -536,8 +536,14 @@ X11_CreateWindow(_THIS, SDL_Window * window)
PropModeReplace,
(unsigned char *)&_NET_WM_WINDOW_TYPE_NORMAL, 1);

/* Allow the window to be deleted by the window manager */
XSetWMProtocols(display, w, &data->WM_DELETE_WINDOW, 1);

{
Atom protocols[] = {
data->WM_DELETE_WINDOW, /* Allow window to be deleted by the WM */
data->_NET_WM_PING, /* Respond so WM knows we're alive */
};
XSetWMProtocols(display, w, protocols, sizeof (protocols) / sizeof (protocols[0]));
}

if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
XDestroyWindow(display, w);

0 comments on commit 61c1035

Please sign in to comment.