X11: Added support to _NET_WM_PID and WM_CLIENT_MACHINE atoms SDL-1.2
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Tue, 28 Jun 2011 22:26:47 +0200
branchSDL-1.2
changeset 6169 6f3e5ccfd585
parent 6158 6f3a2bb301d6
child 6170 044ca54328b4
X11: Added support to _NET_WM_PID and WM_CLIENT_MACHINE atoms 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.
src/video/x11/SDL_x11video.c
--- a/src/video/x11/SDL_x11video.c	Thu Jan 05 19:19:58 2012 -0500
+++ b/src/video/x11/SDL_x11video.c	Tue Jun 28 22:26:47 2011 +0200
@@ -417,6 +417,25 @@
 	}
     }
 
+	{
+		char hostname[256];
+
+		if (gethostname(hostname, sizeof(hostname)) > -1) {
+			hostname[sizeof(hostname)-1] = '\0';
+			pid_t pid = getpid();
+
+			if (pid > 0) {
+				Atom _NET_WM_PID = XInternAtom(SDL_Display, "_NET_WM_PID", False);
+				Atom WM_CLIENT_MACHINE = XInternAtom(SDL_Display, "WM_CLIENT_MACHINE", False);
+				
+				XChangeProperty(SDL_Display, WMwindow, _NET_WM_PID, XA_CARDINAL, 32,
+				                PropModeReplace, (unsigned char *)&pid, 1);
+				XChangeProperty(SDL_Display, WMwindow, WM_CLIENT_MACHINE, XA_STRING, 8,
+				                PropModeReplace, hostname, SDL_strlen(hostname));
+			}
+		}
+	}
+
 	/* Setup the communication with the IM server */
 	/* create_aux_windows may be called several times against the same
 	   Display.  We should reuse the SDL_IM if one has been opened for