Merge audio capture work back into the mainline.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 28 Aug 2016 13:36:13 -0400
changeset 102863b884985835c
parent 10285 b1f031450499
parent 10230 9859cda24699
child 10287 d4495a97f89c
Merge audio capture work back into the mainline.
VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj
VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters
VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj
VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters
VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj
VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters
VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj
VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters
VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj
VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters
src/audio/alsa/SDL_alsa_audio.c
     1.1 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj	Fri Aug 12 22:50:48 2016 -0400
     1.2 +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj	Sun Aug 28 13:36:13 2016 -0400
     1.3 @@ -155,6 +155,7 @@
     1.4      <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
     1.5      <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
     1.6      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
     1.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
     1.8      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
     1.9      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
    1.10      <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
    1.11 @@ -310,6 +311,14 @@
    1.12        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.13        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.14      </ClCompile>
    1.15 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
    1.16 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.17 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.18 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.19 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.20 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    1.21 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.22 +    </ClCompile>
    1.23      <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
    1.24        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.25        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
     2.1 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters	Fri Aug 12 22:50:48 2016 -0400
     2.2 +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters	Sun Aug 28 13:36:13 2016 -0400
     2.3 @@ -399,6 +399,9 @@
     2.4      <ClInclude Include="..\..\src\audio\xaudio2\SDL_xaudio2.h">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClInclude>
     2.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
     2.8 +      <Filter>Source Files</Filter>
     2.9 +    </ClInclude>
    2.10    </ItemGroup>
    2.11    <ItemGroup>
    2.12      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
    2.13 @@ -713,5 +716,8 @@
    2.14      <ClCompile Include="..\..\src\audio\xaudio2\SDL_xaudio2.c">
    2.15        <Filter>Source Files</Filter>
    2.16      </ClCompile>
    2.17 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
    2.18 +      <Filter>Source Files</Filter>
    2.19 +    </ClCompile>
    2.20    </ItemGroup>
    2.21  </Project>
    2.22 \ No newline at end of file
     3.1 --- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj	Fri Aug 12 22:50:48 2016 -0400
     3.2 +++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj	Sun Aug 28 13:36:13 2016 -0400
     3.3 @@ -272,6 +272,7 @@
     3.4      <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
     3.5      <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
     3.6      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
     3.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
     3.8      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
     3.9      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
    3.10      <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
    3.11 @@ -407,6 +408,12 @@
    3.12        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    3.13        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    3.14      </ClCompile>
    3.15 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
    3.16 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    3.17 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    3.18 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    3.19 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    3.20 +    </ClCompile>
    3.21      <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
    3.22        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    3.23        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
     4.1 --- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters	Fri Aug 12 22:50:48 2016 -0400
     4.2 +++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters	Sun Aug 28 13:36:13 2016 -0400
     4.3 @@ -369,6 +369,9 @@
     4.4      <ClInclude Include="..\..\src\video\SDL_egl_c.h">
     4.5        <Filter>Source Files</Filter>
     4.6      </ClInclude>
     4.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
     4.8 +      <Filter>Source Files</Filter>
     4.9 +    </ClInclude>
    4.10    </ItemGroup>
    4.11    <ItemGroup>
    4.12      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
    4.13 @@ -671,5 +674,8 @@
    4.14      <ClCompile Include="..\..\src\video\SDL_egl.c">
    4.15        <Filter>Source Files</Filter>
    4.16      </ClCompile>
    4.17 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
    4.18 +      <Filter>Source Files</Filter>
    4.19 +    </ClCompile>
    4.20    </ItemGroup>
    4.21  </Project>
    4.22 \ No newline at end of file
     5.1 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj	Fri Aug 12 22:50:48 2016 -0400
     5.2 +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj	Sun Aug 28 13:36:13 2016 -0400
     5.3 @@ -138,6 +138,7 @@
     5.4      <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
     5.5      <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
     5.6      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
     5.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
     5.8      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
     5.9      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
    5.10      <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
    5.11 @@ -274,6 +275,12 @@
    5.12        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    5.13        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    5.14      </ClCompile>
    5.15 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
    5.16 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    5.17 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    5.18 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    5.19 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    5.20 +    </ClCompile>
    5.21      <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
    5.22        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    5.23        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
     6.1 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters	Fri Aug 12 22:50:48 2016 -0400
     6.2 +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters	Sun Aug 28 13:36:13 2016 -0400
     6.3 @@ -378,6 +378,9 @@
     6.4      <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
     6.5        <Filter>Source Files</Filter>
     6.6      </ClInclude>
     6.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
     6.8 +      <Filter>Source Files</Filter>
     6.9 +    </ClInclude>
    6.10    </ItemGroup>
    6.11    <ItemGroup>
    6.12      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
    6.13 @@ -683,5 +686,8 @@
    6.14      <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c">
    6.15        <Filter>Source Files</Filter>
    6.16      </ClCompile>
    6.17 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
    6.18 +      <Filter>Source Files</Filter>
    6.19 +    </ClCompile>
    6.20    </ItemGroup>
    6.21  </Project>
    6.22 \ No newline at end of file
     7.1 --- a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj	Fri Aug 12 22:50:48 2016 -0400
     7.2 +++ b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj	Sun Aug 28 13:36:13 2016 -0400
     7.3 @@ -175,6 +175,14 @@
     7.4        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
     7.5        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
     7.6      </ClCompile>
     7.7 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
     7.8 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
     7.9 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    7.10 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    7.11 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    7.12 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    7.13 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    7.14 +    </ClCompile>
    7.15      <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
    7.16        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    7.17        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    7.18 @@ -352,6 +360,7 @@
    7.19      <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
    7.20      <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
    7.21      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
    7.22 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
    7.23      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
    7.24      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
    7.25      <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
     8.1 --- a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters	Fri Aug 12 22:50:48 2016 -0400
     8.2 +++ b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters	Sun Aug 28 13:36:13 2016 -0400
     8.3 @@ -316,6 +316,9 @@
     8.4      <ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c">
     8.5        <Filter>Source Files</Filter>
     8.6      </ClCompile>
     8.7 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
     8.8 +      <Filter>Source Files</Filter>
     8.9 +    </ClCompile>
    8.10    </ItemGroup>
    8.11    <ItemGroup>
    8.12      <ClInclude Include="..\..\include\begin_code.h">
    8.13 @@ -711,6 +714,9 @@
    8.14      <ClInclude Include="..\..\src\haptic\windows\SDL_xinputhaptic_c.h">
    8.15        <Filter>Source Files</Filter>
    8.16      </ClInclude>
    8.17 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
    8.18 +      <Filter>Source Files</Filter>
    8.19 +    </ClInclude>
    8.20    </ItemGroup>
    8.21    <ItemGroup>
    8.22      <Filter Include="Header Files">
     9.1 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj	Fri Aug 12 22:50:48 2016 -0400
     9.2 +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj	Sun Aug 28 13:36:13 2016 -0400
     9.3 @@ -152,6 +152,7 @@
     9.4      <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
     9.5      <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
     9.6      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
     9.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
     9.8      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
     9.9      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
    9.10      <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
    9.11 @@ -308,6 +309,14 @@
    9.12        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    9.13        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    9.14      </ClCompile>
    9.15 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
    9.16 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    9.17 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    9.18 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    9.19 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    9.20 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    9.21 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    9.22 +    </ClCompile>
    9.23      <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
    9.24        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    9.25        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    10.1 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters	Fri Aug 12 22:50:48 2016 -0400
    10.2 +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters	Sun Aug 28 13:36:13 2016 -0400
    10.3 @@ -390,6 +390,9 @@
    10.4      <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
    10.5        <Filter>Source Files</Filter>
    10.6      </ClInclude>
    10.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
    10.8 +      <Filter>Source Files</Filter>
    10.9 +    </ClInclude>
   10.10    </ItemGroup>
   10.11    <ItemGroup>
   10.12      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
   10.13 @@ -707,5 +710,8 @@
   10.14      <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c">
   10.15        <Filter>Source Files</Filter>
   10.16      </ClCompile>
   10.17 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
   10.18 +      <Filter>Source Files</Filter>
   10.19 +    </ClCompile>
   10.20    </ItemGroup>
   10.21  </Project>
   10.22 \ No newline at end of file
    11.1 --- a/include/SDL.h	Fri Aug 12 22:50:48 2016 -0400
    11.2 +++ b/include/SDL.h	Sun Aug 28 13:36:13 2016 -0400
    11.3 @@ -95,8 +95,8 @@
    11.4   *  This function initializes specific SDL subsystems
    11.5   *
    11.6   *  Subsystem initialization is ref-counted, you must call
    11.7 - *  SDL_QuitSubSystem for each SDL_InitSubSystem to correctly
    11.8 - *  shutdown a subsystem manually (or call SDL_Quit to force shutdown).
    11.9 + *  SDL_QuitSubSystem() for each SDL_InitSubSystem() to correctly
   11.10 + *  shutdown a subsystem manually (or call SDL_Quit() to force shutdown).
   11.11   *  If a subsystem is already loaded then this call will
   11.12   *  increase the ref-count and return.
   11.13   */
    12.1 --- a/include/SDL_gamecontroller.h	Fri Aug 12 22:50:48 2016 -0400
    12.2 +++ b/include/SDL_gamecontroller.h	Sun Aug 28 13:36:13 2016 -0400
    12.3 @@ -93,7 +93,7 @@
    12.4   *      }
    12.5   *  }
    12.6   *
    12.7 - *  Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
    12.8 + *  Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
    12.9   *  guid,name,mappings
   12.10   *
   12.11   *  Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones.
   12.12 @@ -136,14 +136,14 @@
   12.13  /**
   12.14   *  Get a mapping string for a GUID
   12.15   *
   12.16 - *  \return the mapping string.  Must be freed with SDL_free.  Returns NULL if no mapping is available
   12.17 + *  \return the mapping string.  Must be freed with SDL_free().  Returns NULL if no mapping is available
   12.18   */
   12.19  extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid );
   12.20  
   12.21  /**
   12.22   *  Get a mapping string for an open GameController
   12.23   *
   12.24 - *  \return the mapping string.  Must be freed with SDL_free.  Returns NULL if no mapping is available
   12.25 + *  \return the mapping string.  Must be freed with SDL_free().  Returns NULL if no mapping is available
   12.26   */
   12.27  extern DECLSPEC char * SDLCALL SDL_GameControllerMapping( SDL_GameController * gamecontroller );
   12.28  
    13.1 --- a/include/SDL_hints.h	Fri Aug 12 22:50:48 2016 -0400
    13.2 +++ b/include/SDL_hints.h	Sun Aug 28 13:36:13 2016 -0400
    13.3 @@ -431,7 +431,7 @@
    13.4   *  privacy policy.
    13.5   *
    13.6   *  To setup a URL to an app's privacy policy, set SDL_HINT_WINRT_PRIVACY_POLICY_URL
    13.7 - *  before calling any SDL_Init functions.  The contents of the hint should
    13.8 + *  before calling any SDL_Init() functions.  The contents of the hint should
    13.9   *  be a valid URL.  For example, "http://www.example.com".
   13.10   *
   13.11   *  The default value is "", which will prevent SDL from adding a privacy policy
   13.12 @@ -461,7 +461,7 @@
   13.13   *  The contents of this hint should be encoded as a UTF8 string.
   13.14   *
   13.15   *  The default value is "Privacy Policy".  This hint should only be set during app
   13.16 - *  initialization, preferably before any calls to SDL_Init.
   13.17 + *  initialization, preferably before any calls to SDL_Init().
   13.18   *
   13.19   *  For additional information on linking to a privacy policy, see the documentation for
   13.20   *  SDL_HINT_WINRT_PRIVACY_POLICY_URL.
    14.1 --- a/include/SDL_joystick.h	Fri Aug 12 22:50:48 2016 -0400
    14.2 +++ b/include/SDL_joystick.h	Sun Aug 28 13:36:13 2016 -0400
    14.3 @@ -24,7 +24,7 @@
    14.4   *
    14.5   *  Include file for SDL joystick event handling
    14.6   *
    14.7 - * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks, with the exact joystick
    14.8 + * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks(), with the exact joystick
    14.9   *   behind a device_index changing as joysticks are plugged and unplugged.
   14.10   *
   14.11   * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted
    15.1 --- a/include/SDL_keyboard.h	Fri Aug 12 22:50:48 2016 -0400
    15.2 +++ b/include/SDL_keyboard.h	Sun Aug 28 13:36:13 2016 -0400
    15.3 @@ -136,7 +136,7 @@
    15.4   *          copy it.  If the key doesn't have a name, this function returns an
    15.5   *          empty string ("").
    15.6   *
    15.7 - *  \sa SDL_Key
    15.8 + *  \sa SDL_Keycode
    15.9   */
   15.10  extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key);
   15.11  
    16.1 --- a/include/SDL_mouse.h	Fri Aug 12 22:50:48 2016 -0400
    16.2 +++ b/include/SDL_mouse.h	Sun Aug 28 13:36:13 2016 -0400
    16.3 @@ -41,7 +41,7 @@
    16.4  typedef struct SDL_Cursor SDL_Cursor;   /* Implementation dependent */
    16.5  
    16.6  /**
    16.7 - * \brief Cursor types for SDL_CreateSystemCursor.
    16.8 + * \brief Cursor types for SDL_CreateSystemCursor().
    16.9   */
   16.10  typedef enum
   16.11  {
    17.1 --- a/include/SDL_video.h	Fri Aug 12 22:50:48 2016 -0400
    17.2 +++ b/include/SDL_video.h	Sun Aug 28 13:36:13 2016 -0400
    17.3 @@ -789,7 +789,7 @@
    17.4   *  \return 0 on success, or -1 on error.
    17.5   *
    17.6   *  \sa SDL_GetWindowSurface()
    17.7 - *  \sa SDL_UpdateWindowSurfaceRect()
    17.8 + *  \sa SDL_UpdateWindowSurface()
    17.9   */
   17.10  extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window,
   17.11                                                           const SDL_Rect * rects,
    18.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Fri Aug 12 22:50:48 2016 -0400
    18.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Sun Aug 28 13:36:13 2016 -0400
    18.3 @@ -699,90 +699,196 @@
    18.4      return 0;
    18.5  }
    18.6  
    18.7 +typedef struct ALSA_Device
    18.8 +{
    18.9 +    char *name;
   18.10 +    SDL_bool iscapture;
   18.11 +    struct ALSA_Device *next;
   18.12 +} ALSA_Device;
   18.13 +
   18.14  static void
   18.15 -ALSA_Deinitialize(void)
   18.16 +add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSeen)
   18.17  {
   18.18 -    UnloadALSALibrary();
   18.19 +    ALSA_Device *dev = SDL_malloc(sizeof (ALSA_Device));
   18.20 +    char *desc = ALSA_snd_device_name_get_hint(hint, "DESC");
   18.21 +    char *handle = NULL;
   18.22 +    char *ptr;
   18.23 +
   18.24 +    if (!desc) {
   18.25 +        SDL_free(dev);
   18.26 +        return;
   18.27 +    } else if (!dev) {
   18.28 +        free(desc);
   18.29 +        return;
   18.30 +    }
   18.31 +
   18.32 +    SDL_assert(name != NULL);
   18.33 +
   18.34 +    /* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output".
   18.35 +       just chop the extra lines off, this seems to get a reasonable device
   18.36 +       name without extra details. */
   18.37 +    if ((ptr = strchr(desc, '\n')) != NULL) {
   18.38 +        *ptr = '\0';
   18.39 +    }
   18.40 +
   18.41 +    /*printf("ALSA: adding %s device '%s' (%s)\n", iscapture ? "capture" : "output", name, desc);*/
   18.42 +
   18.43 +    handle = SDL_strdup(name);
   18.44 +    if (!handle) {
   18.45 +        free(desc);
   18.46 +        SDL_free(dev);
   18.47 +        return;
   18.48 +    }
   18.49 +
   18.50 +    SDL_AddAudioDevice(iscapture, desc, handle);
   18.51 +    free(desc);
   18.52 +
   18.53 +    dev->name = handle;
   18.54 +    dev->iscapture = iscapture;
   18.55 +    dev->next = *pSeen;
   18.56 +    *pSeen = dev;
   18.57  }
   18.58  
   18.59 -static void
   18.60 -add_device(const int iscapture, const char *name, const char *_desc)
   18.61 +
   18.62 +static SDL_atomic_t ALSA_hotplug_shutdown;
   18.63 +static SDL_Thread *ALSA_hotplug_thread;
   18.64 +
   18.65 +static int SDLCALL
   18.66 +ALSA_HotplugThread(void *arg)
   18.67  {
   18.68 -    char *desc = NULL;
   18.69 -    char *handle = NULL;
   18.70 -    char *ptr = NULL;
   18.71 +    SDL_sem *first_run_semaphore = (SDL_sem *) arg;
   18.72 +    ALSA_Device *devices = NULL;
   18.73 +    ALSA_Device *next;
   18.74 +    ALSA_Device *dev;
   18.75 +    Uint32 ticks;
   18.76  
   18.77 -    if (!name || !_desc) {
   18.78 -        return;  /* nothing we can do with this...? */
   18.79 +    while (!SDL_AtomicGet(&ALSA_hotplug_shutdown)) {
   18.80 +        void **hints = NULL;
   18.81 +        if (ALSA_snd_device_name_hint(-1, "pcm", &hints) != -1) {
   18.82 +            ALSA_Device *unseen = devices;
   18.83 +            ALSA_Device *seen = NULL;
   18.84 +            ALSA_Device *prev;
   18.85 +            int i;
   18.86 +
   18.87 +            for (i = 0; hints[i]; i++) {
   18.88 +                char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
   18.89 +                if (!name) {
   18.90 +                    continue;
   18.91 +                }
   18.92 +
   18.93 +                /* only want physical hardware interfaces */
   18.94 +                if (SDL_strncmp(name, "hw:", 3) == 0) {
   18.95 +                    char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
   18.96 +                    const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0);
   18.97 +                    const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);
   18.98 +                    SDL_bool have_output = SDL_FALSE;
   18.99 +                    SDL_bool have_input = SDL_FALSE;
  18.100 +
  18.101 +                    free(ioid);
  18.102 +
  18.103 +                    if (!isoutput && !isinput) {
  18.104 +                        free(name);
  18.105 +                        continue;
  18.106 +                    }
  18.107 +
  18.108 +                    prev = NULL;
  18.109 +                    for (dev = unseen; dev; dev = next) {
  18.110 +                        next = dev->next;
  18.111 +                        if ( (SDL_strcmp(dev->name, name) == 0) && (((isinput) && dev->iscapture) || ((isoutput) && !dev->iscapture)) ) {
  18.112 +                            if (prev) {
  18.113 +                                prev->next = next;
  18.114 +                            } else {
  18.115 +                                unseen = next;
  18.116 +                            }
  18.117 +                            dev->next = seen;
  18.118 +                            seen = dev;
  18.119 +                            if (isinput) have_input = SDL_TRUE;
  18.120 +                            if (isoutput) have_output = SDL_TRUE;
  18.121 +                        } else {
  18.122 +                            prev = dev;
  18.123 +                        }
  18.124 +                    }
  18.125 +
  18.126 +                    if (isinput && !have_input) {
  18.127 +                        add_device(SDL_TRUE, name, hints[i], &seen);
  18.128 +                    }
  18.129 +                    if (isoutput && !have_output) {
  18.130 +                        add_device(SDL_FALSE, name, hints[i], &seen);
  18.131 +                    }
  18.132 +                }
  18.133 +
  18.134 +                free(name);
  18.135 +            }
  18.136 +
  18.137 +            ALSA_snd_device_name_free_hint(hints);
  18.138 +
  18.139 +            devices = seen;   /* now we have a known-good list of attached devices. */
  18.140 +
  18.141 +            /* report anything still in unseen as removed. */
  18.142 +            for (dev = unseen; dev; dev = next) {
  18.143 +                /*printf("ALSA: removing %s device '%s'\n", dev->iscapture ? "capture" : "output", dev->name);*/
  18.144 +                next = dev->next;
  18.145 +                SDL_RemoveAudioDevice(dev->iscapture, dev->name);
  18.146 +                SDL_free(dev->name);
  18.147 +                SDL_free(dev);
  18.148 +            }
  18.149 +        }
  18.150 +
  18.151 +        /* On first run, tell ALSA_DetectDevices() that we have a complete device list so it can return. */
  18.152 +        if (first_run_semaphore) {
  18.153 +            SDL_SemPost(first_run_semaphore);
  18.154 +            first_run_semaphore = NULL;  /* let other thread clean it up. */
  18.155 +        }
  18.156 +
  18.157 +        /* Block awhile before checking again, unless we're told to stop. */
  18.158 +        ticks = SDL_GetTicks() + 5000;
  18.159 +        while (!SDL_AtomicGet(&ALSA_hotplug_shutdown) && !SDL_TICKS_PASSED(SDL_GetTicks(), ticks)) {
  18.160 +            SDL_Delay(100);
  18.161 +        }
  18.162      }
  18.163  
  18.164 -    desc = SDL_strdup(_desc);
  18.165 -    if (!desc) {
  18.166 -        return;  /* oh well, out of memory. Skip it. */
  18.167 +    /* Shutting down! Clean up any data we've gathered. */
  18.168 +    for (dev = devices; dev; dev = next) {
  18.169 +        /*printf("ALSA: at shutdown, removing %s device '%s'\n", dev->iscapture ? "capture" : "output", dev->name);*/
  18.170 +        next = dev->next;
  18.171 +        SDL_free(dev->name);
  18.172 +        SDL_free(dev);
  18.173      }
  18.174  
  18.175 -    /* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output" */
  18.176 -    for (ptr = strchr(desc, '\n'); ptr; ptr = strchr(ptr + 1, '\n')) {
  18.177 -        *ptr = ' ';
  18.178 -    }
  18.179 -
  18.180 -    handle = SDL_strdup(name);
  18.181 -    if (handle != NULL) {
  18.182 -        SDL_AddAudioDevice(iscapture, desc, handle);
  18.183 -    }
  18.184 -
  18.185 -    SDL_free(desc);
  18.186 +    return 0;
  18.187  }
  18.188  
  18.189  static void
  18.190  ALSA_DetectDevices(void)
  18.191  {
  18.192 -    void **hints = NULL;
  18.193 -    int i;
  18.194 -
  18.195 -    /* !!! FIXME: use udev instead. */
  18.196 -    /* We won't deal with disconnects and hotplugs without udev, but at least
  18.197 -       you'll get a reasonable device list at startup. */
  18.198 -#if 1 /*!SDL_USE_LIBUDEV */
  18.199 -    if (ALSA_snd_device_name_hint(-1, "pcm", &hints) == -1) {
  18.200 +    /* Start the device detection thread here, wait for an initial iteration to complete. */
  18.201 +    SDL_sem *semaphore = SDL_CreateSemaphore(0);
  18.202 +    if (!semaphore) {
  18.203          return;  /* oh well. */
  18.204      }
  18.205  
  18.206 -    for (i = 0; hints[i]; i++) {
  18.207 -        char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
  18.208 -        char *desc = ALSA_snd_device_name_get_hint(hints[i], "DESC");
  18.209 -        char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
  18.210 +    SDL_AtomicSet(&ALSA_hotplug_shutdown, 0);
  18.211  
  18.212 -        if ((ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0)) {
  18.213 -            add_device(SDL_FALSE, name, desc);
  18.214 -        }
  18.215 -
  18.216 -        if ((ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0)) {
  18.217 -            add_device(SDL_TRUE, name, desc);
  18.218 -        }
  18.219 -
  18.220 -        free(name);
  18.221 -        free(desc);
  18.222 -        free(ioid);
  18.223 +    ALSA_hotplug_thread = SDL_CreateThread(ALSA_HotplugThread, "SDLHotplugALSA", semaphore);
  18.224 +    if (ALSA_hotplug_thread) {
  18.225 +        SDL_SemWait(semaphore);  /* wait for the first iteration to finish. */
  18.226      }
  18.227  
  18.228 -    ALSA_snd_device_name_free_hint(hints);
  18.229 -#else
  18.230 -#error Fill in udev support here.
  18.231 -#endif
  18.232 +    SDL_DestroySemaphore(semaphore);
  18.233  }
  18.234  
  18.235  static void
  18.236 -ALSA_FreeDeviceHandle(void *handle)
  18.237 +ALSA_Deinitialize(void)
  18.238  {
  18.239 -#if 1 /*!SDL_USE_LIBUDEV*/
  18.240 -    SDL_free(handle);
  18.241 -#else
  18.242 -#error Fill in udev support here.
  18.243 -#endif
  18.244 +    if (ALSA_hotplug_thread != NULL) {
  18.245 +        SDL_AtomicSet(&ALSA_hotplug_shutdown, 1);
  18.246 +        SDL_WaitThread(ALSA_hotplug_thread, NULL);
  18.247 +        ALSA_hotplug_thread = NULL;
  18.248 +    }
  18.249 +
  18.250 +    UnloadALSALibrary();
  18.251  }
  18.252  
  18.253 -
  18.254  static int
  18.255  ALSA_Init(SDL_AudioDriverImpl * impl)
  18.256  {
  18.257 @@ -798,7 +904,6 @@
  18.258      impl->PlayDevice = ALSA_PlayDevice;
  18.259      impl->CloseDevice = ALSA_CloseDevice;
  18.260      impl->Deinitialize = ALSA_Deinitialize;
  18.261 -    impl->FreeDeviceHandle = ALSA_FreeDeviceHandle;
  18.262      impl->CaptureFromDevice = ALSA_CaptureFromDevice;
  18.263      impl->FlushCapture = ALSA_FlushCapture;
  18.264  
    19.1 --- a/src/joystick/SDL_gamecontroller.c	Fri Aug 12 22:50:48 2016 -0400
    19.2 +++ b/src/joystick/SDL_gamecontroller.c	Sun Aug 28 13:36:13 2016 -0400
    19.3 @@ -106,6 +106,35 @@
    19.4  int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state);
    19.5  
    19.6  /*
    19.7 + * If there is an existing add event in the queue, it needs to be modified
    19.8 + * to have the right value for which, because the number of controllers in
    19.9 + * the system is now one less.
   19.10 + */
   19.11 +static void UpdateEventsForDeviceRemoval()
   19.12 +{
   19.13 +    int i, num_events;
   19.14 +    SDL_Event *events;
   19.15 +
   19.16 +    num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
   19.17 +    if (num_events <= 0) {
   19.18 +        return;
   19.19 +    }
   19.20 +
   19.21 +    events = SDL_stack_alloc(SDL_Event, num_events);
   19.22 +    if (!events) {
   19.23 +        return;
   19.24 +    }
   19.25 +
   19.26 +    num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
   19.27 +    for (i = 0; i < num_events; ++i) {
   19.28 +        --events[i].cdevice.which;
   19.29 +    }
   19.30 +    SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
   19.31 +
   19.32 +    SDL_stack_free(events);
   19.33 +}
   19.34 +
   19.35 +/*
   19.36   * Event filter to fire controller events from joystick ones
   19.37   */
   19.38  int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
   19.39 @@ -223,9 +252,12 @@
   19.40              while (controllerlist) {
   19.41                  if (controllerlist->joystick->instance_id == event->jdevice.which) {
   19.42                      SDL_Event deviceevent;
   19.43 +
   19.44                      deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
   19.45                      deviceevent.cdevice.which = event->jdevice.which;
   19.46                      SDL_PushEvent(&deviceevent);
   19.47 +
   19.48 +                    UpdateEventsForDeviceRemoval();
   19.49                      break;
   19.50                  }
   19.51                  controllerlist = controllerlist->next;
    20.1 --- a/src/joystick/SDL_joystick.c	Fri Aug 12 22:50:48 2016 -0400
    20.2 +++ b/src/joystick/SDL_joystick.c	Sun Aug 28 13:36:13 2016 -0400
    20.3 @@ -497,6 +497,71 @@
    20.4  
    20.5  /* These are global for SDL_sysjoystick.c and SDL_events.c */
    20.6  
    20.7 +void SDL_PrivateJoystickAdded(int device_index)
    20.8 +{
    20.9 +#if !SDL_EVENTS_DISABLED
   20.10 +    SDL_Event event;
   20.11 +
   20.12 +    event.type = SDL_JOYDEVICEADDED;
   20.13 +
   20.14 +    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   20.15 +        event.jdevice.which = device_index;
   20.16 +        if ( (SDL_EventOK == NULL) ||
   20.17 +             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
   20.18 +            SDL_PushEvent(&event);
   20.19 +        }
   20.20 +    }
   20.21 +#endif /* !SDL_EVENTS_DISABLED */
   20.22 +}
   20.23 +
   20.24 +/*
   20.25 + * If there is an existing add event in the queue, it needs to be modified
   20.26 + * to have the right value for which, because the number of controllers in
   20.27 + * the system is now one less.
   20.28 + */
   20.29 +static void UpdateEventsForDeviceRemoval()
   20.30 +{
   20.31 +    int i, num_events;
   20.32 +    SDL_Event *events;
   20.33 +
   20.34 +    num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
   20.35 +    if (num_events <= 0) {
   20.36 +        return;
   20.37 +    }
   20.38 +
   20.39 +    events = SDL_stack_alloc(SDL_Event, num_events);
   20.40 +    if (!events) {
   20.41 +        return;
   20.42 +    }
   20.43 +
   20.44 +    num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
   20.45 +    for (i = 0; i < num_events; ++i) {
   20.46 +        --events[i].jdevice.which;
   20.47 +    }
   20.48 +    SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
   20.49 +
   20.50 +    SDL_stack_free(events);
   20.51 +}
   20.52 +
   20.53 +void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
   20.54 +{
   20.55 +#if !SDL_EVENTS_DISABLED
   20.56 +    SDL_Event event;
   20.57 +
   20.58 +    event.type = SDL_JOYDEVICEREMOVED;
   20.59 +
   20.60 +    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   20.61 +        event.jdevice.which = device_instance;
   20.62 +        if ( (SDL_EventOK == NULL) ||
   20.63 +             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
   20.64 +            SDL_PushEvent(&event);
   20.65 +        }
   20.66 +    }
   20.67 +
   20.68 +    UpdateEventsForDeviceRemoval();
   20.69 +#endif /* !SDL_EVENTS_DISABLED */
   20.70 +}
   20.71 +
   20.72  int
   20.73  SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
   20.74  {
    21.1 --- a/src/joystick/SDL_joystick_c.h	Fri Aug 12 22:50:48 2016 -0400
    21.2 +++ b/src/joystick/SDL_joystick_c.h	Sun Aug 28 13:36:13 2016 -0400
    21.3 @@ -33,6 +33,8 @@
    21.4  
    21.5  
    21.6  /* Internal event queueing functions */
    21.7 +extern void SDL_PrivateJoystickAdded(int device_index);
    21.8 +extern void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance);
    21.9  extern int SDL_PrivateJoystickAxis(SDL_Joystick * joystick,
   21.10                                     Uint8 axis, Sint16 value);
   21.11  extern int SDL_PrivateJoystickBall(SDL_Joystick * joystick,
   21.12 @@ -41,8 +43,8 @@
   21.13                                    Uint8 hat, Uint8 value);
   21.14  extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
   21.15                                       Uint8 button, Uint8 state);
   21.16 -extern void SDL_PrivateJoystickBatteryLevel( SDL_Joystick * joystick,
   21.17 -    SDL_JoystickPowerLevel ePowerLevel );
   21.18 +extern void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick,
   21.19 +                                            SDL_JoystickPowerLevel ePowerLevel);
   21.20  
   21.21  /* Internal sanity checking functions */
   21.22  extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick);
    22.1 --- a/src/joystick/android/SDL_sysjoystick.c	Fri Aug 12 22:50:48 2016 -0400
    22.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Sun Aug 28 13:36:13 2016 -0400
    22.3 @@ -27,10 +27,6 @@
    22.4  #include "SDL_error.h"
    22.5  #include "SDL_events.h"
    22.6  
    22.7 -#if !SDL_EVENTS_DISABLED
    22.8 -#include "../../events/SDL_events_c.h"
    22.9 -#endif
   22.10 -
   22.11  #include "SDL_joystick.h"
   22.12  #include "SDL_hints.h"
   22.13  #include "SDL_assert.h"
   22.14 @@ -252,9 +248,6 @@
   22.15  {
   22.16      SDL_JoystickGUID guid;
   22.17      SDL_joylist_item *item;
   22.18 -#if !SDL_EVENTS_DISABLED
   22.19 -    SDL_Event event;
   22.20 -#endif
   22.21      
   22.22      if(JoystickByDeviceId(device_id) != NULL || name == NULL) {
   22.23          return -1;
   22.24 @@ -299,17 +292,7 @@
   22.25      /* Need to increment the joystick count before we post the event */
   22.26      ++numjoysticks;
   22.27  
   22.28 -#if !SDL_EVENTS_DISABLED
   22.29 -    event.type = SDL_JOYDEVICEADDED;
   22.30 -
   22.31 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   22.32 -        event.jdevice.which = (numjoysticks - 1);
   22.33 -        if ( (SDL_EventOK == NULL) ||
   22.34 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
   22.35 -            SDL_PushEvent(&event);
   22.36 -        }
   22.37 -    }
   22.38 -#endif /* !SDL_EVENTS_DISABLED */
   22.39 +    SDL_PrivateJoystickAdded(numjoysticks - 1);
   22.40  
   22.41  #ifdef DEBUG_JOYSTICK
   22.42      SDL_Log("Added joystick %s with device_id %d", name, device_id);
   22.43 @@ -323,9 +306,6 @@
   22.44  {
   22.45      SDL_joylist_item *item = SDL_joylist;
   22.46      SDL_joylist_item *prev = NULL;
   22.47 -#if !SDL_EVENTS_DISABLED
   22.48 -    SDL_Event event;
   22.49 -#endif
   22.50      
   22.51      /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */
   22.52      while (item != NULL) {
   22.53 @@ -357,17 +337,7 @@
   22.54      /* Need to decrement the joystick count before we post the event */
   22.55      --numjoysticks;
   22.56  
   22.57 -#if !SDL_EVENTS_DISABLED
   22.58 -    event.type = SDL_JOYDEVICEREMOVED;
   22.59 -
   22.60 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   22.61 -        event.jdevice.which = item->device_instance;
   22.62 -        if ( (SDL_EventOK == NULL) ||
   22.63 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
   22.64 -            SDL_PushEvent(&event);
   22.65 -        }
   22.66 -    }
   22.67 -#endif /* !SDL_EVENTS_DISABLED */
   22.68 +    SDL_PrivateJoystickRemoved(item->device_instance);
   22.69  
   22.70  #ifdef DEBUG_JOYSTICK
   22.71      SDL_Log("Removed joystick with device_id %d", device_id);
   22.72 @@ -538,6 +508,10 @@
   22.73  void
   22.74  SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   22.75  {
   22.76 +    SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
   22.77 +    if (item) {
   22.78 +        item->joystick = NULL;
   22.79 +    }
   22.80  }
   22.81  
   22.82  /* Function to perform any system-specific joystick related cleanup */
    23.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Fri Aug 12 22:50:48 2016 -0400
    23.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Sun Aug 28 13:36:13 2016 -0400
    23.3 @@ -34,9 +34,6 @@
    23.4  #include "SDL_sysjoystick_c.h"
    23.5  #include "SDL_events.h"
    23.6  #include "../../haptic/darwin/SDL_syshaptic_c.h"    /* For haptic hot plugging */
    23.7 -#if !SDL_EVENTS_DISABLED
    23.8 -#include "../../events/SDL_events_c.h"
    23.9 -#endif
   23.10  
   23.11  #define SDL_JOYSTICK_RUNLOOP_MODE CFSTR("SDLJoystick")
   23.12  
   23.13 @@ -154,21 +151,7 @@
   23.14      MacHaptic_MaybeRemoveDevice(device->ffservice);
   23.15  #endif
   23.16  
   23.17 -/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceRemoved()? */
   23.18 -#if !SDL_EVENTS_DISABLED
   23.19 -    {
   23.20 -        SDL_Event event;
   23.21 -        event.type = SDL_JOYDEVICEREMOVED;
   23.22 -
   23.23 -        if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   23.24 -            event.jdevice.which = device->instance_id;
   23.25 -            if ((SDL_EventOK == NULL)
   23.26 -                || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   23.27 -                SDL_PushEvent(&event);
   23.28 -            }
   23.29 -        }
   23.30 -    }
   23.31 -#endif /* !SDL_EVENTS_DISABLED */
   23.32 +    SDL_PrivateJoystickRemoved(device->instance_id);
   23.33  }
   23.34  
   23.35  
   23.36 @@ -249,6 +232,7 @@
   23.37                              case kHIDUsage_GD_DPadLeft:
   23.38                              case kHIDUsage_GD_Start:
   23.39                              case kHIDUsage_GD_Select:
   23.40 +                            case kHIDUsage_GD_SystemMainMenu:
   23.41                                  if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
   23.42                                      element = (recElement *) SDL_calloc(1, sizeof (recElement));
   23.43                                      if (element) {
   23.44 @@ -475,21 +459,7 @@
   23.45          ++device_index;  /* bump by one since we counted by pNext. */
   23.46      }
   23.47  
   23.48 -/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceAdded()? */
   23.49 -#if !SDL_EVENTS_DISABLED
   23.50 -    {
   23.51 -        SDL_Event event;
   23.52 -        event.type = SDL_JOYDEVICEADDED;
   23.53 -
   23.54 -        if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   23.55 -            event.jdevice.which = device_index;
   23.56 -            if ((SDL_EventOK == NULL)
   23.57 -                || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   23.58 -                SDL_PushEvent(&event);
   23.59 -            }
   23.60 -        }
   23.61 -    }
   23.62 -#endif /* !SDL_EVENTS_DISABLED */
   23.63 +    SDL_PrivateJoystickAdded(device_index);
   23.64  }
   23.65  
   23.66  static SDL_bool
    24.1 --- a/src/joystick/emscripten/SDL_sysjoystick.c	Fri Aug 12 22:50:48 2016 -0400
    24.2 +++ b/src/joystick/emscripten/SDL_sysjoystick.c	Sun Aug 28 13:36:13 2016 -0400
    24.3 @@ -27,10 +27,6 @@
    24.4  #include "SDL_error.h"
    24.5  #include "SDL_events.h"
    24.6  
    24.7 -#if !SDL_EVENTS_DISABLED
    24.8 -#include "../../events/SDL_events_c.h"
    24.9 -#endif
   24.10 -
   24.11  #include "SDL_joystick.h"
   24.12  #include "SDL_hints.h"
   24.13  #include "SDL_assert.h"
   24.14 @@ -57,10 +53,6 @@
   24.15        return 1;
   24.16      }
   24.17  
   24.18 -#if !SDL_EVENTS_DISABLED
   24.19 -    SDL_Event event;
   24.20 -#endif
   24.21 -
   24.22      item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
   24.23      if (item == NULL) {
   24.24          return 1;
   24.25 @@ -105,20 +97,12 @@
   24.26      }
   24.27  
   24.28      ++numjoysticks;
   24.29 +
   24.30 +    SDL_PrivateJoystickAdded(numjoysticks - 1);
   24.31 +
   24.32  #ifdef DEBUG_JOYSTICK
   24.33      SDL_Log("Number of joysticks is %d", numjoysticks);
   24.34  #endif
   24.35 -#if !SDL_EVENTS_DISABLED
   24.36 -    event.type = SDL_JOYDEVICEADDED;
   24.37 -
   24.38 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   24.39 -        event.jdevice.which = numjoysticks - 1;
   24.40 -        if ( (SDL_EventOK == NULL) ||
   24.41 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
   24.42 -            SDL_PushEvent(&event);
   24.43 -        }
   24.44 -    }
   24.45 -#endif /* !SDL_EVENTS_DISABLED */
   24.46  
   24.47  #ifdef DEBUG_JOYSTICK
   24.48      SDL_Log("Added joystick with index %d", item->index);
   24.49 @@ -132,9 +116,6 @@
   24.50  {
   24.51      SDL_joylist_item *item = SDL_joylist;
   24.52      SDL_joylist_item *prev = NULL;
   24.53 -#if !SDL_EVENTS_DISABLED
   24.54 -    SDL_Event event;
   24.55 -#endif
   24.56  
   24.57      while (item != NULL) {
   24.58          if (item->index == gamepadEvent->index) {
   24.59 @@ -165,17 +146,7 @@
   24.60      /* Need to decrement the joystick count before we post the event */
   24.61      --numjoysticks;
   24.62  
   24.63 -#if !SDL_EVENTS_DISABLED
   24.64 -    event.type = SDL_JOYDEVICEREMOVED;
   24.65 -
   24.66 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   24.67 -        event.jdevice.which = item->device_instance;
   24.68 -        if ( (SDL_EventOK == NULL) ||
   24.69 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
   24.70 -            SDL_PushEvent(&event);
   24.71 -        }
   24.72 -    }
   24.73 -#endif /* !SDL_EVENTS_DISABLED */
   24.74 +	SDL_PrivateJoystickRemoved(item->device_instance);
   24.75  
   24.76  #ifdef DEBUG_JOYSTICK
   24.77      SDL_Log("Removed joystick with id %d", item->device_instance);
   24.78 @@ -377,6 +348,10 @@
   24.79  void
   24.80  SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   24.81  {
   24.82 +    SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
   24.83 +    if (item) {
   24.84 +        item->joystick = NULL;
   24.85 +    }
   24.86  }
   24.87  
   24.88  /* Function to perform any system-specific joystick related cleanup */
    25.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Fri Aug 12 22:50:48 2016 -0400
    25.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Sun Aug 28 13:36:13 2016 -0400
    25.3 @@ -26,16 +26,13 @@
    25.4  /* needed for SDL_IPHONE_MAX_GFORCE macro */
    25.5  #include "SDL_config_iphoneos.h"
    25.6  
    25.7 +#include "SDL_events.h"
    25.8  #include "SDL_joystick.h"
    25.9  #include "SDL_hints.h"
   25.10  #include "SDL_stdinc.h"
   25.11  #include "../SDL_sysjoystick.h"
   25.12  #include "../SDL_joystick_c.h"
   25.13  
   25.14 -#if !SDL_EVENTS_DISABLED
   25.15 -#include "../../events/SDL_events_c.h"
   25.16 -#endif
   25.17 -
   25.18  #import <CoreMotion/CoreMotion.h>
   25.19  
   25.20  #ifdef SDL_JOYSTICK_MFI
   25.21 @@ -127,9 +124,6 @@
   25.22  SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer)
   25.23  {
   25.24      SDL_JoystickDeviceItem *device = deviceList;
   25.25 -#if !SDL_EVENTS_DISABLED
   25.26 -    SDL_Event event;
   25.27 -#endif
   25.28  
   25.29      while (device != NULL) {
   25.30          if (device->controller == controller) {
   25.31 @@ -172,17 +166,7 @@
   25.32  
   25.33      ++numjoysticks;
   25.34  
   25.35 -#if !SDL_EVENTS_DISABLED
   25.36 -    event.type = SDL_JOYDEVICEADDED;
   25.37 -
   25.38 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   25.39 -        event.jdevice.which = numjoysticks - 1;
   25.40 -        if ((SDL_EventOK == NULL) ||
   25.41 -            (*SDL_EventOK)(SDL_EventOKParam, &event)) {
   25.42 -            SDL_PushEvent(&event);
   25.43 -        }
   25.44 -    }
   25.45 -#endif /* !SDL_EVENTS_DISABLED */
   25.46 +    SDL_PrivateJoystickAdded(numjoysticks - 1);
   25.47  }
   25.48  
   25.49  static SDL_JoystickDeviceItem *
   25.50 @@ -191,9 +175,6 @@
   25.51      SDL_JoystickDeviceItem *prev = NULL;
   25.52      SDL_JoystickDeviceItem *next = NULL;
   25.53      SDL_JoystickDeviceItem *item = deviceList;
   25.54 -#if !SDL_EVENTS_DISABLED
   25.55 -    SDL_Event event;
   25.56 -#endif
   25.57  
   25.58      if (device == NULL) {
   25.59          return NULL;
   25.60 @@ -234,17 +215,7 @@
   25.61  
   25.62      --numjoysticks;
   25.63  
   25.64 -#if !SDL_EVENTS_DISABLED
   25.65 -    event.type = SDL_JOYDEVICEREMOVED;
   25.66 -
   25.67 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   25.68 -        event.jdevice.which = device->instance_id;
   25.69 -        if ((SDL_EventOK == NULL) ||
   25.70 -            (*SDL_EventOK)(SDL_EventOKParam, &event)) {
   25.71 -            SDL_PushEvent(&event);
   25.72 -        }
   25.73 -    }
   25.74 -#endif /* !SDL_EVENTS_DISABLED */
   25.75 +	SDL_PrivateJoystickRemoved(device->instance_id);
   25.76  
   25.77      SDL_free(device->name);
   25.78      SDL_free(device);
    26.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Fri Aug 12 22:50:48 2016 -0400
    26.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Sun Aug 28 13:36:13 2016 -0400
    26.3 @@ -42,11 +42,6 @@
    26.4  #include "../SDL_joystick_c.h"
    26.5  #include "SDL_sysjoystick_c.h"
    26.6  
    26.7 -/* !!! FIXME: move this somewhere else. */
    26.8 -#if !SDL_EVENTS_DISABLED
    26.9 -#include "../../events/SDL_events_c.h"
   26.10 -#endif
   26.11 -
   26.12  /* This isn't defined in older Linux kernel headers */
   26.13  #ifndef SYN_DROPPED
   26.14  #define SYN_DROPPED 3
   26.15 @@ -176,9 +171,6 @@
   26.16      char namebuf[128];
   26.17      SDL_JoystickGUID guid;
   26.18      SDL_joylist_item *item;
   26.19 -#if !SDL_EVENTS_DISABLED
   26.20 -    SDL_Event event;
   26.21 -#endif
   26.22  
   26.23      if (path == NULL) {
   26.24          return -1;
   26.25 @@ -239,18 +231,7 @@
   26.26      /* Need to increment the joystick count before we post the event */
   26.27      ++numjoysticks;
   26.28  
   26.29 -    /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
   26.30 -#if !SDL_EVENTS_DISABLED
   26.31 -    event.type = SDL_JOYDEVICEADDED;
   26.32 -
   26.33 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   26.34 -        event.jdevice.which = (numjoysticks - 1);
   26.35 -        if ( (SDL_EventOK == NULL) ||
   26.36 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
   26.37 -            SDL_PushEvent(&event);
   26.38 -        }
   26.39 -    }
   26.40 -#endif /* !SDL_EVENTS_DISABLED */
   26.41 +    SDL_PrivateJoystickAdded(numjoysticks - 1);
   26.42  
   26.43      return numjoysticks;
   26.44  }
   26.45 @@ -262,9 +243,6 @@
   26.46  {
   26.47      SDL_joylist_item *item;
   26.48      SDL_joylist_item *prev = NULL;
   26.49 -#if !SDL_EVENTS_DISABLED
   26.50 -    SDL_Event event;
   26.51 -#endif
   26.52  
   26.53      if (path == NULL) {
   26.54          return -1;
   26.55 @@ -290,18 +268,7 @@
   26.56              /* Need to decrement the joystick count before we post the event */
   26.57              --numjoysticks;
   26.58  
   26.59 -            /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
   26.60 -#if !SDL_EVENTS_DISABLED
   26.61 -            event.type = SDL_JOYDEVICEREMOVED;
   26.62 -
   26.63 -            if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   26.64 -                event.jdevice.which = item->device_instance;
   26.65 -                if ( (SDL_EventOK == NULL) ||
   26.66 -                     (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
   26.67 -                    SDL_PushEvent(&event);
   26.68 -                }
   26.69 -            }
   26.70 -#endif /* !SDL_EVENTS_DISABLED */
   26.71 +            SDL_PrivateJoystickRemoved(item->device_instance);
   26.72  
   26.73              SDL_free(item->path);
   26.74              SDL_free(item->name);
    27.1 --- a/src/joystick/windows/SDL_dinputjoystick.c	Fri Aug 12 22:50:48 2016 -0400
    27.2 +++ b/src/joystick/windows/SDL_dinputjoystick.c	Sun Aug 28 13:36:13 2016 -0400
    27.3 @@ -240,11 +240,23 @@
    27.4      static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
    27.5      static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
    27.6      static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
    27.7 +    static GUID IID_XOneWiredGamepad = { MAKELONG(0x045E, 0x02FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
    27.8 +    static GUID IID_XOneWirelessGamepad = { MAKELONG(0x045E, 0x02DD), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
    27.9 +    static GUID IID_XOneNewWirelessGamepad = { MAKELONG(0x045E, 0x02D1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
   27.10 +    static GUID IID_XOneSWirelessGamepad = { MAKELONG(0x045E, 0x02EA), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
   27.11 +    static GUID IID_XOneSBluetoothGamepad = { MAKELONG(0x045E, 0x02E0), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
   27.12 +    static GUID IID_XOneEliteWirelessGamepad = { MAKELONG(0x045E, 0x02E3), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
   27.13  
   27.14      static const GUID *s_XInputProductGUID[] = {
   27.15          &IID_ValveStreamingGamepad,
   27.16 -        &IID_X360WiredGamepad,   /* Microsoft's wired X360 controller for Windows. */
   27.17 -        &IID_X360WirelessGamepad /* Microsoft's wireless X360 controller for Windows. */
   27.18 +        &IID_X360WiredGamepad,         /* Microsoft's wired X360 controller for Windows. */
   27.19 +        &IID_X360WirelessGamepad,      /* Microsoft's wireless X360 controller for Windows. */
   27.20 +        &IID_XOneWiredGamepad,         /* Microsoft's wired Xbox One controller for Windows. */
   27.21 +        &IID_XOneWirelessGamepad,      /* Microsoft's wireless Xbox One controller for Windows. */
   27.22 +        &IID_XOneNewWirelessGamepad,   /* Microsoft's updated wireless Xbox One controller (w/ 3.5 mm jack) for Windows. */
   27.23 +        &IID_XOneSWirelessGamepad,     /* Microsoft's wireless Xbox One S controller for Windows. */
   27.24 +        &IID_XOneSBluetoothGamepad,    /* Microsoft's Bluetooth Xbox One S controller for Windows. */
   27.25 +        &IID_XOneEliteWirelessGamepad  /* Microsoft's wireless Xbox One Elite controller for Windows. */
   27.26      };
   27.27  
   27.28      size_t iDevice;
    28.1 --- a/src/joystick/windows/SDL_windowsjoystick.c	Fri Aug 12 22:50:48 2016 -0400
    28.2 +++ b/src/joystick/windows/SDL_windowsjoystick.c	Sun Aug 28 13:36:13 2016 -0400
    28.3 @@ -42,9 +42,6 @@
    28.4  #include "SDL_joystick.h"
    28.5  #include "../SDL_sysjoystick.h"
    28.6  #include "../../thread/SDL_systhread.h"
    28.7 -#if !SDL_EVENTS_DISABLED
    28.8 -#include "../../events/SDL_events_c.h"
    28.9 -#endif
   28.10  #include "../../core/windows/SDL_windows.h"
   28.11  #if !defined(__WINRT__)
   28.12  #include <dbt.h>
   28.13 @@ -327,9 +324,6 @@
   28.14  SDL_SYS_JoystickDetect()
   28.15  {
   28.16      JoyStick_DeviceData *pCurList = NULL;
   28.17 -#if !SDL_EVENTS_DISABLED
   28.18 -    SDL_Event event;
   28.19 -#endif
   28.20  
   28.21      /* only enum the devices if the joystick thread told us something changed */
   28.22      if (!s_bDeviceAdded && !s_bDeviceRemoved) {
   28.23 @@ -361,17 +355,7 @@
   28.24              SDL_DINPUT_MaybeRemoveDevice(&pCurList->dxdevice);
   28.25          }
   28.26  
   28.27 -#if !SDL_EVENTS_DISABLED
   28.28 -        SDL_zero(event);
   28.29 -        event.type = SDL_JOYDEVICEREMOVED;
   28.30 -
   28.31 -        if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   28.32 -            event.jdevice.which = pCurList->nInstanceID;
   28.33 -            if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   28.34 -                SDL_PushEvent(&event);
   28.35 -            }
   28.36 -        }
   28.37 -#endif /* !SDL_EVENTS_DISABLED */
   28.38 +        SDL_PrivateJoystickRemoved(pCurList->nInstanceID);
   28.39  
   28.40          pListNext = pCurList->pNext;
   28.41          SDL_free(pCurList->joystickname);
   28.42 @@ -392,17 +376,8 @@
   28.43                      SDL_DINPUT_MaybeAddDevice(&pNewJoystick->dxdevice);
   28.44                  }
   28.45  
   28.46 -#if !SDL_EVENTS_DISABLED
   28.47 -                SDL_zero(event);
   28.48 -                event.type = SDL_JOYDEVICEADDED;
   28.49 +                SDL_PrivateJoystickAdded(device_index);
   28.50  
   28.51 -                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   28.52 -                    event.jdevice.which = device_index;
   28.53 -                    if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   28.54 -                        SDL_PushEvent(&event);
   28.55 -                    }
   28.56 -                }
   28.57 -#endif /* !SDL_EVENTS_DISABLED */
   28.58                  pNewJoystick->send_add_event = SDL_FALSE;
   28.59              }
   28.60              device_index++;
    29.1 --- a/src/video/psp/SDL_pspvideo.c	Fri Aug 12 22:50:48 2016 -0400
    29.2 +++ b/src/video/psp/SDL_pspvideo.c	Sun Aug 28 13:36:13 2016 -0400
    29.3 @@ -92,6 +92,7 @@
    29.4      if (gldata == NULL) {
    29.5          SDL_OutOfMemory();
    29.6          SDL_free(device);
    29.7 +        SDL_free(phdata);
    29.8          return NULL;
    29.9      }
   29.10      device->gl_data = gldata;
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/src/video/winrt/SDL_winrtgamebar.cpp	Sun Aug 28 13:36:13 2016 -0400
    30.3 @@ -0,0 +1,196 @@
    30.4 +/*
    30.5 +  Simple DirectMedia Layer
    30.6 +  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
    30.7 +
    30.8 +  This software is provided 'as-is', without any express or implied
    30.9 +  warranty.  In no event will the authors be held liable for any damages
   30.10 +  arising from the use of this software.
   30.11 +
   30.12 +  Permission is granted to anyone to use this software for any purpose,
   30.13 +  including commercial applications, and to alter it and redistribute it
   30.14 +  freely, subject to the following restrictions:
   30.15 +
   30.16 +  1. The origin of this software must not be misrepresented; you must not
   30.17 +     claim that you wrote the original software. If you use this software
   30.18 +     in a product, an acknowledgment in the product documentation would be
   30.19 +     appreciated but is not required.
   30.20 +  2. Altered source versions must be plainly marked as such, and must not be
   30.21 +     misrepresented as being the original software.
   30.22 +  3. This notice may not be removed or altered from any source distribution.
   30.23 +*/
   30.24 +#include "../../SDL_internal.h"
   30.25 +
   30.26 +#if SDL_VIDEO_DRIVER_WINRT
   30.27 +
   30.28 +/* Windows includes */
   30.29 +#include <roapi.h>
   30.30 +#include <windows.foundation.h>
   30.31 +#include <EventToken.h>
   30.32 +
   30.33 +
   30.34 +/* SDL includes */
   30.35 +extern "C" {
   30.36 +#include "SDL_mouse.h"
   30.37 +#include "../SDL_sysvideo.h"
   30.38 +}
   30.39 +#include "SDL_winrtvideo_cpp.h"
   30.40 +
   30.41 +
   30.42 +/* Game Bar events can come in off the main thread.  Use the following
   30.43 +   WinRT CoreDispatcher to deal with them on SDL's thread.
   30.44 +*/
   30.45 +static Platform::WeakReference WINRT_MainThreadDispatcher;
   30.46 +
   30.47 +
   30.48 +/* Win10's initial SDK (the 10.0.10240.0 release) does not include references
   30.49 +   to Game Bar APIs, as the Game Bar was released via Win10 10.0.10586.0.
   30.50 +
   30.51 +   Declare its WinRT/COM interface here, to allow compilation with earlier
   30.52 +   Windows SDKs.
   30.53 +*/
   30.54 +MIDL_INTERFACE("1DB9A292-CC78-4173-BE45-B61E67283EA7")
   30.55 +IGameBarStatics_ : public IInspectable
   30.56 +{
   30.57 +public:
   30.58 +    virtual HRESULT STDMETHODCALLTYPE add_VisibilityChanged( 
   30.59 +        __FIEventHandler_1_IInspectable *handler,
   30.60 +        Windows::Foundation::EventRegistrationToken *token) = 0;
   30.61 +    
   30.62 +    virtual HRESULT STDMETHODCALLTYPE remove_VisibilityChanged( 
   30.63 +        Windows::Foundation::EventRegistrationToken token) = 0;
   30.64 +    
   30.65 +    virtual HRESULT STDMETHODCALLTYPE add_IsInputRedirectedChanged( 
   30.66 +        __FIEventHandler_1_IInspectable *handler,
   30.67 +        Windows::Foundation::EventRegistrationToken *token) = 0;
   30.68 +    
   30.69 +    virtual HRESULT STDMETHODCALLTYPE remove_IsInputRedirectedChanged( 
   30.70 +        Windows::Foundation::EventRegistrationToken token) = 0;
   30.71 +    
   30.72 +    virtual HRESULT STDMETHODCALLTYPE get_Visible( 
   30.73 +        boolean *value) = 0;
   30.74 +    
   30.75 +    virtual HRESULT STDMETHODCALLTYPE get_IsInputRedirected( 
   30.76 +        boolean *value) = 0;
   30.77 +};
   30.78 +
   30.79 +/* Declare the game bar's COM GUID */
   30.80 +static GUID IID_IGameBarStatics_ = { MAKELONG(0xA292, 0x1DB9), 0xCC78, 0x4173, { 0xBE, 0x45, 0xB6, 0x1E, 0x67, 0x28, 0x3E, 0xA7 } };
   30.81 +
   30.82 +/* Retrieves a pointer to the game bar, or NULL if it is not available.
   30.83 +   If a pointer is returned, it's ->Release() method must be called
   30.84 +   after the caller has finished using it.
   30.85 +*/
   30.86 +static IGameBarStatics_ *
   30.87 +WINRT_GetGameBar()
   30.88 +{
   30.89 +    wchar_t *wClassName = L"Windows.Gaming.UI.GameBar";
   30.90 +    HSTRING hClassName;
   30.91 +    IActivationFactory *pActivationFactory = NULL;
   30.92 +    IGameBarStatics_ *pGameBar = NULL;
   30.93 +    HRESULT hr;
   30.94 +
   30.95 +    hr = ::WindowsCreateString(wClassName, (UINT32)wcslen(wClassName), &hClassName);
   30.96 +    if (FAILED(hr)) {
   30.97 +        goto done;
   30.98 +    }
   30.99 +
  30.100 +    hr = Windows::Foundation::GetActivationFactory(hClassName, &pActivationFactory);
  30.101 +    if (FAILED(hr)) {
  30.102 +        goto done;
  30.103 +    }
  30.104 +
  30.105 +    pActivationFactory->QueryInterface(IID_IGameBarStatics_, (void **) &pGameBar);
  30.106 +
  30.107 +done:
  30.108 +    if (pActivationFactory) {
  30.109 +        pActivationFactory->Release();
  30.110 +    }
  30.111 +    if (hClassName) {
  30.112 +        ::WindowsDeleteString(hClassName);
  30.113 +    }
  30.114 +    return pGameBar;
  30.115 +}
  30.116 +
  30.117 +static void
  30.118 +WINRT_HandleGameBarIsInputRedirected_MainThread()
  30.119 +{
  30.120 +    IGameBarStatics_ *gameBar;
  30.121 +    boolean isInputRedirected = 0;
  30.122 +    if (!WINRT_MainThreadDispatcher) {
  30.123 +        /* The game bar event handler has been deregistered! */
  30.124 +        return;
  30.125 +    }
  30.126 +    gameBar = WINRT_GetGameBar();
  30.127 +    if (!gameBar) {
  30.128 +        /* Shouldn't happen, but just in case... */
  30.129 +        return;
  30.130 +    }
  30.131 +    if (SUCCEEDED(gameBar->get_IsInputRedirected(&isInputRedirected))) {
  30.132 +        if ( ! isInputRedirected) {
  30.133 +            /* Input-control is now back to the SDL app. Restore the cursor,
  30.134 +               in case Windows does not (it does not in either Win10
  30.135 +               10.0.10240.0 or 10.0.10586.0, maybe later version(s) too.
  30.136 +            */
  30.137 +            SDL_Cursor *cursor = SDL_GetCursor();
  30.138 +            SDL_SetCursor(cursor);
  30.139 +        }
  30.140 +    }
  30.141 +    gameBar->Release();
  30.142 +}
  30.143 +
  30.144 +static void
  30.145 +WINRT_HandleGameBarIsInputRedirected_NonMainThread(Platform::Object ^ o1, Platform::Object ^o2)
  30.146 +{
  30.147 +    Windows::UI::Core::CoreDispatcher ^dispatcher = WINRT_MainThreadDispatcher.Resolve<Windows::UI::Core::CoreDispatcher>();
  30.148 +    if (dispatcher) {
  30.149 +        dispatcher->RunAsync(
  30.150 +            Windows::UI::Core::CoreDispatcherPriority::Normal,
  30.151 +            ref new Windows::UI::Core::DispatchedHandler(&WINRT_HandleGameBarIsInputRedirected_MainThread));
  30.152 +    }
  30.153 +}
  30.154 +
  30.155 +void
  30.156 +WINRT_InitGameBar(_THIS)
  30.157 +{
  30.158 +    SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata;
  30.159 +    IGameBarStatics_ *gameBar = WINRT_GetGameBar();
  30.160 +    if (gameBar) {
  30.161 +        /* GameBar.IsInputRedirected events can come in via something other than
  30.162 +           the main/SDL thread.
  30.163 +
  30.164 +           Get a WinRT 'CoreDispatcher' that can be used to call back into the
  30.165 +           SDL thread.
  30.166 +        */
  30.167 +        WINRT_MainThreadDispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
  30.168 +        Windows::Foundation::EventHandler<Platform::Object ^> ^handler = \
  30.169 +            ref new Windows::Foundation::EventHandler<Platform::Object ^>(&WINRT_HandleGameBarIsInputRedirected_NonMainThread);
  30.170 +        __FIEventHandler_1_IInspectable * pHandler = reinterpret_cast<__FIEventHandler_1_IInspectable *>(handler);
  30.171 +        gameBar->add_IsInputRedirectedChanged(pHandler, &driverdata->gameBarIsInputRedirectedToken);
  30.172 +        gameBar->Release();
  30.173 +    }
  30.174 +}
  30.175 +
  30.176 +void
  30.177 +WINRT_QuitGameBar(_THIS)
  30.178 +{
  30.179 +    SDL_VideoData *driverdata;
  30.180 +    IGameBarStatics_ *gameBar;
  30.181 +    if (!_this || !_this->driverdata) {
  30.182 +        return;
  30.183 +    }
  30.184 +    gameBar = WINRT_GetGameBar();
  30.185 +    if (!gameBar) {
  30.186 +        return;
  30.187 +    }
  30.188 +    driverdata = (SDL_VideoData *)_this->driverdata;
  30.189 +    if (driverdata->gameBarIsInputRedirectedToken.Value) {
  30.190 +        gameBar->remove_IsInputRedirectedChanged(driverdata->gameBarIsInputRedirectedToken);
  30.191 +        driverdata->gameBarIsInputRedirectedToken.Value = 0;
  30.192 +    }
  30.193 +    WINRT_MainThreadDispatcher = nullptr;
  30.194 +    gameBar->Release();
  30.195 +}
  30.196 +
  30.197 +#endif /* SDL_VIDEO_DRIVER_WINRT */
  30.198 +
  30.199 +/* vi: set ts=4 sw=4 expandtab: */
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/src/video/winrt/SDL_winrtgamebar_cpp.h	Sun Aug 28 13:36:13 2016 -0400
    31.3 @@ -0,0 +1,35 @@
    31.4 +/*
    31.5 +  Simple DirectMedia Layer
    31.6 +  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
    31.7 +
    31.8 +  This software is provided 'as-is', without any express or implied
    31.9 +  warranty.  In no event will the authors be held liable for any damages
   31.10 +  arising from the use of this software.
   31.11 +
   31.12 +  Permission is granted to anyone to use this software for any purpose,
   31.13 +  including commercial applications, and to alter it and redistribute it
   31.14 +  freely, subject to the following restrictions:
   31.15 +
   31.16 +  1. The origin of this software must not be misrepresented; you must not
   31.17 +     claim that you wrote the original software. If you use this software
   31.18 +     in a product, an acknowledgment in the product documentation would be
   31.19 +     appreciated but is not required.
   31.20 +  2. Altered source versions must be plainly marked as such, and must not be
   31.21 +     misrepresented as being the original software.
   31.22 +  3. This notice may not be removed or altered from any source distribution.
   31.23 +*/
   31.24 +#include "SDL_config.h"
   31.25 +
   31.26 +#ifndef _SDL_winrtgamebar_h
   31.27 +#define _SDL_winrtgamebar_h
   31.28 +
   31.29 +#ifdef __cplusplus
   31.30 +/* These are exported as C++ functions, rather than C, to fix a compilation
   31.31 +   bug with MSVC 2013, for Windows 8.x builds. */
   31.32 +extern void WINRT_InitGameBar(_THIS);
   31.33 +extern void WINRT_QuitGameBar(_THIS);
   31.34 +#endif
   31.35 +
   31.36 +#endif /* _SDL_winrtmouse_h */
   31.37 +
   31.38 +/* vi: set ts=4 sw=4 expandtab: */
    32.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Fri Aug 12 22:50:48 2016 -0400
    32.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Sun Aug 28 13:36:13 2016 -0400
    32.3 @@ -61,6 +61,7 @@
    32.4  #include "../../core/winrt/SDL_winrtapp_xaml.h"
    32.5  #include "SDL_winrtvideo_cpp.h"
    32.6  #include "SDL_winrtevents_c.h"
    32.7 +#include "SDL_winrtgamebar_cpp.h"
    32.8  #include "SDL_winrtmouse_c.h"
    32.9  #include "SDL_main.h"
   32.10  #include "SDL_system.h"
   32.11 @@ -127,7 +128,6 @@
   32.12          SDL_free(device);
   32.13          return (0);
   32.14      }
   32.15 -    SDL_zerop(data);
   32.16      device->driverdata = data;
   32.17  
   32.18      /* Set the function pointers */
   32.19 @@ -178,6 +178,7 @@
   32.20      }
   32.21      WINRT_InitMouse(_this);
   32.22      WINRT_InitTouch(_this);
   32.23 +    WINRT_InitGameBar(_this);
   32.24  
   32.25      return 0;
   32.26  }
   32.27 @@ -420,6 +421,7 @@
   32.28  void
   32.29  WINRT_VideoQuit(_THIS)
   32.30  {
   32.31 +    WINRT_QuitGameBar(_this);
   32.32      WINRT_QuitMouse(_this);
   32.33  }
   32.34  
    33.1 --- a/src/video/winrt/SDL_winrtvideo_cpp.h	Fri Aug 12 22:50:48 2016 -0400
    33.2 +++ b/src/video/winrt/SDL_winrtvideo_cpp.h	Sun Aug 28 13:36:13 2016 -0400
    33.3 @@ -46,6 +46,11 @@
    33.4       * passed to eglGetDisplay and eglCreateWindowSurface:
    33.5       */
    33.6      IUnknown *winrtEglWindow;
    33.7 +
    33.8 +    /* Event token(s), for unregistering WinRT event handler(s).
    33.9 +       These are just a struct with a 64-bit integer inside them
   33.10 +    */
   33.11 +    Windows::Foundation::EventRegistrationToken gameBarIsInputRedirectedToken;
   33.12  } SDL_VideoData;
   33.13  
   33.14  /* The global, WinRT, SDL Window.