Prevented case where no window was set when waiting for events.
[freeglut] / src / x11 / fg_window_x11.c
index f9e94a4..0233f94 100644 (file)
@@ -28,8 +28,9 @@
 
 #define FREEGLUT_BUILDING_LIB
 #include <GL/freeglut.h>
-#include <limits.h>  /* LONG_MAX */
-#include <unistd.h>  /* usleep */
+#include <limits.h>     /* LONG_MAX */
+#include <unistd.h>     /* usleep, gethostname, getpid */
+#include <sys/types.h>  /* pid_t */
 #include "../fg_internal.h"
 
 #ifdef EGL_VERSION_1_0
@@ -340,6 +341,41 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
     XSetWMProtocols( fgDisplay.pDisplay.Display, window->Window.Handle,
                      &fgDisplay.pDisplay.DeleteWindow, 1 );
 
+    if (fgDisplay.pDisplay.NetWMSupported
+        && fgDisplay.pDisplay.NetWMPid != None
+        && fgDisplay.pDisplay.ClientMachine != None)
+    {
+      char hostname[HOST_NAME_MAX];
+      pid_t pid = getpid();
+
+      if (pid > 0 && gethostname(hostname, sizeof(hostname)) > -1)
+      {
+        hostname[sizeof(hostname) - 1] = '\0';
+
+        XChangeProperty(
+            fgDisplay.pDisplay.Display,
+            window->Window.Handle,
+            fgDisplay.pDisplay.NetWMPid,
+            XA_CARDINAL,
+            32,
+            PropModeReplace,
+            (unsigned char *) &pid,
+            1
+        );
+
+        XChangeProperty(
+            fgDisplay.pDisplay.Display,
+            window->Window.Handle,
+            fgDisplay.pDisplay.ClientMachine,
+            XA_STRING,
+            8,
+            PropModeReplace,
+            (unsigned char *) hostname,
+            strlen(hostname)
+        );
+      }
+    }
+
 #ifdef EGL_VERSION_1_0
     fghPlatformOpenWindowEGL(window);
 #else
@@ -364,7 +400,8 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
 
     XFree(visualInfo);
 
-    if( !isSubWindow)
+    /* wait till window visible */
+    if( !isSubWindow && !window->IsMenu)
         XPeekIfEvent( fgDisplay.pDisplay.Display, &eventReturnBuffer, &fghWindowIsVisible, (XPointer)(window->Window.Handle) );
 #undef WINDOW_CONFIG
 }