Skip to content

Commit

Permalink
dinput: Add SDL support
Browse files Browse the repository at this point in the history
v2: Include comments from Andrew including opening and closing devices more cleanly
Signed-off-by: Aric Stewart <[email protected]>
(cherry picked from commit f0aaf2dbacb307d64f078d5e39588fc53c74afb1)
  • Loading branch information
AricStewart authored and aeikum committed Apr 30, 2018
1 parent 4472d7e commit 045f32e
Show file tree
Hide file tree
Showing 4 changed files with 736 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dlls/dinput/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
MODULE = dinput.dll
IMPORTLIB = dinput
IMPORTS = dxguid uuid comctl32 ole32 user32 advapi32
EXTRALIBS = $(IOKIT_LIBS) $(FORCEFEEDBACK_LIBS)
EXTRALIBS = $(IOKIT_LIBS) $(FORCEFEEDBACK_LIBS) $(SDL_LIBS)
EXTRAINCL = $(SDL_CFLAGS)

C_SRCS = \
config.c \
Expand All @@ -13,6 +14,7 @@ C_SRCS = \
joystick_linux.c \
joystick_linuxinput.c \
joystick_osx.c \
joystick_sdl.c \
keyboard.c \
mouse.c

Expand Down
21 changes: 21 additions & 0 deletions dlls/dinput/dinput_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static const struct dinput_device *dinput_devices[] =
{
&mouse_device,
&keyboard_device,
&joystick_sdl_device,
&joystick_linuxinput_device,
&joystick_linux_device,
&joystick_osx_device
Expand Down Expand Up @@ -395,6 +396,7 @@ static HRESULT WINAPI IDirectInputAImpl_EnumDevices(
unsigned int i;
int j;
HRESULT r;
BOOL found_device = FALSE;

TRACE("(this=%p,0x%04x '%s',%p,%p,0x%04x)\n",
This, dwDevType, _dump_DIDEVTYPE_value(dwDevType, This->dwVersion),
Expand All @@ -416,9 +418,15 @@ static HRESULT WINAPI IDirectInputAImpl_EnumDevices(
TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name);
r = dinput_devices[i]->enum_deviceA(dwDevType, dwFlags, &devInstance, This->dwVersion, j);
if (r == S_OK)
{
found_device = TRUE;
if (enum_callback_wrapper(lpCallback, &devInstance, pvRef) == DIENUM_STOP)
return S_OK;
}
}
/* If we have found devices after SDL stop enumeration */
if (dinput_devices[i] == &joystick_sdl_device && found_device)
return S_OK;
}

return S_OK;
Expand All @@ -435,6 +443,7 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
unsigned int i;
int j;
HRESULT r;
BOOL found_device = FALSE;

TRACE("(this=%p,0x%04x '%s',%p,%p,0x%04x)\n",
This, dwDevType, _dump_DIDEVTYPE_value(dwDevType, This->dwVersion),
Expand All @@ -456,9 +465,15 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name);
r = dinput_devices[i]->enum_deviceW(dwDevType, dwFlags, &devInstance, This->dwVersion, j);
if (r == S_OK)
{
found_device = TRUE;
if (enum_callback_wrapper(lpCallback, &devInstance, pvRef) == DIENUM_STOP)
return S_OK;
}
}
/* If we have found devices after SDL stop enumeration */
if (dinput_devices[i] == &joystick_sdl_device && found_device)
return S_OK;
}

return S_OK;
Expand Down Expand Up @@ -1028,6 +1043,9 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics(
didevis[device_count-1] = didevi;
}
}
/* If we have found devices after SDL stop enumeration */
if (dinput_devices[i] == &joystick_sdl_device && device_count)
return S_OK;
}

remain = device_count;
Expand Down Expand Up @@ -1129,6 +1147,9 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
didevis[device_count-1] = didevi;
}
}
/* If we have found devices after SDL stop enumeration */
if (dinput_devices[i] == &joystick_sdl_device && device_count)
return S_OK;
}

remain = device_count;
Expand Down
1 change: 1 addition & 0 deletions dlls/dinput/dinput_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern const struct dinput_device keyboard_device DECLSPEC_HIDDEN;
extern const struct dinput_device joystick_linux_device DECLSPEC_HIDDEN;
extern const struct dinput_device joystick_linuxinput_device DECLSPEC_HIDDEN;
extern const struct dinput_device joystick_osx_device DECLSPEC_HIDDEN;
extern const struct dinput_device joystick_sdl_device DECLSPEC_HIDDEN;

extern void check_dinput_hooks(LPDIRECTINPUTDEVICE8W) DECLSPEC_HIDDEN;
extern void check_dinput_events(void) DECLSPEC_HIDDEN;
Expand Down
Loading

0 comments on commit 045f32e

Please sign in to comment.