+#if TARGET_HOST_POSIX_X11
+
+/* Return the atom associated with "name". */
+static Atom fghGetAtom(const char * name)
+{
+ return XInternAtom(fgDisplay.Display, name, False);
+}
+
+/*
+ * Check if "property" is set on "window". The property's values are returned
+ * through "data". If the property is set and is of type "type", return the
+ * number of elements in "data". Return zero otherwise. In both cases, use
+ * "Xfree()" to free "data".
+ */
+static int fghGetWindowProperty(Window window,
+ Atom property,
+ Atom type,
+ unsigned char ** data)
+{
+ /*
+ * Caller always has to use "Xfree()" to free "data", since
+ * "XGetWindowProperty() always allocates one extra byte in prop_return
+ * [i.e. "data"] (even if the property is zero length) [..]".
+ */
+
+ int status; /* Returned by "XGetWindowProperty". */
+
+ Atom type_returned;
+ int temp_format; /* Not used. */
+ unsigned long number_of_elements;
+ unsigned long temp_bytes_after; /* Not used. */
+
+
+ status = XGetWindowProperty(fgDisplay.Display,
+ window,
+ property,
+ 0,
+ LONG_MAX,
+ False,
+ type,
+ &type_returned,
+ &temp_format,
+ &number_of_elements,
+ &temp_bytes_after,
+ data);
+
+ FREEGLUT_INTERNAL_ERROR_EXIT(status == Success,
+ "XGetWindowProperty failled",
+ "fghGetWindowProperty");
+
+ if (type_returned != type)
+ {
+ number_of_elements = 0;
+ }
+
+ return number_of_elements;
+}
+
+/* Check if the window manager is NET WM compliant. */
+static int fghNetWMSupported(void)
+{
+ Atom wm_check;
+ Window ** window_ptr_1;
+
+ int number_of_windows;
+ int net_wm_supported;
+
+
+ net_wm_supported = 0;
+
+ wm_check = fghGetAtom("_NET_SUPPORTING_WM_CHECK");
+ window_ptr_1 = malloc(sizeof(Window *));
+
+ /*
+ * Check that the window manager has set this property on the root window.
+ * The property must be the ID of a child window.
+ */
+ number_of_windows = fghGetWindowProperty(fgDisplay.RootWindow,
+ wm_check,
+ XA_WINDOW,
+ (unsigned char **) window_ptr_1);
+ if (number_of_windows == 1)
+ {
+ Window ** window_ptr_2;
+
+ window_ptr_2 = malloc(sizeof(Window *));
+
+ /* Check that the window has the same property set to the same value. */
+ number_of_windows = fghGetWindowProperty(**window_ptr_1,
+ wm_check,
+ XA_WINDOW,
+ (unsigned char **) window_ptr_2);
+ if ((number_of_windows == 1) && (**window_ptr_1 == **window_ptr_2))
+ {
+ /* NET WM compliant */
+ net_wm_supported = 1;
+ }
+
+ XFree(*window_ptr_2);
+ free(window_ptr_2);
+ }
+
+ XFree(*window_ptr_1);
+ free(window_ptr_1);
+
+ return net_wm_supported;
+}
+
+/* Check if "hint" is present in "property" for "window". */
+int fgHintPresent(Window window, Atom property, Atom hint)
+{
+ Atom ** atoms_ptr;
+ int number_of_atoms;
+ int supported;
+ int i;
+
+ supported = 0;
+
+ atoms_ptr = malloc(sizeof(Atom *));
+ number_of_atoms = fghGetWindowProperty(window,
+ property,
+ XA_ATOM,
+ (unsigned char **) atoms_ptr);
+ for (i = 0; i < number_of_atoms; i++)
+ {
+ if ((*atoms_ptr)[i] == hint)
+ {
+ supported = 1;
+ break;
+ }
+ }
+
+ return supported;
+}
+
+#endif /* TARGET_HOST_POSIX_X11 */
+
+