Subject: [PATCH] X11: Added support to _NET_WM_PID and WM_CLIENT_MACHINE atoms Date: Mon, 27 Jun 2011 18:32:19 +0200 From: Marco Trevisan (Treviño) # HG changeset patch # User Marco Trevisan (Treviño) # Date 1309191876 -7200 # Node ID 78e3f2790eb907f5d9d7911aae620c615c5ac4c3 # Parent c1ed57cbfd66e146a7af034a806377bb271b1696 X11: Added support to _NET_WM_PID and WM_CLIENT_MACHINE atoms These parameters are needed by many windows managers to correctly associate a SDL window to its process and to related .desktop file and icon. diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -328,6 +328,13 @@ /* Get the window class name, usually the name of the application */ data->classname = get_classname(); + /* Get the process PID and hostname to be associated with the window */ + if (gethostname(data->hostname, sizeof(data->hostname)) > -1) { + data->hostname[sizeof(data->hostname)-1] = '\0'; + data->pid = getpid(); + printf("PID is %d - host: %s\n", (int) data->pid, data->hostname); + } + /* Open a connection to the X input manager */ #ifdef X_HAVE_UTF8_STRING if (SDL_X11_HAVE_UTF8) { diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -69,6 +69,8 @@ { Display *display; char *classname; + pid_t pid; + char hostname[256]; XIM im; Uint32 screensaver_activity; int numwindows; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -273,6 +273,8 @@ XClassHint *classhints; Atom _NET_WM_WINDOW_TYPE; Atom _NET_WM_WINDOW_TYPE_NORMAL; + Atom _NET_WM_PID; + Atom WM_CLIENT_MACHINE; int wmstate_count; Atom wmstate_atoms[3]; @@ -539,6 +541,16 @@ XFree(classhints); } + /* Set the PID related to the window for the given hostname, if possible */ + if (data->pid > 0) { + WM_CLIENT_MACHINE = XInternAtom(display, "WM_CLIENT_MACHINE", False); + XChangeProperty(display, w, WM_CLIENT_MACHINE, XA_STRING, 8, + PropModeReplace, data->hostname, SDL_strlen(data->hostname)); + _NET_WM_PID = XInternAtom(display, "_NET_WM_PID", False); + XChangeProperty(display, w, _NET_WM_PID, XA_CARDINAL, 32, PropModeReplace, + (unsigned char *)&data->pid, 1); + } + /* Set the window manager state */ wmstate_count = X11_GetWMStateProperty(_this, window, wmstate_atoms); if (wmstate_count > 0) {