Browse Source

Upgrade to SDL2.0.2 (8393682d9d96d1516831a397290cb34ceb82129f).

rude 11 years ago
parent
commit
2fb789ce68
63 changed files with 1387 additions and 989 deletions
  1. 4 3
      libs/SDL2/CMakeLists.txt
  2. 3 3
      libs/SDL2/README-macosx.txt
  3. 1 1
      libs/SDL2/README-windows.txt
  4. 24 9
      libs/SDL2/VisualC/SDL_VS2013.sln
  5. 17 7
      libs/SDL2/WhatsNew.txt
  6. 3 3
      libs/SDL2/cmake/sdlchecks.cmake
  7. 10 10
      libs/SDL2/configure
  8. 8 8
      libs/SDL2/configure.in
  9. 2 2
      libs/SDL2/include/SDL_events.h
  10. 36 16
      libs/SDL2/include/SDL_hints.h
  11. 7 2
      libs/SDL2/src/SDL.c
  12. 47 7
      libs/SDL2/src/audio/SDL_audiocvt.c
  13. 16 4
      libs/SDL2/src/cpuinfo/SDL_cpuinfo.c
  14. 14 3
      libs/SDL2/src/events/SDL_events.c
  15. 1 6
      libs/SDL2/src/events/SDL_gesture.c
  16. 4 1
      libs/SDL2/src/events/SDL_mouse.c
  17. 53 11
      libs/SDL2/src/filesystem/windows/SDL_sysfilesystem.c
  18. 2 3
      libs/SDL2/src/haptic/darwin/SDL_syshaptic.c
  19. 2 2
      libs/SDL2/src/haptic/linux/SDL_syshaptic.c
  20. 17 7
      libs/SDL2/src/haptic/windows/SDL_syshaptic.c
  21. 2 0
      libs/SDL2/src/joystick/SDL_gamecontroller.c
  22. 2 1
      libs/SDL2/src/joystick/SDL_gamecontrollerdb.h
  23. 3 3
      libs/SDL2/src/joystick/android/SDL_sysjoystick.c
  24. 336 567
      libs/SDL2/src/joystick/darwin/SDL_sysjoystick.c
  25. 14 31
      libs/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h
  26. 4 1
      libs/SDL2/src/joystick/windows/SDL_dxjoystick.c
  27. 2 2
      libs/SDL2/src/power/uikit/SDL_syspower.m
  28. 3 1
      libs/SDL2/src/render/SDL_render.c
  29. 21 3
      libs/SDL2/src/render/direct3d/SDL_render_d3d.c
  30. 21 1
      libs/SDL2/src/render/opengl/SDL_render_gl.c
  31. 21 4
      libs/SDL2/src/render/opengles/SDL_render_gles.c
  32. 20 4
      libs/SDL2/src/render/opengles2/SDL_render_gles2.c
  33. 0 6
      libs/SDL2/src/stdlib/SDL_stdlib.c
  34. 1 0
      libs/SDL2/src/test/SDL_test_common.c
  35. 2 1
      libs/SDL2/src/timer/SDL_timer_c.h
  36. 8 2
      libs/SDL2/src/timer/dummy/SDL_systimer.c
  37. 8 2
      libs/SDL2/src/timer/haiku/SDL_systimer.c
  38. 9 2
      libs/SDL2/src/timer/psp/SDL_systimer.c
  39. 10 4
      libs/SDL2/src/timer/unix/SDL_systimer.c
  40. 22 6
      libs/SDL2/src/timer/windows/SDL_systimer.c
  41. 19 1
      libs/SDL2/src/video/SDL_video.c
  42. 25 13
      libs/SDL2/src/video/cocoa/SDL_cocoaevents.m
  43. 9 2
      libs/SDL2/src/video/cocoa/SDL_cocoamouse.h
  44. 104 22
      libs/SDL2/src/video/cocoa/SDL_cocoamouse.m
  45. 56 29
      libs/SDL2/src/video/cocoa/SDL_cocoaopengl.m
  46. 1 0
      libs/SDL2/src/video/cocoa/SDL_cocoavideo.h
  47. 6 0
      libs/SDL2/src/video/cocoa/SDL_cocoavideo.m
  48. 8 0
      libs/SDL2/src/video/cocoa/SDL_cocoawindow.h
  49. 163 49
      libs/SDL2/src/video/cocoa/SDL_cocoawindow.m
  50. 4 2
      libs/SDL2/src/video/mir/SDL_mirframebuffer.c
  51. 6 5
      libs/SDL2/src/video/uikit/SDL_uikitopenglview.m
  52. 27 5
      libs/SDL2/src/video/windows/SDL_windowsevents.c
  53. 11 29
      libs/SDL2/src/video/windows/SDL_windowsmouse.c
  54. 0 2
      libs/SDL2/src/video/windows/SDL_windowsopengles.c
  55. 1 1
      libs/SDL2/src/video/windows/SDL_windowsvideo.c
  56. 2 2
      libs/SDL2/src/video/windows/SDL_windowswindow.c
  57. 1 0
      libs/SDL2/src/video/windows/SDL_windowswindow.h
  58. 41 41
      libs/SDL2/src/video/windows/wmmsg.h
  59. 12 12
      libs/SDL2/src/video/x11/SDL_x11events.c
  60. 77 0
      libs/SDL2/src/video/x11/SDL_x11video.c
  61. 3 0
      libs/SDL2/src/video/x11/SDL_x11video.h
  62. 18 14
      libs/SDL2/src/video/x11/SDL_x11xinput2.c
  63. 13 11
      libs/SDL2/test/testgles2.c

+ 4 - 3
libs/SDL2/CMakeLists.txt

@@ -235,8 +235,8 @@ set_option(RPATH               "Use an rpath when linking SDL" ${UNIX_SYS})
 set_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" OFF)
 set_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" OFF)
 set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
 set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
 set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
 set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
-set_option(VIDEO_WAYLAND       "Use Wayland video driver" OFF) #${UNIX_SYS})
-set_option(VIDEO_MIR           "Use Mir video driver" OFF) #${UNIX_SYS})
+set_option(VIDEO_WAYLAND       "Use Wayland video driver" ${UNIX_SYS})
+set_option(VIDEO_MIR           "Use Mir video driver" ${UNIX_SYS})
 dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
 dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
 set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
 set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
 foreach(_SUB ${SDL_X11_OPTIONS})
 foreach(_SUB ${SDL_X11_OPTIONS})
@@ -993,6 +993,7 @@ elseif(APPLE)
   if(SDL_FILESYSTEM)
   if(SDL_FILESYSTEM)
     set(SDL_FILESYSTEM_COCOA 1)
     set(SDL_FILESYSTEM_COCOA 1)
     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
+    set_source_files_properties(${FILESYSTEM_SOURCES} PROPERTIES LANGUAGE C)
     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
     set(HAVE_SDL_FILESYSTEM TRUE)
     set(HAVE_SDL_FILESYSTEM TRUE)
   endif()
   endif()
@@ -1261,7 +1262,7 @@ if(SDL_STATIC)
   set (BUILD_SHARED_LIBS FALSE)
   set (BUILD_SHARED_LIBS FALSE)
   add_library(SDL2-static STATIC ${SOURCE_FILES})
   add_library(SDL2-static STATIC ${SOURCE_FILES})
   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
-  if(WINDOWS)
+  if(MSVC)
     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
     set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
     set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")

+ 3 - 3
libs/SDL2/README-macosx.txt

@@ -26,9 +26,9 @@ ABI compatibility on x86_64 architectures.  For best compatibility you
 should compile your application the same way.  A script which wraps
 should compile your application the same way.  A script which wraps
 gcc to make this easy is provided in test/gcc-fat.sh
 gcc to make this easy is provided in test/gcc-fat.sh
 
 
-Please note that building SDL requires at least the 10.7 SDK (even if you
-target back to 10.5 systems). PowerPC support for Mac OS X has been officially
-dropped as of SDL 2.0.2.
+Please note that building SDL requires at least Xcode 4.6 and the 10.7 SDK
+(even if you target back to 10.5 systems). PowerPC support for Mac OS X has
+been officially dropped as of SDL 2.0.2.
 
 
 To use the library once it's built, you essential have two possibilities:
 To use the library once it's built, you essential have two possibilities:
 use the traditional autoconf/automake/make method, or use Xcode.
 use the traditional autoconf/automake/make method, or use Xcode.

+ 1 - 1
libs/SDL2/README-windows.txt

@@ -32,7 +32,7 @@ d3dcompiler_* DLL at all (for details on this, see their documentation).
 However, by default SDL will try to preload the d3dcompiler_46.dll to
 However, by default SDL will try to preload the d3dcompiler_46.dll to
 comply with ANGLE's requirements. If you wish SDL to preload d3dcompiler_43.dll (to
 comply with ANGLE's requirements. If you wish SDL to preload d3dcompiler_43.dll (to
 support Windows XP) or to skip this step at all, you can use the 
 support Windows XP) or to skip this step at all, you can use the 
-SDL_VIDEO_WIN_D3DCOMPILER hint (see SDL_hints.h for more details).
+SDL_HINT_VIDEO_WIN_D3DCOMPILER hint (see SDL_hints.h for more details).
 
 
 Known Bugs:
 Known Bugs:
     
     

+ 24 - 9
libs/SDL2/VisualC/SDL_VS2013.sln

@@ -106,6 +106,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testjoystick", "tests\testj
 	EndProjectSection
 	EndProjectSection
 EndProject
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testgles2", "tests\testgles2\testgles2_VS2013.vcxproj", "{E5287C64-0646-4BFA-A772-1DB5A649F35E}"
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testgles2", "tests\testgles2\testgles2_VS2013.vcxproj", "{E5287C64-0646-4BFA-A772-1DB5A649F35E}"
+	ProjectSection(ProjectDependencies) = postProject
+		{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}
+		{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}
+		{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}
+	EndProjectSection
 EndProject
 EndProject
 Global
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -137,62 +142,72 @@ Global
 		{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.Build.0 = Debug|x64
 		{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.Build.0 = Debug|x64
 		{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.ActiveCfg = Release|Win32
 		{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.ActiveCfg = Release|Win32
 		{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.Build.0 = Release|Win32
 		{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.Build.0 = Release|Win32
-		{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|x64.ActiveCfg = Release|Win32
+		{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|x64.ActiveCfg = Release|x64
+		{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|x64.Build.0 = Release|x64
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.ActiveCfg = Debug|Win32
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.ActiveCfg = Debug|Win32
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.Build.0 = Debug|Win32
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.Build.0 = Debug|Win32
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.ActiveCfg = Debug|x64
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.ActiveCfg = Debug|x64
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.Build.0 = Debug|x64
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.Build.0 = Debug|x64
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.ActiveCfg = Release|Win32
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.ActiveCfg = Release|Win32
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.Build.0 = Release|Win32
 		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.Build.0 = Release|Win32
-		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|x64.ActiveCfg = Release|Win32
+		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|x64.ActiveCfg = Release|x64
+		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|x64.Build.0 = Release|x64
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.ActiveCfg = Debug|Win32
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.ActiveCfg = Debug|Win32
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.Build.0 = Debug|Win32
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.Build.0 = Debug|Win32
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.ActiveCfg = Debug|x64
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.ActiveCfg = Debug|x64
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.Build.0 = Debug|x64
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.Build.0 = Debug|x64
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.ActiveCfg = Release|Win32
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.ActiveCfg = Release|Win32
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.Build.0 = Release|Win32
 		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.Build.0 = Release|Win32
-		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|x64.ActiveCfg = Release|Win32
+		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|x64.ActiveCfg = Release|x64
+		{CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|x64.Build.0 = Release|x64
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.ActiveCfg = Debug|Win32
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.ActiveCfg = Debug|Win32
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.Build.0 = Debug|Win32
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.Build.0 = Debug|Win32
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.ActiveCfg = Debug|x64
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.ActiveCfg = Debug|x64
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.Build.0 = Debug|x64
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.Build.0 = Debug|x64
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.ActiveCfg = Release|Win32
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.ActiveCfg = Release|Win32
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.Build.0 = Release|Win32
 		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.Build.0 = Release|Win32
-		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|x64.ActiveCfg = Release|Win32
+		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|x64.ActiveCfg = Release|x64
+		{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|x64.Build.0 = Release|x64
 		{26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.ActiveCfg = Debug|Win32
 		{26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.ActiveCfg = Debug|Win32
 		{26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.Build.0 = Debug|Win32
 		{26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.Build.0 = Debug|Win32
 		{26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.ActiveCfg = Debug|x64
 		{26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.ActiveCfg = Debug|x64
 		{26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.Build.0 = Debug|x64
 		{26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.Build.0 = Debug|x64
 		{26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.ActiveCfg = Release|Win32
 		{26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.ActiveCfg = Release|Win32
 		{26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.Build.0 = Release|Win32
 		{26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.Build.0 = Release|Win32
-		{26828762-C95D-4637-9CB1-7F0979523813}.Release|x64.ActiveCfg = Release|Win32
+		{26828762-C95D-4637-9CB1-7F0979523813}.Release|x64.ActiveCfg = Release|x64
+		{26828762-C95D-4637-9CB1-7F0979523813}.Release|x64.Build.0 = Release|x64
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.ActiveCfg = Debug|Win32
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.ActiveCfg = Debug|Win32
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.Build.0 = Debug|Win32
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.Build.0 = Debug|Win32
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.ActiveCfg = Debug|x64
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.ActiveCfg = Debug|x64
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.Build.0 = Debug|x64
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.Build.0 = Debug|x64
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.ActiveCfg = Release|Win32
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.ActiveCfg = Release|Win32
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.Build.0 = Release|Win32
 		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.Build.0 = Release|Win32
-		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|x64.ActiveCfg = Release|Win32
+		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|x64.ActiveCfg = Release|x64
+		{40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|x64.Build.0 = Release|x64
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.ActiveCfg = Debug|Win32
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.ActiveCfg = Debug|Win32
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.Build.0 = Debug|Win32
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.Build.0 = Debug|Win32
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.ActiveCfg = Debug|x64
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.ActiveCfg = Debug|x64
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.Build.0 = Debug|x64
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.Build.0 = Debug|x64
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|Win32.ActiveCfg = Release|Win32
 		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|Win32.ActiveCfg = Release|Win32
-		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|x64.ActiveCfg = Release|Win32
+		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|Win32.Build.0 = Release|Win32
+		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|x64.ActiveCfg = Release|x64
+		{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|x64.Build.0 = Release|x64
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.ActiveCfg = Debug|Win32
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.ActiveCfg = Debug|Win32
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.Build.0 = Debug|Win32
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.Build.0 = Debug|Win32
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.ActiveCfg = Debug|x64
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.ActiveCfg = Debug|x64
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.Build.0 = Debug|x64
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.Build.0 = Debug|x64
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.ActiveCfg = Release|Win32
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.ActiveCfg = Release|Win32
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.Build.0 = Release|Win32
 		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.Build.0 = Release|Win32
-		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|x64.ActiveCfg = Release|Win32
+		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|x64.ActiveCfg = Release|x64
+		{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|x64.Build.0 = Release|x64
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.ActiveCfg = Debug|Win32
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.ActiveCfg = Debug|Win32
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.Build.0 = Debug|Win32
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.Build.0 = Debug|Win32
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.ActiveCfg = Debug|x64
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.ActiveCfg = Debug|x64
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.Build.0 = Debug|x64
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.Build.0 = Debug|x64
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.ActiveCfg = Release|Win32
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.ActiveCfg = Release|Win32
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.Build.0 = Release|Win32
 		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.Build.0 = Release|Win32
-		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|x64.ActiveCfg = Release|Win32
+		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|x64.ActiveCfg = Release|x64
+		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|x64.Build.0 = Release|x64
 		{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.ActiveCfg = Debug|Win32
 		{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.ActiveCfg = Debug|Win32
 		{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.Build.0 = Debug|Win32
 		{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.Build.0 = Debug|Win32
 		{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.ActiveCfg = Debug|x64
 		{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.ActiveCfg = Debug|x64

+ 17 - 7
libs/SDL2/WhatsNew.txt

@@ -6,8 +6,8 @@ This is a list of major changes in SDL's version history.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 General:
 General:
 * Added SDL_GL_ResetAttributes() to reset OpenGL attributes to default values
 * Added SDL_GL_ResetAttributes() to reset OpenGL attributes to default values
-* Added an API to load a database of Game Controller mappings from a file:    
-    SDL_GameControllerAddMappingsFromFile
+* Added an API to load a database of game controller mappings from a file:
+    SDL_GameControllerAddMappingsFromFile(), SDL_GameControllerAddMappingsFromRW()
 * Added game controller mappings for the PS4 and OUYA controllers
 * Added game controller mappings for the PS4 and OUYA controllers
 * Added SDL_GetDefaultAssertionHandler() and SDL_GetAssertionHandler()
 * Added SDL_GetDefaultAssertionHandler() and SDL_GetAssertionHandler()
 * Added SDL_DetachThread()
 * Added SDL_DetachThread()
@@ -15,23 +15,33 @@ General:
 * Added SDL_vsscanf(), SDL_acos(), and SDL_asin() to the stdlib routines
 * Added SDL_vsscanf(), SDL_acos(), and SDL_asin() to the stdlib routines
 * EGL can now create/manage OpenGL and OpenGL ES 1.x/2.x contexts, and share
 * EGL can now create/manage OpenGL and OpenGL ES 1.x/2.x contexts, and share
   them using SDL_GL_SHARE_WITH_CURRENT_CONTEXT
   them using SDL_GL_SHARE_WITH_CURRENT_CONTEXT
+* Added a field "clicks" to the mouse button event which records whether the event is a single click, double click, etc.
+* The screensaver is now disabled by default, and there is a hint SDL_HINT_VIDEO_ALLOW_SCREENSAVER that can change that behavior.
+* Added a hint SDL_HINT_MOUSE_RELATIVE_MODE_WARP to specify whether mouse relative mode should be emulated using mouse warping.
 * testgl2 does not need to link with libGL anymore
 * testgl2 does not need to link with libGL anymore
 * Added testgles2 test program to demonstrate working with OpenGL ES 2.0
 * Added testgles2 test program to demonstrate working with OpenGL ES 2.0
 * Added controllermap test program to visually map a game controller
 * Added controllermap test program to visually map a game controller
-  
+
 Windows:
 Windows:
 * Support for OpenGL ES 2.x contexts using either WGL or EGL (natively via
 * Support for OpenGL ES 2.x contexts using either WGL or EGL (natively via
   the driver or emulated through ANGLE)
   the driver or emulated through ANGLE)
+* Added a hint SDL_HINT_VIDEO_WIN_D3DCOMPILER to specify which D3D shader compiler to use for OpenGL ES 2 support through ANGLE
+* Added a hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that is useful when creating multiple windows that should share the same OpenGL context.
+* Added an event SDL_RENDER_TARGETS_RESET that is sent when D3D9 render targets are reset after the device has been restored.
+
+Mac OS X:
+* Added a hint SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK to control whether Ctrl+click should be treated as a right click on Mac OS X. This is off by default.
+
+Linux:
+* Fixed fullscreen and focused behavior when receiving NotifyGrab events
+* Added experimental Wayland and Mir support, disabled by default
 
 
 Android:
 Android:
 * Joystick support (minimum SDK version required to build SDL is now 12, 
 * Joystick support (minimum SDK version required to build SDL is now 12, 
   the required runtime version remains at 10, but on such devices joystick 
   the required runtime version remains at 10, but on such devices joystick 
   support won't be available).
   support won't be available).
 * Hotplugging support for joysticks
 * Hotplugging support for joysticks
-
-Linux:
-* Fixed fullscreen and focused behavior when receiving NotifyGrab events
-* Added experimental Wayland and Mir support, disabled by default
+* Added a hint SDL_HINT_ACCELEROMETER_AS_JOYSTICK to control whether the accelerometer should be listed as a 3 axis joystick, which it will by default.
 
 
 
 
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------

+ 3 - 3
libs/SDL2/cmake/sdlchecks.cmake

@@ -556,9 +556,9 @@ endmacro(CheckWayland)
 #
 #
 macro(CheckCOCOA)
 macro(CheckCOCOA)
   if(VIDEO_COCOA)
   if(VIDEO_COCOA)
-    check_objc_source_compiles("
-        #import <Cocoa/Cocoa.h>
-        int main (int argc, char** argv) {}" HAVE_VIDEO_COCOA)
+    if(APPLE) # Apple always has Cocoa.
+      set(HAVE_VIDEO_COCOA TRUE)
+    endif(APPLE)
     if(HAVE_VIDEO_COCOA)
     if(HAVE_VIDEO_COCOA)
       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)

+ 10 - 10
libs/SDL2/configure

@@ -18688,9 +18688,9 @@ CheckWayland()
 if test "${enable_video_wayland+set}" = set; then :
 if test "${enable_video_wayland+set}" = set; then :
   enableval=$enable_video_wayland;
   enableval=$enable_video_wayland;
 else
 else
-  enable_video_wayland=no
+  enable_video_wayland=yes
 fi
 fi
- #yes)
+
 
 
     # Check whether --enable-video-wayland-qt-touch was given.
     # Check whether --enable-video-wayland-qt-touch was given.
 if test "${enable_video_wayland_qt_touch+set}" = set; then :
 if test "${enable_video_wayland_qt_touch+set}" = set; then :
@@ -18842,9 +18842,9 @@ CheckMir()
 if test "${enable_video_mir+set}" = set; then :
 if test "${enable_video_mir+set}" = set; then :
   enableval=$enable_video_mir;
   enableval=$enable_video_mir;
 else
 else
-  enable_video_mir=no
+  enable_video_mir=yes
 fi
 fi
- #yes)
+
 
 
     if test x$enable_video = xyes -a x$enable_video_mir = xyes; then
     if test x$enable_video = xyes -a x$enable_video_mir = xyes; then
         # Extract the first word of "pkg-config", so it can be a program name with args.
         # Extract the first word of "pkg-config", so it can be a program name with args.
@@ -20173,11 +20173,6 @@ main ()
 
 
 int event_type = XI_TouchBegin;
 int event_type = XI_TouchBegin;
 XITouchClassInfo *t;
 XITouchClassInfo *t;
-Status
-XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
-{
-    return (Status)0;
-}
 
 
   ;
   ;
   return 0;
   return 0;
@@ -22808,7 +22803,12 @@ $as_echo "#define SDL_LOADSO_WINDOWS 1" >>confdefs.h
             have_loadso=yes
             have_loadso=yes
         fi
         fi
         # Set up the system libraries we need
         # Set up the system libraries we need
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -XCClinker -static-libgcc"
+        if test -f /lib/w32api/libuuid.a; then
+            LIBUUID=/lib/w32api/libuuid.a
+        else
+            LIBUUID=-luuid
+        fi
+        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion $LIBUUID -XCClinker -static-libgcc"
         # The Windows platform requires special setup
         # The Windows platform requires special setup
         VERSION_SOURCES="$srcdir/src/main/windows/*.rc"
         VERSION_SOURCES="$srcdir/src/main/windows/*.rc"
         SDLMAIN_SOURCES="$srcdir/src/main/windows/*.c"
         SDLMAIN_SOURCES="$srcdir/src/main/windows/*.c"

+ 8 - 8
libs/SDL2/configure.in

@@ -1164,7 +1164,7 @@ CheckWayland()
 {
 {
     AC_ARG_ENABLE(video-wayland,
     AC_ARG_ENABLE(video-wayland,
 AC_HELP_STRING([--enable-video-wayland], [use Wayland video driver [[default=yes]]]),
 AC_HELP_STRING([--enable-video-wayland], [use Wayland video driver [[default=yes]]]),
-                  ,enable_video_wayland=no) #yes)
+                  ,enable_video_wayland=yes)
 
 
     AC_ARG_ENABLE(video-wayland-qt-touch,
     AC_ARG_ENABLE(video-wayland-qt-touch,
 AC_HELP_STRING([--enable-video-wayland-qt-touch], [QtWayland server support for Wayland video driver [[default=yes]]]),
 AC_HELP_STRING([--enable-video-wayland-qt-touch], [QtWayland server support for Wayland video driver [[default=yes]]]),
@@ -1246,7 +1246,7 @@ CheckMir()
 {
 {
     AC_ARG_ENABLE(video-mir,
     AC_ARG_ENABLE(video-mir,
 AC_HELP_STRING([--enable-video-mir], [use Mir video driver [[default=yes]]]),
 AC_HELP_STRING([--enable-video-mir], [use Mir video driver [[default=yes]]]),
-                  ,enable_video_mir=no) #yes)
+                  ,enable_video_mir=yes)
 
 
     if test x$enable_video = xyes -a x$enable_video_mir = xyes; then
     if test x$enable_video = xyes -a x$enable_video_mir = xyes; then
         AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
         AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
@@ -1555,11 +1555,6 @@ AC_HELP_STRING([--enable-video-x11-xinput], [enable X11 XInput extension for man
             	],[
             	],[
 int event_type = XI_TouchBegin;
 int event_type = XI_TouchBegin;
 XITouchClassInfo *t;
 XITouchClassInfo *t;
-Status 
-XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
-{
-    return (Status)0;
-}
             	],[
             	],[
             	have_xinput2_multitouch=yes
             	have_xinput2_multitouch=yes
             	AC_DEFINE(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH)
             	AC_DEFINE(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH)
@@ -2860,7 +2855,12 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
             have_loadso=yes
             have_loadso=yes
         fi
         fi
         # Set up the system libraries we need
         # Set up the system libraries we need
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -XCClinker -static-libgcc"
+        if test -f /lib/w32api/libuuid.a; then
+            LIBUUID=/lib/w32api/libuuid.a
+        else
+            LIBUUID=-luuid
+        fi
+        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion $LIBUUID -XCClinker -static-libgcc"
         # The Windows platform requires special setup
         # The Windows platform requires special setup
         VERSION_SOURCES="$srcdir/src/main/windows/*.rc"
         VERSION_SOURCES="$srcdir/src/main/windows/*.rc"
         SDLMAIN_SOURCES="$srcdir/src/main/windows/*.c"
         SDLMAIN_SOURCES="$srcdir/src/main/windows/*.c"

+ 2 - 2
libs/SDL2/include/SDL_events.h

@@ -257,8 +257,8 @@ typedef struct SDL_MouseWheelEvent
     Uint32 timestamp;
     Uint32 timestamp;
     Uint32 windowID;    /**< The window with mouse focus, if any */
     Uint32 windowID;    /**< The window with mouse focus, if any */
     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
-    Sint32 x;           /**< The amount scrolled horizontally */
-    Sint32 y;           /**< The amount scrolled vertically */
+    Sint32 x;           /**< The amount scrolled horizontally, positive to the right and negative to the left */
+    Sint32 y;           /**< The amount scrolled vertically, positive away from the user and negative toward the user */
 } SDL_MouseWheelEvent;
 } SDL_MouseWheelEvent;
 
 
 /**
 /**

+ 36 - 16
libs/SDL2/include/SDL_hints.h

@@ -128,6 +128,17 @@ extern "C" {
  */
  */
 #define SDL_HINT_RENDER_VSYNC               "SDL_RENDER_VSYNC"
 #define SDL_HINT_RENDER_VSYNC               "SDL_RENDER_VSYNC"
 
 
+/**
+ *  \brief  A variable controlling whether the screensaver is enabled. 
+ *
+ *  This variable can be set to the following values:
+ *    "0"       - Disable screensaver
+ *    "1"       - Enable screensaver
+ *
+ *  By default SDL will disable the screensaver.
+ */
+#define SDL_HINT_VIDEO_ALLOW_SCREENSAVER    "SDL_VIDEO_ALLOW_SCREENSAVER"
+
 /**
 /**
  *  \brief  A variable controlling whether the X11 VidMode extension should be used.
  *  \brief  A variable controlling whether the X11 VidMode extension should be used.
  *
  *
@@ -189,17 +200,6 @@ extern "C" {
  */
  */
 #define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS   "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
 #define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS   "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
 
 
-/**
- *  \brief Set whether windows go fullscreen in their own spaces on Mac OS X
- *
- *  This variable can be set to the following values:
- *    "0"       - Fullscreen windows will use the classic fullscreen mode
- *    "1"       - Fullscreen windows will use fullscreen spaces
- *
- *  By default SDL will use the classic fullscreen mode.
- */
-#define SDL_HINT_VIDEO_FULLSCREEN_SPACES   "SDL_VIDEO_FULLSCREEN_SPACES"
-
 /**
 /**
  *  \brief  A variable controlling whether the idle timer is disabled on iOS.
  *  \brief  A variable controlling whether the idle timer is disabled on iOS.
  *
  *
@@ -233,15 +233,15 @@ extern "C" {
  *    "0"       - List only real joysticks and accept input from them
  *    "0"       - List only real joysticks and accept input from them
  *    "1"       - List real joysticks along with the accelerometer as if it were a 3 axis joystick (the default).
  *    "1"       - List real joysticks along with the accelerometer as if it were a 3 axis joystick (the default).
  */
  */
-#define SDL_HINT_ACCEL_AS_JOY "SDL_ACCEL_AS_JOY"
+#define SDL_HINT_ACCELEROMETER_AS_JOYSTICK "SDL_ACCELEROMETER_AS_JOYSTICK"
 
 
 
 
 /**
 /**
  *  \brief  A variable that lets you disable the detection and use of Xinput gamepad devices
  *  \brief  A variable that lets you disable the detection and use of Xinput gamepad devices
  *
  *
  *  The variable can be set to the following values:
  *  The variable can be set to the following values:
- *    "0"       - Disable XInput timer (only uses direct input)
- *    "1"       - Enable XInput timer (the default)
+ *    "0"       - Disable XInput detection (only uses direct input)
+ *    "1"       - Enable XInput detection (the default)
  */
  */
 #define SDL_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED"
 #define SDL_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED"
 
 
@@ -264,7 +264,7 @@ extern "C" {
  *    "0"       - Disable joystick & gamecontroller input events when the
  *    "0"       - Disable joystick & gamecontroller input events when the
  *                application is in the background.
  *                application is in the background.
  *    "1"       - Enable joystick & gamecontroller input events when the
  *    "1"       - Enable joystick & gamecontroller input events when the
- *                application is in the backgroumd.
+ *                application is in the background.
  *
  *
  *  The default value is "0".  This hint may be set at any time.
  *  The default value is "0".  This hint may be set at any time.
  */
  */
@@ -318,7 +318,7 @@ extern "C" {
 *  SDL has EGL and OpenGL ES2 support on Windows via the ANGLE project. It
 *  SDL has EGL and OpenGL ES2 support on Windows via the ANGLE project. It
 *  can use two different sets of binaries, those compiled by the user from source
 *  can use two different sets of binaries, those compiled by the user from source
 *  or those provided by the Chrome browser. In the later case, these binaries require
 *  or those provided by the Chrome browser. In the later case, these binaries require
-*  that SDL loads 
+*  that SDL loads a DLL providing the shader compiler.
 *
 *
 *  This variable can be set to the following values:
 *  This variable can be set to the following values:
 *    "d3dcompiler_46.dll" - default, best for Vista or later.
 *    "d3dcompiler_46.dll" - default, best for Vista or later.
@@ -347,6 +347,26 @@ extern "C" {
 */
 */
 #define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT    "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"
 #define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT    "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"
 
 
+/**
+ *  \brief  A variable that dictates policy for fullscreen Spaces on Mac OS X.
+ *
+ *  This hint only applies to Mac OS X.
+ *
+ *  The variable can be set to the following values:
+ *    "0"       - Disable Spaces support (FULLSCREEN_DESKTOP won't use them and
+ *                SDL_WINDOW_RESIZABLE windows won't offer the "fullscreen"
+ *                button on their titlebars).
+ *    "1"       - Enable Spaces support (FULLSCREEN_DESKTOP will use them and
+ *                SDL_WINDOW_RESIZABLE windows will offer the "fullscreen"
+ *                button on their titlebars.
+ *
+ *  The default value is "1". Spaces are disabled regardless of this hint if
+ *   the OS isn't at least Mac OS X Lion (10.7). This hint must be set before
+ *   any windows are created.
+ */
+#define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES    "SDL_VIDEO_MAC_FULLSCREEN_SPACES"
+
+
 /**
 /**
  *  \brief  An enumeration of hint priorities
  *  \brief  An enumeration of hint priorities
  */
  */

+ 7 - 2
libs/SDL2/src/SDL.c

@@ -38,7 +38,8 @@
 #if !SDL_TIMERS_DISABLED
 #if !SDL_TIMERS_DISABLED
 extern int SDL_TimerInit(void);
 extern int SDL_TimerInit(void);
 extern void SDL_TimerQuit(void);
 extern void SDL_TimerQuit(void);
-extern void SDL_InitTicks(void);
+extern void SDL_TicksInit(void);
+extern void SDL_TicksQuit(void);
 #endif
 #endif
 #if SDL_VIDEO_DRIVER_WINDOWS
 #if SDL_VIDEO_DRIVER_WINDOWS
 extern int SDL_HelperWindowCreate(void);
 extern int SDL_HelperWindowCreate(void);
@@ -123,7 +124,7 @@ SDL_InitSubSystem(Uint32 flags)
 #endif
 #endif
 
 
 #if !SDL_TIMERS_DISABLED
 #if !SDL_TIMERS_DISABLED
-    SDL_InitTicks();
+    SDL_TicksInit();
 #endif
 #endif
 
 
     if ((flags & SDL_INIT_GAMECONTROLLER)) {
     if ((flags & SDL_INIT_GAMECONTROLLER)) {
@@ -355,6 +356,10 @@ SDL_Quit(void)
 #endif
 #endif
     SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
     SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
 
 
+#if !SDL_TIMERS_DISABLED
+    SDL_TicksQuit();
+#endif
+
     SDL_ClearHints();
     SDL_ClearHints();
     SDL_AssertionsQuit();
     SDL_AssertionsQuit();
     SDL_LogResetPriorities();
     SDL_LogResetPriorities();

+ 47 - 7
libs/SDL2/src/audio/SDL_audiocvt.c

@@ -39,7 +39,9 @@ SDL_ConvertMono(SDL_AudioCVT * cvt, SDL_AudioFormat format)
 #ifdef DEBUG_CONVERT
 #ifdef DEBUG_CONVERT
     fprintf(stderr, "Converting to mono\n");
     fprintf(stderr, "Converting to mono\n");
 #endif
 #endif
-    switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) {
+	switch (format & (SDL_AUDIO_MASK_SIGNED |
+                      SDL_AUDIO_MASK_BITSIZE |
+                      SDL_AUDIO_MASK_DATATYPE)) {
     case AUDIO_U8:
     case AUDIO_U8:
         {
         {
             Uint8 *src, *dst;
             Uint8 *src, *dst;
@@ -331,7 +333,9 @@ SDL_ConvertSurround(SDL_AudioCVT * cvt, SDL_AudioFormat format)
     fprintf(stderr, "Converting stereo to surround\n");
     fprintf(stderr, "Converting stereo to surround\n");
 #endif
 #endif
 
 
-    switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) {
+    switch (format & (SDL_AUDIO_MASK_SIGNED  |
+                      SDL_AUDIO_MASK_BITSIZE |
+                      SDL_AUDIO_MASK_DATATYPE)) {
     case AUDIO_U8:
     case AUDIO_U8:
         {
         {
             Uint8 *src, *dst, lf, rf, ce;
             Uint8 *src, *dst, lf, rf, ce;
@@ -499,8 +503,8 @@ SDL_ConvertSurround(SDL_AudioCVT * cvt, SDL_AudioFormat format)
     case AUDIO_S32:
     case AUDIO_S32:
         {
         {
             Sint32 lf, rf, ce;
             Sint32 lf, rf, ce;
-            const Uint32 *src = (const Uint32 *) cvt->buf + cvt->len_cvt;
-            Uint32 *dst = (Uint32 *) cvt->buf + cvt->len_cvt * 3;
+            const Uint32 *src = (const Uint32 *) (cvt->buf + cvt->len_cvt);
+            Uint32 *dst = (Uint32 *) (cvt->buf + cvt->len_cvt * 3);
 
 
             if (SDL_AUDIO_ISBIGENDIAN(format)) {
             if (SDL_AUDIO_ISBIGENDIAN(format)) {
                 for (i = cvt->len_cvt / 8; i; --i) {
                 for (i = cvt->len_cvt / 8; i; --i) {
@@ -537,8 +541,8 @@ SDL_ConvertSurround(SDL_AudioCVT * cvt, SDL_AudioFormat format)
     case AUDIO_F32:
     case AUDIO_F32:
         {
         {
             float lf, rf, ce;
             float lf, rf, ce;
-            const float *src = (const float *) cvt->buf + cvt->len_cvt;
-            float *dst = (float *) cvt->buf + cvt->len_cvt * 3;
+            const float *src = (const float *) (cvt->buf + cvt->len_cvt);
+            float *dst = (float *) (cvt->buf + cvt->len_cvt * 3);
 
 
             if (SDL_AUDIO_ISBIGENDIAN(format)) {
             if (SDL_AUDIO_ISBIGENDIAN(format)) {
                 for (i = cvt->len_cvt / 8; i; --i) {
                 for (i = cvt->len_cvt / 8; i; --i) {
@@ -588,7 +592,9 @@ SDL_ConvertSurround_4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
     fprintf(stderr, "Converting stereo to quad\n");
     fprintf(stderr, "Converting stereo to quad\n");
 #endif
 #endif
 
 
-    switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) {
+    switch (format & (SDL_AUDIO_MASK_SIGNED |
+                      SDL_AUDIO_MASK_BITSIZE |
+                      SDL_AUDIO_MASK_DATATYPE)) {
     case AUDIO_U8:
     case AUDIO_U8:
         {
         {
             Uint8 *src, *dst, lf, rf, ce;
             Uint8 *src, *dst, lf, rf, ce;
@@ -762,6 +768,40 @@ SDL_ConvertSurround_4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
             }
             }
         }
         }
         break;
         break;
+
+    case AUDIO_F32:
+        {
+            const float *src = (const float *) (cvt->buf + cvt->len_cvt);
+            float *dst = (float *) (cvt->buf + cvt->len_cvt * 2);
+            float lf, rf, ce;
+
+            if (SDL_AUDIO_ISBIGENDIAN(format)) {
+                for (i = cvt->len_cvt / 8; i; --i) {
+                    dst -= 4;
+                    src -= 2;
+                    lf = SDL_SwapFloatBE(src[0]);
+                    rf = SDL_SwapFloatBE(src[1]);
+                    ce = (lf / 2) + (rf / 2);
+                    dst[0] = src[0];
+                    dst[1] = src[1];
+                    dst[2] = SDL_SwapFloatBE(lf - ce);
+                    dst[3] = SDL_SwapFloatBE(rf - ce);
+                }
+            } else {
+                for (i = cvt->len_cvt / 8; i; --i) {
+                    dst -= 4;
+                    src -= 2;
+                    lf = SDL_SwapFloatLE(src[0]);
+                    rf = SDL_SwapFloatLE(src[1]);
+                    ce = (lf / 2) + (rf / 2);
+                    dst[0] = src[0];
+                    dst[1] = src[1];
+                    dst[2] = SDL_SwapFloatLE(lf - ce);
+                    dst[3] = SDL_SwapFloatLE(rf - ce);
+                }
+            }
+        }
+        break;
     }
     }
     cvt->len_cvt *= 2;
     cvt->len_cvt *= 2;
     if (cvt->filters[++cvt->filter_index]) {
     if (cvt->filters[++cvt->filter_index]) {

+ 16 - 4
libs/SDL2/src/cpuinfo/SDL_cpuinfo.c

@@ -98,7 +98,7 @@ CPU_haveCPUID(void)
     );
     );
 #elif defined(__GNUC__) && defined(__x86_64__)
 #elif defined(__GNUC__) && defined(__x86_64__)
 /* Technically, if this is being compiled under __x86_64__ then it has 
 /* Technically, if this is being compiled under __x86_64__ then it has 
-CPUid by definition.  But it's nice to be able to prove it.  :)      */
+   CPUid by definition.  But it's nice to be able to prove it.  :)      */
     __asm__ (
     __asm__ (
 "        pushfq                      # Get original EFLAGS             \n"
 "        pushfq                      # Get original EFLAGS             \n"
 "        popq    %%rax                                                 \n"
 "        popq    %%rax                                                 \n"
@@ -131,6 +131,8 @@ CPUid by definition.  But it's nice to be able to prove it.  :)      */
         mov     has_CPUID,1         ; We have CPUID support
         mov     has_CPUID,1         ; We have CPUID support
 done:
 done:
     }
     }
+#elif defined(_MSC_VER) && defined(_M_X64)
+    has_CPUID = 1;
 #elif defined(__sun) && defined(__i386)
 #elif defined(__sun) && defined(__i386)
     __asm (
     __asm (
 "       pushfl                 \n"
 "       pushfl                 \n"
@@ -191,7 +193,17 @@ done:
         __asm mov b, ebx \
         __asm mov b, ebx \
         __asm mov c, ecx \
         __asm mov c, ecx \
         __asm mov d, edx \
         __asm mov d, edx \
-    }
+}
+#elif defined(_MSC_VER) && defined(_M_X64)
+#define cpuid(func, a, b, c, d) \
+{ \
+    int CPUInfo[4]; \
+    __cpuid(CPUInfo, func); \
+    a = CPUInfo[0]; \
+    b = CPUInfo[1]; \
+    c = CPUInfo[2]; \
+    d = CPUInfo[3]; \
+}
 #else
 #else
 #define cpuid(func, a, b, c, d) \
 #define cpuid(func, a, b, c, d) \
     a = b = c = d = 0
     a = b = c = d = 0
@@ -653,7 +665,7 @@ SDL_GetSystemRAM(void)
 #endif
 #endif
 #ifdef HAVE_SYSCTLBYNAME
 #ifdef HAVE_SYSCTLBYNAME
         if (SDL_SystemRAM <= 0) {
         if (SDL_SystemRAM <= 0) {
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 #ifdef HW_REALMEM
 #ifdef HW_REALMEM
             int mib[2] = {CTL_HW, HW_REALMEM};
             int mib[2] = {CTL_HW, HW_REALMEM};
 #else
 #else
@@ -662,7 +674,7 @@ SDL_GetSystemRAM(void)
 #endif /* HW_REALMEM */
 #endif /* HW_REALMEM */
 #else
 #else
             int mib[2] = {CTL_HW, HW_MEMSIZE};
             int mib[2] = {CTL_HW, HW_MEMSIZE};
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __FreeBSD_kernel__ */
             Uint64 memsize = 0;
             Uint64 memsize = 0;
             size_t len = sizeof(memsize);
             size_t len = sizeof(memsize);
             
             

+ 14 - 3
libs/SDL2/src/events/SDL_events.c

@@ -503,17 +503,28 @@ SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
 void
 void
 SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
 SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
 {
 {
-    SDL_EventWatcher *watcher;
+    SDL_EventWatcher *watcher, *tail;
 
 
     watcher = (SDL_EventWatcher *)SDL_malloc(sizeof(*watcher));
     watcher = (SDL_EventWatcher *)SDL_malloc(sizeof(*watcher));
     if (!watcher) {
     if (!watcher) {
         /* Uh oh... */
         /* Uh oh... */
         return;
         return;
     }
     }
+
+    /* create the watcher */
     watcher->callback = filter;
     watcher->callback = filter;
     watcher->userdata = userdata;
     watcher->userdata = userdata;
-    watcher->next = SDL_event_watchers;
-    SDL_event_watchers = watcher;
+    watcher->next = NULL;
+
+    /* add the watcher to the end of the list */
+    if (SDL_event_watchers) {
+        for (tail = SDL_event_watchers; tail->next; tail = tail->next) {
+            continue;
+        }
+        tail->next = watcher;
+    } else {
+        SDL_event_watchers = watcher;
+    }
 }
 }
 
 
 /* FIXME: This is not thread-safe yet */
 /* FIXME: This is not thread-safe yet */

+ 1 - 6
libs/SDL2/src/events/SDL_gesture.c

@@ -418,13 +418,8 @@ int SDL_GestureAddTouch(SDL_TouchID touchId)
 
 
     SDL_gestureTouch = gestureTouch;
     SDL_gestureTouch = gestureTouch;
 
 
-    SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0;
+    SDL_zero(SDL_gestureTouch[SDL_numGestureTouches]);
     SDL_gestureTouch[SDL_numGestureTouches].id = touchId;
     SDL_gestureTouch[SDL_numGestureTouches].id = touchId;
-
-    SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0;
-
-    SDL_gestureTouch[SDL_numGestureTouches].recording = SDL_FALSE;
-
     SDL_numGestureTouches++;
     SDL_numGestureTouches++;
     return 0;
     return 0;
 }
 }

+ 4 - 1
libs/SDL2/src/events/SDL_mouse.c

@@ -538,7 +538,10 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
     } else if (enabled && ShouldUseRelativeModeWarp(mouse)) {
     } else if (enabled && ShouldUseRelativeModeWarp(mouse)) {
         mouse->relative_mode_warp = SDL_TRUE;
         mouse->relative_mode_warp = SDL_TRUE;
     } else if (mouse->SetRelativeMouseMode(enabled) < 0) {
     } else if (mouse->SetRelativeMouseMode(enabled) < 0) {
-        return -1;
+        if (enabled) {
+            // Fall back to warp mode if native relative mode failed
+            mouse->relative_mode_warp = SDL_TRUE;
+        }
     }
     }
     mouse->relative_mode = enabled;
     mouse->relative_mode = enabled;
 
 

+ 53 - 11
libs/SDL2/src/filesystem/windows/SDL_sysfilesystem.c

@@ -69,28 +69,70 @@ SDL_GetPrefPath(const char *org, const char *app)
      *                          NULL, &wszPath);
      *                          NULL, &wszPath);
      */
      */
 
 
-    TCHAR path[MAX_PATH];
+    WCHAR path[MAX_PATH];
     char *utf8 = NULL;
     char *utf8 = NULL;
     char *retval = NULL;
     char *retval = NULL;
+    WCHAR* worg = NULL;
+    WCHAR* wapp = NULL;
+    size_t new_wpath_len = 0;
+    BOOL api_result = FALSE;
 
 
-    if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) {
+    if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) {
         WIN_SetError("Couldn't locate our prefpath");
         WIN_SetError("Couldn't locate our prefpath");
         return NULL;
         return NULL;
     }
     }
 
 
-    utf8 = WIN_StringToUTF8(path);
-    if (utf8) {
-        const size_t len = SDL_strlen(utf8) + SDL_strlen(org) + SDL_strlen(app) + 4;
-        retval = (char *) SDL_malloc(len);
-        if (!retval) {
-            SDL_free(utf8);
-            SDL_OutOfMemory();
+    worg = WIN_UTF8ToString(org);
+    if (worg == NULL) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
+
+    wapp = WIN_UTF8ToString(app);
+    if (wapp == NULL) {
+        SDL_free(worg);
+        SDL_OutOfMemory();
+        return NULL;
+    }
+
+    new_wpath_len = lstrlenW(worg) + lstrlenW(wapp) + lstrlenW(path) + 3;
+
+    if ((new_wpath_len + 1) > MAX_PATH) {
+        SDL_free(worg);
+        SDL_free(wapp);
+        WIN_SetError("Path too long.");
+        return NULL;
+    }
+
+    lstrcatW(path, L"\\");
+    lstrcatW(path, worg);
+    SDL_free(worg);
+
+    api_result = CreateDirectoryW(path, NULL);
+    if (api_result == FALSE) {
+        if (GetLastError() != ERROR_ALREADY_EXISTS) {
+            SDL_free(wapp);
+            WIN_SetError("Couldn't create a prefpath.");
             return NULL;
             return NULL;
         }
         }
-        SDL_snprintf(retval, len, "%s\\%s\\%s\\", utf8, org, app);
-        SDL_free(utf8);
     }
     }
 
 
+    lstrcatW(path, L"\\");
+    lstrcatW(path, wapp);
+    SDL_free(wapp);
+
+    api_result = CreateDirectoryW(path, NULL);
+    if (api_result == FALSE) {
+        if (GetLastError() != ERROR_ALREADY_EXISTS) {
+            WIN_SetError("Couldn't create a prefpath.");
+            return NULL;
+        }
+    }
+
+    lstrcatW(path, L"\\");
+
+    retval = WIN_StringToUTF8(path);
+
     return retval;
     return retval;
 }
 }
 
 

+ 2 - 3
libs/SDL2/src/haptic/darwin/SDL_syshaptic.c

@@ -156,7 +156,7 @@ SDL_SYS_HapticInit(void)
     io_service_t device;
     io_service_t device;
 
 
     if (numhaptics != -1) {
     if (numhaptics != -1) {
-        return SDL_Error("Haptic subsystem already initialized!");
+        return SDL_SetError("Haptic subsystem already initialized!");
     }
     }
     numhaptics = 0;
     numhaptics = 0;
 
 
@@ -237,7 +237,7 @@ MacHaptic_MaybeAddDevice( io_object_t device )
         }
         }
     }
     }
 
 
-    item = (SDL_hapticlist_item *)SDL_malloc( sizeof(SDL_hapticlist_item));
+    item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
     if (item == NULL) {
     if (item == NULL) {
         return SDL_SetError("Could not allocate haptic storage");
         return SDL_SetError("Could not allocate haptic storage");
     }
     }
@@ -248,7 +248,6 @@ MacHaptic_MaybeAddDevice( io_object_t device )
     /* Set basic device data. */
     /* Set basic device data. */
     HIDGetDeviceProduct(device, item->name);
     HIDGetDeviceProduct(device, item->name);
     item->dev = device;
     item->dev = device;
-    item->haptic = NULL;
 
 
     /* Set usage pages. */
     /* Set usage pages. */
     hidProperties = 0;
     hidProperties = 0;

+ 2 - 2
libs/SDL2/src/haptic/linux/SDL_syshaptic.c

@@ -282,11 +282,11 @@ MaybeAddDevice(const char *path)
         return -1;
         return -1;
     }
     }
 
 
-    item = (SDL_hapticlist_item *) SDL_malloc(sizeof (SDL_hapticlist_item));
+    item = (SDL_hapticlist_item *) SDL_calloc(1, sizeof (SDL_hapticlist_item));
     if (item == NULL) {
     if (item == NULL) {
         return -1;
         return -1;
     }
     }
-    SDL_zerop(item);
+
     item->fname = SDL_strdup(path);
     item->fname = SDL_strdup(path);
     if ( (item->fname == NULL) ) {
     if ( (item->fname == NULL) ) {
         SDL_free(item->fname);
         SDL_free(item->fname);

+ 17 - 7
libs/SDL2/src/haptic/windows/SDL_syshaptic.c

@@ -253,13 +253,11 @@ DirectInputHaptic_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
         return -1;  /* not a device we can use. */
         return -1;  /* not a device we can use. */
     }
     }
 
 
-    item = (SDL_hapticlist_item *)SDL_malloc( sizeof(SDL_hapticlist_item));
+    item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
     if (item == NULL) {
     if (item == NULL) {
         return SDL_OutOfMemory();
         return SDL_OutOfMemory();
     }
     }
 
 
-    SDL_zerop(item);
-
     item->name = WIN_StringToUTF8(pdidInstance->tszProductName);
     item->name = WIN_StringToUTF8(pdidInstance->tszProductName);
     if (!item->name) {
     if (!item->name) {
         SDL_free(item);
         SDL_free(item);
@@ -941,20 +939,32 @@ SDL_SYS_HapticQuit(void)
 {
 {
     SDL_hapticlist_item *item;
     SDL_hapticlist_item *item;
     SDL_hapticlist_item *next = NULL;
     SDL_hapticlist_item *next = NULL;
-
-    if (loaded_xinput) {
-        WIN_UnloadXInputDLL();
-        loaded_xinput = SDL_FALSE;
+    SDL_Haptic *hapticitem = NULL;
+
+    extern SDL_Haptic *SDL_haptics;
+    for (hapticitem = SDL_haptics; hapticitem; hapticitem = hapticitem->next) {
+        if ((hapticitem->hwdata->bXInputHaptic) && (hapticitem->hwdata->thread)) {
+            /* we _have_ to stop the thread before we free the XInput DLL! */
+            hapticitem->hwdata->stopThread = 1;
+            SDL_WaitThread(hapticitem->hwdata->thread, NULL);
+            hapticitem->hwdata->thread = NULL;
+        }
     }
     }
 
 
     for (item = SDL_hapticlist; item; item = next) {
     for (item = SDL_hapticlist; item; item = next) {
         /* Opened and not closed haptics are leaked, this is on purpose.
         /* Opened and not closed haptics are leaked, this is on purpose.
          * Close your haptic devices after usage. */
          * Close your haptic devices after usage. */
+        /* !!! FIXME: (...is leaking on purpose a good idea?) */
         next = item->next;
         next = item->next;
         SDL_free(item->name);
         SDL_free(item->name);
         SDL_free(item);
         SDL_free(item);
     }
     }
 
 
+    if (loaded_xinput) {
+        WIN_UnloadXInputDLL();
+        loaded_xinput = SDL_FALSE;
+    }
+
     if (dinput != NULL) {
     if (dinput != NULL) {
         IDirectInput8_Release(dinput);
         IDirectInput8_Release(dinput);
         dinput = NULL;
         dinput = NULL;

+ 2 - 0
libs/SDL2/src/joystick/SDL_gamecontroller.c

@@ -835,6 +835,7 @@ SDL_GameControllerLoadHints()
         char *pUserMappings = SDL_malloc( nchHints + 1 );
         char *pUserMappings = SDL_malloc( nchHints + 1 );
         char *pTempMappings = pUserMappings;
         char *pTempMappings = pUserMappings;
         SDL_memcpy( pUserMappings, hint, nchHints );
         SDL_memcpy( pUserMappings, hint, nchHints );
+        pUserMappings[nchHints] = '\0';
         while ( pUserMappings ) {
         while ( pUserMappings ) {
             char *pchNewLine = NULL;
             char *pchNewLine = NULL;
 
 
@@ -1223,6 +1224,7 @@ SDL_GameControllerQuit(void)
         pControllerMap = s_pSupportedControllers;
         pControllerMap = s_pSupportedControllers;
         s_pSupportedControllers = s_pSupportedControllers->next;
         s_pSupportedControllers = s_pSupportedControllers->next;
         SDL_free( pControllerMap->name );
         SDL_free( pControllerMap->name );
+        SDL_free( pControllerMap->mapping );
         SDL_free( pControllerMap );
         SDL_free( pControllerMap );
     }
     }
 
 

+ 2 - 1
libs/SDL2/src/joystick/SDL_gamecontrollerdb.h

@@ -49,7 +49,7 @@ static const char *s_ControllerMappings [] =
     "6d040000000000001fc2000000000000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
     "6d040000000000001fc2000000000000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
     "6d0400000000000019c2000000000000,Logitech Wireless Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least. */
     "6d0400000000000019c2000000000000,Logitech Wireless Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least. */
     "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
     "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
-    "4c05000000000000c405000000000000,PS4 Controller,x:b0,a:b1,b:b2,y:b3,back:b8,guide:b12,start:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,rightshoulder:b5,lefttrigger:a3,rightshoulder:b5,righttrigger:a4,leftstick:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a5,"
+    "4c05000000000000c405000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
     "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
     "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
 #elif defined(__LINUX__)
 #elif defined(__LINUX__)
     "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
     "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
@@ -59,6 +59,7 @@ static const char *s_ControllerMappings [] =
     "030000006d0400001ec2000020200000,Logitech F510 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
     "030000006d0400001ec2000020200000,Logitech F510 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
     "030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
     "030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
     "030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
     "030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+"050000003620000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,platform:Linux,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,",
     "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
     "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
     "030000004c050000c405000011010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
     "030000004c050000c405000011010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
     "03000000de280000ff11000001000000,Valve Streaming Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
     "03000000de280000ff11000001000000,Valve Streaming Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",

+ 3 - 3
libs/SDL2/src/joystick/android/SDL_sysjoystick.c

@@ -379,11 +379,11 @@ Android_RemoveJoystick(int device_id)
 int
 int
 SDL_SYS_JoystickInit(void)
 SDL_SYS_JoystickInit(void)
 {
 {
-    const char *env;
+    const char *hint;
     SDL_SYS_JoystickDetect();
     SDL_SYS_JoystickDetect();
     
     
-    env = SDL_GetHint(SDL_HINT_ACCEL_AS_JOY);
-    if (!env || SDL_atoi(env)) {
+    hint = SDL_GetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK);
+    if (!hint || SDL_atoi(hint)) {
         /* Default behavior, accelerometer as joystick */
         /* Default behavior, accelerometer as joystick */
         Android_AddJoystick(ANDROID_ACCELEROMETER_DEVICE_ID, ANDROID_ACCELEROMETER_NAME, SDL_TRUE, 0, 3, 0, 0);
         Android_AddJoystick(ANDROID_ACCELEROMETER_DEVICE_ID, ANDROID_ACCELEROMETER_NAME, SDL_TRUE, 0, 3, 0, 0);
     }
     }

File diff suppressed because it is too large
+ 336 - 567
libs/SDL2/src/joystick/darwin/SDL_sysjoystick.c


+ 14 - 31
libs/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h

@@ -22,34 +22,19 @@
 
 
 #ifndef SDL_JOYSTICK_IOKIT_H
 #ifndef SDL_JOYSTICK_IOKIT_H
 
 
-
 #include <IOKit/hid/IOHIDLib.h>
 #include <IOKit/hid/IOHIDLib.h>
-#include <IOKit/hid/IOHIDKeys.h>
-#include <IOKit/IOKitLib.h>
-
 
 
 struct recElement
 struct recElement
 {
 {
-    IOHIDElementCookie cookie;  /* unique value which identifies element, will NOT change */
-    long usagePage, usage;      /* HID usage */
-    long min;                   /* reported min value possible */
-    long max;                   /* reported max value possible */
-#if 0
-    /* TODO: maybe should handle the following stuff somehow? */
-
-    long scaledMin;             /* reported scaled min value possible */
-    long scaledMax;             /* reported scaled max value possible */
-    long size;                  /* size in bits of data return from element */
-    Boolean relative;           /* are reports relative to last report (deltas) */
-    Boolean wrapping;           /* does element wrap around (one value higher than max is min) */
-    Boolean nonLinear;          /* are the values reported non-linear relative to element movement */
-    Boolean preferredState;     /* does element have a preferred state (such as a button) */
-    Boolean nullState;          /* does element have null state */
-#endif                          /* 0 */
+    IOHIDElementRef elementRef;
+    IOHIDElementCookie cookie;
+    uint32_t usagePage, usage;      /* HID usage */
+    SInt32 min;                   /* reported min value possible */
+    SInt32 max;                   /* reported max value possible */
 
 
     /* runtime variables used for auto-calibration */
     /* runtime variables used for auto-calibration */
-    long minReport;             /* min returned value */
-    long maxReport;             /* max returned value */
+    SInt32 minReport;             /* min returned value */
+    SInt32 maxReport;             /* max returned value */
 
 
     struct recElement *pNext;   /* next element in list */
     struct recElement *pNext;   /* next element in list */
 };
 };
@@ -57,19 +42,17 @@ typedef struct recElement recElement;
 
 
 struct joystick_hwdata
 struct joystick_hwdata
 {
 {
+    IOHIDDeviceRef deviceRef;   /* HIDManager device handle */
     io_service_t ffservice;     /* Interface for force feedback, 0 = no ff */
     io_service_t ffservice;     /* Interface for force feedback, 0 = no ff */
-    IOHIDDeviceInterface **interface;   /* interface to device, NULL = no interface */
-    IONotificationPortRef notificationPort; /* port to be notified on joystick removal */
-    io_iterator_t portIterator; /* iterator for removal callback */
 
 
     char product[256];          /* name of product */
     char product[256];          /* name of product */
-    long usage;                 /* usage page from IOUSBHID Parser.h which defines general usage */
-    long usagePage;             /* usage within above page from IOUSBHID Parser.h which defines specific usage */
+    uint32_t usage;                 /* usage page from IOUSBHID Parser.h which defines general usage */
+    uint32_t usagePage;             /* usage within above page from IOUSBHID Parser.h which defines specific usage */
 
 
-    long axes;                  /* number of axis (calculated, not reported by device) */
-    long buttons;               /* number of buttons (calculated, not reported by device) */
-    long hats;                  /* number of hat switches (calculated, not reported by device) */
-    long elements;              /* number of total elements (should be total of above) (calculated, not reported by device) */
+    int axes;                  /* number of axis (calculated, not reported by device) */
+    int buttons;               /* number of buttons (calculated, not reported by device) */
+    int hats;                  /* number of hat switches (calculated, not reported by device) */
+    int elements;              /* number of total elements (should be total of above) (calculated, not reported by device) */
 
 
     recElement *firstAxis;
     recElement *firstAxis;
     recElement *firstButton;
     recElement *firstButton;

+ 4 - 1
libs/SDL2/src/joystick/windows/SDL_dxjoystick.c

@@ -782,7 +782,7 @@ EnumXInputDevices(JoyStick_DeviceData **pContext)
             XINPUT_CAPABILITIES capabilities;
             XINPUT_CAPABILITIES capabilities;
             if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
             if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
                 /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */
                 /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */
-                /* !!! FIXME: we might want to support steering wheels or guitars or whatever laster. */
+                /* !!! FIXME: we might want to support steering wheels or guitars or whatever later. */
                 if (capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD) {
                 if (capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD) {
                     AddXInputDevice(userid, pContext);
                     AddXInputDevice(userid, pContext);
                 }
                 }
@@ -1448,6 +1448,7 @@ SDL_SYS_JoystickUpdate_XInput(SDL_Joystick * joystick)
         XINPUT_STATE_EX *pXInputState = &joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot];
         XINPUT_STATE_EX *pXInputState = &joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot];
         XINPUT_STATE_EX *pXInputStatePrev = &joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot ^ 1];
         XINPUT_STATE_EX *pXInputStatePrev = &joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot ^ 1];
 
 
+        /* !!! FIXME: why isn't this just using SDL_PrivateJoystickAxis_Int()? */
         SDL_PrivateJoystickAxis( joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX );
         SDL_PrivateJoystickAxis( joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX );
         SDL_PrivateJoystickAxis( joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)) );
         SDL_PrivateJoystickAxis( joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)) );
         SDL_PrivateJoystickAxis( joystick, 2, (Sint16)pXInputState->Gamepad.sThumbRX );
         SDL_PrivateJoystickAxis( joystick, 2, (Sint16)pXInputState->Gamepad.sThumbRX );
@@ -1455,6 +1456,7 @@ SDL_SYS_JoystickUpdate_XInput(SDL_Joystick * joystick)
         SDL_PrivateJoystickAxis( joystick, 4, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger*65535/255) - 32768));
         SDL_PrivateJoystickAxis( joystick, 4, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger*65535/255) - 32768));
         SDL_PrivateJoystickAxis( joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger*65535/255) - 32768));
         SDL_PrivateJoystickAxis( joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger*65535/255) - 32768));
 
 
+        /* !!! FIXME: why isn't this just using SDL_PrivateJoystickButton_Int(), instead of keeping these two alternating state buffers? */
         if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_UP ) )
         if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_UP ) )
             SDL_PrivateJoystickButton(joystick, 0, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP ? SDL_PRESSED :  SDL_RELEASED );
             SDL_PrivateJoystickButton(joystick, 0, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP ? SDL_PRESSED :  SDL_RELEASED );
         if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_DOWN ) )
         if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_DOWN ) )
@@ -1522,6 +1524,7 @@ TranslatePOV(DWORD value)
 
 
 /* SDL_PrivateJoystick* doesn't discard duplicate events, so we need to
 /* SDL_PrivateJoystick* doesn't discard duplicate events, so we need to
  * do it. */
  * do it. */
+/* !!! FIXME: SDL_PrivateJoystickAxis _does_ discard duplicate events now. Ditch this code. */
 static int
 static int
 SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
 SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
 {
 {

+ 2 - 2
libs/SDL2/src/power/uikit/SDL_syspower.m

@@ -87,8 +87,8 @@ SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
     }
     }
 
 
     const float level = [uidev batteryLevel];
     const float level = [uidev batteryLevel];
-    *percent = ( (level < 0.0f) ? -1 : (((int) (level + 0.5f)) * 100) );
-    return SDL_TRUE;            /* always the definitive answer on iPhoneOS. */
+    *percent = ( (level < 0.0f) ? -1 : ((int) ((level * 100) + 0.5f)) );
+    return SDL_TRUE;            /* always the definitive answer on iOS. */
 }
 }
 
 
 #endif /* SDL_POWER_UIKIT */
 #endif /* SDL_POWER_UIKIT */

+ 3 - 1
libs/SDL2/src/render/SDL_render.c

@@ -1876,7 +1876,9 @@ int SDL_GL_UnbindTexture(SDL_Texture *texture)
 
 
     CHECK_TEXTURE_MAGIC(texture, -1);
     CHECK_TEXTURE_MAGIC(texture, -1);
     renderer = texture->renderer;
     renderer = texture->renderer;
-    if (renderer && renderer->GL_UnbindTexture) {
+    if (texture->native) {
+        return SDL_GL_UnbindTexture(texture->native);
+    } else if (renderer && renderer->GL_UnbindTexture) {
         return renderer->GL_UnbindTexture(renderer, texture);
         return renderer->GL_UnbindTexture(renderer, texture);
     }
     }
 
 

+ 21 - 3
libs/SDL2/src/render/direct3d/SDL_render_d3d.c

@@ -217,6 +217,7 @@ static int D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
 static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
 static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
                            const SDL_Rect * rect, void **pixels, int *pitch);
                            const SDL_Rect * rect, void **pixels, int *pitch);
 static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
 static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture);
 static int D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
 static int D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
 static int D3D_UpdateViewport(SDL_Renderer * renderer);
 static int D3D_UpdateViewport(SDL_Renderer * renderer);
 static int D3D_UpdateClipRect(SDL_Renderer * renderer);
 static int D3D_UpdateClipRect(SDL_Renderer * renderer);
@@ -481,6 +482,10 @@ D3D_Reset(SDL_Renderer * renderer)
         IDirect3DSurface9_Release(data->defaultRenderTarget);
         IDirect3DSurface9_Release(data->defaultRenderTarget);
         data->defaultRenderTarget = NULL;
         data->defaultRenderTarget = NULL;
     }
     }
+    if (data->currentRenderTarget != NULL) {
+        IDirect3DSurface9_Release(data->currentRenderTarget);
+        data->currentRenderTarget = NULL;
+    }
 
 
     /* Release application render targets */
     /* Release application render targets */
     for (texture = renderer->textures; texture; texture = texture->next) {
     for (texture = renderer->textures; texture; texture = texture->next) {
@@ -508,6 +513,7 @@ D3D_Reset(SDL_Renderer * renderer)
 
 
     IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
     IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
     D3D_InitRenderState(data);
     D3D_InitRenderState(data);
+    D3D_SetRenderTargetInternal(renderer, renderer->target);
     D3D_UpdateViewport(renderer);
     D3D_UpdateViewport(renderer);
 
 
     /* Let the application know that render targets were reset */
     /* Let the application know that render targets were reset */
@@ -1003,6 +1009,12 @@ D3D_UpdateTextureInternal(IDirect3DTexture9 *texture, Uint32 format, SDL_bool fu
     if (length == pitch && length == locked.Pitch) {
     if (length == pitch && length == locked.Pitch) {
         SDL_memcpy(dst, src, length*h);
         SDL_memcpy(dst, src, length*h);
     } else {
     } else {
+        if (length > pitch) {
+            length = pitch;
+        }
+        if (length > locked.Pitch) {
+            length = locked.Pitch;
+        }
         for (row = 0; row < h; ++row) {
         for (row = 0; row < h; ++row) {
             SDL_memcpy(dst, src, length);
             SDL_memcpy(dst, src, length);
             src += pitch;
             src += pitch;
@@ -1155,14 +1167,12 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 }
 }
 
 
 static int
 static int
-D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture)
 {
 {
     D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
     D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
     D3D_TextureData *texturedata;
     D3D_TextureData *texturedata;
     HRESULT result;
     HRESULT result;
 
 
-    D3D_ActivateRenderer(renderer);
-
     /* Release the previous render target if it wasn't the default one */
     /* Release the previous render target if it wasn't the default one */
     if (data->currentRenderTarget != NULL) {
     if (data->currentRenderTarget != NULL) {
         IDirect3DSurface9_Release(data->currentRenderTarget);
         IDirect3DSurface9_Release(data->currentRenderTarget);
@@ -1192,6 +1202,14 @@ D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
     return 0;
     return 0;
 }
 }
 
 
+static int
+D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+    D3D_ActivateRenderer(renderer);
+
+    return D3D_SetRenderTargetInternal(renderer, texture);
+}
+
 static int
 static int
 D3D_UpdateViewport(SDL_Renderer * renderer)
 D3D_UpdateViewport(SDL_Renderer * renderer)
 {
 {

+ 21 - 1
libs/SDL2/src/render/opengl/SDL_render_gl.c

@@ -32,6 +32,12 @@
 #include <OpenGL/OpenGL.h>
 #include <OpenGL/OpenGL.h>
 #endif
 #endif
 
 
+/* To prevent unnecessary window recreation, 
+ * these should match the defaults selected in SDL_GL_ResetAttributes 
+ */
+
+#define RENDERER_CONTEXT_MAJOR 2
+#define RENDERER_CONTEXT_MINOR 1
 
 
 /* OpenGL renderer implementation */
 /* OpenGL renderer implementation */
 
 
@@ -381,11 +387,25 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
     const char *hint;
     const char *hint;
     GLint value;
     GLint value;
     Uint32 window_flags;
     Uint32 window_flags;
+    int profile_mask, major, minor;
 
 
+    SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
+    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
+    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
+    
     window_flags = SDL_GetWindowFlags(window);
     window_flags = SDL_GetWindowFlags(window);
-    if (!(window_flags & SDL_WINDOW_OPENGL)) {
+    if (!(window_flags & SDL_WINDOW_OPENGL) ||
+        profile_mask == SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
+        
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
+
         if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
         if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
             /* Uh oh, better try to put it back... */
             /* Uh oh, better try to put it back... */
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
             SDL_RecreateWindow(window, window_flags);
             SDL_RecreateWindow(window, window_flags);
             return NULL;
             return NULL;
         }
         }

+ 21 - 4
libs/SDL2/src/render/opengles/SDL_render_gles.c

@@ -26,6 +26,13 @@
 #include "SDL_opengles.h"
 #include "SDL_opengles.h"
 #include "../SDL_sysrender.h"
 #include "../SDL_sysrender.h"
 
 
+/* To prevent unnecessary window recreation, 
+ * these should match the defaults selected in SDL_GL_ResetAttributes 
+ */
+
+#define RENDERER_CONTEXT_MAJOR 1
+#define RENDERER_CONTEXT_MINOR 1
+
 #if defined(SDL_VIDEO_DRIVER_PANDORA)
 #if defined(SDL_VIDEO_DRIVER_PANDORA)
 
 
 /* Empty function stub to get OpenGL ES 1.x support without  */
 /* Empty function stub to get OpenGL ES 1.x support without  */
@@ -279,15 +286,25 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
     GLES_RenderData *data;
     GLES_RenderData *data;
     GLint value;
     GLint value;
     Uint32 windowFlags;
     Uint32 windowFlags;
+    int profile_mask, major, minor;
 
 
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+    SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
+    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
+    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
 
 
     windowFlags = SDL_GetWindowFlags(window);
     windowFlags = SDL_GetWindowFlags(window);
-    if (!(windowFlags & SDL_WINDOW_OPENGL)) {
+    if (!(windowFlags & SDL_WINDOW_OPENGL) ||
+        profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
+
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
+
         if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
         if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
             /* Uh oh, better try to put it back... */
             /* Uh oh, better try to put it back... */
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
             SDL_RecreateWindow(window, windowFlags);
             SDL_RecreateWindow(window, windowFlags);
             return NULL;
             return NULL;
         }
         }

+ 20 - 4
libs/SDL2/src/render/opengles2/SDL_render_gles2.c

@@ -28,6 +28,12 @@
 #include "../../video/SDL_blit.h"
 #include "../../video/SDL_blit.h"
 #include "SDL_shaders_gles2.h"
 #include "SDL_shaders_gles2.h"
 
 
+/* To prevent unnecessary window recreation, 
+ * these should match the defaults selected in SDL_GL_ResetAttributes 
+ */
+#define RENDERER_CONTEXT_MAJOR 2
+#define RENDERER_CONTEXT_MINOR 0
+
 /* Used to re-create the window with OpenGL ES capability */
 /* Used to re-create the window with OpenGL ES capability */
 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
 
 
@@ -1740,15 +1746,25 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
     Uint32 windowFlags;
     Uint32 windowFlags;
     GLint window_framebuffer;
     GLint window_framebuffer;
     GLint value;
     GLint value;
+    int profile_mask, major, minor;
 
 
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+    SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
+    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
+    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
 
 
     windowFlags = SDL_GetWindowFlags(window);
     windowFlags = SDL_GetWindowFlags(window);
-    if (!(windowFlags & SDL_WINDOW_OPENGL)) {
+    if (!(windowFlags & SDL_WINDOW_OPENGL) ||
+        profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
+        
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
+
         if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
         if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
             /* Uh oh, better try to put it back... */
             /* Uh oh, better try to put it back... */
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
             SDL_RecreateWindow(window, windowFlags);
             SDL_RecreateWindow(window, windowFlags);
             return NULL;
             return NULL;
         }
         }

+ 0 - 6
libs/SDL2/src/stdlib/SDL_stdlib.c

@@ -278,12 +278,6 @@ void * memcpy ( void * destination, const void * source, size_t num )
 
 
 #ifdef _M_IX86
 #ifdef _M_IX86
 
 
-void
-__declspec(naked)
-_chkstk()
-{
-}
-
 /* Float to long */
 /* Float to long */
 void
 void
 __declspec(naked)
 __declspec(naked)

+ 1 - 0
libs/SDL2/src/test/SDL_test_common.c

@@ -1542,6 +1542,7 @@ SDLTest_CommonQuit(SDLTest_CommonState * state)
         SDL_AudioQuit();
         SDL_AudioQuit();
     }
     }
     SDL_free(state);
     SDL_free(state);
+    SDL_Quit();
 }
 }
 
 
 /* vi: set ts=4 sw=4 expandtab: */
 /* vi: set ts=4 sw=4 expandtab: */

+ 2 - 1
libs/SDL2/src/timer/SDL_timer_c.h

@@ -26,7 +26,8 @@
 #define ROUND_RESOLUTION(X) \
 #define ROUND_RESOLUTION(X) \
     (((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)
     (((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)
 
 
-extern void SDL_InitTicks(void);
+extern void SDL_TicksInit(void);
+extern void SDL_TicksQuit(void);
 extern int SDL_TimerInit(void);
 extern int SDL_TimerInit(void);
 extern void SDL_TimerQuit(void);
 extern void SDL_TimerQuit(void);
 
 

+ 8 - 2
libs/SDL2/src/timer/dummy/SDL_systimer.c

@@ -27,7 +27,7 @@
 static SDL_bool ticks_started = SDL_FALSE;
 static SDL_bool ticks_started = SDL_FALSE;
 
 
 void
 void
-SDL_InitTicks(void)
+SDL_TicksInit(void)
 {
 {
     if (ticks_started) {
     if (ticks_started) {
         return;
         return;
@@ -35,11 +35,17 @@ SDL_InitTicks(void)
     ticks_started = SDL_TRUE;
     ticks_started = SDL_TRUE;
 }
 }
 
 
+void
+SDL_TicksQuit(void)
+{
+    ticks_started = SDL_FALSE;
+}
+
 Uint32
 Uint32
 SDL_GetTicks(void)
 SDL_GetTicks(void)
 {
 {
     if (!ticks_started) {
     if (!ticks_started) {
-        SDL_InitTicks();
+        SDL_TicksInit();
     }
     }
 
 
     SDL_Unsupported();
     SDL_Unsupported();

+ 8 - 2
libs/SDL2/src/timer/haiku/SDL_systimer.c

@@ -30,7 +30,7 @@ static bigtime_t start;
 static SDL_bool ticks_started = SDL_FALSE;
 static SDL_bool ticks_started = SDL_FALSE;
 
 
 void
 void
-SDL_InitTicks(void)
+SDL_TicksInit(void)
 {
 {
     if (ticks_started) {
     if (ticks_started) {
         return;
         return;
@@ -41,11 +41,17 @@ SDL_InitTicks(void)
     start = system_time();
     start = system_time();
 }
 }
 
 
+void
+SDL_TicksQuit(void)
+{
+    ticks_started = SDL_FALSE;
+}
+
 Uint32
 Uint32
 SDL_GetTicks(void)
 SDL_GetTicks(void)
 {
 {
     if (!ticks_started) {
     if (!ticks_started) {
-        SDL_InitTicks();
+        SDL_TicksInit();
     }
     }
 
 
     return ((system_time() - start) / 1000);
     return ((system_time() - start) / 1000);

+ 9 - 2
libs/SDL2/src/timer/psp/SDL_systimer.c

@@ -31,7 +31,8 @@
 static struct timeval start;
 static struct timeval start;
 static SDL_bool ticks_started = SDL_FALSE;
 static SDL_bool ticks_started = SDL_FALSE;
 
 
-void SDL_InitTicks(void)
+void
+SDL_TicksInit(void)
 {
 {
     if (ticks_started) {
     if (ticks_started) {
         return;
         return;
@@ -41,10 +42,16 @@ void SDL_InitTicks(void)
     gettimeofday(&start, NULL);
     gettimeofday(&start, NULL);
 }
 }
 
 
+void
+SDL_TicksQuit(void)
+{
+    ticks_started = SDL_FALSE;
+}
+
 Uint32 SDL_GetTicks(void)
 Uint32 SDL_GetTicks(void)
 {
 {
     if (!ticks_started) {
     if (!ticks_started) {
-        SDL_InitTicks();
+        SDL_TicksInit();
     }
     }
 
 
     struct timeval now;
     struct timeval now;

+ 10 - 4
libs/SDL2/src/timer/unix/SDL_systimer.c

@@ -59,7 +59,7 @@ static struct timeval start_tv;
 static SDL_bool ticks_started = SDL_FALSE;
 static SDL_bool ticks_started = SDL_FALSE;
 
 
 void
 void
-SDL_InitTicks(void)
+SDL_TicksInit(void)
 {
 {
     if (ticks_started) {
     if (ticks_started) {
         return;
         return;
@@ -83,12 +83,18 @@ SDL_InitTicks(void)
     }
     }
 }
 }
 
 
+void
+SDL_TicksQuit(void)
+{
+    ticks_started = SDL_FALSE;
+}
+
 Uint32
 Uint32
 SDL_GetTicks(void)
 SDL_GetTicks(void)
 {
 {
     Uint32 ticks;
     Uint32 ticks;
     if (!ticks_started) {
     if (!ticks_started) {
-        SDL_InitTicks();
+        SDL_TicksInit();
     }
     }
 
 
     if (has_monotonic_time) {
     if (has_monotonic_time) {
@@ -117,7 +123,7 @@ SDL_GetPerformanceCounter(void)
 {
 {
     Uint64 ticks;
     Uint64 ticks;
     if (!ticks_started) {
     if (!ticks_started) {
-        SDL_InitTicks();
+        SDL_TicksInit();
     }
     }
 
 
     if (has_monotonic_time) {
     if (has_monotonic_time) {
@@ -146,7 +152,7 @@ Uint64
 SDL_GetPerformanceFrequency(void)
 SDL_GetPerformanceFrequency(void)
 {
 {
     if (!ticks_started) {
     if (!ticks_started) {
-        SDL_InitTicks();
+        SDL_TicksInit();
     }
     }
 
 
     if (has_monotonic_time) {
     if (has_monotonic_time) {

+ 22 - 6
libs/SDL2/src/timer/windows/SDL_systimer.c

@@ -40,7 +40,6 @@ static BOOL hires_timer_available;
 static LARGE_INTEGER hires_start_ticks;
 static LARGE_INTEGER hires_start_ticks;
 /* The number of ticks per second of the high-resolution performance counter */
 /* The number of ticks per second of the high-resolution performance counter */
 static LARGE_INTEGER hires_ticks_per_second;
 static LARGE_INTEGER hires_ticks_per_second;
-#endif
 
 
 static void
 static void
 timeSetPeriod(UINT uPeriod)
 timeSetPeriod(UINT uPeriod)
@@ -76,13 +75,15 @@ SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValu
     }
     }
 }
 }
 
 
+#endif /* !USE_GETTICKCOUNT */
+
 void
 void
-SDL_InitTicks(void)
+SDL_TicksInit(void)
 {
 {
     if (ticks_started) {
     if (ticks_started) {
         return;
         return;
     }
     }
-    ticks_started = TRUE;
+    ticks_started = SDL_TRUE;
 
 
     /* Set first ticks value */
     /* Set first ticks value */
 #ifdef USE_GETTICKCOUNT
 #ifdef USE_GETTICKCOUNT
@@ -98,11 +99,26 @@ SDL_InitTicks(void)
         hires_timer_available = FALSE;
         hires_timer_available = FALSE;
         timeSetPeriod(1);     /* use 1 ms timer precision */
         timeSetPeriod(1);     /* use 1 ms timer precision */
         start = timeGetTime();
         start = timeGetTime();
+
+        SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
+                            SDL_TimerResolutionChanged, NULL);
+    }
+#endif
+}
+
+void
+SDL_TicksQuit(void)
+{
+#ifndef USE_GETTICKCOUNT
+    if (!hires_timer_available) {
+        SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION,
+                            SDL_TimerResolutionChanged, NULL);
+
+        timeSetPeriod(0);
     }
     }
 #endif
 #endif
 
 
-    SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
-                        SDL_TimerResolutionChanged, NULL);
+    ticks_started = SDL_FALSE;
 }
 }
 
 
 Uint32
 Uint32
@@ -114,7 +130,7 @@ SDL_GetTicks(void)
 #endif
 #endif
 
 
     if (!ticks_started) {
     if (!ticks_started) {
-        SDL_InitTicks();
+        SDL_TicksInit();
     }
     }
 
 
 #ifdef USE_GETTICKCOUNT
 #ifdef USE_GETTICKCOUNT

+ 19 - 1
libs/SDL2/src/video/SDL_video.c

@@ -421,8 +421,10 @@ int
 SDL_VideoInit(const char *driver_name)
 SDL_VideoInit(const char *driver_name)
 {
 {
     SDL_VideoDevice *video;
     SDL_VideoDevice *video;
+    const char *hint;
     int index;
     int index;
     int i;
     int i;
+    SDL_bool allow_screensaver;
 
 
     /* Check to make sure we don't overwrite '_this' */
     /* Check to make sure we don't overwrite '_this' */
     if (_this != NULL) {
     if (_this != NULL) {
@@ -430,7 +432,7 @@ SDL_VideoInit(const char *driver_name)
     }
     }
 
 
 #if !SDL_TIMERS_DISABLED
 #if !SDL_TIMERS_DISABLED
-    SDL_InitTicks();
+    SDL_TicksInit();
 #endif
 #endif
 
 
     /* Start the event loop */
     /* Start the event loop */
@@ -504,6 +506,22 @@ SDL_VideoInit(const char *driver_name)
         _this->DestroyWindowFramebuffer = SDL_DestroyWindowTexture;
         _this->DestroyWindowFramebuffer = SDL_DestroyWindowTexture;
     }
     }
 
 
+    /* Disable the screen saver by default. This is a change from <= 2.0.1,
+       but most things using SDL are games or media players; you wouldn't
+       want a screensaver to trigger if you're playing exclusively with a
+       joystick, or passively watching a movie. Things that use SDL but
+       function more like a normal desktop app should explicitly reenable the
+       screensaver. */
+    hint = SDL_GetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER);
+    if (hint) {
+        allow_screensaver = SDL_atoi(hint) ? SDL_TRUE : SDL_FALSE;
+    } else {
+        allow_screensaver = SDL_FALSE;
+    }
+    if (!allow_screensaver) {
+        SDL_DisableScreenSaver();
+    }
+
     /* If we don't use a screen keyboard, turn on text input by default,
     /* If we don't use a screen keyboard, turn on text input by default,
        otherwise programs that expect to get text events without enabling
        otherwise programs that expect to get text events without enabling
        UNICODE input won't get any events.
        UNICODE input won't get any events.

+ 25 - 13
libs/SDL2/src/video/cocoa/SDL_cocoaevents.m

@@ -36,6 +36,22 @@
 #define UsrActivity 1
 #define UsrActivity 1
 #endif
 #endif
 
 
+@interface SDLApplication : NSApplication
+
+- (void)terminate:(id)sender;
+
+@end
+
+@implementation SDLApplication
+
+// Override terminate to handle Quit and System Shutdown smoothly.
+- (void)terminate:(id)sender
+{
+    SDL_SendQuit();
+}
+
+@end // SDLApplication
+
 /* setAppleMenu disappeared from the headers in 10.4 */
 /* setAppleMenu disappeared from the headers in 10.4 */
 @interface NSApplication(NSAppleMenu)
 @interface NSApplication(NSAppleMenu)
 - (void)setAppleMenu:(NSMenu *)menu;
 - (void)setAppleMenu:(NSMenu *)menu;
@@ -71,12 +87,6 @@
     [super dealloc];
     [super dealloc];
 }
 }
 
 
-- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
-{
-    SDL_SendQuit();
-    return NSTerminateCancel;
-}
-
 - (void)focusSomeWindow:(NSNotification *)aNotification
 - (void)focusSomeWindow:(NSNotification *)aNotification
 {
 {
     /* HACK: Ignore the first call. The application gets a
     /* HACK: Ignore the first call. The application gets a
@@ -125,13 +135,12 @@ static SDLAppDelegate *appDelegate = nil;
 static NSString *
 static NSString *
 GetApplicationName(void)
 GetApplicationName(void)
 {
 {
-    NSDictionary *dict;
-    NSString *appName = 0;
+    NSString *appName;
 
 
     /* Determine the application name */
     /* Determine the application name */
-    dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
-    if (dict)
-        appName = [dict objectForKey: @"CFBundleName"];
+    appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
+    if (!appName)
+        appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
 
 
     if (![appName length])
     if (![appName length])
         appName = [[NSProcessInfo processInfo] processName];
         appName = [[NSProcessInfo processInfo] processName];
@@ -256,13 +265,16 @@ Cocoa_RegisterApp(void)
 
 
     pool = [[NSAutoreleasePool alloc] init];
     pool = [[NSAutoreleasePool alloc] init];
     if (NSApp == nil) {
     if (NSApp == nil) {
-        [NSApplication sharedApplication];
+        [SDLApplication sharedApplication];
 
 
         if ([NSApp mainMenu] == nil) {
         if ([NSApp mainMenu] == nil) {
             CreateApplicationMenus();
             CreateApplicationMenus();
         }
         }
         [NSApp finishLaunching];
         [NSApp finishLaunching];
-        NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"AppleMomentumScrollSupported"];
+        NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
+            [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
+            [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
+            nil];
         [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
         [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
 
 
     }
     }

+ 9 - 2
libs/SDL2/src/video/cocoa/SDL_cocoamouse.h

@@ -28,11 +28,18 @@
 extern void Cocoa_InitMouse(_THIS);
 extern void Cocoa_InitMouse(_THIS);
 extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
 extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
 extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
 extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
+extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y);
 extern void Cocoa_QuitMouse(_THIS);
 extern void Cocoa_QuitMouse(_THIS);
 
 
 typedef struct {
 typedef struct {
-    int deltaXOffset;
-    int deltaYOffset;
+    /* Wether we've seen a cursor warp since the last move event. */
+    SDL_bool seenWarp;
+    /* What location our last cursor warp was to. */
+    CGFloat lastWarpX;
+    CGFloat lastWarpY;
+    /* What location we last saw the cursor move to. */
+    CGFloat lastMoveX;
+    CGFloat lastMoveY;
     void *tapdata;
     void *tapdata;
 } SDL_MouseData;
 } SDL_MouseData;
 
 

+ 104 - 22
libs/SDL2/src/video/cocoa/SDL_cocoamouse.m

@@ -29,6 +29,14 @@
 
 
 #include "../../events/SDL_mouse_c.h"
 #include "../../events/SDL_mouse_c.h"
 
 
+/* #define DEBUG_COCOAMOUSE */
+
+#ifdef DEBUG_COCOAMOUSE
+#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#else
+#define DLog(...) do { } while (0)
+#endif
+
 @implementation NSCursor (InvisibleCursor)
 @implementation NSCursor (InvisibleCursor)
 + (NSCursor *)invisibleCursor
 + (NSCursor *)invisibleCursor
 {
 {
@@ -203,18 +211,19 @@ Cocoa_ShowCursor(SDL_Cursor * cursor)
 static void
 static void
 Cocoa_WarpMouse(SDL_Window * window, int x, int y)
 Cocoa_WarpMouse(SDL_Window * window, int x, int y)
 {
 {
+    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+    if ([data->listener isMoving])
+    {
+        DLog("Postponing warp, window being moved.");
+        [data->listener setPendingMoveX:x
+                                      Y:y];
+        return;
+    }
+
     SDL_Mouse *mouse = SDL_GetMouse();
     SDL_Mouse *mouse = SDL_GetMouse();
     CGPoint point = CGPointMake(x + (float)window->x, y + (float)window->y);
     CGPoint point = CGPointMake(x + (float)window->x, y + (float)window->y);
 
 
-    {
-        /* This makes Cocoa_HandleMouseEvent ignore this delta in the next
-         * movement event.
-         */
-        SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
-        NSPoint location =  [NSEvent mouseLocation];
-        driverdata->deltaXOffset = location.x - point.x;
-        driverdata->deltaYOffset = point.y - location.y;
-    }
+    Cocoa_HandleMouseWarp(point.x, point.y);
 
 
     /* According to the docs, this was deprecated in 10.6, but it's still
     /* According to the docs, this was deprecated in 10.6, but it's still
      * around. The substitute requires a CGEventSource, but I'm not entirely
      * around. The substitute requires a CGEventSource, but I'm not entirely
@@ -235,11 +244,28 @@ Cocoa_WarpMouse(SDL_Window * window, int x, int y)
 static int
 static int
 Cocoa_SetRelativeMouseMode(SDL_bool enabled)
 Cocoa_SetRelativeMouseMode(SDL_bool enabled)
 {
 {
-    CGError result;
+    /* We will re-apply the relative mode when the window gets focus, if it
+     * doesn't have focus right now.
+     */
+    SDL_Window *window = SDL_GetMouseFocus();
+    if (!window) {
+      return 0;
+    }
 
 
+    /* We will re-apply the relative mode when the window finishes being moved,
+     * if it is being moved right now.
+     */
+    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+    if ([data->listener isMoving]) {
+        return 0;
+    }
+
+    CGError result;
     if (enabled) {
     if (enabled) {
+        DLog("Turning on.");
         result = CGAssociateMouseAndMouseCursorPosition(NO);
         result = CGAssociateMouseAndMouseCursorPosition(NO);
     } else {
     } else {
+        DLog("Turning off.");
         result = CGAssociateMouseAndMouseCursorPosition(YES);
         result = CGAssociateMouseAndMouseCursorPosition(YES);
     }
     }
     if (result != kCGErrorSuccess) {
     if (result != kCGErrorSuccess) {
@@ -265,25 +291,67 @@ Cocoa_InitMouse(_THIS)
     SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
     SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
 
 
     Cocoa_InitMouseEventTap(mouse->driverdata);
     Cocoa_InitMouseEventTap(mouse->driverdata);
+
+    SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
+    const NSPoint location =  [NSEvent mouseLocation];
+    driverdata->lastMoveX = location.x;
+    driverdata->lastMoveY = location.y;
 }
 }
 
 
 void
 void
 Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
 Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
 {
 {
+    switch ([event type])
+    {
+        case NSMouseMoved:
+        case NSLeftMouseDragged:
+        case NSRightMouseDragged:
+        case NSOtherMouseDragged:
+            break;
+
+        default:
+            /* Ignore any other events. */
+            return;
+    }
+
     SDL_Mouse *mouse = SDL_GetMouse();
     SDL_Mouse *mouse = SDL_GetMouse();
 
 
-    if (mouse->relative_mode &&
-        ([event type] == NSMouseMoved ||
-         [event type] == NSLeftMouseDragged ||
-         [event type] == NSRightMouseDragged ||
-         [event type] == NSOtherMouseDragged)) {
-        SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
-        float x = [event deltaX] + driverdata->deltaXOffset;
-        float y = [event deltaY] + driverdata->deltaYOffset;
-        driverdata->deltaXOffset = driverdata->deltaYOffset = 0;
-
-        SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)x, (int)y);
+    SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
+    const SDL_bool seenWarp = driverdata->seenWarp;
+    driverdata->seenWarp = NO;
+
+    const NSPoint location =  [NSEvent mouseLocation];
+    const CGFloat lastMoveX = driverdata->lastMoveX;
+    const CGFloat lastMoveY = driverdata->lastMoveY;
+    driverdata->lastMoveX = location.x;
+    driverdata->lastMoveY = location.y;
+    DLog("Last seen mouse: (%g, %g)", location.x, location.y);
+
+    /* Non-relative movement is handled in -[Cocoa_WindowListener mouseMoved:] */
+    if (!mouse->relative_mode) {
+        return;
+    }
+
+    /* Ignore events that aren't inside the client area (i.e. title bar.) */
+    if ([event window]) {
+        NSRect windowRect = [[[event window] contentView] frame];
+        if (!NSPointInRect([event locationInWindow], windowRect)) {
+            return;
+        }
+    }
+
+    float deltaX = [event deltaX];
+    float deltaY = [event deltaY];
+
+    if (seenWarp)
+    {
+        deltaX += (lastMoveX - driverdata->lastWarpX);
+        deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
+
+        DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
     }
     }
+
+    SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)deltaX, (int)deltaY);
 }
 }
 
 
 void
 void
@@ -291,7 +359,7 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
 {
 {
     SDL_Mouse *mouse = SDL_GetMouse();
     SDL_Mouse *mouse = SDL_GetMouse();
 
 
-    float x = [event deltaX];
+    float x = -[event deltaX];
     float y = [event deltaY];
     float y = [event deltaY];
 
 
     if (x > 0) {
     if (x > 0) {
@@ -307,6 +375,20 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
     SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y);
     SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y);
 }
 }
 
 
+void
+Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
+{
+    /* This makes Cocoa_HandleMouseEvent ignore the delta caused by the warp,
+     * since it gets included in the next movement event.
+     */
+    SDL_MouseData *driverdata = (SDL_MouseData*)SDL_GetMouse()->driverdata;
+    driverdata->lastWarpX = x;
+    driverdata->lastWarpY = y;
+    driverdata->seenWarp = SDL_TRUE;
+
+    DLog("(%g, %g)", x, y);
+}
+
 void
 void
 Cocoa_QuitMouse(_THIS)
 Cocoa_QuitMouse(_THIS)
 {
 {

+ 56 - 29
libs/SDL2/src/video/cocoa/SDL_cocoaopengl.m

@@ -35,17 +35,14 @@
 
 
 #define DEFAULT_OPENGL  "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
 #define DEFAULT_OPENGL  "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
 
 
-#ifndef kCGLPFAOpenGLProfile
-#define kCGLPFAOpenGLProfile 99
+#ifndef NSOpenGLPFAOpenGLProfile
+#define NSOpenGLPFAOpenGLProfile 99
 #endif
 #endif
-#ifndef kCGLOGLPVersion_Legacy
-#define kCGLOGLPVersion_Legacy 0x1000
+#ifndef NSOpenGLProfileVersionLegacy
+#define NSOpenGLProfileVersionLegacy 0x1000
 #endif
 #endif
-#ifndef kCGLOGLPVersion_GL3_Core
-#define kCGLOGLPVersion_GL3_Core 0x3200
-#endif
-#ifndef kCGLOGLPVersion_GL4_Core
-#define kCGLOGLPVersion_GL4_Core 0x4100
+#ifndef NSOpenGLProfileVersion3_2Core
+#define NSOpenGLProfileVersion3_2Core 0x3200
 #endif
 #endif
 
 
 @implementation SDLOpenGLContext : NSOpenGLContext
 @implementation SDLOpenGLContext : NSOpenGLContext
@@ -110,11 +107,19 @@
 
 
         if ([self view] != [windowdata->nswindow contentView]) {
         if ([self view] != [windowdata->nswindow contentView]) {
             [self setView:[windowdata->nswindow contentView]];
             [self setView:[windowdata->nswindow contentView]];
-            [self scheduleUpdate];
+            if (self == [NSOpenGLContext currentContext]) {
+                [self update];
+            } else {
+                [self scheduleUpdate];
+            }
         }
         }
     } else {
     } else {
         [self clearDrawable];
         [self clearDrawable];
-        [self scheduleUpdate];
+        if (self == [NSOpenGLContext currentContext]) {
+            [self update];
+        } else {
+            [self scheduleUpdate];
+        }
     }
     }
 }
 }
 
 
@@ -156,9 +161,8 @@ Cocoa_GL_UnloadLibrary(_THIS)
 SDL_GLContext
 SDL_GLContext
 Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
 Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
 {
 {
-    const int wantver = (_this->gl_config.major_version << 8) |
-                        (_this->gl_config.minor_version);
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+    const GLubyte *(APIENTRY * glGetStringFunc)(GLenum) = NULL;
     NSAutoreleasePool *pool;
     NSAutoreleasePool *pool;
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
     SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
@@ -167,16 +171,16 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
     SDLOpenGLContext *context;
     SDLOpenGLContext *context;
     NSOpenGLContext *share_context = nil;
     NSOpenGLContext *share_context = nil;
     int i = 0;
     int i = 0;
+    const char *glversion;
+    int glversion_major;
+    int glversion_minor;
 
 
     if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
     if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
         SDL_SetError ("OpenGL ES is not supported on this platform");
         SDL_SetError ("OpenGL ES is not supported on this platform");
         return NULL;
         return NULL;
     }
     }
-
-    /* Sadly, we'll have to update this as life progresses, since we need to
-       set an enum for context profiles, not a context version number */
-    if (wantver > 0x0401) {
-        SDL_SetError ("OpenGL > 4.1 is not supported on this platform");
+    if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && (data->osversion < 0x1070)) {
+        SDL_SetError ("OpenGL Core Profile is not supported on this platform version");
         return NULL;
         return NULL;
     }
     }
 
 
@@ -184,19 +188,11 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
 
 
     /* specify a profile if we're on Lion (10.7) or later. */
     /* specify a profile if we're on Lion (10.7) or later. */
     if (data->osversion >= 0x1070) {
     if (data->osversion >= 0x1070) {
-        NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
+        NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
         if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
         if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
-            if (wantver == 0x0302) {
-                profile = kCGLOGLPVersion_GL3_Core;
-            } else if ((wantver == 0x0401) && (data->osversion >= 0x1090)) {
-                profile = kCGLOGLPVersion_GL4_Core;
-            } else {
-                SDL_SetError("Requested GL version is not supported on this platform");
-                [pool release];
-                return NULL;
-            }
+            profile = NSOpenGLProfileVersion3_2Core;
         }
         }
-        attr[i++] = kCGLPFAOpenGLProfile;
+        attr[i++] = NSOpenGLPFAOpenGLProfile;
         attr[i++] = profile;
         attr[i++] = profile;
     }
     }
 
 
@@ -276,9 +272,40 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
 
 
     if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
     if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
         Cocoa_GL_DeleteContext(_this, context);
         Cocoa_GL_DeleteContext(_this, context);
+        SDL_SetError ("Failed making OpenGL context current");
+        return NULL;
+    }
+
+    glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
+    if (!glGetStringFunc) {
+        Cocoa_GL_DeleteContext(_this, context);
+        SDL_SetError ("Failed getting OpenGL glGetString entry point");
         return NULL;
         return NULL;
     }
     }
 
 
+    glversion = (const char *)glGetStringFunc(GL_VERSION);
+    if (glversion == NULL) {
+        Cocoa_GL_DeleteContext(_this, context);
+        SDL_SetError ("Failed getting OpenGL context version");
+        return NULL;
+    }
+
+    if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) {
+        Cocoa_GL_DeleteContext(_this, context);
+        SDL_SetError ("Failed parsing OpenGL context version");
+        return NULL;
+    }
+
+    if ((glversion_major <  _this->gl_config.major_version) ||
+       ((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) {
+        Cocoa_GL_DeleteContext(_this, context);
+        SDL_SetError ("Failed creating OpenGL context at version requested");
+        return NULL;
+    }
+
+    _this->gl_config.major_version = glversion_major;
+    _this->gl_config.minor_version = glversion_minor;
+
     return context;
     return context;
 }
 }
 
 

+ 1 - 0
libs/SDL2/src/video/cocoa/SDL_cocoavideo.h

@@ -46,6 +46,7 @@
 typedef struct SDL_VideoData
 typedef struct SDL_VideoData
 {
 {
     SInt32 osversion;
     SInt32 osversion;
+    int allow_spaces;
     unsigned int modifierFlags;
     unsigned int modifierFlags;
     void *key_layout;
     void *key_layout;
     SDLTranslatorResponder *fieldEdit;
     SDLTranslatorResponder *fieldEdit;

+ 6 - 0
libs/SDL2/src/video/cocoa/SDL_cocoavideo.m

@@ -148,9 +148,15 @@ VideoBootStrap COCOA_bootstrap = {
 int
 int
 Cocoa_VideoInit(_THIS)
 Cocoa_VideoInit(_THIS)
 {
 {
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
     Cocoa_InitModes(_this);
     Cocoa_InitModes(_this);
     Cocoa_InitKeyboard(_this);
     Cocoa_InitKeyboard(_this);
     Cocoa_InitMouse(_this);
     Cocoa_InitMouse(_this);
+
+    const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
+    data->allow_spaces = ( (data->osversion >= 0x1070) && (!hint || (*hint != '0')) );
+
     return 0;
     return 0;
 }
 }
 
 

+ 8 - 0
libs/SDL2/src/video/cocoa/SDL_cocoawindow.h

@@ -43,6 +43,8 @@ typedef enum
     BOOL isFullscreenSpace;
     BOOL isFullscreenSpace;
     BOOL inFullscreenTransition;
     BOOL inFullscreenTransition;
     PendingWindowOperation pendingWindowOperation;
     PendingWindowOperation pendingWindowOperation;
+    BOOL isMoving;
+    int pendingWindowWarpX, pendingWindowWarpY;
 }
 }
 
 
 -(void) listen:(SDL_WindowData *) data;
 -(void) listen:(SDL_WindowData *) data;
@@ -54,6 +56,10 @@ typedef enum
 -(void) addPendingWindowOperation:(PendingWindowOperation) operation;
 -(void) addPendingWindowOperation:(PendingWindowOperation) operation;
 -(void) close;
 -(void) close;
 
 
+-(BOOL) isMoving;
+-(void) setPendingMoveX:(int)x Y:(int)y;
+-(void) windowDidFinishMoving;
+
 /* Window delegate functionality */
 /* Window delegate functionality */
 -(BOOL) windowShouldClose:(id) sender;
 -(BOOL) windowShouldClose:(id) sender;
 -(void) windowDidExpose:(NSNotification *) aNotification;
 -(void) windowDidExpose:(NSNotification *) aNotification;
@@ -67,6 +73,7 @@ typedef enum
 -(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
 -(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
 -(void) windowWillExitFullScreen:(NSNotification *) aNotification;
 -(void) windowWillExitFullScreen:(NSNotification *) aNotification;
 -(void) windowDidExitFullScreen:(NSNotification *) aNotification;
 -(void) windowDidExitFullScreen:(NSNotification *) aNotification;
+-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions;
 
 
 /* Window event handling */
 /* Window event handling */
 -(void) mouseDown:(NSEvent *) theEvent;
 -(void) mouseDown:(NSEvent *) theEvent;
@@ -105,6 +112,7 @@ struct SDL_WindowData
     NSWindow *nswindow;
     NSWindow *nswindow;
     NSMutableArray *nscontexts;
     NSMutableArray *nscontexts;
     SDL_bool created;
     SDL_bool created;
+    SDL_bool inWindowMove;
     Cocoa_WindowListener *listener;
     Cocoa_WindowListener *listener;
     struct SDL_VideoData *videodata;
     struct SDL_VideoData *videodata;
 };
 };

+ 163 - 49
libs/SDL2/src/video/cocoa/SDL_cocoawindow.m

@@ -38,6 +38,54 @@
 #include "SDL_cocoashape.h"
 #include "SDL_cocoashape.h"
 #include "SDL_cocoamouse.h"
 #include "SDL_cocoamouse.h"
 #include "SDL_cocoaopengl.h"
 #include "SDL_cocoaopengl.h"
+#include "SDL_assert.h"
+
+/* #define DEBUG_COCOAWINDOW */
+
+#ifdef DEBUG_COCOAWINDOW
+#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#else
+#define DLog(...) do { } while (0)
+#endif
+
+
+@interface SDLWindow : NSWindow
+/* These are needed for borderless/fullscreen windows */
+- (BOOL)canBecomeKeyWindow;
+- (BOOL)canBecomeMainWindow;
+- (void)sendEvent:(NSEvent *)event;
+@end
+
+@implementation SDLWindow
+- (BOOL)canBecomeKeyWindow
+{
+    return YES;
+}
+
+- (BOOL)canBecomeMainWindow
+{
+    return YES;
+}
+
+- (void)sendEvent:(NSEvent *)event
+{
+  [super sendEvent:event];
+
+  if ([event type] != NSLeftMouseUp) {
+      return;
+  }
+
+  id delegate = [self delegate];
+  if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
+      return;
+  }
+
+  if ([delegate isMoving]) {
+      [delegate windowDidFinishMoving];
+  }
+}
+@end
+
 
 
 static Uint32 s_moveHack;
 static Uint32 s_moveHack;
 
 
@@ -49,10 +97,15 @@ static void ConvertNSRect(NSRect *r)
 static void
 static void
 ScheduleContextUpdates(SDL_WindowData *data)
 ScheduleContextUpdates(SDL_WindowData *data)
 {
 {
+    NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
     NSMutableArray *contexts = data->nscontexts;
     NSMutableArray *contexts = data->nscontexts;
     @synchronized (contexts) {
     @synchronized (contexts) {
         for (SDLOpenGLContext *context in contexts) {
         for (SDLOpenGLContext *context in contexts) {
-            [context scheduleUpdate];
+            if (context == currentContext) {
+                [context update];
+            } else {
+                [context scheduleUpdate];
+            }
         }
         }
     }
     }
 }
 }
@@ -125,6 +178,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     isFullscreenSpace = NO;
     isFullscreenSpace = NO;
     inFullscreenTransition = NO;
     inFullscreenTransition = NO;
     pendingWindowOperation = PENDING_OPERATION_NONE;
     pendingWindowOperation = PENDING_OPERATION_NONE;
+    isMoving = NO;
 
 
     center = [NSNotificationCenter defaultCenter];
     center = [NSNotificationCenter defaultCenter];
 
 
@@ -203,20 +257,18 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     }
     }
 }
 }
 
 
--(BOOL) setFullscreenSpace:(BOOL) state;
+-(BOOL) setFullscreenSpace:(BOOL) state
 {
 {
     SDL_Window *window = _data->window;
     SDL_Window *window = _data->window;
     NSWindow *nswindow = _data->nswindow;
     NSWindow *nswindow = _data->nswindow;
+    SDL_VideoData *videodata = ((SDL_WindowData *) window->driverdata)->videodata;
 
 
-    if (![nswindow respondsToSelector: @selector(collectionBehavior)]) {
-        return NO;
-    }
-    if ([nswindow collectionBehavior] != NSWindowCollectionBehaviorFullScreenPrimary) {
-        return NO;
-    }
-
-    if (state == isFullscreenSpace) {
-        return YES;
+    if (!videodata->allow_spaces) {
+        return NO;  /* Spaces are forcibly disabled. */
+    } else if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
+        return NO;  /* we only allow you to make a Space on FULLSCREEN_DESKTOP windows. */
+    } else if (state == isFullscreenSpace) {
+        return YES;  /* already there. */
     }
     }
 
 
     if (inFullscreenTransition) {
     if (inFullscreenTransition) {
@@ -229,13 +281,8 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     }
     }
     inFullscreenTransition = YES;
     inFullscreenTransition = YES;
 
 
-    /* Update the flags here so the state change is available immediately */
-    if (state) {
-        window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
-    } else {
-        window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
-    }
-
+    /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
+    [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
     [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
     [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
     return YES;
     return YES;
 }
 }
@@ -310,6 +357,34 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     }
     }
 }
 }
 
 
+- (BOOL)isMoving
+{
+    return isMoving;
+}
+
+-(void) setPendingMoveX:(int)x Y:(int)y
+{
+    pendingWindowWarpX = x;
+    pendingWindowWarpY = y;
+}
+
+- (void)windowDidFinishMoving
+{
+    if ([self isMoving])
+    {
+        isMoving = NO;
+
+        SDL_Mouse *mouse = SDL_GetMouse();
+        if (pendingWindowWarpX >= 0 && pendingWindowWarpY >= 0) {
+            mouse->WarpMouse(_data->window, pendingWindowWarpX, pendingWindowWarpY);
+            pendingWindowWarpX = pendingWindowWarpY = -1;
+        }
+        if (mouse->relative_mode && SDL_GetMouseFocus() == _data->window) {
+            mouse->SetRelativeMouseMode(SDL_TRUE);
+        }
+    }
+}
+
 - (BOOL)windowShouldClose:(id)sender
 - (BOOL)windowShouldClose:(id)sender
 {
 {
     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
@@ -321,6 +396,14 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
 }
 }
 
 
+- (void)windowWillMove:(NSNotification *)aNotification
+{
+    if ([_data->nswindow isKindOfClass:[SDLWindow class]]) {
+        pendingWindowWarpX = pendingWindowWarpY = -1;
+        isMoving = YES;
+    }
+}
+
 - (void)windowDidMove:(NSNotification *)aNotification
 - (void)windowDidMove:(NSNotification *)aNotification
 {
 {
     int x, y;
     int x, y;
@@ -354,6 +437,11 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
 
 
 - (void)windowDidResize:(NSNotification *)aNotification
 - (void)windowDidResize:(NSNotification *)aNotification
 {
 {
+    if (inFullscreenTransition) {
+        /* We'll take care of this at the end of the transition */
+        return;
+    }
+
     SDL_Window *window = _data->window;
     SDL_Window *window = _data->window;
     NSWindow *nswindow = _data->nswindow;
     NSWindow *nswindow = _data->nswindow;
     int x, y, w, h;
     int x, y, w, h;
@@ -364,11 +452,6 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     w = (int)rect.size.width;
     w = (int)rect.size.width;
     h = (int)rect.size.height;
     h = (int)rect.size.height;
 
 
-    if (inFullscreenTransition) {
-        /* We'll take care of this at the end of the transition */
-        return;
-    }
-
     if (SDL_IsShapedWindow(window)) {
     if (SDL_IsShapedWindow(window)) {
         Cocoa_ResizeWindowShape(window);
         Cocoa_ResizeWindowShape(window);
     }
     }
@@ -402,6 +485,9 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
 {
 {
     SDL_Window *window = _data->window;
     SDL_Window *window = _data->window;
     SDL_Mouse *mouse = SDL_GetMouse();
     SDL_Mouse *mouse = SDL_GetMouse();
+    if (mouse->relative_mode && ![self isMoving]) {
+        mouse->SetRelativeMouseMode(SDL_TRUE);
+    }
 
 
     /* We're going to get keyboard events, since we're key. */
     /* We're going to get keyboard events, since we're key. */
     SDL_SetKeyboardFocus(window);
     SDL_SetKeyboardFocus(window);
@@ -422,10 +508,19 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
 
 
     /* Check to see if someone updated the clipboard */
     /* Check to see if someone updated the clipboard */
     Cocoa_CheckClipboardUpdate(_data->videodata);
     Cocoa_CheckClipboardUpdate(_data->videodata);
+
+    if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
+        [NSMenu setMenuBarVisible:NO];
+    }
 }
 }
 
 
 - (void)windowDidResignKey:(NSNotification *)aNotification
 - (void)windowDidResignKey:(NSNotification *)aNotification
 {
 {
+    SDL_Mouse *mouse = SDL_GetMouse();
+    if (mouse->relative_mode) {
+        mouse->SetRelativeMouseMode(SDL_FALSE);
+    }
+
     /* Some other window will get mouse events, since we're not key. */
     /* Some other window will get mouse events, since we're not key. */
     if (SDL_GetMouseFocus() == _data->window) {
     if (SDL_GetMouseFocus() == _data->window) {
         SDL_SetMouseFocus(NULL);
         SDL_SetMouseFocus(NULL);
@@ -435,13 +530,16 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     if (SDL_GetKeyboardFocus() == _data->window) {
     if (SDL_GetKeyboardFocus() == _data->window) {
         SDL_SetKeyboardFocus(NULL);
         SDL_SetKeyboardFocus(NULL);
     }
     }
+
+    if (isFullscreenSpace) {
+        [NSMenu setMenuBarVisible:YES];
+    }
 }
 }
 
 
 - (void)windowWillEnterFullScreen:(NSNotification *)aNotification
 - (void)windowWillEnterFullScreen:(NSNotification *)aNotification
 {
 {
     SDL_Window *window = _data->window;
     SDL_Window *window = _data->window;
 
 
-    window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
     SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
     SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
 
 
     isFullscreenSpace = YES;
     isFullscreenSpace = YES;
@@ -458,6 +556,10 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
         pendingWindowOperation = PENDING_OPERATION_NONE;
         pendingWindowOperation = PENDING_OPERATION_NONE;
         [self setFullscreenSpace:NO];
         [self setFullscreenSpace:NO];
     } else {
     } else {
+        if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
+            [NSMenu setMenuBarVisible:NO];
+        }
+
         pendingWindowOperation = PENDING_OPERATION_NONE;
         pendingWindowOperation = PENDING_OPERATION_NONE;
         /* Force the size change event in case it was delivered earlier
         /* Force the size change event in case it was delivered earlier
            while the window was still animating into place.
            while the window was still animating into place.
@@ -472,7 +574,6 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
 {
 {
     SDL_Window *window = _data->window;
     SDL_Window *window = _data->window;
 
 
-    window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
     SetWindowStyle(window, GetWindowStyle(window));
     SetWindowStyle(window, GetWindowStyle(window));
 
 
     isFullscreenSpace = NO;
     isFullscreenSpace = NO;
@@ -493,6 +594,15 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
         pendingWindowOperation = PENDING_OPERATION_NONE;
         pendingWindowOperation = PENDING_OPERATION_NONE;
         [nswindow miniaturize:nil];
         [nswindow miniaturize:nil];
     } else {
     } else {
+        /* Adjust the fullscreen toggle button and readd menu now that we're here. */
+        if (window->flags & SDL_WINDOW_RESIZABLE) {
+            /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
+            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
+        } else {
+            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
+        }
+        [NSMenu setMenuBarVisible:YES];
+
         pendingWindowOperation = PENDING_OPERATION_NONE;
         pendingWindowOperation = PENDING_OPERATION_NONE;
         /* Force the size change event in case it was delivered earlier
         /* Force the size change event in case it was delivered earlier
            while the window was still animating into place.
            while the window was still animating into place.
@@ -503,6 +613,16 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     }
     }
 }
 }
 
 
+-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
+{
+    if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
+        return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
+    } else {
+        return proposedOptions;
+    }
+}
+
+
 /* We'll respond to key events by doing nothing so we don't beep.
 /* We'll respond to key events by doing nothing so we don't beep.
  * We could handle key messages here, but we lose some in the NSApp dispatch,
  * We could handle key messages here, but we lose some in the NSApp dispatch,
  * where they get converted to action messages, etc.
  * where they get converted to action messages, etc.
@@ -619,8 +739,6 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
 
 
     if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
     if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
         if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
         if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
-            CGPoint cgpoint;
-
             if (x < 0) {
             if (x < 0) {
                 x = 0;
                 x = 0;
             } else if (x >= window->w) {
             } else if (x >= window->w) {
@@ -633,6 +751,8 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
             }
             }
 
 
 #if !SDL_MAC_NO_SANDBOX
 #if !SDL_MAC_NO_SANDBOX
+            CGPoint cgpoint;
+
             /* When SDL_MAC_NO_SANDBOX is set, this is handled by
             /* When SDL_MAC_NO_SANDBOX is set, this is handled by
              * SDL_cocoamousetap.m.
              * SDL_cocoamousetap.m.
              */
              */
@@ -647,6 +767,8 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
             CGSetLocalEventsSuppressionInterval(0.0);
             CGSetLocalEventsSuppressionInterval(0.0);
             CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
             CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
             CGSetLocalEventsSuppressionInterval(0.25);
             CGSetLocalEventsSuppressionInterval(0.25);
+
+            Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
 #endif
 #endif
         }
         }
     }
     }
@@ -749,24 +871,6 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
 
 
 @end
 @end
 
 
-@interface SDLWindow : NSWindow
-/* These are needed for borderless/fullscreen windows */
-- (BOOL)canBecomeKeyWindow;
-- (BOOL)canBecomeMainWindow;
-@end
-
-@implementation SDLWindow
-- (BOOL)canBecomeKeyWindow
-{
-    return YES;
-}
-
-- (BOOL)canBecomeMainWindow
-{
-    return YES;
-}
-@end
-
 @interface SDLView : NSView
 @interface SDLView : NSView
 
 
 /* The default implementation doesn't pass rightMouseDown to responder chain */
 /* The default implementation doesn't pass rightMouseDown to responder chain */
@@ -883,6 +987,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
 int
 int
 Cocoa_CreateWindow(_THIS, SDL_Window * window)
 Cocoa_CreateWindow(_THIS, SDL_Window * window)
 {
 {
+    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSWindow *nswindow;
     NSWindow *nswindow;
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
@@ -926,9 +1031,13 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
         return -1;
         return -1;
     }
     }
     [nswindow setBackgroundColor:[NSColor blackColor]];
     [nswindow setBackgroundColor:[NSColor blackColor]];
-    if ([nswindow respondsToSelector:@selector(setCollectionBehavior:)]) {
-        const char *hint = SDL_GetHint(SDL_HINT_VIDEO_FULLSCREEN_SPACES);
-        if (hint && SDL_atoi(hint) > 0) {
+
+    if (videodata->allow_spaces) {
+        SDL_assert(videodata->osversion >= 0x1070);
+        SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
+        /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
+        if (window->flags & SDL_WINDOW_RESIZABLE) {
+            /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
             [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
             [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
         }
         }
     }
     }
@@ -1333,13 +1442,18 @@ void
 Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
 Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
 {
 {
     /* Move the cursor to the nearest point in the window */
     /* Move the cursor to the nearest point in the window */
-    if (grabbed) {
+    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+    if (grabbed && data && ![data->listener isMoving]) {
         int x, y;
         int x, y;
         CGPoint cgpoint;
         CGPoint cgpoint;
 
 
         SDL_GetMouseState(&x, &y);
         SDL_GetMouseState(&x, &y);
         cgpoint.x = window->x + x;
         cgpoint.x = window->x + x;
         cgpoint.y = window->y + y;
         cgpoint.y = window->y + y;
+
+        Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
+
+        DLog("Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
         CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
         CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
     }
     }
 
 

+ 4 - 2
libs/SDL2/src/video/mir/SDL_mirframebuffer.c

@@ -91,11 +91,13 @@ MIR_UpdateWindowFramebuffer(_THIS, SDL_Window* window,
     MirGraphicsRegion region;
     MirGraphicsRegion region;
     int i, j, x, y, w, h, start;
     int i, j, x, y, w, h, start;
     int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
     int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
+    char* s_dest;
+    char* pixels;
 
 
     MIR_mir_surface_get_graphics_region(mir_window->surface, &region);
     MIR_mir_surface_get_graphics_region(mir_window->surface, &region);
 
 
-    char* s_dest = region.vaddr;
-    char* pixels = (char*)window->surface->pixels;
+    s_dest = region.vaddr;
+    pixels = (char*)window->surface->pixels;
 
 
     s_stride = window->surface->pitch;
     s_stride = window->surface->pitch;
     d_stride = region.stride;
     d_stride = region.stride;

+ 6 - 5
libs/SDL2/src/video/uikit/SDL_uikitopenglview.m

@@ -56,6 +56,11 @@
         const BOOL useDepthBuffer = (depthBits != 0);
         const BOOL useDepthBuffer = (depthBits != 0);
         NSString *colorFormat = nil;
         NSString *colorFormat = nil;
 
 
+        /* The EAGLRenderingAPI enum values currently map 1:1 to major GLES
+           versions, and this allows us to handle future OpenGL ES versions.
+         */
+        EAGLRenderingAPI api = majorVersion;
+
         if (rBits == 8 && gBits == 8 && bBits == 8) {
         if (rBits == 8 && gBits == 8 && bBits == 8) {
             /* if user specifically requests rbg888 or some color format higher than 16bpp */
             /* if user specifically requests rbg888 or some color format higher than 16bpp */
             colorFormat = kEAGLColorFormatRGBA8;
             colorFormat = kEAGLColorFormatRGBA8;
@@ -71,11 +76,7 @@
         eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
         eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                         [NSNumber numberWithBool: retained], kEAGLDrawablePropertyRetainedBacking, colorFormat, kEAGLDrawablePropertyColorFormat, nil];
                                         [NSNumber numberWithBool: retained], kEAGLDrawablePropertyRetainedBacking, colorFormat, kEAGLDrawablePropertyColorFormat, nil];
 
 
-        if (majorVersion > 1) {
-            context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:shareGroup];
-        } else {
-            context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:shareGroup];
-        }
+        context = [[EAGLContext alloc] initWithAPI:api sharegroup:shareGroup];
         if (!context || ![EAGLContext setCurrentContext:context]) {
         if (!context || ![EAGLContext setCurrentContext:context]) {
             [self release];
             [self release];
             SDL_SetError("OpenGL ES %d not supported", majorVersion);
             SDL_SetError("OpenGL ES %d not supported", majorVersion);

+ 27 - 5
libs/SDL2/src/video/windows/SDL_windowsevents.c

@@ -25,6 +25,7 @@
 #include "SDL_windowsvideo.h"
 #include "SDL_windowsvideo.h"
 #include "SDL_windowsshape.h"
 #include "SDL_windowsshape.h"
 #include "SDL_syswm.h"
 #include "SDL_syswm.h"
+#include "SDL_timer.h"
 #include "SDL_vkeys.h"
 #include "SDL_vkeys.h"
 #include "../../events/SDL_events_c.h"
 #include "../../events/SDL_events_c.h"
 #include "../../events/SDL_touch_c.h"
 #include "../../events/SDL_touch_c.h"
@@ -537,10 +538,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
 
             /* Detect relevant keyboard shortcuts */
             /* Detect relevant keyboard shortcuts */
             if (keyboardState[SDL_SCANCODE_LALT] == SDL_PRESSED || keyboardState[SDL_SCANCODE_RALT] == SDL_PRESSED ) {
             if (keyboardState[SDL_SCANCODE_LALT] == SDL_PRESSED || keyboardState[SDL_SCANCODE_RALT] == SDL_PRESSED ) {
-	            /* ALT+F4: Close window */
-	            if (code == SDL_SCANCODE_F4) {
-		            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
-	            }
+                /* ALT+F4: Close window */
+                if (code == SDL_SCANCODE_F4) {
+                    SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
+                }
             }
             }
 
 
             if ( code != SDL_SCANCODE_UNKNOWN ) {
             if ( code != SDL_SCANCODE_UNKNOWN ) {
@@ -569,6 +570,20 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
         break;
         break;
 #endif /* WM_INPUTLANGCHANGE */
 #endif /* WM_INPUTLANGCHANGE */
 
 
+    case WM_NCLBUTTONDOWN:
+        {
+            data->in_title_click = SDL_TRUE;
+            WIN_UpdateClipCursor(data->window);
+        }
+        break;
+
+    case WM_NCMOUSELEAVE:
+        {
+            data->in_title_click = SDL_FALSE;
+            WIN_UpdateClipCursor(data->window);
+        }
+        break;
+
     case WM_ENTERSIZEMOVE:
     case WM_ENTERSIZEMOVE:
     case WM_ENTERMENULOOP:
     case WM_ENTERMENULOOP:
         {
         {
@@ -860,10 +875,17 @@ WIN_PumpEvents(_THIS)
 {
 {
     const Uint8 *keystate;
     const Uint8 *keystate;
     MSG msg;
     MSG msg;
+    DWORD start_ticks = GetTickCount();
+
     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
         /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
         /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
         TranslateMessage(&msg);
         TranslateMessage(&msg);
-        DispatchMessage(&msg);
+        DispatchMessage( &msg );
+
+        /* Make sure we don't busy loop here forever if there are lots of events coming in */
+        if (SDL_TICKS_PASSED(msg.time, start_ticks)) {
+            break;
+        }
     }
     }
 
 
     /* Windows loses a shift KEYUP event when you have both pressed at once and let go of one.
     /* Windows loses a shift KEYUP event when you have both pressed at once and let go of one.

+ 11 - 29
libs/SDL2/src/video/windows/SDL_windowsmouse.c

@@ -183,9 +183,15 @@ WIN_ShowCursor(SDL_Cursor * cursor)
 static void
 static void
 WIN_WarpMouse(SDL_Window * window, int x, int y)
 WIN_WarpMouse(SDL_Window * window, int x, int y)
 {
 {
-    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+    HWND hwnd = data->hwnd;
     POINT pt;
     POINT pt;
 
 
+    /* Don't warp the mouse while we're doing a modal interaction */
+    if (data->in_title_click || data->in_modal_loop) {
+        return;
+    }
+
     pt.x = x;
     pt.x = x;
     pt.y = y;
     pt.y = y;
     ClientToScreen(hwnd, &pt);
     ClientToScreen(hwnd, &pt);
@@ -196,44 +202,20 @@ static int
 WIN_SetRelativeMouseMode(SDL_bool enabled)
 WIN_SetRelativeMouseMode(SDL_bool enabled)
 {
 {
     RAWINPUTDEVICE rawMouse = { 0x01, 0x02, 0, NULL }; /* Mouse: UsagePage = 1, Usage = 2 */
     RAWINPUTDEVICE rawMouse = { 0x01, 0x02, 0, NULL }; /* Mouse: UsagePage = 1, Usage = 2 */
-    HWND hWnd;
-    hWnd = GetActiveWindow();
 
 
-    rawMouse.hwndTarget = hWnd;
-    if(!enabled) {
+    if (!enabled) {
         rawMouse.dwFlags |= RIDEV_REMOVE;
         rawMouse.dwFlags |= RIDEV_REMOVE;
-        rawMouse.hwndTarget = NULL;
     }
     }
 
 
-
     /* (Un)register raw input for mice */
     /* (Un)register raw input for mice */
     if (RegisterRawInputDevices(&rawMouse, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
     if (RegisterRawInputDevices(&rawMouse, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
 
 
-        /* Only return an error when registering. If we unregister and fail, then
-        it's probably that we unregistered twice. That's OK. */
-        if(enabled) {
+        /* Only return an error when registering. If we unregister and fail,
+           then it's probably that we unregistered twice. That's OK. */
+        if (enabled) {
             return SDL_Unsupported();
             return SDL_Unsupported();
         }
         }
     }
     }
-
-    if (enabled) {
-        LONG cx, cy;
-        RECT rect;
-        GetWindowRect(hWnd, &rect);
-
-        cx = (rect.left + rect.right) / 2;
-        cy = (rect.top + rect.bottom) / 2;
-
-        /* Make an absurdly small clip rect */
-        rect.left = cx-1;
-        rect.right = cx+1;
-        rect.top = cy-1;
-        rect.bottom = cy+1;
-
-        ClipCursor(&rect);
-    } else {
-        ClipCursor(NULL);
-    }
     return 0;
     return 0;
 }
 }
 
 

+ 0 - 2
libs/SDL2/src/video/windows/SDL_windowsopengles.c

@@ -32,8 +32,6 @@
 int
 int
 WIN_GLES_LoadLibrary(_THIS, const char *path) {
 WIN_GLES_LoadLibrary(_THIS, const char *path) {
 
 
-    SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
-
     /* If the profile requested is not GL ES, switch over to WIN_GL functions  */
     /* If the profile requested is not GL ES, switch over to WIN_GL functions  */
     if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
     if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
 #if SDL_VIDEO_OPENGL_WGL
 #if SDL_VIDEO_OPENGL_WGL

+ 1 - 1
libs/SDL2/src/video/windows/SDL_windowsvideo.c

@@ -261,7 +261,7 @@ DXGI_LoadDLL( void **pDXGIDLL , IDXGIFactory **pDXGIFactory )
 			"CreateDXGIFactory");
 			"CreateDXGIFactory");
 		if (CreateDXGI) {
 		if (CreateDXGI) {
 			GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
 			GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
-			if( !SUCCEEDED( CreateDXGI( &dxgiGUID, pDXGIFactory ))) {
+			if( !SUCCEEDED( CreateDXGI( &dxgiGUID, (void**)pDXGIFactory ))) {
 				*pDXGIFactory = NULL;
 				*pDXGIFactory = NULL;
 			}
 			}
 		}
 		}

+ 2 - 2
libs/SDL2/src/video/windows/SDL_windowswindow.c

@@ -673,7 +673,7 @@ SDL_HelperWindowCreate(void)
 
 
     /* Register the class. */
     /* Register the class. */
     SDL_HelperWindowClass = RegisterClass(&wce);
     SDL_HelperWindowClass = RegisterClass(&wce);
-    if (SDL_HelperWindowClass == 0) {
+    if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
         return WIN_SetError("Unable to create Helper Window Class");
         return WIN_SetError("Unable to create Helper Window Class");
     }
     }
 
 
@@ -746,7 +746,7 @@ WIN_UpdateClipCursor(SDL_Window *window)
     SDL_Mouse *mouse = SDL_GetMouse();
     SDL_Mouse *mouse = SDL_GetMouse();
 
 
     /* Don't clip the cursor while we're in the modal resize or move loop */
     /* Don't clip the cursor while we're in the modal resize or move loop */
-    if (data->in_modal_loop) {
+    if (data->in_title_click || data->in_modal_loop) {
         ClipCursor(NULL);
         ClipCursor(NULL);
         return;
         return;
     }
     }

+ 1 - 0
libs/SDL2/src/video/windows/SDL_windowswindow.h

@@ -38,6 +38,7 @@ typedef struct
     SDL_bool created;
     SDL_bool created;
     WPARAM mouse_button_flags;
     WPARAM mouse_button_flags;
     BOOL expected_resize;
     BOOL expected_resize;
+    SDL_bool in_title_click;
     SDL_bool in_modal_loop;
     SDL_bool in_modal_loop;
     struct SDL_VideoData *videodata;
     struct SDL_VideoData *videodata;
 #if SDL_VIDEO_OPENGL_EGL  
 #if SDL_VIDEO_OPENGL_EGL  

+ 41 - 41
libs/SDL2/src/video/windows/wmmsg.h

@@ -257,7 +257,7 @@ char *wmtab[] = {
     "UNKNOWN (252)",
     "UNKNOWN (252)",
     "UNKNOWN (253)",
     "UNKNOWN (253)",
     "UNKNOWN (254)",
     "UNKNOWN (254)",
-    "UNKNOWN (255)",
+    "WM_INPUT",
     "WM_KEYDOWN",
     "WM_KEYDOWN",
     "WM_KEYUP",
     "WM_KEYUP",
     "WM_CHAR",
     "WM_CHAR",
@@ -570,30 +570,30 @@ char *wmtab[] = {
     "UNKNOWN (565)",
     "UNKNOWN (565)",
     "UNKNOWN (566)",
     "UNKNOWN (566)",
     "UNKNOWN (567)",
     "UNKNOWN (567)",
-    "UNKNOWN (568)",
-    "UNKNOWN (569)",
-    "UNKNOWN (570)",
+    "WM_POINTERDEVICECHANGE",
+    "WM_POINTERDEVICEINRANGE",
+    "WM_POINTERDEVICEOUTOFRANGE",
     "UNKNOWN (571)",
     "UNKNOWN (571)",
     "UNKNOWN (572)",
     "UNKNOWN (572)",
     "UNKNOWN (573)",
     "UNKNOWN (573)",
     "UNKNOWN (574)",
     "UNKNOWN (574)",
     "UNKNOWN (575)",
     "UNKNOWN (575)",
     "WM_TOUCH",
     "WM_TOUCH",
-    "UNKNOWN (577)",
-    "UNKNOWN (578)",
-    "UNKNOWN (579)",
+    "WM_NCPOINTERUPDATE",
+    "WM_NCPOINTERDOWN",
+    "WM_NCPOINTERUP",
     "UNKNOWN (580)",
     "UNKNOWN (580)",
-    "UNKNOWN (581)",
-    "UNKNOWN (582)",
-    "UNKNOWN (583)",
-    "UNKNOWN (584)",
-    "UNKNOWN (585)",
-    "UNKNOWN (586)",
-    "UNKNOWN (587)",
-    "UNKNOWN (588)",
-    "UNKNOWN (589)",
-    "UNKNOWN (590)",
-    "UNKNOWN (591)",
+    "WM_POINTERUPDATE",
+    "WM_POINTERDOWN",
+    "WM_POINTERUP",
+    "WM_POINTERENTER",
+    "WM_POINTERLEAVE",
+    "WM_POINTERACTIVATE",
+    "WM_POINTERCAPTURECHANGED",
+    "WM_TOUCHHITTESTING",
+    "WM_POINTERWHEEL",
+    "WM_POINTERHWHEEL",
+    "DM_POINTERHITTEST",
     "UNKNOWN (592)",
     "UNKNOWN (592)",
     "UNKNOWN (593)",
     "UNKNOWN (593)",
     "UNKNOWN (594)",
     "UNKNOWN (594)",
@@ -643,14 +643,14 @@ char *wmtab[] = {
     "UNKNOWN (638)",
     "UNKNOWN (638)",
     "UNKNOWN (639)",
     "UNKNOWN (639)",
     "UNKNOWN (640)",
     "UNKNOWN (640)",
-    "UNKNOWN (641)",
-    "UNKNOWN (642)",
-    "UNKNOWN (643)",
-    "UNKNOWN (644)",
-    "UNKNOWN (645)",
-    "UNKNOWN (646)",
+    "WM_IME_SETCONTEXT",
+    "WM_IME_NOTIFY",
+    "WM_IME_CONTROL",
+    "WM_IME_COMPOSITIONFULL",
+    "WM_IME_SELECT",
+    "WM_IME_CHAR",
     "UNKNOWN (647)",
     "UNKNOWN (647)",
-    "UNKNOWN (648)",
+    "WM_IME_REQUEST",
     "UNKNOWN (649)",
     "UNKNOWN (649)",
     "UNKNOWN (650)",
     "UNKNOWN (650)",
     "UNKNOWN (651)",
     "UNKNOWN (651)",
@@ -658,8 +658,8 @@ char *wmtab[] = {
     "UNKNOWN (653)",
     "UNKNOWN (653)",
     "UNKNOWN (654)",
     "UNKNOWN (654)",
     "UNKNOWN (655)",
     "UNKNOWN (655)",
-    "UNKNOWN (656)",
-    "UNKNOWN (657)",
+    "WM_IME_KEYDOWN",
+    "WM_IME_KEYUP",
     "UNKNOWN (658)",
     "UNKNOWN (658)",
     "UNKNOWN (659)",
     "UNKNOWN (659)",
     "UNKNOWN (660)",
     "UNKNOWN (660)",
@@ -674,9 +674,9 @@ char *wmtab[] = {
     "UNKNOWN (669)",
     "UNKNOWN (669)",
     "UNKNOWN (670)",
     "UNKNOWN (670)",
     "UNKNOWN (671)",
     "UNKNOWN (671)",
-    "UNKNOWN (672)",
+    "WM_NCMOUSEHOVER",
     "WM_MOUSEHOVER",
     "WM_MOUSEHOVER",
-    "UNKNOWN (674)",
+    "WM_NCMOUSELEAVE",
     "WM_MOUSELEAVE",
     "WM_MOUSELEAVE",
     "UNKNOWN (676)",
     "UNKNOWN (676)",
     "UNKNOWN (677)",
     "UNKNOWN (677)",
@@ -691,7 +691,7 @@ char *wmtab[] = {
     "UNKNOWN (686)",
     "UNKNOWN (686)",
     "UNKNOWN (687)",
     "UNKNOWN (687)",
     "UNKNOWN (688)",
     "UNKNOWN (688)",
-    "UNKNOWN (689)",
+    "WM_WTSSESSION_CHANGE",
     "UNKNOWN (690)",
     "UNKNOWN (690)",
     "UNKNOWN (691)",
     "UNKNOWN (691)",
     "UNKNOWN (692)",
     "UNKNOWN (692)",
@@ -738,7 +738,7 @@ char *wmtab[] = {
     "UNKNOWN (733)",
     "UNKNOWN (733)",
     "UNKNOWN (734)",
     "UNKNOWN (734)",
     "UNKNOWN (735)",
     "UNKNOWN (735)",
-    "UNKNOWN (736)",
+    "WM_DPICHANGED",
     "UNKNOWN (737)",
     "UNKNOWN (737)",
     "UNKNOWN (738)",
     "UNKNOWN (738)",
     "UNKNOWN (739)",
     "UNKNOWN (739)",
@@ -795,20 +795,20 @@ char *wmtab[] = {
     "UNKNOWN (790)",
     "UNKNOWN (790)",
     "WM_PRINT",
     "WM_PRINT",
     "WM_PRINTCLIENT",
     "WM_PRINTCLIENT",
-    "UNKNOWN (793)",
-    "UNKNOWN (794)",
+    "WM_APPCOMMAND",
+    "WM_THEMECHANGED",
     "UNKNOWN (795)",
     "UNKNOWN (795)",
     "UNKNOWN (796)",
     "UNKNOWN (796)",
-    "UNKNOWN (797)",
-    "UNKNOWN (798)",
-    "UNKNOWN (799)",
-    "UNKNOWN (800)",
-    "UNKNOWN (801)",
+    "WM_CLIPBOARDUPDATE",
+    "WM_DWMCOMPOSITIONCHANGED",
+    "WM_DWMNCRENDERINGCHANGED",
+    "WM_DWMCOLORIZATIONCOLORCHANGED",
+    "WM_DWMWINDOWMAXIMIZEDCHANGE",
     "UNKNOWN (802)",
     "UNKNOWN (802)",
-    "UNKNOWN (803)",
+    "WM_DWMSENDICONICTHUMBNAIL",
     "UNKNOWN (804)",
     "UNKNOWN (804)",
     "UNKNOWN (805)",
     "UNKNOWN (805)",
-    "UNKNOWN (806)",
+    "WM_DWMSENDICONICLIVEPREVIEWBITMAP",
     "UNKNOWN (807)",
     "UNKNOWN (807)",
     "UNKNOWN (808)",
     "UNKNOWN (808)",
     "UNKNOWN (809)",
     "UNKNOWN (809)",
@@ -833,7 +833,7 @@ char *wmtab[] = {
     "UNKNOWN (828)",
     "UNKNOWN (828)",
     "UNKNOWN (829)",
     "UNKNOWN (829)",
     "UNKNOWN (830)",
     "UNKNOWN (830)",
-    "UNKNOWN (831)",
+    "WM_GETTITLEBARINFOEX",
     "UNKNOWN (832)",
     "UNKNOWN (832)",
     "UNKNOWN (833)",
     "UNKNOWN (833)",
     "UNKNOWN (834)",
     "UNKNOWN (834)",

+ 12 - 12
libs/SDL2/src/video/x11/SDL_x11events.c

@@ -28,7 +28,6 @@
 #include <unistd.h>
 #include <unistd.h>
 #include <limits.h> /* For INT_MAX */
 #include <limits.h> /* For INT_MAX */
 
 
-#include "SDL_x11video.h"
 #include "SDL_x11video.h"
 #include "SDL_x11video.h"
 #include "SDL_x11touch.h"
 #include "SDL_x11touch.h"
 #include "SDL_x11xinput2.h"
 #include "SDL_x11xinput2.h"
@@ -993,11 +992,6 @@ X11_Pending(Display * display)
     return (0);
     return (0);
 }
 }
 
 
-
-/* !!! FIXME: this should be exposed in a header, or something. */
-int SDL_GetNumTouch(void);
-void SDL_dbus_screensaver_tickle(_THIS);
-
 void
 void
 X11_PumpEvents(_THIS)
 X11_PumpEvents(_THIS)
 {
 {
@@ -1035,7 +1029,19 @@ X11_SuspendScreenSaver(_THIS)
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     int dummy;
     int dummy;
     int major_version, minor_version;
     int major_version, minor_version;
+#endif /* SDL_VIDEO_DRIVER_X11_XSCRNSAVER */
+
+#if SDL_USE_LIBDBUS
+    if (SDL_dbus_screensaver_inhibit(_this)) {
+        return;
+    }
 
 
+    if (_this->suspend_screensaver) {
+        SDL_dbus_screensaver_tickle(_this);
+    }
+#endif
+
+#if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
     if (SDL_X11_HAVE_XSS) {
     if (SDL_X11_HAVE_XSS) {
         /* X11_XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
         /* X11_XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
         if (!X11_XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
         if (!X11_XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
@@ -1049,12 +1055,6 @@ X11_SuspendScreenSaver(_THIS)
         X11_XResetScreenSaver(data->display);
         X11_XResetScreenSaver(data->display);
     }
     }
 #endif
 #endif
-
-#if SDL_USE_LIBDBUS
-    if (_this->suspend_screensaver) {
-        SDL_dbus_screensaver_tickle(_this);
-    }
-#endif
 }
 }
 
 
 #endif /* SDL_VIDEO_DRIVER_X11 */
 #endif /* SDL_VIDEO_DRIVER_X11 */

+ 77 - 0
libs/SDL2/src/video/x11/SDL_x11video.c

@@ -45,6 +45,7 @@
 #include "SDL_loadso.h"
 #include "SDL_loadso.h"
 static const char *dbus_library = "libdbus-1.so.3";
 static const char *dbus_library = "libdbus-1.so.3";
 static void *dbus_handle = NULL;
 static void *dbus_handle = NULL;
+static unsigned int screensaver_cookie = 0;
 
 
 /* !!! FIXME: this is kinda ugly. */
 /* !!! FIXME: this is kinda ugly. */
 static SDL_bool
 static SDL_bool
@@ -63,10 +64,13 @@ load_dbus_sym(const char *fn, void **addr)
 static DBusConnection *(*DBUS_dbus_bus_get_private)(DBusBusType, DBusError *) = NULL;
 static DBusConnection *(*DBUS_dbus_bus_get_private)(DBusBusType, DBusError *) = NULL;
 static void (*DBUS_dbus_connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t) = NULL;
 static void (*DBUS_dbus_connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t) = NULL;
 static dbus_bool_t (*DBUS_dbus_connection_send)(DBusConnection *, DBusMessage *, dbus_uint32_t *) = NULL;
 static dbus_bool_t (*DBUS_dbus_connection_send)(DBusConnection *, DBusMessage *, dbus_uint32_t *) = NULL;
+static DBusMessage *(*DBUS_dbus_connection_send_with_reply_and_block)(DBusConnection *, DBusMessage *, int, DBusError *) = NULL;
 static void (*DBUS_dbus_connection_close)(DBusConnection *) = NULL;
 static void (*DBUS_dbus_connection_close)(DBusConnection *) = NULL;
 static void (*DBUS_dbus_connection_unref)(DBusConnection *) = NULL;
 static void (*DBUS_dbus_connection_unref)(DBusConnection *) = NULL;
 static void (*DBUS_dbus_connection_flush)(DBusConnection *) = NULL;
 static void (*DBUS_dbus_connection_flush)(DBusConnection *) = NULL;
 static DBusMessage *(*DBUS_dbus_message_new_method_call)(const char *, const char *, const char *, const char *) = NULL;
 static DBusMessage *(*DBUS_dbus_message_new_method_call)(const char *, const char *, const char *, const char *) = NULL;
+static dbus_bool_t (*DBUS_dbus_message_append_args)(DBusMessage *, int, ...) = NULL;
+static dbus_bool_t (*DBUS_dbus_message_get_args)(DBusMessage *, DBusError *, int, ...) = NULL;
 static void (*DBUS_dbus_message_unref)(DBusMessage *) = NULL;
 static void (*DBUS_dbus_message_unref)(DBusMessage *) = NULL;
 static void (*DBUS_dbus_error_init)(DBusError *) = NULL;
 static void (*DBUS_dbus_error_init)(DBusError *) = NULL;
 static dbus_bool_t (*DBUS_dbus_error_is_set)(const DBusError *) = NULL;
 static dbus_bool_t (*DBUS_dbus_error_is_set)(const DBusError *) = NULL;
@@ -82,9 +86,12 @@ load_dbus_syms(void)
     SDL_DBUS_SYM(dbus_bus_get_private);
     SDL_DBUS_SYM(dbus_bus_get_private);
     SDL_DBUS_SYM(dbus_connection_set_exit_on_disconnect);
     SDL_DBUS_SYM(dbus_connection_set_exit_on_disconnect);
     SDL_DBUS_SYM(dbus_connection_send);
     SDL_DBUS_SYM(dbus_connection_send);
+    SDL_DBUS_SYM(dbus_connection_send_with_reply_and_block);
     SDL_DBUS_SYM(dbus_connection_close);
     SDL_DBUS_SYM(dbus_connection_close);
     SDL_DBUS_SYM(dbus_connection_unref);
     SDL_DBUS_SYM(dbus_connection_unref);
     SDL_DBUS_SYM(dbus_connection_flush);
     SDL_DBUS_SYM(dbus_connection_flush);
+    SDL_DBUS_SYM(dbus_message_append_args);
+    SDL_DBUS_SYM(dbus_message_get_args);
     SDL_DBUS_SYM(dbus_message_new_method_call);
     SDL_DBUS_SYM(dbus_message_new_method_call);
     SDL_DBUS_SYM(dbus_message_unref);
     SDL_DBUS_SYM(dbus_message_unref);
     SDL_DBUS_SYM(dbus_error_init);
     SDL_DBUS_SYM(dbus_error_init);
@@ -174,6 +181,76 @@ SDL_dbus_screensaver_tickle(_THIS)
         }
         }
     }
     }
 }
 }
+
+SDL_bool
+SDL_dbus_screensaver_inhibit(_THIS)
+{
+    const SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+    DBusConnection *conn = data->dbus;
+
+    if (conn == NULL)
+        return SDL_FALSE;
+
+    if (_this->suspend_screensaver &&
+        screensaver_cookie != 0)
+        return SDL_TRUE;
+    if (!_this->suspend_screensaver &&
+        screensaver_cookie == 0)
+        return SDL_TRUE;
+
+    if (_this->suspend_screensaver) {
+        const char *app = "My SDL application";
+        const char *reason = "Playing a game";
+
+        DBusMessage *msg = DBUS_dbus_message_new_method_call("org.freedesktop.ScreenSaver",
+                                                             "/org/freedesktop/ScreenSaver",
+                                                             "org.freedesktop.ScreenSaver",
+                                                             "Inhibit");
+        if (msg != NULL) {
+            DBUS_dbus_message_append_args (msg,
+                                           DBUS_TYPE_STRING, &app,
+                                           DBUS_TYPE_STRING, &reason,
+                                           DBUS_TYPE_INVALID);
+        }
+
+        if (msg != NULL) {
+            DBusMessage *reply;
+
+            reply = DBUS_dbus_connection_send_with_reply_and_block(conn, msg, 300, NULL);
+            if (reply) {
+                if (!DBUS_dbus_message_get_args(reply, NULL,
+                                                DBUS_TYPE_UINT32, &screensaver_cookie,
+                                                DBUS_TYPE_INVALID))
+                    screensaver_cookie = 0;
+                DBUS_dbus_message_unref(reply);
+            }
+
+            DBUS_dbus_message_unref(msg);
+        }
+
+        if (screensaver_cookie == 0) {
+            return SDL_FALSE;
+        }
+        return SDL_TRUE;
+    } else {
+        DBusMessage *msg = DBUS_dbus_message_new_method_call("org.freedesktop.ScreenSaver",
+                                                             "/org/freedesktop/ScreenSaver",
+                                                             "org.freedesktop.ScreenSaver",
+                                                             "UnInhibit");
+        DBUS_dbus_message_append_args (msg,
+                                       DBUS_TYPE_UINT32, &screensaver_cookie,
+                                       DBUS_TYPE_INVALID);
+        if (msg != NULL) {
+            if (DBUS_dbus_connection_send(conn, msg, NULL)) {
+                DBUS_dbus_connection_flush(conn);
+            }
+            DBUS_dbus_message_unref(msg);
+        }
+
+        screensaver_cookie = 0;
+        return SDL_TRUE;
+    }
+}
 #endif
 #endif
 
 
 /* Initialization/Query functions */
 /* Initialization/Query functions */

+ 3 - 0
libs/SDL2/src/video/x11/SDL_x11video.h

@@ -121,6 +121,9 @@ typedef struct SDL_VideoData
 
 
 extern SDL_bool X11_UseDirectColorVisuals(void);
 extern SDL_bool X11_UseDirectColorVisuals(void);
 
 
+SDL_bool SDL_dbus_screensaver_inhibit(_THIS);
+void SDL_dbus_screensaver_tickle(_THIS);
+
 #endif /* _SDL_x11video_h */
 #endif /* _SDL_x11video_h */
 
 
 /* vi: set ts=4 sw=4 expandtab: */
 /* vi: set ts=4 sw=4 expandtab: */

+ 18 - 14
libs/SDL2/src/video/x11/SDL_x11xinput2.c

@@ -60,16 +60,18 @@ static void parse_valuators(const double *input_values,unsigned char *mask,int m
     }
     }
 }
 }
 
 
-static SDL_bool
-xinput2_version_okay(Display *display, const int major, const int minor)
+static int
+query_xinput2_version(Display *display, int major, int minor)
 {
 {
-    int outmajor = major;
-    int outminor = minor;
-    if (X11_XIQueryVersion(display, &outmajor, &outminor) != Success) {
-        return SDL_FALSE;
-    }
+    /* We don't care if this fails, so long as it sets major/minor on it's way out the door. */
+    X11_XIQueryVersion(display, &major, &minor);
+    return ((major * 1000) + minor);
+}
 
 
-    return ( ((outmajor * 1000) + outminor) >= ((major * 1000) + minor) );
+static SDL_bool
+xinput2_version_atleast(const int version, const int wantmajor, const int wantminor)
+{
+    return ( version >= ((wantmajor * 1000) + wantminor) );
 }
 }
 #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
 #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
 
 
@@ -79,9 +81,11 @@ X11_InitXinput2(_THIS)
 #if SDL_VIDEO_DRIVER_X11_XINPUT2
 #if SDL_VIDEO_DRIVER_X11_XINPUT2
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
 
 
+    int version = 0;
     XIEventMask eventmask;
     XIEventMask eventmask;
     unsigned char mask[3] = { 0,0,0 };
     unsigned char mask[3] = { 0,0,0 };
     int event, err;
     int event, err;
+
     /*
     /*
     * Initialize XInput 2
     * Initialize XInput 2
     * According to http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html its better
     * According to http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html its better
@@ -96,16 +100,16 @@ X11_InitXinput2(_THIS)
         return; /* X server does not have XInput at all */
         return; /* X server does not have XInput at all */
     }
     }
 
 
-    if (!xinput2_version_okay(data->display, 2, 0)) {
-        return; /* X server does not support the version we want */
+    /* We need at least 2.2 for Multitouch, 2.0 otherwise. */
+    version = query_xinput2_version(data->display, 2, 2);
+    if (!xinput2_version_atleast(version, 2, 0)) {
+        return; /* X server does not support the version we want at all. */
     }
     }
 
 
     xinput2_initialized = 1;
     xinput2_initialized = 1;
 
 
-#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
-    if (xinput2_version_okay(data->display, 2, 2)) {  /* Multitouch needs XInput 2.2 */
-        xinput2_multitouch_supported = 1;
-    }
+#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH  /* Multitouch needs XInput 2.2 */
+    xinput2_multitouch_supported = xinput2_version_atleast(version, 2, 2);
 #endif
 #endif
 
 
     /* Enable  Raw motion events for this display */
     /* Enable  Raw motion events for this display */

+ 13 - 11
libs/SDL2/test/testgles2.c

@@ -629,7 +629,7 @@ main(int argc, char *argv[])
     while (!done) {
     while (!done) {
         /* Check for events */
         /* Check for events */
         ++frames;
         ++frames;
-        while (SDL_PollEvent(&event)) {
+        while (SDL_PollEvent(&event) && !done) {
             switch (event.type) {
             switch (event.type) {
             case SDL_WINDOWEVENT:
             case SDL_WINDOWEVENT:
                 switch (event.window.event) {
                 switch (event.window.event) {
@@ -654,16 +654,18 @@ main(int argc, char *argv[])
             }
             }
             SDLTest_CommonEvent(state, &event, &done);
             SDLTest_CommonEvent(state, &event, &done);
         }
         }
-        for (i = 0; i < state->num_windows; ++i) {
-            status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
-            if (status) {
-                SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
-
-                /* Continue for next window */
-                continue;
-            }
-            Render(state->window_w, state->window_h, &datas[i]);
-            SDL_GL_SwapWindow(state->windows[i]);
+        if (!done) {
+          for (i = 0; i < state->num_windows; ++i) {
+              status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
+              if (status) {
+                  SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
+
+                  /* Continue for next window */
+                  continue;
+              }
+              Render(state->window_w, state->window_h, &datas[i]);
+              SDL_GL_SwapWindow(state->windows[i]);
+          }
         }
         }
     }
     }
 
 

Some files were not shown because too many files changed in this diff