From 9cb82d5ff2f6815e44ea249c23315f9a2ebf796e Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Wed, 3 Aug 2016 22:30:31 +0200 Subject: [PATCH 01/18] Added brackets to function names in header comments so that doxygen links them. --- include/SDL.h | 4 ++-- include/SDL_gamecontroller.h | 6 +++--- include/SDL_hints.h | 4 ++-- include/SDL_joystick.h | 2 +- include/SDL_mouse.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) 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_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 { From d932507b4e741985bd07dfe6a569bfa8f4237d8a Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Wed, 3 Aug 2016 22:32:02 +0200 Subject: [PATCH 02/18] WinRT: Removed not needed SDL_zerop() after SDL_calloc(). SDL_calloc() already sets memory to zero. --- src/video/winrt/SDL_winrtvideo.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index 03a11adb6..4a936df24 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -127,7 +127,6 @@ WINRT_CreateDevice(int devindex) SDL_free(device); return (0); } - SDL_zerop(data); device->driverdata = data; /* Set the function pointers */ From f73dc1f190fe4c7a4432007b44e74aa60e1e13b7 Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Wed, 3 Aug 2016 22:32:20 +0200 Subject: [PATCH 03/18] PSP: Fixed memory leak if video init failed. --- src/video/psp/SDL_pspvideo.c | 1 + 1 file changed, 1 insertion(+) 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; From e0a678cddf0b3012894843f763f2fe17674efb3c Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Wed, 3 Aug 2016 22:39:44 +0200 Subject: [PATCH 04/18] Fixed two old identifiers in header comments. --- include/SDL_keyboard.h | 2 +- include/SDL_video.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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_video.h b/include/SDL_video.h index b9096024d..1b8dc2b20 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -789,7 +789,6 @@ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window); * \return 0 on success, or -1 on error. * * \sa SDL_GetWindowSurface() - * \sa SDL_UpdateWindowSurfaceRect() */ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects, From f9e9b84c074641e8e412f356b9553f0ec19d7786 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Sat, 6 Aug 2016 15:09:20 +0200 Subject: [PATCH 05/18] Add Xbox One controller GUIDs to the XInput filter in the DirectInput joystick driver. The Windows 10 Anniversary Update (1607) breaks the method uses that SDL uses to detect XInput devices. That is, on Windows 10 Anniversary Update, it is no longer possible to query RAWINPUT for HID devices, and check for "IG_" in the device name. Presumably, this will be fixed in the future. This patch works around the issue by adding the Xbox One controller series to the well-known device list. This skips the more expensive RAWINPUT check for those devices, and causes them to be detected as XInput devices once again. --- src/joystick/windows/SDL_dinputjoystick.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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; From cb8e57bda002938ed958098a64a81f7f9075ca89 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 8 Aug 2016 12:17:53 -0700 Subject: [PATCH 06/18] [ OSX ] enables Xbox One S Guide (System Main Menu) button detection. the one possible impact is that since button identifiers on OSX are just their sequence in the HID report descriptor we might change the button order, and any existing/saved mappings may get their order changed. --- src/joystick/darwin/SDL_sysjoystick.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 65cd2fca0..2afab337f 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -249,6 +249,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) { From e688740f8eff03938cc4f7fd87c76e31ffccb442 Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Wed, 17 Aug 2016 21:04:32 +0200 Subject: [PATCH 07/18] Android: Fixed opening previously closed joystick (thanks, Sylvain!). Fixes Bugzilla #3408. --- src/joystick/android/SDL_sysjoystick.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index 6ef16a93b..89b816399 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -538,6 +538,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) void SDL_SYS_JoystickClose(SDL_Joystick * joystick) { + SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata; + item->joystick = NULL; } /* Function to perform any system-specific joystick related cleanup */ From 7cc86e8e8d63529c0913834e895a669731238be0 Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Wed, 17 Aug 2016 21:04:50 +0200 Subject: [PATCH 08/18] Emscripten: Fixed opening previously closed joystick. --- src/joystick/emscripten/SDL_sysjoystick.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/joystick/emscripten/SDL_sysjoystick.c b/src/joystick/emscripten/SDL_sysjoystick.c index e0c5833bf..c3becd291 100644 --- a/src/joystick/emscripten/SDL_sysjoystick.c +++ b/src/joystick/emscripten/SDL_sysjoystick.c @@ -377,6 +377,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) void SDL_SYS_JoystickClose(SDL_Joystick * joystick) { + SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata; + item->joystick = NULL; } /* Function to perform any system-specific joystick related cleanup */ From 7276d8862d2190415bade267fa514c6e7ebbd1f6 Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Wed, 17 Aug 2016 21:05:00 +0200 Subject: [PATCH 09/18] Added link in header comment. --- include/SDL_video.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/SDL_video.h b/include/SDL_video.h index 1b8dc2b20..0e138a780 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -789,6 +789,7 @@ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window); * \return 0 on success, or -1 on error. * * \sa SDL_GetWindowSurface() + * \sa SDL_UpdateWindowSurface() */ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects, From d5a6c71aca4ad4c3651cbadb12fb918ede336c55 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Sat, 20 Aug 2016 13:46:45 -0400 Subject: [PATCH 10/18] WinRT: fixed bug where Win10 GameBar, when shown + hidden, might not restore a cursor's hidden state The repro steps were this: 1. run an sdl2 winrt/uwp app, on Win10, v10.0.10586.0 or higher 2. hide the cursor, via a call to SDL_ShowCursor(0) 3. make the Win10 game bar appear, by pressing the Windows + G hotkey 4. observe that the mouse cursor appears, in order to interact with the game bar (this is expected behavior) 5. make the Win10 game bar disappear, either by pressing the Windows + G hotkey again, or clicking somewhere in the app EXPECTED RESULT: cursor disappears, as game bar disappears ACTUAL RESULT: cursor didn't always disappear --HG-- extra : rebase_source : 79e7effb57db209f08a3995a4c087be04fe3582c --- VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj | 9 + .../UWP_VS2015/SDL-UWP.vcxproj.filters | 6 + .../WinPhone80_VS2012/SDL-WinPhone80.vcxproj | 7 + .../SDL-WinPhone80.vcxproj.filters | 6 + .../WinPhone81_VS2013/SDL-WinPhone81.vcxproj | 7 + .../SDL-WinPhone81.vcxproj.filters | 6 + .../WinRT80_VS2012/SDL-WinRT80.vcxproj | 9 + .../SDL-WinRT80.vcxproj.filters | 6 + .../WinRT81_VS2013/SDL-WinRT81.vcxproj | 9 + .../SDL-WinRT81.vcxproj.filters | 6 + src/video/winrt/SDL_winrtgamebar.cpp | 196 ++++++++++++++++++ src/video/winrt/SDL_winrtgamebar_cpp.h | 35 ++++ src/video/winrt/SDL_winrtvideo.cpp | 3 + src/video/winrt/SDL_winrtvideo_cpp.h | 5 + 14 files changed, 310 insertions(+) create mode 100644 src/video/winrt/SDL_winrtgamebar.cpp create mode 100644 src/video/winrt/SDL_winrtgamebar_cpp.h diff --git a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj index 305a3ca5f..998040ff3 100644 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj @@ -156,6 +156,7 @@ + @@ -311,6 +312,14 @@ true true + + true + true + true + true + true + true + true true diff --git a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters index b8c6d712d..652c04172 100644 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters @@ -402,6 +402,9 @@ Source Files + + Source Files + @@ -716,5 +719,8 @@ Source Files + + Source Files + \ 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 3776d2433..469e5c67c 100644 --- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj +++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj @@ -273,6 +273,7 @@ + @@ -408,6 +409,12 @@ true true + + true + true + true + true + true true diff --git a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters index 1f4df44e4..c3c309cd3 100644 --- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters +++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters @@ -372,6 +372,9 @@ Source Files + + Source Files + @@ -674,5 +677,8 @@ Source Files + + Source Files + \ 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 573bc4286..29a7adac6 100644 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj @@ -139,6 +139,7 @@ + @@ -275,6 +276,12 @@ true true + + true + true + true + true + true true diff --git a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters index 907e1bfb7..d96e06e70 100644 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters @@ -381,6 +381,9 @@ Source Files + + Source Files + @@ -686,5 +689,8 @@ Source Files + + Source Files + \ 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 fbcd94b6b..0ad0cc014 100644 --- a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj +++ b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj @@ -175,6 +175,14 @@ true true + + true + true + true + true + true + true + true true @@ -353,6 +361,7 @@ + diff --git a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters index aa539d37e..6ad1ef486 100644 --- a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters +++ b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters @@ -316,6 +316,9 @@ Source Files + + Source Files + @@ -714,6 +717,9 @@ Source Files + + Source Files + diff --git a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj index a56516ead..88093b7e2 100644 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj @@ -153,6 +153,7 @@ + @@ -309,6 +310,14 @@ true true + + true + true + true + true + true + true + true true diff --git a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters index a36811dd4..20f7423cc 100644 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters @@ -393,6 +393,9 @@ Source Files + + Source Files + @@ -710,5 +713,8 @@ Source Files + + Source Files + \ No newline at end of file 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 + + 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 +#include +#include + + +/* 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(); + 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 ^handler = \ + ref new Windows::Foundation::EventHandler(&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 + + 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 4a936df24..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" @@ -177,6 +178,7 @@ WINRT_VideoInit(_THIS) } WINRT_InitMouse(_this); WINRT_InitTouch(_this); + WINRT_InitGameBar(_this); return 0; } @@ -419,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. From ea2a180c905e7956d330846e23144ebfae643117 Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Thu, 25 Aug 2016 22:31:33 +0200 Subject: [PATCH 11/18] Android: Fixed crash if closing removed joystick (thanks, Sylvain!). Fixes fix for Bugzilla #3408. --- src/joystick/android/SDL_sysjoystick.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index 89b816399..4225099c8 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -539,7 +539,9 @@ void SDL_SYS_JoystickClose(SDL_Joystick * joystick) { SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata; - item->joystick = NULL; + if (item) { + item->joystick = NULL; + } } /* Function to perform any system-specific joystick related cleanup */ From 7d1e740ea225970dc5d84ce4ce31c971c31fd77b Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Thu, 25 Aug 2016 22:31:44 +0200 Subject: [PATCH 12/18] Emscripten: Fixed crash if closing removed joystick (thanks, Sylvain!). --- src/joystick/emscripten/SDL_sysjoystick.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/joystick/emscripten/SDL_sysjoystick.c b/src/joystick/emscripten/SDL_sysjoystick.c index c3becd291..c3edf4967 100644 --- a/src/joystick/emscripten/SDL_sysjoystick.c +++ b/src/joystick/emscripten/SDL_sysjoystick.c @@ -378,7 +378,9 @@ void SDL_SYS_JoystickClose(SDL_Joystick * joystick) { SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata; - item->joystick = NULL; + if (item) { + item->joystick = NULL; + } } /* Function to perform any system-specific joystick related cleanup */ From b97a48ebad97640874d7c1698783ed4fcef708fe Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 26 Aug 2016 11:16:44 -0700 Subject: [PATCH 13/18] commit 1170112da3776fdb06425f62d57b63144c33dc51 Author: James Zipperer Date: Sun Aug 21 01:19:19 2016 -0700 bugfix for controller / joystick add / remove being in the event queue at the same time --- src/joystick/SDL_gamecontroller.c | 12 ++++++++++++ src/joystick/linux/SDL_sysjoystick.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 93e6fbfb2..4834bba3a 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -222,7 +222,19 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) SDL_GameController *controllerlist = SDL_gamecontrollers; while (controllerlist) { if (controllerlist->joystick->instance_id == event->jdevice.which) { + SDL_Event peeped; SDL_Event deviceevent; + + /* 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. + */ + if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED) > 0) { + peeped.jdevice.which--; + SDL_PushEvent(&peeped); + } + deviceevent.type = SDL_CONTROLLERDEVICEREMOVED; deviceevent.cdevice.which = event->jdevice.which; SDL_PushEvent(&deviceevent); diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 8c73859ea..421a3bf58 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -295,6 +295,18 @@ MaybeRemoveDevice(const char *path) event.type = SDL_JOYDEVICEREMOVED; if (SDL_GetEventState(event.type) == SDL_ENABLE) { + SDL_Event peeped; + + /* 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. + */ + if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED) > 0) { + peeped.jdevice.which--; + SDL_PushEvent(&peeped); + } + event.jdevice.which = item->device_instance; if ( (SDL_EventOK == NULL) || (*SDL_EventOK) (SDL_EventOKParam, &event) ) { From f98a06ec45c6630c0dac9da48ea3f8bac7c3a21c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 26 Aug 2016 12:18:08 -0700 Subject: [PATCH 14/18] Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved() Updated the removal code to iterate over all joystick add messages instead of just the first one. --- src/joystick/SDL_gamecontroller.c | 42 ++++++++++---- src/joystick/SDL_joystick.c | 65 ++++++++++++++++++++++ src/joystick/SDL_joystick_c.h | 6 +- src/joystick/android/SDL_sysjoystick.c | 34 +---------- src/joystick/darwin/SDL_sysjoystick.c | 35 +----------- src/joystick/emscripten/SDL_sysjoystick.c | 37 ++---------- src/joystick/iphoneos/SDL_sysjoystick.m | 34 +---------- src/joystick/linux/SDL_sysjoystick.c | 49 +--------------- src/joystick/windows/SDL_windowsjoystick.c | 29 +--------- 9 files changed, 114 insertions(+), 217 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 4834bba3a..a312a86ba 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -105,6 +105,35 @@ struct _SDL_GameController int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value); 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 */ @@ -222,22 +251,13 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) SDL_GameController *controllerlist = SDL_gamecontrollers; while (controllerlist) { if (controllerlist->joystick->instance_id == event->jdevice.which) { - SDL_Event peeped; SDL_Event deviceevent; - /* 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. - */ - if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED) > 0) { - peeped.jdevice.which--; - SDL_PushEvent(&peeped); - } - 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 4225099c8..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); diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 2afab337f..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); } @@ -476,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 c3edf4967..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); diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m index c8a42af05..efac5c44b 100644 --- a/src/joystick/iphoneos/SDL_sysjoystick.m +++ b/src/joystick/iphoneos/SDL_sysjoystick.m @@ -32,10 +32,6 @@ #include "../SDL_sysjoystick.h" #include "../SDL_joystick_c.h" -#if !SDL_EVENTS_DISABLED -#include "../../events/SDL_events_c.h" -#endif - #import #ifdef SDL_JOYSTICK_MFI @@ -127,9 +123,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 +165,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 +174,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 +214,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 421a3bf58..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,30 +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) { - SDL_Event peeped; - - /* 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. - */ - if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED) > 0) { - peeped.jdevice.which--; - SDL_PushEvent(&peeped); - } - - 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_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 @@ -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++; From 3d116adb664f6ef56dcc523dfc006cf7ca5d31e3 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 15 Aug 2016 10:09:41 -0400 Subject: [PATCH 15/18] alsa: don't enumerate virtual devices, just physical hardware. --HG-- extra : rebase_source : 1d46508b4063ed81d386fe43c0cdc309d7a9628e --- src/audio/alsa/SDL_alsa_audio.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index 1a84380f2..2b65e13fc 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -714,12 +714,15 @@ ALSA_DetectDevices(void) char *desc = ALSA_snd_device_name_get_hint(hints[i], "DESC"); char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID"); - if ((ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0)) { - add_device(SDL_FALSE, name, desc); - } + /* only want physical hardware interfaces */ + if (SDL_strncmp(name, "hw:", 3) == 0) { + if ((ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0)) { + add_device(SDL_FALSE, name, desc); + } - if ((ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0)) { - add_device(SDL_TRUE, name, desc); + if ((ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0)) { + add_device(SDL_TRUE, name, desc); + } } free(name); From 1255ef83fa13cdcaf3590b15761d55845813e7f3 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 26 Aug 2016 15:46:29 -0400 Subject: [PATCH 16/18] ios: patched to compile. --HG-- extra : rebase_source : 6b3c529e5b6a8db2e011c32de084381c0827b0a9 --- src/joystick/iphoneos/SDL_sysjoystick.m | 1 + 1 file changed, 1 insertion(+) diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m index efac5c44b..b7b3395a9 100644 --- a/src/joystick/iphoneos/SDL_sysjoystick.m +++ b/src/joystick/iphoneos/SDL_sysjoystick.m @@ -26,6 +26,7 @@ /* 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" From 8de6259b93c3f00076c7d4eeb506a15e47070b2f Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 28 Aug 2016 08:50:26 -0700 Subject: [PATCH 17/18] alsa: Implemented hotplug support, cleaned up device names. --- src/audio/alsa/SDL_alsa_audio.c | 217 +++++++++++++++++++++++--------- 1 file changed, 160 insertions(+), 57 deletions(-) diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index 2b65e13fc..2011934ee 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -29,6 +29,7 @@ #include #include +#include "SDL_assert.h" #include "SDL_timer.h" #include "SDL_audio.h" #include "../SDL_audiomem.h" @@ -660,92 +661,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; + char *ptr; - if (!name || !_desc) { - return; /* nothing we can do with this...? */ - } - - 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 SDL_atomic_t ALSA_hotplug_shutdown; +static SDL_Thread *ALSA_hotplug_thread; + +static int SDLCALL +ALSA_HotplugThread(void *arg) +{ + 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); + + devices = seen; /* now we have a known-good list of attached devices. */ + + /* 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); + } + } + + /* 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. */ + } + + /* 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); + } + } + + /* 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_DetectDevices(void) { - 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) { + /* Start the device detection thread here, wait for an initial iteration to complete. */ + SDL_sem *semaphore = SDL_CreateSemaphore(0); + if (!semaphore) { return; /* oh well. */ } - 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"); + SDL_AtomicSet(&ALSA_hotplug_shutdown, 0); - /* only want physical hardware interfaces */ - if (SDL_strncmp(name, "hw:", 3) == 0) { - if ((ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0)) { - add_device(SDL_FALSE, name, desc); - } - - if ((ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0)) { - add_device(SDL_TRUE, name, desc); - } - } - - free(name); - free(desc); - free(ioid); + ALSA_hotplug_thread = SDL_CreateThread(ALSA_HotplugThread, "SDLHotplugALSA", semaphore); + if (ALSA_hotplug_thread) { + SDL_SemWait(semaphore); /* wait for the first iteration to finish. */ } - ALSA_snd_device_name_free_hint(hints); -#else -#error Fill in udev support here. -#endif + SDL_DestroySemaphore(semaphore); } static void -ALSA_FreeDeviceHandle(void *handle) +ALSA_Deinitialize(void) { -#if 1 /*!SDL_USE_LIBUDEV*/ - SDL_free(handle); -#else -#error Fill in udev support here. -#endif -} + 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) @@ -762,7 +866,6 @@ ALSA_Init(SDL_AudioDriverImpl * impl) impl->PlayDevice = ALSA_PlayDevice; impl->CloseDevice = ALSA_CloseDevice; impl->Deinitialize = ALSA_Deinitialize; - impl->FreeDeviceHandle = ALSA_FreeDeviceHandle; return 1; /* this audio target is available. */ } From 74eda003eee85913650fe87a712657aa2748f51c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 28 Aug 2016 11:56:11 -0400 Subject: [PATCH 18/18] Patched to compile. --- src/audio/alsa/SDL_alsa_audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index 2011934ee..12de104e2 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -804,7 +804,7 @@ ALSA_HotplugThread(void *arg) /* 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)) + while (!SDL_AtomicGet(&ALSA_hotplug_shutdown) && !SDL_TICKS_PASSED(SDL_GetTicks(), ticks)) { SDL_Delay(100); } }