winebus.sys: Move SDL mapping loading to a separate helper.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-08-13 09:46:18 +02:00 committed by Alexandre Julliard
parent 90b8a97237
commit a67ac02dc3
1 changed files with 52 additions and 51 deletions

View File

@ -862,23 +862,8 @@ static void process_device_event(SDL_Event *event)
set_mapped_report_from_event(event);
}
static DWORD CALLBACK deviceloop_thread(void *args)
static void sdl_load_mappings(void)
{
HANDLE init_done = args;
SDL_Event event;
if (pSDL_Init(SDL_INIT_GAMECONTROLLER|SDL_INIT_HAPTIC) < 0)
{
ERR("Can't init SDL: %s\n", pSDL_GetError());
return STATUS_UNSUCCESSFUL;
}
pSDL_JoystickEventState(SDL_ENABLE);
pSDL_GameControllerEventState(SDL_ENABLE);
/* Process mappings */
if (pSDL_GameControllerAddMapping != NULL)
{
HKEY key;
static const WCHAR szPath[] = {'m','a','p',0};
const char *mapping;
@ -896,7 +881,8 @@ static DWORD CALLBACK deviceloop_thread(void *args)
DWORD buffer_len = 0;
LSTATUS rc;
do {
do
{
CHAR name[255];
DWORD name_len;
DWORD type;
@ -906,10 +892,8 @@ static DWORD CALLBACK deviceloop_thread(void *args)
rc = RegEnumValueA(key, index, name, &name_len, NULL, &type, (LPBYTE)buffer, &data_len);
if (rc == ERROR_MORE_DATA || buffer == NULL)
{
if (buffer)
buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, data_len);
else
buffer = HeapAlloc(GetProcessHeap(), 0, data_len);
if (buffer) buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, data_len);
else buffer = HeapAlloc(GetProcessHeap(), 0, data_len);
buffer_len = data_len;
name_len = sizeof(name);
@ -921,14 +905,31 @@ static DWORD CALLBACK deviceloop_thread(void *args)
TRACE("Setting registry mapping %s\n", debugstr_a(buffer));
if (pSDL_GameControllerAddMapping(buffer) < 0)
WARN("Failed to add registry mapping %s\n", pSDL_GetError());
index ++;
index++;
}
} while (rc == STATUS_SUCCESS);
HeapFree(GetProcessHeap(), 0, buffer);
NtClose(key);
}
}
static DWORD CALLBACK deviceloop_thread(void *args)
{
HANDLE init_done = args;
SDL_Event event;
if (pSDL_Init(SDL_INIT_GAMECONTROLLER|SDL_INIT_HAPTIC) < 0)
{
ERR("Can't init SDL: %s\n", pSDL_GetError());
return STATUS_UNSUCCESSFUL;
}
pSDL_JoystickEventState(SDL_ENABLE);
pSDL_GameControllerEventState(SDL_ENABLE);
/* Process mappings */
if (pSDL_GameControllerAddMapping != NULL) sdl_load_mappings();
SetEvent(init_done);
while (1) {