Fix accidental switch/teleporter behavior changes
[neverball] / share / sync.c
index 000838c..7a7df36 100644 (file)
  * General Public License for more details.
  */
 
+#include <SDL_syswm.h>
 #include "glext.h"
 
 /*---------------------------------------------------------------------------*/
-#ifndef __APPLE__
+#if defined(_WIN32)
+
+void sync_init(void)
+{
+    return;
+}
+
+/*---------------------------------------------------------------------------*/
+#elif defined(__APPLE__)
+
+#include <OpenGL/OpenGL.h>
+
+void sync_init(void)
+{
+    long swap = 1;
+    CGLSetParameter(CGLGetCurrentContext(),  kCGLCPSwapInterval, &swap);
+}
+
+/*---------------------------------------------------------------------------*/
+#elif SDL_VIDEO_DRIVER_X11
+
+#include <GL/glx.h>
 
 static int search(const char *haystack, const char *needle)
 {
@@ -34,60 +56,37 @@ static int search(const char *haystack, const char *needle)
     return 0;
 }
 
-#endif
-/*---------------------------------------------------------------------------*/
-#ifdef __linux__
-
-#include <GL/glx.h>
-
 void sync_init(void)
 {
+    SDL_SysWMinfo info;
     Display *dpy;
 
-    if ((dpy = glXGetCurrentDisplay()))
+    SDL_VERSION(&info.version);
+
+    if (SDL_GetWMInfo(&info) != 1)
+        return;
+
+    if (info.subsystem != SDL_SYSWM_X11)
+        return;
+
+    dpy = info.info.x11.display;
+
+    info.info.x11.lock_func();
     {
         int scr = DefaultScreen(dpy);
 
-        PFNGLXSWAPINTERVALSGIPROC _glXSwapInvervalSGI = NULL;
+        PFNGLXSWAPINTERVALSGIPROC _glXSwapIntervalSGI = NULL;
 
         if (search(glXQueryExtensionsString(dpy, scr), "GLX_SGI_swap_control"))
         {
-            if ((_glXSwapInvervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
+            if ((_glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
                  glXGetProcAddress((const GLubyte *) "glXSwapIntervalSGI")))
-                _glXSwapInvervalSGI(1);
+                _glXSwapIntervalSGI(1);
         }
     }
+    info.info.x11.unlock_func();
 }
 
 #endif
-/*---------------------------------------------------------------------------*/
-#ifdef _WIN32
-
-void sync_init(void)
-{
-/* TODO: Sit down at a Windows machine and make this work.
-    PFNWGLSWAPINTERVALEXTPROC _wglSwapInvervalEXT = NULL;
-
-    if (search(wglGetExtensionsString(), "WGL_EXT_swap_control"))
-    {
-        if ((_wglSwapInvervalEXT = (PFNGLXSWAPINTERVALEXTPROC)
-             wglGetProcAddress((const GLubyte *) "wglSwapIntervalEXT")))
-            _wglSwapInvervalEXT(1);
-    }
-*/
-}
 
-#endif
-/*---------------------------------------------------------------------------*/
-#ifdef __APPLE__
-
-#include <OpenGL/OpenGL.h>
-
-void sync_init(void)
-{
-    long swap = 1;
-    CGLSetParameter(CGLGetCurrentContext(),  kCGLCPSwapInterval, &swap);
-}
-
-#endif
 /*---------------------------------------------------------------------------*/