Subject: [PATCH] X11: Move to XSetWMProperties and add support to _NET_WM_PID Date: Mon, 27 Jun 2011 19:32:06 +0200 From: Marco Trevisan (Treviño) # HG changeset patch # User Marco Trevisan (Treviño) # Date 1309195852 -7200 # Node ID c1f8d1b2b430deb0547071be1117ed7e6616f89a # Parent c66457356b515d99931f7d5a30a4b2a71439b3f2 X11: Move to XSetWMProperties and add support to _NET_WM_PID Use the convenience function XSetWMProperties to set size, input and class hints, it also automatically sets the WM_CLIENT_MACHINE (this one needed by _NET_WM_PID) and WM_LOCALE_NAME windows hints. Plus we add support to the _NET_WM_PID atom which is needed by many windows managers to correctly associate a SDL window to its process and to related .desktop file and icon for the given host. diff -r c66457356b51 -r c1f8d1b2b430 src/video/x11/SDL_x11video.c --- a/src/video/x11/SDL_x11video.c Mon Jun 27 19:00:59 2011 +0200 +++ b/src/video/x11/SDL_x11video.c Mon Jun 27 19:30:52 2011 +0200 @@ -328,6 +328,9 @@ /* Get the window class name, usually the name of the application */ data->classname = get_classname(); + /* Get the process PID to be associated to the window */ + data->pid = getpid(); + /* Open a connection to the X input manager */ #ifdef X_HAVE_UTF8_STRING if (SDL_X11_HAVE_UTF8) { diff -r c66457356b51 -r c1f8d1b2b430 src/video/x11/SDL_x11video.h --- a/src/video/x11/SDL_x11video.h Mon Jun 27 19:00:59 2011 +0200 +++ b/src/video/x11/SDL_x11video.h Mon Jun 27 19:30:52 2011 +0200 @@ -69,6 +69,7 @@ { Display *display; char *classname; + pid_t pid; XIM im; Uint32 screensaver_activity; int numwindows; diff -r c66457356b51 -r c1f8d1b2b430 src/video/x11/SDL_x11window.c --- a/src/video/x11/SDL_x11window.c Mon Jun 27 19:00:59 2011 +0200 +++ b/src/video/x11/SDL_x11window.c Mon Jun 27 19:30:52 2011 +0200 @@ -268,11 +268,12 @@ int depth; XSetWindowAttributes xattr; Window w; - XSizeHints *sizehints; - XWMHints *wmhints; - XClassHint *classhints; + XSizeHints sizehints; + XWMHints wmhints; + XClassHint classhints; Atom _NET_WM_WINDOW_TYPE; Atom _NET_WM_WINDOW_TYPE_NORMAL; + Atom _NET_WM_PID; int wmstate_count; Atom wmstate_atoms[3]; @@ -424,20 +425,6 @@ } #endif - sizehints = XAllocSizeHints(); - if (sizehints) { - if (!(window->flags & SDL_WINDOW_RESIZABLE)) { - sizehints->min_width = sizehints->max_width = window->w; - sizehints->min_height = sizehints->max_height = window->h; - sizehints->flags = PMaxSize | PMinSize; - } - sizehints->x = window->x; - sizehints->y = window->y; - sizehints->flags |= USPosition; - XSetWMNormalHints(display, w, sizehints); - XFree(sizehints); - } - if (window->flags & SDL_WINDOW_BORDERLESS) { SDL_bool set; Atom WM_HINTS; @@ -521,22 +508,32 @@ } } - /* Set the input hints so we get keyboard input */ - wmhints = XAllocWMHints(); - if (wmhints) { - wmhints->input = True; - wmhints->flags = InputHint; - XSetWMHints(display, w, wmhints); - XFree(wmhints); + /* Setup the normal size hints */ + if (!(window->flags & SDL_WINDOW_RESIZABLE)) { + sizehints.min_width = sizehints.max_width = window->w; + sizehints.min_height = sizehints.max_height = window->h; + sizehints.flags = PMaxSize | PMinSize; } + sizehints.x = window->x; + sizehints.y = window->y; + sizehints.flags |= USPosition; - /* Set the class hints so we can get an icon (AfterStep) */ - classhints = XAllocClassHint(); - if (classhints != NULL) { - classhints->res_name = data->classname; - classhints->res_class = data->classname; - XSetClassHint(display, w, classhints); - XFree(classhints); + /* Setup the input hints so we get keyboard input */ + wmhints.input = True; + wmhints.flags = InputHint; + + /* Setup the class hints so we can get an icon (AfterStep) */ + classhints.res_name = data->classname; + classhints.res_class = data->classname; + + /* Set the size, input and class hints, and define WM_CLIENT_MACHINE and WM_LOCALE_NAME */ + XSetWMProperties(display, w, NULL, NULL, NULL, 0, &sizehints, &wmhints, &classhints); + + /* Set the PID related to the window for the given hostname, if possible */ + if (data->pid > 0) { + _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 */