diff options
33 files changed, 619 insertions, 261 deletions
diff --git a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj index 25e414a70..3becf4b6e 100644 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj @@ -155,6 +155,7 @@ <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
<ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
@@ -310,6 +311,14 @@ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
+ </ClCompile>
<ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
diff --git a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters index 874df6ace..9b4323d40 100644 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters @@ -399,6 +399,9 @@ <ClInclude Include="..\..\src\audio\xaudio2\SDL_xaudio2.h">
<Filter>Source Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\atomic\SDL_atomic.c">
@@ -713,5 +716,8 @@ <ClCompile Include="..\..\src\audio\xaudio2\SDL_xaudio2.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file diff --git a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj index 997101d87..a2af852d7 100644 --- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj +++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj @@ -272,6 +272,7 @@ <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
<ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
@@ -407,6 +408,12 @@ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+ </ClCompile>
<ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
diff --git a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters index f699eec48..182e79e1d 100644 --- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters +++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters @@ -369,6 +369,9 @@ <ClInclude Include="..\..\src\video\SDL_egl_c.h">
<Filter>Source Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\atomic\SDL_atomic.c">
@@ -671,5 +674,8 @@ <ClCompile Include="..\..\src\video\SDL_egl.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file diff --git a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj index e40a6577f..631c26c35 100644 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj @@ -138,6 +138,7 @@ <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
<ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
@@ -274,6 +275,12 @@ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+ </ClCompile>
<ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
diff --git a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters index a36ce69e1..732f1e541 100644 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters @@ -378,6 +378,9 @@ <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
<Filter>Source Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\atomic\SDL_atomic.c">
@@ -683,5 +686,8 @@ <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file diff --git a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj index 6dd130f57..44a5eeb34 100644 --- a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj +++ b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj @@ -175,6 +175,14 @@ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
+ </ClCompile>
<ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
@@ -352,6 +360,7 @@ <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
<ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
diff --git a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters index 0e07f29a9..7bdc9d547 100644 --- a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters +++ b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters @@ -316,6 +316,9 @@ <ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\begin_code.h">
@@ -711,6 +714,9 @@ <ClInclude Include="..\..\src\haptic\windows\SDL_xinputhaptic_c.h">
<Filter>Source Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
diff --git a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj index 21a452cd2..5c448c4c6 100644 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj @@ -152,6 +152,7 @@ <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
<ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
@@ -308,6 +309,14 @@ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
+ </ClCompile>
<ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
diff --git a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters index e3e208cc0..5af736fee 100644 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters @@ -390,6 +390,9 @@ <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
<Filter>Source Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\atomic\SDL_atomic.c">
@@ -707,5 +710,8 @@ <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file diff --git a/include/SDL.h b/include/SDL.h index 7647b5111..12d22c4f8 100644 --- a/include/SDL.h +++ b/include/SDL.h @@ -95,8 +95,8 @@ extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags); * This function initializes specific SDL subsystems * * Subsystem initialization is ref-counted, you must call - * SDL_QuitSubSystem for each SDL_InitSubSystem to correctly - * shutdown a subsystem manually (or call SDL_Quit to force shutdown). + * SDL_QuitSubSystem() for each SDL_InitSubSystem() to correctly + * shutdown a subsystem manually (or call SDL_Quit() to force shutdown). * If a subsystem is already loaded then this call will * increase the ref-count and return. */ diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h index 42087eea1..e67fd9fd0 100644 --- a/include/SDL_gamecontroller.h +++ b/include/SDL_gamecontroller.h @@ -93,7 +93,7 @@ typedef struct SDL_GameControllerButtonBind * } * } * - * 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: + * 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: * guid,name,mappings * * 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. @@ -136,14 +136,14 @@ extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping( const char* mappingStr /** * Get a mapping string for a GUID * - * \return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available + * \return the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available */ extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid ); /** * Get a mapping string for an open GameController * - * \return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available + * \return the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available */ extern DECLSPEC char * SDLCALL SDL_GameControllerMapping( SDL_GameController * gamecontroller ); diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 36b931895..9d8e65402 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -431,7 +431,7 @@ extern "C" { * privacy policy. * * To setup a URL to an app's privacy policy, set SDL_HINT_WINRT_PRIVACY_POLICY_URL - * before calling any SDL_Init functions. The contents of the hint should + * before calling any SDL_Init() functions. The contents of the hint should * be a valid URL. For example, "http://www.example.com". * * The default value is "", which will prevent SDL from adding a privacy policy @@ -461,7 +461,7 @@ extern "C" { * The contents of this hint should be encoded as a UTF8 string. * * The default value is "Privacy Policy". This hint should only be set during app - * initialization, preferably before any calls to SDL_Init. + * initialization, preferably before any calls to SDL_Init(). * * For additional information on linking to a privacy policy, see the documentation for * SDL_HINT_WINRT_PRIVACY_POLICY_URL. diff --git a/include/SDL_joystick.h b/include/SDL_joystick.h index 266f3b387..f5dbc9487 100644 --- a/include/SDL_joystick.h +++ b/include/SDL_joystick.h @@ -24,7 +24,7 @@ * * Include file for SDL joystick event handling * - * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks, with the exact joystick + * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks(), with the exact joystick * behind a device_index changing as joysticks are plugged and unplugged. * * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted diff --git a/include/SDL_keyboard.h b/include/SDL_keyboard.h index bbba0f07b..f80b6d2de 100644 --- a/include/SDL_keyboard.h +++ b/include/SDL_keyboard.h @@ -136,7 +136,7 @@ extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *name); * copy it. If the key doesn't have a name, this function returns an * empty string (""). * - * \sa SDL_Key + * \sa SDL_Keycode */ extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key); diff --git a/include/SDL_mouse.h b/include/SDL_mouse.h index 8053bf5a4..46f046d0c 100644 --- a/include/SDL_mouse.h +++ b/include/SDL_mouse.h @@ -41,7 +41,7 @@ extern "C" { typedef struct SDL_Cursor SDL_Cursor; /* Implementation dependent */ /** - * \brief Cursor types for SDL_CreateSystemCursor. + * \brief Cursor types for SDL_CreateSystemCursor(). */ typedef enum { diff --git a/include/SDL_video.h b/include/SDL_video.h index b9096024d..0e138a780 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -789,7 +789,7 @@ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window); * \return 0 on success, or -1 on error. * * \sa SDL_GetWindowSurface() - * \sa SDL_UpdateWindowSurfaceRect() + * \sa SDL_UpdateWindowSurface() */ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects, diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index b029b667d..6a5863fa5 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -699,89 +699,195 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) return 0; } -static void -ALSA_Deinitialize(void) +typedef struct ALSA_Device { - UnloadALSALibrary(); -} + char *name; + SDL_bool iscapture; + struct ALSA_Device *next; +} ALSA_Device; static void -add_device(const int iscapture, const char *name, const char *_desc) +add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSeen) { - char *desc = NULL; + ALSA_Device *dev = SDL_malloc(sizeof (ALSA_Device)); + char *desc = ALSA_snd_device_name_get_hint(hint, "DESC"); char *handle = NULL; - char *ptr = NULL; - - if (!name || !_desc) { - return; /* nothing we can do with this...? */ - } + char *ptr; - desc = SDL_strdup(_desc); if (!desc) { - return; /* oh well, out of memory. Skip it. */ + SDL_free(dev); + return; + } else if (!dev) { + free(desc); + return; } - /* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output" */ - for (ptr = strchr(desc, '\n'); ptr; ptr = strchr(ptr + 1, '\n')) { - *ptr = ' '; + SDL_assert(name != NULL); + + /* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output". + just chop the extra lines off, this seems to get a reasonable device + name without extra details. */ + if ((ptr = strchr(desc, '\n')) != NULL) { + *ptr = '\0'; } + /*printf("ALSA: adding %s device '%s' (%s)\n", iscapture ? "capture" : "output", name, desc);*/ + handle = SDL_strdup(name); - if (handle != NULL) { - SDL_AddAudioDevice(iscapture, desc, handle); + if (!handle) { + free(desc); + SDL_free(dev); + return; } - SDL_free(desc); + SDL_AddAudioDevice(iscapture, desc, handle); + free(desc); + + dev->name = handle; + dev->iscapture = iscapture; + dev->next = *pSeen; + *pSeen = dev; } -static void -ALSA_DetectDevices(void) + +static SDL_atomic_t ALSA_hotplug_shutdown; +static SDL_Thread *ALSA_hotplug_thread; + +static int SDLCALL +ALSA_HotplugThread(void *arg) { - void **hints = NULL; - int i; - - /* !!! FIXME: use udev instead. */ - /* We won't deal with disconnects and hotplugs without udev, but at least - you'll get a reasonable device list at startup. */ -#if 1 /*!SDL_USE_LIBUDEV */ - if (ALSA_snd_device_name_hint(-1, "pcm", &hints) == -1) { - return; /* oh well. */ - } + SDL_sem *first_run_semaphore = (SDL_sem *) arg; + ALSA_Device *devices = NULL; + ALSA_Device *next; + ALSA_Device *dev; + Uint32 ticks; + + while (!SDL_AtomicGet(&ALSA_hotplug_shutdown)) { + void **hints = NULL; + if (ALSA_snd_device_name_hint(-1, "pcm", &hints) != -1) { + ALSA_Device *unseen = devices; + ALSA_Device *seen = NULL; + ALSA_Device *prev; + int i; + + for (i = 0; hints[i]; i++) { + char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME"); + if (!name) { + continue; + } + + /* only want physical hardware interfaces */ + if (SDL_strncmp(name, "hw:", 3) == 0) { + char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID"); + const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0); + const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0); + SDL_bool have_output = SDL_FALSE; + SDL_bool have_input = SDL_FALSE; + + free(ioid); + + if (!isoutput && !isinput) { + free(name); + continue; + } + + prev = NULL; + for (dev = unseen; dev; dev = next) { + next = dev->next; + if ( (SDL_strcmp(dev->name, name) == 0) && (((isinput) && dev->iscapture) || ((isoutput) && !dev->iscapture)) ) { + if (prev) { + prev->next = next; + } else { + unseen = next; + } + dev->next = seen; + seen = dev; + if (isinput) have_input = SDL_TRUE; + if (isoutput) have_output = SDL_TRUE; + } else { + prev = dev; + } + } + + if (isinput && !have_input) { + add_device(SDL_TRUE, name, hints[i], &seen); + } + if (isoutput && !have_output) { + add_device(SDL_FALSE, name, hints[i], &seen); + } + } + + free(name); + } + + ALSA_snd_device_name_free_hint(hints); - for (i = 0; hints[i]; i++) { - char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME"); - char *desc = ALSA_snd_device_name_get_hint(hints[i], "DESC"); - char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID"); + devices = seen; /* now we have a known-good list of attached devices. */ - if ((ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0)) { - add_device(SDL_FALSE, name, desc); + /* report anything still in unseen as removed. */ + for (dev = unseen; dev; dev = next) { + /*printf("ALSA: removing %s device '%s'\n", dev->iscapture ? "capture" : "output", dev->name);*/ + next = dev->next; + SDL_RemoveAudioDevice(dev->iscapture, dev->name); + SDL_free(dev->name); + SDL_free(dev); + } } - if ((ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0)) { - add_device(SDL_TRUE, name, desc); + /* On first run, tell ALSA_DetectDevices() that we have a complete device list so it can return. */ + if (first_run_semaphore) { + SDL_SemPost(first_run_semaphore); + first_run_semaphore = NULL; /* let other thread clean it up. */ } - free(name); - free(desc); - free(ioid); + /* Block awhile before checking again, unless we're told to stop. */ + ticks = SDL_GetTicks() + 5000; + while (!SDL_AtomicGet(&ALSA_hotplug_shutdown) && !SDL_TICKS_PASSED(SDL_GetTicks(), ticks)) { + SDL_Delay(100); + } } - ALSA_snd_device_name_free_hint(hints); -#else -#error Fill in udev support here. -#endif + /* Shutting down! Clean up any data we've gathered. */ + for (dev = devices; dev; dev = next) { + /*printf("ALSA: at shutdown, removing %s device '%s'\n", dev->iscapture ? "capture" : "output", dev->name);*/ + next = dev->next; + SDL_free(dev->name); + SDL_free(dev); + } + + return 0; } static void -ALSA_FreeDeviceHandle(void *handle) +ALSA_DetectDevices(void) { -#if 1 /*!SDL_USE_LIBUDEV*/ - SDL_free(handle); -#else -#error Fill in udev support here. -#endif + /* Start the device detection thread here, wait for an initial iteration to complete. */ + SDL_sem *semaphore = SDL_CreateSemaphore(0); + if (!semaphore) { + return; /* oh well. */ + } + + SDL_AtomicSet(&ALSA_hotplug_shutdown, 0); + + ALSA_hotplug_thread = SDL_CreateThread(ALSA_HotplugThread, "SDLHotplugALSA", semaphore); + if (ALSA_hotplug_thread) { + SDL_SemWait(semaphore); /* wait for the first iteration to finish. */ + } + + SDL_DestroySemaphore(semaphore); } +static void +ALSA_Deinitialize(void) +{ + if (ALSA_hotplug_thread != NULL) { + SDL_AtomicSet(&ALSA_hotplug_shutdown, 1); + SDL_WaitThread(ALSA_hotplug_thread, NULL); + ALSA_hotplug_thread = NULL; + } + + UnloadALSALibrary(); +} static int ALSA_Init(SDL_AudioDriverImpl * impl) @@ -798,7 +904,6 @@ ALSA_Init(SDL_AudioDriverImpl * impl) impl->PlayDevice = ALSA_PlayDevice; impl->CloseDevice = ALSA_CloseDevice; impl->Deinitialize = ALSA_Deinitialize; - impl->FreeDeviceHandle = ALSA_FreeDeviceHandle; impl->CaptureFromDevice = ALSA_CaptureFromDevice; impl->FlushCapture = ALSA_FlushCapture; diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 93e6fbfb2..a312a86ba 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -106,6 +106,35 @@ int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameC int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state); /* + * If there is an existing add event in the queue, it needs to be modified + * to have the right value for which, because the number of controllers in + * the system is now one less. + */ +static void UpdateEventsForDeviceRemoval() +{ + int i, num_events; + SDL_Event *events; + + num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED); + if (num_events <= 0) { + return; + } + + events = SDL_stack_alloc(SDL_Event, num_events); + if (!events) { + return; + } + + num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED); + for (i = 0; i < num_events; ++i) { + --events[i].cdevice.which; + } + SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0); + + SDL_stack_free(events); +} + +/* * Event filter to fire controller events from joystick ones */ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) @@ -223,9 +252,12 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) while (controllerlist) { if (controllerlist->joystick->instance_id == event->jdevice.which) { SDL_Event deviceevent; + deviceevent.type = SDL_CONTROLLERDEVICEREMOVED; deviceevent.cdevice.which = event->jdevice.which; SDL_PushEvent(&deviceevent); + + UpdateEventsForDeviceRemoval(); break; } controllerlist = controllerlist->next; diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index dc910a82b..49b8cbcd5 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -497,6 +497,71 @@ SDL_PrivateJoystickShouldIgnoreEvent() /* These are global for SDL_sysjoystick.c and SDL_events.c */ +void SDL_PrivateJoystickAdded(int device_index) +{ +#if !SDL_EVENTS_DISABLED + SDL_Event event; + + event.type = SDL_JOYDEVICEADDED; + + if (SDL_GetEventState(event.type) == SDL_ENABLE) { + event.jdevice.which = device_index; + if ( (SDL_EventOK == NULL) || + (*SDL_EventOK) (SDL_EventOKParam, &event) ) { + SDL_PushEvent(&event); + } + } +#endif /* !SDL_EVENTS_DISABLED */ +} + +/* + * If there is an existing add event in the queue, it needs to be modified + * to have the right value for which, because the number of controllers in + * the system is now one less. + */ +static void UpdateEventsForDeviceRemoval() +{ + int i, num_events; + SDL_Event *events; + + num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED); + if (num_events <= 0) { + return; + } + + events = SDL_stack_alloc(SDL_Event, num_events); + if (!events) { + return; + } + + num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED); + for (i = 0; i < num_events; ++i) { + --events[i].jdevice.which; + } + SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0); + + SDL_stack_free(events); +} + +void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance) +{ +#if !SDL_EVENTS_DISABLED + SDL_Event event; + + event.type = SDL_JOYDEVICEREMOVED; + + if (SDL_GetEventState(event.type) == SDL_ENABLE) { + event.jdevice.which = device_instance; + if ( (SDL_EventOK == NULL) || + (*SDL_EventOK) (SDL_EventOKParam, &event) ) { + SDL_PushEvent(&event); + } + } + + UpdateEventsForDeviceRemoval(); +#endif /* !SDL_EVENTS_DISABLED */ +} + int SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value) { diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h index 4a076f6d6..cb9c92544 100644 --- a/src/joystick/SDL_joystick_c.h +++ b/src/joystick/SDL_joystick_c.h @@ -33,6 +33,8 @@ extern void SDL_GameControllerQuit(void); /* Internal event queueing functions */ +extern void SDL_PrivateJoystickAdded(int device_index); +extern void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance); extern int SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value); extern int SDL_PrivateJoystickBall(SDL_Joystick * joystick, @@ -41,8 +43,8 @@ extern int SDL_PrivateJoystickHat(SDL_Joystick * joystick, Uint8 hat, Uint8 value); extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state); -extern void SDL_PrivateJoystickBatteryLevel( SDL_Joystick * joystick, - SDL_JoystickPowerLevel ePowerLevel ); +extern void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick, + SDL_JoystickPowerLevel ePowerLevel); /* Internal sanity checking functions */ extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick); diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index 6ef16a93b..929a9ac44 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -27,10 +27,6 @@ #include "SDL_error.h" #include "SDL_events.h" -#if !SDL_EVENTS_DISABLED -#include "../../events/SDL_events_c.h" -#endif - #include "SDL_joystick.h" #include "SDL_hints.h" #include "SDL_assert.h" @@ -252,9 +248,6 @@ Android_AddJoystick(int device_id, const char *name, SDL_bool is_accelerometer, { SDL_JoystickGUID guid; SDL_joylist_item *item; -#if !SDL_EVENTS_DISABLED - SDL_Event event; -#endif if(JoystickByDeviceId(device_id) != NULL || name == NULL) { return -1; @@ -299,17 +292,7 @@ Android_AddJoystick(int device_id, const char *name, SDL_bool is_accelerometer, /* Need to increment the joystick count before we post the event */ ++numjoysticks; -#if !SDL_EVENTS_DISABLED - event.type = SDL_JOYDEVICEADDED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = (numjoysticks - 1); - if ( (SDL_EventOK == NULL) || - (*SDL_EventOK) (SDL_EventOKParam, &event) ) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickAdded(numjoysticks - 1); #ifdef DEBUG_JOYSTICK SDL_Log("Added joystick %s with device_id %d", name, device_id); @@ -323,9 +306,6 @@ Android_RemoveJoystick(int device_id) { SDL_joylist_item *item = SDL_joylist; SDL_joylist_item *prev = NULL; -#if !SDL_EVENTS_DISABLED - SDL_Event event; -#endif /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */ while (item != NULL) { @@ -357,17 +337,7 @@ Android_RemoveJoystick(int device_id) /* Need to decrement the joystick count before we post the event */ --numjoysticks; -#if !SDL_EVENTS_DISABLED - event.type = SDL_JOYDEVICEREMOVED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = item->device_instance; - if ( (SDL_EventOK == NULL) || - (*SDL_EventOK) (SDL_EventOKParam, &event) ) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickRemoved(item->device_instance); #ifdef DEBUG_JOYSTICK SDL_Log("Removed joystick with device_id %d", device_id); @@ -538,6 +508,10 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) void SDL_SYS_JoystickClose(SDL_Joystick * joystick) { + SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata; + if (item) { + item->joystick = NULL; + } } /* Function to perform any system-specific joystick related cleanup */ diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 65cd2fca0..da10fbac5 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -34,9 +34,6 @@ #include "SDL_sysjoystick_c.h" #include "SDL_events.h" #include "../../haptic/darwin/SDL_syshaptic_c.h" /* For haptic hot plugging */ -#if !SDL_EVENTS_DISABLED -#include "../../events/SDL_events_c.h" -#endif #define SDL_JOYSTICK_RUNLOOP_MODE CFSTR("SDLJoystick") @@ -154,21 +151,7 @@ JoystickDeviceWasRemovedCallback(void *ctx, IOReturn result, void *sender) MacHaptic_MaybeRemoveDevice(device->ffservice); #endif -/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceRemoved()? */ -#if !SDL_EVENTS_DISABLED - { - SDL_Event event; - event.type = SDL_JOYDEVICEREMOVED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = device->instance_id; - if ((SDL_EventOK == NULL) - || (*SDL_EventOK) (SDL_EventOKParam, &event)) { - SDL_PushEvent(&event); - } - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickRemoved(device->instance_id); } @@ -249,6 +232,7 @@ AddHIDElement(const void *value, void *parameter) case kHIDUsage_GD_DPadLeft: case kHIDUsage_GD_Start: case kHIDUsage_GD_Select: + case kHIDUsage_GD_SystemMainMenu: if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) { element = (recElement *) SDL_calloc(1, sizeof (recElement)); if (element) { @@ -475,21 +459,7 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic ++device_index; /* bump by one since we counted by pNext. */ } -/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceAdded()? */ -#if !SDL_EVENTS_DISABLED - { - SDL_Event event; - event.type = SDL_JOYDEVICEADDED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = device_index; - if ((SDL_EventOK == NULL) - || (*SDL_EventOK) (SDL_EventOKParam, &event)) { - SDL_PushEvent(&event); - } - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickAdded(device_index); } static SDL_bool diff --git a/src/joystick/emscripten/SDL_sysjoystick.c b/src/joystick/emscripten/SDL_sysjoystick.c index e0c5833bf..6b203667a 100644 --- a/src/joystick/emscripten/SDL_sysjoystick.c +++ b/src/joystick/emscripten/SDL_sysjoystick.c @@ -27,10 +27,6 @@ #include "SDL_error.h" #include "SDL_events.h" -#if !SDL_EVENTS_DISABLED -#include "../../events/SDL_events_c.h" -#endif - #include "SDL_joystick.h" #include "SDL_hints.h" #include "SDL_assert.h" @@ -57,10 +53,6 @@ Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepa return 1; } -#if !SDL_EVENTS_DISABLED - SDL_Event event; -#endif - item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item)); if (item == NULL) { return 1; @@ -105,20 +97,12 @@ Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepa } ++numjoysticks; + + SDL_PrivateJoystickAdded(numjoysticks - 1); + #ifdef DEBUG_JOYSTICK SDL_Log("Number of joysticks is %d", numjoysticks); #endif -#if !SDL_EVENTS_DISABLED - event.type = SDL_JOYDEVICEADDED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = numjoysticks - 1; - if ( (SDL_EventOK == NULL) || - (*SDL_EventOK) (SDL_EventOKParam, &event) ) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ #ifdef DEBUG_JOYSTICK SDL_Log("Added joystick with index %d", item->index); @@ -132,9 +116,6 @@ Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gam { SDL_joylist_item *item = SDL_joylist; SDL_joylist_item *prev = NULL; -#if !SDL_EVENTS_DISABLED - SDL_Event event; -#endif while (item != NULL) { if (item->index == gamepadEvent->index) { @@ -165,17 +146,7 @@ Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gam /* Need to decrement the joystick count before we post the event */ --numjoysticks; -#if !SDL_EVENTS_DISABLED - event.type = SDL_JOYDEVICEREMOVED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = item->device_instance; - if ( (SDL_EventOK == NULL) || - (*SDL_EventOK) (SDL_EventOKParam, &event) ) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickRemoved(item->device_instance); #ifdef DEBUG_JOYSTICK SDL_Log("Removed joystick with id %d", item->device_instance); @@ -377,6 +348,10 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) void SDL_SYS_JoystickClose(SDL_Joystick * joystick) { + SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata; + if (item) { + item->joystick = NULL; + } } /* Function to perform any system-specific joystick related cleanup */ diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m index c8a42af05..b7b3395a9 100644 --- a/src/joystick/iphoneos/SDL_sysjoystick.m +++ b/src/joystick/iphoneos/SDL_sysjoystick.m @@ -26,16 +26,13 @@ /* needed for SDL_IPHONE_MAX_GFORCE macro */ #include "SDL_config_iphoneos.h" +#include "SDL_events.h" #include "SDL_joystick.h" #include "SDL_hints.h" #include "SDL_stdinc.h" #include "../SDL_sysjoystick.h" #include "../SDL_joystick_c.h" -#if !SDL_EVENTS_DISABLED -#include "../../events/SDL_events_c.h" -#endif - #import <CoreMotion/CoreMotion.h> #ifdef SDL_JOYSTICK_MFI @@ -127,9 +124,6 @@ static void SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer) { SDL_JoystickDeviceItem *device = deviceList; -#if !SDL_EVENTS_DISABLED - SDL_Event event; -#endif while (device != NULL) { if (device->controller == controller) { @@ -172,17 +166,7 @@ SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer) ++numjoysticks; -#if !SDL_EVENTS_DISABLED - event.type = SDL_JOYDEVICEADDED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = numjoysticks - 1; - if ((SDL_EventOK == NULL) || - (*SDL_EventOK)(SDL_EventOKParam, &event)) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickAdded(numjoysticks - 1); } static SDL_JoystickDeviceItem * @@ -191,9 +175,6 @@ SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device) SDL_JoystickDeviceItem *prev = NULL; SDL_JoystickDeviceItem *next = NULL; SDL_JoystickDeviceItem *item = deviceList; -#if !SDL_EVENTS_DISABLED - SDL_Event event; -#endif if (device == NULL) { return NULL; @@ -234,17 +215,7 @@ SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device) --numjoysticks; -#if !SDL_EVENTS_DISABLED - event.type = SDL_JOYDEVICEREMOVED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = device->instance_id; - if ((SDL_EventOK == NULL) || - (*SDL_EventOK)(SDL_EventOKParam, &event)) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickRemoved(device->instance_id); SDL_free(device->name); SDL_free(device); diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 8c73859ea..bd52b1808 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -42,11 +42,6 @@ #include "../SDL_joystick_c.h" #include "SDL_sysjoystick_c.h" -/* !!! FIXME: move this somewhere else. */ -#if !SDL_EVENTS_DISABLED -#include "../../events/SDL_events_c.h" -#endif - /* This isn't defined in older Linux kernel headers */ #ifndef SYN_DROPPED #define SYN_DROPPED 3 @@ -176,9 +171,6 @@ MaybeAddDevice(const char *path) char namebuf[128]; SDL_JoystickGUID guid; SDL_joylist_item *item; -#if !SDL_EVENTS_DISABLED - SDL_Event event; -#endif if (path == NULL) { return -1; @@ -239,18 +231,7 @@ MaybeAddDevice(const char *path) /* Need to increment the joystick count before we post the event */ ++numjoysticks; - /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */ -#if !SDL_EVENTS_DISABLED - event.type = SDL_JOYDEVICEADDED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = (numjoysticks - 1); - if ( (SDL_EventOK == NULL) || - (*SDL_EventOK) (SDL_EventOKParam, &event) ) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickAdded(numjoysticks - 1); return numjoysticks; } @@ -262,9 +243,6 @@ MaybeRemoveDevice(const char *path) { SDL_joylist_item *item; SDL_joylist_item *prev = NULL; -#if !SDL_EVENTS_DISABLED - SDL_Event event; -#endif if (path == NULL) { return -1; @@ -290,18 +268,7 @@ MaybeRemoveDevice(const char *path) /* Need to decrement the joystick count before we post the event */ --numjoysticks; - /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */ -#if !SDL_EVENTS_DISABLED - event.type = SDL_JOYDEVICEREMOVED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = item->device_instance; - if ( (SDL_EventOK == NULL) || - (*SDL_EventOK) (SDL_EventOKParam, &event) ) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickRemoved(item->device_instance); SDL_free(item->path); SDL_free(item->name); diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c index f6b0cc88d..47e086121 100644 --- a/src/joystick/windows/SDL_dinputjoystick.c +++ b/src/joystick/windows/SDL_dinputjoystick.c @@ -240,11 +240,23 @@ SDL_IsXInputDevice(const GUID* pGuidProductFromDirectInput) static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + static GUID IID_XOneWiredGamepad = { MAKELONG(0x045E, 0x02FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + static GUID IID_XOneWirelessGamepad = { MAKELONG(0x045E, 0x02DD), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + static GUID IID_XOneNewWirelessGamepad = { MAKELONG(0x045E, 0x02D1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + static GUID IID_XOneSWirelessGamepad = { MAKELONG(0x045E, 0x02EA), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + static GUID IID_XOneSBluetoothGamepad = { MAKELONG(0x045E, 0x02E0), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + static GUID IID_XOneEliteWirelessGamepad = { MAKELONG(0x045E, 0x02E3), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static const GUID *s_XInputProductGUID[] = { &IID_ValveStreamingGamepad, - &IID_X360WiredGamepad, /* Microsoft's wired X360 controller for Windows. */ - &IID_X360WirelessGamepad /* Microsoft's wireless X360 controller for Windows. */ + &IID_X360WiredGamepad, /* Microsoft's wired X360 controller for Windows. */ + &IID_X360WirelessGamepad, /* Microsoft's wireless X360 controller for Windows. */ + &IID_XOneWiredGamepad, /* Microsoft's wired Xbox One controller for Windows. */ + &IID_XOneWirelessGamepad, /* Microsoft's wireless Xbox One controller for Windows. */ + &IID_XOneNewWirelessGamepad, /* Microsoft's updated wireless Xbox One controller (w/ 3.5 mm jack) for Windows. */ + &IID_XOneSWirelessGamepad, /* Microsoft's wireless Xbox One S controller for Windows. */ + &IID_XOneSBluetoothGamepad, /* Microsoft's Bluetooth Xbox One S controller for Windows. */ + &IID_XOneEliteWirelessGamepad /* Microsoft's wireless Xbox One Elite controller for Windows. */ }; size_t iDevice; diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c index cc61ec9eb..0628627d3 100644 --- a/src/joystick/windows/SDL_windowsjoystick.c +++ b/src/joystick/windows/SDL_windowsjoystick.c @@ -42,9 +42,6 @@ #include "SDL_joystick.h" #include "../SDL_sysjoystick.h" #include "../../thread/SDL_systhread.h" -#if !SDL_EVENTS_DISABLED -#include "../../events/SDL_events_c.h" -#endif #include "../../core/windows/SDL_windows.h" #if !defined(__WINRT__) #include <dbt.h> @@ -327,9 +324,6 @@ void SDL_SYS_JoystickDetect() { JoyStick_DeviceData *pCurList = NULL; -#if !SDL_EVENTS_DISABLED - SDL_Event event; -#endif /* only enum the devices if the joystick thread told us something changed */ if (!s_bDeviceAdded && !s_bDeviceRemoved) { @@ -361,17 +355,7 @@ SDL_SYS_JoystickDetect() SDL_DINPUT_MaybeRemoveDevice(&pCurList->dxdevice); } -#if !SDL_EVENTS_DISABLED - SDL_zero(event); - event.type = SDL_JOYDEVICEREMOVED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = pCurList->nInstanceID; - if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ + SDL_PrivateJoystickRemoved(pCurList->nInstanceID); pListNext = pCurList->pNext; SDL_free(pCurList->joystickname); @@ -392,17 +376,8 @@ SDL_SYS_JoystickDetect() SDL_DINPUT_MaybeAddDevice(&pNewJoystick->dxdevice); } -#if !SDL_EVENTS_DISABLED - SDL_zero(event); - event.type = SDL_JOYDEVICEADDED; + SDL_PrivateJoystickAdded(device_index); - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = device_index; - if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) { - SDL_PushEvent(&event); - } - } -#endif /* !SDL_EVENTS_DISABLED */ pNewJoystick->send_add_event = SDL_FALSE; } device_index++; diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c index d43c76078..381e4899e 100644 --- a/src/video/psp/SDL_pspvideo.c +++ b/src/video/psp/SDL_pspvideo.c @@ -92,6 +92,7 @@ PSP_Create() if (gldata == NULL) { SDL_OutOfMemory(); SDL_free(device); + SDL_free(phdata); return NULL; } device->gl_data = gldata; diff --git a/src/video/winrt/SDL_winrtgamebar.cpp b/src/video/winrt/SDL_winrtgamebar.cpp new file mode 100644 index 000000000..215dfcc83 --- /dev/null +++ b/src/video/winrt/SDL_winrtgamebar.cpp @@ -0,0 +1,196 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_WINRT + +/* Windows includes */ +#include <roapi.h> +#include <windows.foundation.h> +#include <EventToken.h> + + +/* SDL includes */ +extern "C" { +#include "SDL_mouse.h" +#include "../SDL_sysvideo.h" +} +#include "SDL_winrtvideo_cpp.h" + + +/* Game Bar events can come in off the main thread. Use the following + WinRT CoreDispatcher to deal with them on SDL's thread. +*/ +static Platform::WeakReference WINRT_MainThreadDispatcher; + + +/* Win10's initial SDK (the 10.0.10240.0 release) does not include references + to Game Bar APIs, as the Game Bar was released via Win10 10.0.10586.0. + + Declare its WinRT/COM interface here, to allow compilation with earlier + Windows SDKs. +*/ +MIDL_INTERFACE("1DB9A292-CC78-4173-BE45-B61E67283EA7") +IGameBarStatics_ : public IInspectable +{ +public: + virtual HRESULT STDMETHODCALLTYPE add_VisibilityChanged( + __FIEventHandler_1_IInspectable *handler, + Windows::Foundation::EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_VisibilityChanged( + Windows::Foundation::EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_IsInputRedirectedChanged( + __FIEventHandler_1_IInspectable *handler, + Windows::Foundation::EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_IsInputRedirectedChanged( + Windows::Foundation::EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE get_Visible( + boolean *value) = 0; + + virtual HRESULT STDMETHODCALLTYPE get_IsInputRedirected( + boolean *value) = 0; +}; + +/* Declare the game bar's COM GUID */ +static GUID IID_IGameBarStatics_ = { MAKELONG(0xA292, 0x1DB9), 0xCC78, 0x4173, { 0xBE, 0x45, 0xB6, 0x1E, 0x67, 0x28, 0x3E, 0xA7 } }; + +/* Retrieves a pointer to the game bar, or NULL if it is not available. + If a pointer is returned, it's ->Release() method must be called + after the caller has finished using it. +*/ +static IGameBarStatics_ * +WINRT_GetGameBar() +{ + wchar_t *wClassName = L"Windows.Gaming.UI.GameBar"; + HSTRING hClassName; + IActivationFactory *pActivationFactory = NULL; + IGameBarStatics_ *pGameBar = NULL; + HRESULT hr; + + hr = ::WindowsCreateString(wClassName, (UINT32)wcslen(wClassName), &hClassName); + if (FAILED(hr)) { + goto done; + } + + hr = Windows::Foundation::GetActivationFactory(hClassName, &pActivationFactory); + if (FAILED(hr)) { + goto done; + } + + pActivationFactory->QueryInterface(IID_IGameBarStatics_, (void **) &pGameBar); + +done: + if (pActivationFactory) { + pActivationFactory->Release(); + } + if (hClassName) { + ::WindowsDeleteString(hClassName); + } + return pGameBar; +} + +static void +WINRT_HandleGameBarIsInputRedirected_MainThread() +{ + IGameBarStatics_ *gameBar; + boolean isInputRedirected = 0; + if (!WINRT_MainThreadDispatcher) { + /* The game bar event handler has been deregistered! */ + return; + } + gameBar = WINRT_GetGameBar(); + if (!gameBar) { + /* Shouldn't happen, but just in case... */ + return; + } + if (SUCCEEDED(gameBar->get_IsInputRedirected(&isInputRedirected))) { + if ( ! isInputRedirected) { + /* Input-control is now back to the SDL app. Restore the cursor, + in case Windows does not (it does not in either Win10 + 10.0.10240.0 or 10.0.10586.0, maybe later version(s) too. + */ + SDL_Cursor *cursor = SDL_GetCursor(); + SDL_SetCursor(cursor); + } + } + gameBar->Release(); +} + +static void +WINRT_HandleGameBarIsInputRedirected_NonMainThread(Platform::Object ^ o1, Platform::Object ^o2) +{ + Windows::UI::Core::CoreDispatcher ^dispatcher = WINRT_MainThreadDispatcher.Resolve<Windows::UI::Core::CoreDispatcher>(); + if (dispatcher) { + dispatcher->RunAsync( + Windows::UI::Core::CoreDispatcherPriority::Normal, + ref new Windows::UI::Core::DispatchedHandler(&WINRT_HandleGameBarIsInputRedirected_MainThread)); + } +} + +void +WINRT_InitGameBar(_THIS) +{ + SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata; + IGameBarStatics_ *gameBar = WINRT_GetGameBar(); + if (gameBar) { + /* GameBar.IsInputRedirected events can come in via something other than + the main/SDL thread. + + Get a WinRT 'CoreDispatcher' that can be used to call back into the + SDL thread. + */ + WINRT_MainThreadDispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher; + Windows::Foundation::EventHandler<Platform::Object ^> ^handler = \ + ref new Windows::Foundation::EventHandler<Platform::Object ^>(&WINRT_HandleGameBarIsInputRedirected_NonMainThread); + __FIEventHandler_1_IInspectable * pHandler = reinterpret_cast<__FIEventHandler_1_IInspectable *>(handler); + gameBar->add_IsInputRedirectedChanged(pHandler, &driverdata->gameBarIsInputRedirectedToken); + gameBar->Release(); + } +} + +void +WINRT_QuitGameBar(_THIS) +{ + SDL_VideoData *driverdata; + IGameBarStatics_ *gameBar; + if (!_this || !_this->driverdata) { + return; + } + gameBar = WINRT_GetGameBar(); + if (!gameBar) { + return; + } + driverdata = (SDL_VideoData *)_this->driverdata; + if (driverdata->gameBarIsInputRedirectedToken.Value) { + gameBar->remove_IsInputRedirectedChanged(driverdata->gameBarIsInputRedirectedToken); + driverdata->gameBarIsInputRedirectedToken.Value = 0; + } + WINRT_MainThreadDispatcher = nullptr; + gameBar->Release(); +} + +#endif /* SDL_VIDEO_DRIVER_WINRT */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/winrt/SDL_winrtgamebar_cpp.h b/src/video/winrt/SDL_winrtgamebar_cpp.h new file mode 100644 index 000000000..afcef37b2 --- /dev/null +++ b/src/video/winrt/SDL_winrtgamebar_cpp.h @@ -0,0 +1,35 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "SDL_config.h" + +#ifndef _SDL_winrtgamebar_h +#define _SDL_winrtgamebar_h + +#ifdef __cplusplus +/* These are exported as C++ functions, rather than C, to fix a compilation + bug with MSVC 2013, for Windows 8.x builds. */ +extern void WINRT_InitGameBar(_THIS); +extern void WINRT_QuitGameBar(_THIS); +#endif + +#endif /* _SDL_winrtmouse_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index 03a11adb6..e4c29a456 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -61,6 +61,7 @@ extern "C" { #include "../../core/winrt/SDL_winrtapp_xaml.h" #include "SDL_winrtvideo_cpp.h" #include "SDL_winrtevents_c.h" +#include "SDL_winrtgamebar_cpp.h" #include "SDL_winrtmouse_c.h" #include "SDL_main.h" #include "SDL_system.h" @@ -127,7 +128,6 @@ WINRT_CreateDevice(int devindex) SDL_free(device); return (0); } - SDL_zerop(data); device->driverdata = data; /* Set the function pointers */ @@ -178,6 +178,7 @@ WINRT_VideoInit(_THIS) } WINRT_InitMouse(_this); WINRT_InitTouch(_this); + WINRT_InitGameBar(_this); return 0; } @@ -420,6 +421,7 @@ WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) void WINRT_VideoQuit(_THIS) { + WINRT_QuitGameBar(_this); WINRT_QuitMouse(_this); } diff --git a/src/video/winrt/SDL_winrtvideo_cpp.h b/src/video/winrt/SDL_winrtvideo_cpp.h index 26eb008d4..da5f6abeb 100644 --- a/src/video/winrt/SDL_winrtvideo_cpp.h +++ b/src/video/winrt/SDL_winrtvideo_cpp.h @@ -46,6 +46,11 @@ typedef struct SDL_VideoData { * passed to eglGetDisplay and eglCreateWindowSurface: */ IUnknown *winrtEglWindow; + + /* Event token(s), for unregistering WinRT event handler(s). + These are just a struct with a 64-bit integer inside them + */ + Windows::Foundation::EventRegistrationToken gameBarIsInputRedirectedToken; } SDL_VideoData; /* The global, WinRT, SDL Window. |