2018-02-21 13:55:13 +01:00
|
|
|
/*
|
|
|
|
* Plug and Play support for hid devices found through SDL2
|
|
|
|
*
|
|
|
|
* Copyright 2017 CodeWeavers, Aric Stewart
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-09-17 08:50:31 +02:00
|
|
|
#if 0
|
|
|
|
#pragma makedep unix
|
|
|
|
#endif
|
|
|
|
|
2018-02-21 13:55:13 +01:00
|
|
|
#include "config.h"
|
2021-11-03 10:43:50 +01:00
|
|
|
|
2018-02-21 13:55:13 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
2021-11-03 10:43:50 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dlfcn.h>
|
2020-12-02 21:31:15 +01:00
|
|
|
#ifdef HAVE_SDL_H
|
|
|
|
# include <SDL.h>
|
2018-02-21 13:55:50 +01:00
|
|
|
#endif
|
2018-02-21 13:55:13 +01:00
|
|
|
|
2021-09-17 08:50:33 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2018-02-21 13:55:13 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
2019-03-20 14:28:43 +01:00
|
|
|
#include "winreg.h"
|
2018-02-21 13:55:13 +01:00
|
|
|
#include "winternl.h"
|
|
|
|
#include "ddk/wdm.h"
|
2018-02-21 13:55:50 +01:00
|
|
|
#include "ddk/hidtypes.h"
|
2021-09-23 08:55:28 +02:00
|
|
|
#include "ddk/hidsdi.h"
|
2018-02-21 13:55:50 +01:00
|
|
|
#include "hidusage.h"
|
|
|
|
|
2021-10-01 09:31:07 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/hid.h"
|
2021-10-05 10:55:50 +02:00
|
|
|
#include "wine/unixlib.h"
|
2021-10-01 09:31:07 +02:00
|
|
|
|
2021-08-23 10:49:39 +02:00
|
|
|
#include "unix_private.h"
|
2018-02-21 13:55:13 +01:00
|
|
|
|
2021-11-09 09:51:08 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(hid);
|
2018-02-21 13:55:13 +01:00
|
|
|
|
|
|
|
#ifdef SONAME_LIBSDL2
|
|
|
|
|
2021-09-17 08:50:33 +02:00
|
|
|
static pthread_mutex_t sdl_cs = PTHREAD_MUTEX_INITIALIZER;
|
2021-08-23 10:49:40 +02:00
|
|
|
static struct sdl_bus_options options;
|
2018-02-21 13:57:05 +01:00
|
|
|
|
2018-02-21 13:55:50 +01:00
|
|
|
static void *sdl_handle = NULL;
|
2019-09-27 12:37:52 +02:00
|
|
|
static UINT quit_event = -1;
|
2021-08-30 11:22:52 +02:00
|
|
|
static struct list event_queue = LIST_INIT(event_queue);
|
2021-09-15 09:04:41 +02:00
|
|
|
static struct list device_list = LIST_INIT(device_list);
|
2018-02-21 13:55:50 +01:00
|
|
|
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL
|
|
|
|
MAKE_FUNCPTR(SDL_GetError);
|
|
|
|
MAKE_FUNCPTR(SDL_Init);
|
2019-06-11 17:29:14 +02:00
|
|
|
MAKE_FUNCPTR(SDL_JoystickClose);
|
2018-02-21 13:55:50 +01:00
|
|
|
MAKE_FUNCPTR(SDL_JoystickEventState);
|
|
|
|
MAKE_FUNCPTR(SDL_JoystickGetGUID);
|
|
|
|
MAKE_FUNCPTR(SDL_JoystickGetGUIDString);
|
|
|
|
MAKE_FUNCPTR(SDL_JoystickInstanceID);
|
|
|
|
MAKE_FUNCPTR(SDL_JoystickName);
|
|
|
|
MAKE_FUNCPTR(SDL_JoystickNumAxes);
|
|
|
|
MAKE_FUNCPTR(SDL_JoystickOpen);
|
2021-12-02 10:47:48 +01:00
|
|
|
MAKE_FUNCPTR(SDL_WaitEventTimeout);
|
2018-02-21 13:56:31 +01:00
|
|
|
MAKE_FUNCPTR(SDL_JoystickNumButtons);
|
|
|
|
MAKE_FUNCPTR(SDL_JoystickNumBalls);
|
|
|
|
MAKE_FUNCPTR(SDL_JoystickNumHats);
|
2018-02-21 13:56:46 +01:00
|
|
|
MAKE_FUNCPTR(SDL_JoystickGetAxis);
|
|
|
|
MAKE_FUNCPTR(SDL_JoystickGetHat);
|
2018-02-21 13:57:05 +01:00
|
|
|
MAKE_FUNCPTR(SDL_IsGameController);
|
2019-06-11 17:29:14 +02:00
|
|
|
MAKE_FUNCPTR(SDL_GameControllerClose);
|
2018-02-21 13:57:05 +01:00
|
|
|
MAKE_FUNCPTR(SDL_GameControllerGetAxis);
|
2019-05-07 16:01:43 +02:00
|
|
|
MAKE_FUNCPTR(SDL_GameControllerGetButton);
|
2018-02-21 13:57:05 +01:00
|
|
|
MAKE_FUNCPTR(SDL_GameControllerName);
|
|
|
|
MAKE_FUNCPTR(SDL_GameControllerOpen);
|
|
|
|
MAKE_FUNCPTR(SDL_GameControllerEventState);
|
2018-02-21 13:57:18 +01:00
|
|
|
MAKE_FUNCPTR(SDL_HapticClose);
|
|
|
|
MAKE_FUNCPTR(SDL_HapticDestroyEffect);
|
2021-12-02 10:47:48 +01:00
|
|
|
MAKE_FUNCPTR(SDL_HapticGetEffectStatus);
|
2018-02-21 13:57:18 +01:00
|
|
|
MAKE_FUNCPTR(SDL_HapticNewEffect);
|
|
|
|
MAKE_FUNCPTR(SDL_HapticOpenFromJoystick);
|
2021-10-01 09:31:07 +02:00
|
|
|
MAKE_FUNCPTR(SDL_HapticPause);
|
2018-02-21 13:57:18 +01:00
|
|
|
MAKE_FUNCPTR(SDL_HapticQuery);
|
|
|
|
MAKE_FUNCPTR(SDL_HapticRumbleInit);
|
|
|
|
MAKE_FUNCPTR(SDL_HapticRumblePlay);
|
2022-02-14 17:26:18 +01:00
|
|
|
MAKE_FUNCPTR(SDL_HapticRumbleStop);
|
2018-02-21 13:57:18 +01:00
|
|
|
MAKE_FUNCPTR(SDL_HapticRumbleSupported);
|
|
|
|
MAKE_FUNCPTR(SDL_HapticRunEffect);
|
2021-10-01 09:31:07 +02:00
|
|
|
MAKE_FUNCPTR(SDL_HapticSetGain);
|
2018-02-21 13:57:18 +01:00
|
|
|
MAKE_FUNCPTR(SDL_HapticStopAll);
|
2021-10-04 09:51:33 +02:00
|
|
|
MAKE_FUNCPTR(SDL_HapticStopEffect);
|
2021-10-01 09:31:07 +02:00
|
|
|
MAKE_FUNCPTR(SDL_HapticUnpause);
|
2021-10-05 08:43:24 +02:00
|
|
|
MAKE_FUNCPTR(SDL_HapticUpdateEffect);
|
2018-02-21 13:57:18 +01:00
|
|
|
MAKE_FUNCPTR(SDL_JoystickIsHaptic);
|
2019-03-20 14:28:43 +01:00
|
|
|
MAKE_FUNCPTR(SDL_GameControllerAddMapping);
|
2019-09-27 12:37:52 +02:00
|
|
|
MAKE_FUNCPTR(SDL_RegisterEvents);
|
|
|
|
MAKE_FUNCPTR(SDL_PushEvent);
|
2021-12-02 10:47:48 +01:00
|
|
|
MAKE_FUNCPTR(SDL_GetTicks);
|
2021-09-24 11:51:52 +02:00
|
|
|
static int (*pSDL_JoystickRumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
|
2018-02-21 13:55:50 +01:00
|
|
|
static Uint16 (*pSDL_JoystickGetProduct)(SDL_Joystick * joystick);
|
|
|
|
static Uint16 (*pSDL_JoystickGetProductVersion)(SDL_Joystick * joystick);
|
|
|
|
static Uint16 (*pSDL_JoystickGetVendor)(SDL_Joystick * joystick);
|
|
|
|
|
2021-09-23 08:55:29 +02:00
|
|
|
/* internal bits for extended rumble support, SDL_Haptic types are 16-bits */
|
|
|
|
#define WINE_SDL_JOYSTICK_RUMBLE 0x40000000 /* using SDL_JoystickRumble API */
|
|
|
|
#define WINE_SDL_HAPTIC_RUMBLE 0x80000000 /* using SDL_HapticRumble API */
|
|
|
|
|
|
|
|
#define EFFECT_SUPPORT_HAPTICS (SDL_HAPTIC_LEFTRIGHT|WINE_SDL_HAPTIC_RUMBLE|WINE_SDL_JOYSTICK_RUMBLE)
|
2021-10-01 09:31:00 +02:00
|
|
|
#define EFFECT_SUPPORT_PHYSICAL (SDL_HAPTIC_CONSTANT|SDL_HAPTIC_RAMP|SDL_HAPTIC_SINE|SDL_HAPTIC_TRIANGLE| \
|
|
|
|
SDL_HAPTIC_SAWTOOTHUP|SDL_HAPTIC_SAWTOOTHDOWN|SDL_HAPTIC_SPRING|SDL_HAPTIC_DAMPER|SDL_HAPTIC_INERTIA| \
|
|
|
|
SDL_HAPTIC_FRICTION|SDL_HAPTIC_CUSTOM)
|
2021-09-23 08:55:29 +02:00
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
struct sdl_device
|
2018-02-21 13:55:50 +01:00
|
|
|
{
|
2021-08-23 10:49:41 +02:00
|
|
|
struct unix_device unix_device;
|
|
|
|
|
2018-02-21 13:55:50 +01:00
|
|
|
SDL_Joystick *sdl_joystick;
|
2018-02-21 13:57:05 +01:00
|
|
|
SDL_GameController *sdl_controller;
|
2018-02-21 13:55:50 +01:00
|
|
|
SDL_JoystickID id;
|
2018-02-21 13:56:31 +01:00
|
|
|
|
2021-09-23 08:55:29 +02:00
|
|
|
DWORD effect_support;
|
2018-02-21 13:57:18 +01:00
|
|
|
SDL_Haptic *sdl_haptic;
|
|
|
|
int haptic_effect_id;
|
2021-10-01 09:31:07 +02:00
|
|
|
int effect_ids[256];
|
2021-12-02 10:47:48 +01:00
|
|
|
int effect_state[256];
|
|
|
|
LONG effect_flags;
|
2018-02-21 13:55:50 +01:00
|
|
|
};
|
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
static inline struct sdl_device *impl_from_unix_device(struct unix_device *iface)
|
2021-08-23 10:49:41 +02:00
|
|
|
{
|
2021-09-22 10:30:39 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct sdl_device, unix_device);
|
2021-08-23 10:49:41 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
static struct sdl_device *find_device_from_id(SDL_JoystickID id)
|
2018-02-21 13:55:50 +01:00
|
|
|
{
|
2021-09-22 10:30:39 +02:00
|
|
|
struct sdl_device *impl;
|
2021-09-15 09:04:41 +02:00
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(impl, &device_list, struct sdl_device, unix_device.entry)
|
|
|
|
if (impl->id == id) return impl;
|
2021-09-15 09:04:41 +02:00
|
|
|
|
|
|
|
return NULL;
|
2018-02-21 13:55:50 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 08:55:27 +02:00
|
|
|
static void set_hat_value(struct unix_device *iface, int index, int value)
|
2018-02-21 13:56:46 +01:00
|
|
|
{
|
2021-09-23 08:55:27 +02:00
|
|
|
LONG x = 0, y = 0;
|
2018-02-21 13:56:46 +01:00
|
|
|
switch (value)
|
|
|
|
{
|
2021-09-23 08:55:27 +02:00
|
|
|
case SDL_HAT_CENTERED: break;
|
2021-10-15 13:17:40 +02:00
|
|
|
case SDL_HAT_DOWN: y = 1; break;
|
|
|
|
case SDL_HAT_RIGHTDOWN: y = x = 1; break;
|
2021-09-23 08:55:27 +02:00
|
|
|
case SDL_HAT_RIGHT: x = 1; break;
|
2021-10-15 13:17:40 +02:00
|
|
|
case SDL_HAT_RIGHTUP: x = 1; y = -1; break;
|
|
|
|
case SDL_HAT_UP: y = -1; break;
|
|
|
|
case SDL_HAT_LEFTUP: x = y = -1; break;
|
2021-09-23 08:55:27 +02:00
|
|
|
case SDL_HAT_LEFT: x = -1; break;
|
2021-10-15 13:17:40 +02:00
|
|
|
case SDL_HAT_LEFTDOWN: x = -1; y = 1; break;
|
2019-05-07 16:02:22 +02:00
|
|
|
}
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_hatswitch_x(iface, index, x);
|
|
|
|
hid_device_set_hatswitch_y(iface, index, y);
|
2018-02-21 13:56:46 +01:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
static BOOL descriptor_add_haptic(struct sdl_device *impl)
|
2018-02-21 13:57:18 +01:00
|
|
|
{
|
2021-10-05 08:43:22 +02:00
|
|
|
USHORT i, count = 0;
|
|
|
|
USAGE usages[16];
|
2021-10-01 09:31:07 +02:00
|
|
|
|
2021-09-23 08:55:29 +02:00
|
|
|
if (!pSDL_JoystickIsHaptic(impl->sdl_joystick) ||
|
|
|
|
!(impl->sdl_haptic = pSDL_HapticOpenFromJoystick(impl->sdl_joystick)))
|
|
|
|
impl->effect_support = 0;
|
|
|
|
else
|
2018-02-21 13:57:18 +01:00
|
|
|
{
|
2021-10-01 09:31:00 +02:00
|
|
|
impl->effect_support = pSDL_HapticQuery(impl->sdl_haptic);
|
2022-02-14 17:26:16 +01:00
|
|
|
if (!(impl->effect_support & EFFECT_SUPPORT_HAPTICS) &&
|
|
|
|
pSDL_HapticRumbleSupported(impl->sdl_haptic) &&
|
|
|
|
pSDL_HapticRumbleInit(impl->sdl_haptic) == 0)
|
2021-09-23 08:55:29 +02:00
|
|
|
impl->effect_support |= WINE_SDL_HAPTIC_RUMBLE;
|
2018-02-21 13:57:18 +01:00
|
|
|
}
|
|
|
|
|
2021-10-18 17:16:44 +02:00
|
|
|
if (!(impl->effect_support & EFFECT_SUPPORT_HAPTICS) && pSDL_JoystickRumble &&
|
|
|
|
!pSDL_JoystickRumble(impl->sdl_joystick, 0, 0, 0))
|
2021-09-23 08:55:29 +02:00
|
|
|
impl->effect_support |= WINE_SDL_JOYSTICK_RUMBLE;
|
|
|
|
|
|
|
|
if (impl->effect_support & EFFECT_SUPPORT_HAPTICS)
|
|
|
|
{
|
2021-09-23 08:55:30 +02:00
|
|
|
if (!hid_device_add_haptics(&impl->unix_device))
|
2021-09-23 08:55:29 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-01 09:31:00 +02:00
|
|
|
if ((impl->effect_support & EFFECT_SUPPORT_PHYSICAL))
|
|
|
|
{
|
2021-10-05 08:43:22 +02:00
|
|
|
/* SDL_HAPTIC_SQUARE doesn't exist */
|
|
|
|
if (impl->effect_support & SDL_HAPTIC_SINE) usages[count++] = PID_USAGE_ET_SINE;
|
|
|
|
if (impl->effect_support & SDL_HAPTIC_TRIANGLE) usages[count++] = PID_USAGE_ET_TRIANGLE;
|
|
|
|
if (impl->effect_support & SDL_HAPTIC_SAWTOOTHUP) usages[count++] = PID_USAGE_ET_SAWTOOTH_UP;
|
|
|
|
if (impl->effect_support & SDL_HAPTIC_SAWTOOTHDOWN) usages[count++] = PID_USAGE_ET_SAWTOOTH_DOWN;
|
2021-10-08 09:50:24 +02:00
|
|
|
if (impl->effect_support & SDL_HAPTIC_SPRING) usages[count++] = PID_USAGE_ET_SPRING;
|
|
|
|
if (impl->effect_support & SDL_HAPTIC_DAMPER) usages[count++] = PID_USAGE_ET_DAMPER;
|
|
|
|
if (impl->effect_support & SDL_HAPTIC_INERTIA) usages[count++] = PID_USAGE_ET_INERTIA;
|
|
|
|
if (impl->effect_support & SDL_HAPTIC_FRICTION) usages[count++] = PID_USAGE_ET_FRICTION;
|
2021-10-08 09:50:26 +02:00
|
|
|
if (impl->effect_support & SDL_HAPTIC_CONSTANT) usages[count++] = PID_USAGE_ET_CONSTANT_FORCE;
|
2021-10-08 09:50:28 +02:00
|
|
|
if (impl->effect_support & SDL_HAPTIC_RAMP) usages[count++] = PID_USAGE_ET_RAMP;
|
2021-10-05 08:43:22 +02:00
|
|
|
|
|
|
|
if (!hid_device_add_physical(&impl->unix_device, usages, count))
|
2021-10-01 09:31:00 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-09-23 08:55:29 +02:00
|
|
|
impl->haptic_effect_id = -1;
|
2021-10-01 09:31:07 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(impl->effect_ids); ++i) impl->effect_ids[i] = -1;
|
2021-08-12 10:26:58 +02:00
|
|
|
return TRUE;
|
2018-02-21 13:57:18 +01:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
static NTSTATUS build_joystick_report_descriptor(struct unix_device *iface)
|
2018-02-21 13:56:31 +01:00
|
|
|
{
|
2021-10-21 10:27:43 +02:00
|
|
|
static const USAGE_AND_PAGE absolute_usages[] =
|
2021-09-21 08:36:43 +02:00
|
|
|
{
|
2021-10-21 10:27:43 +02:00
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_X},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_Y},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_Z},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_RX},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_RY},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_RZ},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_SIMULATION, .Usage = HID_USAGE_SIMULATION_THROTTLE},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_SIMULATION, .Usage = HID_USAGE_SIMULATION_RUDDER},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_WHEEL},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_SIMULATION, .Usage = HID_USAGE_SIMULATION_ACCELERATOR},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_SIMULATION, .Usage = HID_USAGE_SIMULATION_BRAKE},
|
|
|
|
};
|
|
|
|
static const USAGE_AND_PAGE relative_usages[] =
|
|
|
|
{
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_X},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_Y},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_RX},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_RY},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_Z},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_RZ},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_SLIDER},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_DIAL},
|
|
|
|
{.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_WHEEL},
|
2021-09-21 08:36:43 +02:00
|
|
|
};
|
2021-09-22 10:30:42 +02:00
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
2021-09-22 10:30:44 +02:00
|
|
|
int i, button_count, axis_count, ball_count, hat_count;
|
2018-02-21 13:56:31 +01:00
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
axis_count = pSDL_JoystickNumAxes(impl->sdl_joystick);
|
2021-10-21 10:27:43 +02:00
|
|
|
if (axis_count > ARRAY_SIZE(absolute_usages))
|
2018-02-21 13:56:31 +01:00
|
|
|
{
|
2021-10-21 10:27:43 +02:00
|
|
|
FIXME("More than %zu absolute axes found, ignoring.\n", ARRAY_SIZE(absolute_usages));
|
|
|
|
axis_count = ARRAY_SIZE(absolute_usages);
|
2018-02-21 13:56:31 +01:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
ball_count = pSDL_JoystickNumBalls(impl->sdl_joystick);
|
2021-10-21 10:27:43 +02:00
|
|
|
if (ball_count > ARRAY_SIZE(relative_usages) / 2)
|
2018-02-21 13:56:31 +01:00
|
|
|
{
|
2021-10-21 10:27:43 +02:00
|
|
|
FIXME("More than %zu relative axes found, ignoring.\n", ARRAY_SIZE(relative_usages));
|
|
|
|
ball_count = ARRAY_SIZE(relative_usages) / 2;
|
2018-02-21 13:56:31 +01:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
hat_count = pSDL_JoystickNumHats(impl->sdl_joystick);
|
|
|
|
button_count = pSDL_JoystickNumButtons(impl->sdl_joystick);
|
2018-02-21 13:56:31 +01:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_JOYSTICK))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2018-02-21 13:56:31 +01:00
|
|
|
|
2021-09-23 08:55:28 +02:00
|
|
|
if (!hid_device_begin_input_report(iface))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2021-10-21 10:27:43 +02:00
|
|
|
for (i = 0; i < axis_count; i++)
|
|
|
|
{
|
|
|
|
if (!hid_device_add_axes(iface, 1, absolute_usages[i].UsagePage,
|
|
|
|
&absolute_usages[i].Usage, FALSE, -32768, 32767))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
2018-02-21 13:56:31 +01:00
|
|
|
|
2021-10-21 10:27:43 +02:00
|
|
|
for (i = 0; i < ball_count; i++)
|
|
|
|
{
|
|
|
|
if (!hid_device_add_axes(iface, 2, relative_usages[2 * i].UsagePage,
|
|
|
|
&relative_usages[2 * i].Usage, TRUE, INT32_MIN, INT32_MAX))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
2018-02-21 13:56:31 +01:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (hat_count && !hid_device_add_hatswitch(iface, hat_count))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (button_count && !hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, button_count))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-23 08:55:28 +02:00
|
|
|
if (!hid_device_end_input_report(iface))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
if (!descriptor_add_haptic(impl))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_end_report_descriptor(iface))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2018-02-21 13:56:46 +01:00
|
|
|
/* Initialize axis in the report */
|
|
|
|
for (i = 0; i < axis_count; i++)
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_abs_axis(iface, i, pSDL_JoystickGetAxis(impl->sdl_joystick, i));
|
2018-02-21 13:56:46 +01:00
|
|
|
for (i = 0; i < hat_count; i++)
|
2021-09-23 08:55:27 +02:00
|
|
|
set_hat_value(iface, i, pSDL_JoystickGetHat(impl->sdl_joystick, i));
|
2018-02-21 13:56:31 +01:00
|
|
|
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_SUCCESS;
|
2018-02-21 13:56:31 +01:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
static NTSTATUS build_controller_report_descriptor(struct unix_device *iface)
|
2018-02-21 13:57:05 +01:00
|
|
|
{
|
2021-08-12 10:26:58 +02:00
|
|
|
static const USAGE left_axis_usages[] = {HID_USAGE_GENERIC_X, HID_USAGE_GENERIC_Y};
|
|
|
|
static const USAGE right_axis_usages[] = {HID_USAGE_GENERIC_RX, HID_USAGE_GENERIC_RY};
|
|
|
|
static const USAGE trigger_axis_usages[] = {HID_USAGE_GENERIC_Z, HID_USAGE_GENERIC_RZ};
|
2021-09-22 10:30:42 +02:00
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
2021-09-21 08:36:44 +02:00
|
|
|
ULONG i, button_count = SDL_CONTROLLER_BUTTON_MAX - 1;
|
|
|
|
C_ASSERT(SDL_CONTROLLER_AXIS_MAX == 6);
|
2019-05-20 17:31:06 +02:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_GAMEPAD))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-23 08:55:28 +02:00
|
|
|
if (!hid_device_begin_input_report(iface))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages,
|
|
|
|
FALSE, -32768, 32767))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages,
|
|
|
|
FALSE, -32768, 32767))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages,
|
|
|
|
FALSE, 0, 32767))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_add_hatswitch(iface, 1))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, button_count))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-23 08:55:28 +02:00
|
|
|
if (!hid_device_end_input_report(iface))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
if (!descriptor_add_haptic(impl))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!hid_device_end_report_descriptor(iface))
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2021-08-12 10:26:58 +02:00
|
|
|
|
2018-02-21 13:57:05 +01:00
|
|
|
/* Initialize axis in the report */
|
|
|
|
for (i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++)
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_abs_axis(iface, i, pSDL_GameControllerGetAxis(impl->sdl_controller, i));
|
|
|
|
if (pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_UP))
|
|
|
|
hid_device_set_hatswitch_y(iface, 0, -1);
|
|
|
|
if (pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN))
|
|
|
|
hid_device_set_hatswitch_y(iface, 0, +1);
|
|
|
|
if (pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT))
|
|
|
|
hid_device_set_hatswitch_x(iface, 0, -1);
|
|
|
|
if (pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT))
|
|
|
|
hid_device_set_hatswitch_x(iface, 0, +1);
|
2019-05-07 16:01:43 +02:00
|
|
|
|
2021-08-16 08:56:26 +02:00
|
|
|
return STATUS_SUCCESS;
|
2018-02-21 13:57:05 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:49 +02:00
|
|
|
static void sdl_device_destroy(struct unix_device *iface)
|
2021-04-15 06:22:04 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-15 09:04:46 +02:00
|
|
|
static NTSTATUS sdl_device_start(struct unix_device *iface)
|
2021-08-18 09:14:18 +02:00
|
|
|
{
|
2021-09-22 10:30:39 +02:00
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
2021-09-22 10:30:42 +02:00
|
|
|
if (impl->sdl_controller) return build_controller_report_descriptor(iface);
|
|
|
|
return build_joystick_report_descriptor(iface);
|
2021-08-18 09:14:18 +02:00
|
|
|
}
|
|
|
|
|
2021-09-14 08:58:21 +02:00
|
|
|
static void sdl_device_stop(struct unix_device *iface)
|
|
|
|
{
|
2021-09-22 10:30:39 +02:00
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
2021-09-14 08:58:21 +02:00
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
pSDL_JoystickClose(impl->sdl_joystick);
|
|
|
|
if (impl->sdl_controller) pSDL_GameControllerClose(impl->sdl_controller);
|
|
|
|
if (impl->sdl_haptic) pSDL_HapticClose(impl->sdl_haptic);
|
2021-09-15 09:04:41 +02:00
|
|
|
|
2021-09-17 08:50:33 +02:00
|
|
|
pthread_mutex_lock(&sdl_cs);
|
2021-09-22 10:30:39 +02:00
|
|
|
list_remove(&impl->unix_device.entry);
|
2021-09-17 08:50:33 +02:00
|
|
|
pthread_mutex_unlock(&sdl_cs);
|
2021-09-14 08:58:21 +02:00
|
|
|
}
|
|
|
|
|
2022-02-16 09:26:56 +01:00
|
|
|
static NTSTATUS sdl_device_haptics_start(struct unix_device *iface, UINT duration_ms,
|
|
|
|
USHORT rumble_intensity, USHORT buzz_intensity)
|
2018-02-21 13:55:50 +01:00
|
|
|
{
|
2021-09-22 10:30:39 +02:00
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
2021-09-23 08:55:29 +02:00
|
|
|
SDL_HapticEffect effect;
|
2018-02-21 13:57:18 +01:00
|
|
|
|
2021-09-23 08:55:30 +02:00
|
|
|
TRACE("iface %p, duration_ms %u, rumble_intensity %u, buzz_intensity %u.\n", iface, duration_ms,
|
|
|
|
rumble_intensity, buzz_intensity);
|
2018-02-21 13:57:18 +01:00
|
|
|
|
2021-09-23 08:55:30 +02:00
|
|
|
if (!(impl->effect_support & EFFECT_SUPPORT_HAPTICS)) return STATUS_NOT_SUPPORTED;
|
2021-08-18 09:14:22 +02:00
|
|
|
|
2021-09-23 08:55:30 +02:00
|
|
|
memset(&effect, 0, sizeof(SDL_HapticEffect));
|
|
|
|
effect.type = SDL_HAPTIC_LEFTRIGHT;
|
|
|
|
effect.leftright.length = duration_ms;
|
|
|
|
effect.leftright.large_magnitude = rumble_intensity;
|
|
|
|
effect.leftright.small_magnitude = buzz_intensity;
|
2021-09-23 08:55:29 +02:00
|
|
|
|
|
|
|
if (impl->effect_support & SDL_HAPTIC_LEFTRIGHT)
|
|
|
|
{
|
|
|
|
if (impl->haptic_effect_id >= 0)
|
|
|
|
pSDL_HapticDestroyEffect(impl->sdl_haptic, impl->haptic_effect_id);
|
|
|
|
impl->haptic_effect_id = pSDL_HapticNewEffect(impl->sdl_haptic, &effect);
|
|
|
|
if (impl->haptic_effect_id >= 0)
|
|
|
|
pSDL_HapticRunEffect(impl->sdl_haptic, impl->haptic_effect_id, 1);
|
|
|
|
}
|
|
|
|
else if (impl->effect_support & WINE_SDL_HAPTIC_RUMBLE)
|
|
|
|
{
|
|
|
|
float magnitude = (effect.leftright.large_magnitude + effect.leftright.small_magnitude) / 2.0 / 32767.0;
|
|
|
|
pSDL_HapticRumblePlay(impl->sdl_haptic, magnitude, effect.leftright.length);
|
|
|
|
}
|
|
|
|
else if (impl->effect_support & WINE_SDL_JOYSTICK_RUMBLE)
|
|
|
|
{
|
|
|
|
pSDL_JoystickRumble(impl->sdl_joystick, effect.leftright.large_magnitude,
|
2021-10-18 17:16:44 +02:00
|
|
|
effect.leftright.small_magnitude, duration_ms);
|
2018-02-21 13:57:18 +01:00
|
|
|
}
|
2018-02-21 13:55:50 +01:00
|
|
|
|
2021-09-23 08:55:30 +02:00
|
|
|
return STATUS_SUCCESS;
|
2018-02-21 13:55:50 +01:00
|
|
|
}
|
|
|
|
|
2022-02-16 09:26:56 +01:00
|
|
|
static NTSTATUS sdl_device_haptics_stop(struct unix_device *iface)
|
2022-02-15 09:03:38 +01:00
|
|
|
{
|
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
|
|
|
if (impl->effect_support & SDL_HAPTIC_LEFTRIGHT)
|
|
|
|
pSDL_HapticStopAll(impl->sdl_haptic);
|
|
|
|
else if (impl->effect_support & WINE_SDL_HAPTIC_RUMBLE)
|
|
|
|
pSDL_HapticRumbleStop(impl->sdl_haptic);
|
|
|
|
else if (impl->effect_support & WINE_SDL_JOYSTICK_RUMBLE)
|
|
|
|
pSDL_JoystickRumble(impl->sdl_joystick, 0, 0, 0);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-10-01 09:31:00 +02:00
|
|
|
static NTSTATUS sdl_device_physical_device_control(struct unix_device *iface, USAGE control)
|
|
|
|
{
|
2021-10-01 09:31:07 +02:00
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("iface %p, control %#04x.\n", iface, control);
|
|
|
|
|
|
|
|
switch (control)
|
|
|
|
{
|
|
|
|
case PID_USAGE_DC_ENABLE_ACTUATORS:
|
|
|
|
pSDL_HapticSetGain(impl->sdl_haptic, 100);
|
2021-12-02 10:47:48 +01:00
|
|
|
InterlockedOr(&impl->effect_flags, EFFECT_STATE_ACTUATORS_ENABLED);
|
2021-10-01 09:31:07 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_DC_DISABLE_ACTUATORS:
|
|
|
|
pSDL_HapticSetGain(impl->sdl_haptic, 0);
|
2021-12-02 10:47:48 +01:00
|
|
|
InterlockedAnd(&impl->effect_flags, ~EFFECT_STATE_ACTUATORS_ENABLED);
|
2021-10-01 09:31:07 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_DC_STOP_ALL_EFFECTS:
|
|
|
|
pSDL_HapticStopAll(impl->sdl_haptic);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_DC_DEVICE_RESET:
|
|
|
|
pSDL_HapticStopAll(impl->sdl_haptic);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(impl->effect_ids); ++i)
|
|
|
|
{
|
|
|
|
if (impl->effect_ids[i] < 0) continue;
|
|
|
|
pSDL_HapticDestroyEffect(impl->sdl_haptic, impl->effect_ids[i]);
|
|
|
|
impl->effect_ids[i] = -1;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_DC_DEVICE_PAUSE:
|
|
|
|
pSDL_HapticPause(impl->sdl_haptic);
|
2021-12-02 10:47:48 +01:00
|
|
|
InterlockedOr(&impl->effect_flags, EFFECT_STATE_DEVICE_PAUSED);
|
2021-10-01 09:31:07 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_DC_DEVICE_CONTINUE:
|
|
|
|
pSDL_HapticUnpause(impl->sdl_haptic);
|
2021-12-02 10:47:48 +01:00
|
|
|
InterlockedAnd(&impl->effect_flags, ~EFFECT_STATE_DEVICE_PAUSED);
|
2021-10-01 09:31:07 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2021-10-01 09:31:00 +02:00
|
|
|
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2021-11-19 09:39:39 +01:00
|
|
|
static NTSTATUS sdl_device_physical_device_set_gain(struct unix_device *iface, BYTE percent)
|
2021-11-17 11:51:50 +01:00
|
|
|
{
|
2021-11-17 11:51:54 +01:00
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
|
|
|
|
2021-11-19 09:39:39 +01:00
|
|
|
TRACE("iface %p, percent %#x.\n", iface, percent);
|
2021-11-17 11:51:50 +01:00
|
|
|
|
2021-11-19 09:39:39 +01:00
|
|
|
pSDL_HapticSetGain(impl->sdl_haptic, percent);
|
2021-11-17 11:51:54 +01:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2021-11-17 11:51:50 +01:00
|
|
|
}
|
|
|
|
|
2021-10-04 09:51:31 +02:00
|
|
|
static NTSTATUS sdl_device_physical_effect_control(struct unix_device *iface, BYTE index,
|
|
|
|
USAGE control, BYTE iterations)
|
|
|
|
{
|
2021-10-04 09:51:33 +02:00
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
|
|
|
int id = impl->effect_ids[index];
|
|
|
|
|
|
|
|
TRACE("iface %p, index %u, control %04x, iterations %u.\n", iface, index, control, iterations);
|
|
|
|
|
|
|
|
if (impl->effect_ids[index] < 0) return STATUS_UNSUCCESSFUL;
|
2021-10-04 09:51:31 +02:00
|
|
|
|
2021-10-04 09:51:33 +02:00
|
|
|
switch (control)
|
|
|
|
{
|
|
|
|
case PID_USAGE_OP_EFFECT_START_SOLO:
|
|
|
|
pSDL_HapticStopAll(impl->sdl_haptic);
|
|
|
|
/* fallthrough */
|
|
|
|
case PID_USAGE_OP_EFFECT_START:
|
2021-12-09 14:44:12 +01:00
|
|
|
pSDL_HapticRunEffect(impl->sdl_haptic, id, (iterations == 0xff ? SDL_HAPTIC_INFINITY : iterations));
|
2021-10-04 09:51:33 +02:00
|
|
|
break;
|
|
|
|
case PID_USAGE_OP_EFFECT_STOP:
|
|
|
|
pSDL_HapticStopEffect(impl->sdl_haptic, id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2021-10-04 09:51:31 +02:00
|
|
|
}
|
|
|
|
|
2021-10-05 08:43:24 +02:00
|
|
|
static NTSTATUS set_effect_type_from_usage(SDL_HapticEffect *effect, USAGE type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case PID_USAGE_ET_SINE:
|
|
|
|
effect->type = SDL_HAPTIC_SINE;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_TRIANGLE:
|
|
|
|
effect->type = SDL_HAPTIC_TRIANGLE;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_SAWTOOTH_UP:
|
|
|
|
effect->type = SDL_HAPTIC_SAWTOOTHUP;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_SAWTOOTH_DOWN:
|
|
|
|
effect->type = SDL_HAPTIC_SAWTOOTHDOWN;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_SPRING:
|
|
|
|
effect->type = SDL_HAPTIC_SPRING;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_DAMPER:
|
|
|
|
effect->type = SDL_HAPTIC_DAMPER;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_INERTIA:
|
|
|
|
effect->type = SDL_HAPTIC_INERTIA;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_FRICTION:
|
|
|
|
effect->type = SDL_HAPTIC_FRICTION;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_CONSTANT_FORCE:
|
|
|
|
effect->type = SDL_HAPTIC_CONSTANT;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_RAMP:
|
|
|
|
effect->type = SDL_HAPTIC_RAMP;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
case PID_USAGE_ET_CUSTOM_FORCE_DATA:
|
|
|
|
effect->type = SDL_HAPTIC_CUSTOM;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
default:
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-05 08:43:22 +02:00
|
|
|
static NTSTATUS sdl_device_physical_effect_update(struct unix_device *iface, BYTE index,
|
|
|
|
struct effect_params *params)
|
|
|
|
{
|
2021-10-05 08:43:24 +02:00
|
|
|
struct sdl_device *impl = impl_from_unix_device(iface);
|
|
|
|
int id = impl->effect_ids[index];
|
|
|
|
SDL_HapticEffect effect = {0};
|
2021-12-02 10:47:43 +01:00
|
|
|
UINT16 direction;
|
2021-10-05 08:43:24 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("iface %p, index %u, params %p.\n", iface, index, params);
|
|
|
|
|
2021-11-22 11:05:47 +01:00
|
|
|
if (params->effect_type == PID_USAGE_UNDEFINED) return STATUS_SUCCESS;
|
2021-10-05 08:43:24 +02:00
|
|
|
if ((status = set_effect_type_from_usage(&effect, params->effect_type))) return status;
|
|
|
|
|
2021-12-02 10:47:43 +01:00
|
|
|
/* The first direction we get from PID is in polar coordinate space, so we need to
|
|
|
|
* remove 90° to make it match SDL spherical coordinates. */
|
|
|
|
direction = (params->direction[0] - 9000) % 36000;
|
|
|
|
|
2021-10-05 08:43:24 +02:00
|
|
|
switch (params->effect_type)
|
|
|
|
{
|
|
|
|
case PID_USAGE_ET_SINE:
|
|
|
|
case PID_USAGE_ET_SQUARE:
|
|
|
|
case PID_USAGE_ET_TRIANGLE:
|
|
|
|
case PID_USAGE_ET_SAWTOOTH_UP:
|
|
|
|
case PID_USAGE_ET_SAWTOOTH_DOWN:
|
2021-12-09 14:44:12 +01:00
|
|
|
effect.periodic.length = (params->duration == 0xffff ? SDL_HAPTIC_INFINITY : params->duration);
|
2021-10-05 08:43:24 +02:00
|
|
|
effect.periodic.delay = params->start_delay;
|
|
|
|
effect.periodic.button = params->trigger_button;
|
|
|
|
effect.periodic.interval = params->trigger_repeat_interval;
|
|
|
|
effect.periodic.direction.type = SDL_HAPTIC_SPHERICAL;
|
2021-12-02 10:47:43 +01:00
|
|
|
effect.periodic.direction.dir[0] = direction;
|
2021-11-19 09:39:39 +01:00
|
|
|
effect.periodic.direction.dir[1] = params->direction[1];
|
2021-10-08 09:50:19 +02:00
|
|
|
effect.periodic.period = params->periodic.period;
|
2021-11-19 09:39:39 +01:00
|
|
|
effect.periodic.magnitude = params->periodic.magnitude;
|
2021-10-08 09:50:19 +02:00
|
|
|
effect.periodic.offset = params->periodic.offset;
|
|
|
|
effect.periodic.phase = params->periodic.phase;
|
2021-10-08 09:50:21 +02:00
|
|
|
effect.periodic.attack_length = params->envelope.attack_time;
|
|
|
|
effect.periodic.attack_level = params->envelope.attack_level;
|
|
|
|
effect.periodic.fade_length = params->envelope.fade_time;
|
|
|
|
effect.periodic.fade_level = params->envelope.fade_level;
|
2021-10-05 08:43:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PID_USAGE_ET_SPRING:
|
|
|
|
case PID_USAGE_ET_DAMPER:
|
|
|
|
case PID_USAGE_ET_INERTIA:
|
|
|
|
case PID_USAGE_ET_FRICTION:
|
2021-12-09 14:44:12 +01:00
|
|
|
effect.condition.length = (params->duration == 0xffff ? SDL_HAPTIC_INFINITY : params->duration);
|
2021-10-08 09:50:24 +02:00
|
|
|
effect.condition.delay = params->start_delay;
|
|
|
|
effect.condition.button = params->trigger_button;
|
|
|
|
effect.condition.interval = params->trigger_repeat_interval;
|
|
|
|
effect.condition.direction.type = SDL_HAPTIC_SPHERICAL;
|
2021-12-02 10:47:43 +01:00
|
|
|
effect.condition.direction.dir[0] = direction;
|
2021-11-19 09:39:39 +01:00
|
|
|
effect.condition.direction.dir[1] = params->direction[1];
|
2021-10-08 09:50:24 +02:00
|
|
|
if (params->condition_count >= 1)
|
|
|
|
{
|
|
|
|
effect.condition.right_sat[0] = params->condition[0].positive_saturation;
|
|
|
|
effect.condition.left_sat[0] = params->condition[0].negative_saturation;
|
|
|
|
effect.condition.right_coeff[0] = params->condition[0].positive_coefficient;
|
|
|
|
effect.condition.left_coeff[0] = params->condition[0].negative_coefficient;
|
|
|
|
effect.condition.deadband[0] = params->condition[0].dead_band;
|
|
|
|
effect.condition.center[0] = params->condition[0].center_point_offset;
|
|
|
|
}
|
|
|
|
if (params->condition_count >= 2)
|
|
|
|
{
|
|
|
|
effect.condition.right_sat[1] = params->condition[1].positive_saturation;
|
|
|
|
effect.condition.left_sat[1] = params->condition[1].negative_saturation;
|
|
|
|
effect.condition.right_coeff[1] = params->condition[1].positive_coefficient;
|
|
|
|
effect.condition.left_coeff[1] = params->condition[1].negative_coefficient;
|
|
|
|
effect.condition.deadband[1] = params->condition[1].dead_band;
|
|
|
|
effect.condition.center[1] = params->condition[1].center_point_offset;
|
|
|
|
}
|
2021-10-05 08:43:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PID_USAGE_ET_CONSTANT_FORCE:
|
2021-12-09 14:44:12 +01:00
|
|
|
effect.constant.length = (params->duration == 0xffff ? SDL_HAPTIC_INFINITY : params->duration);
|
2021-10-08 09:50:26 +02:00
|
|
|
effect.constant.delay = params->start_delay;
|
|
|
|
effect.constant.button = params->trigger_button;
|
|
|
|
effect.constant.interval = params->trigger_repeat_interval;
|
|
|
|
effect.constant.direction.type = SDL_HAPTIC_SPHERICAL;
|
2021-12-02 10:47:43 +01:00
|
|
|
effect.constant.direction.dir[0] = direction;
|
2021-11-19 09:39:39 +01:00
|
|
|
effect.constant.direction.dir[1] = params->direction[1];
|
2021-10-08 09:50:26 +02:00
|
|
|
effect.constant.level = params->constant_force.magnitude;
|
|
|
|
effect.constant.attack_length = params->envelope.attack_time;
|
|
|
|
effect.constant.attack_level = params->envelope.attack_level;
|
|
|
|
effect.constant.fade_length = params->envelope.fade_time;
|
|
|
|
effect.constant.fade_level = params->envelope.fade_level;
|
2021-10-05 08:43:24 +02:00
|
|
|
break;
|
2021-10-08 09:50:26 +02:00
|
|
|
|
2021-12-09 14:44:12 +01:00
|
|
|
/* According to the SDL documentation, ramp effect doesn't
|
|
|
|
* support SDL_HAPTIC_INFINITY. */
|
2021-10-05 08:43:24 +02:00
|
|
|
case PID_USAGE_ET_RAMP:
|
2021-10-08 09:50:28 +02:00
|
|
|
effect.ramp.length = params->duration;
|
|
|
|
effect.ramp.delay = params->start_delay;
|
|
|
|
effect.ramp.button = params->trigger_button;
|
|
|
|
effect.ramp.interval = params->trigger_repeat_interval;
|
|
|
|
effect.ramp.direction.type = SDL_HAPTIC_SPHERICAL;
|
2021-11-19 09:39:39 +01:00
|
|
|
effect.ramp.direction.dir[0] = params->direction[0];
|
|
|
|
effect.ramp.direction.dir[1] = params->direction[1];
|
2021-10-08 09:50:28 +02:00
|
|
|
effect.ramp.start = params->ramp_force.ramp_start;
|
|
|
|
effect.ramp.end = params->ramp_force.ramp_end;
|
|
|
|
effect.ramp.attack_length = params->envelope.attack_time;
|
|
|
|
effect.ramp.attack_level = params->envelope.attack_level;
|
|
|
|
effect.ramp.fade_length = params->envelope.fade_time;
|
|
|
|
effect.ramp.fade_level = params->envelope.fade_level;
|
2021-10-05 08:43:24 +02:00
|
|
|
break;
|
2021-10-08 09:50:28 +02:00
|
|
|
|
2021-10-05 08:43:24 +02:00
|
|
|
case PID_USAGE_ET_CUSTOM_FORCE_DATA:
|
2021-10-20 16:37:14 +02:00
|
|
|
FIXME("not implemented!\n");
|
2021-10-05 08:43:24 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-10-05 08:43:22 +02:00
|
|
|
|
2021-10-05 08:43:24 +02:00
|
|
|
if (id < 0) impl->effect_ids[index] = pSDL_HapticNewEffect(impl->sdl_haptic, &effect);
|
|
|
|
else pSDL_HapticUpdateEffect(impl->sdl_haptic, id, &effect);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2021-10-05 08:43:22 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
static const struct hid_device_vtbl sdl_device_vtbl =
|
2018-02-21 13:55:50 +01:00
|
|
|
{
|
2021-09-03 09:30:49 +02:00
|
|
|
sdl_device_destroy,
|
|
|
|
sdl_device_start,
|
2021-09-14 08:58:21 +02:00
|
|
|
sdl_device_stop,
|
2021-09-23 08:55:30 +02:00
|
|
|
sdl_device_haptics_start,
|
2022-02-15 09:03:38 +01:00
|
|
|
sdl_device_haptics_stop,
|
2021-10-01 09:31:00 +02:00
|
|
|
sdl_device_physical_device_control,
|
2021-11-17 11:51:50 +01:00
|
|
|
sdl_device_physical_device_set_gain,
|
2021-10-04 09:51:31 +02:00
|
|
|
sdl_device_physical_effect_control,
|
2021-10-05 08:43:22 +02:00
|
|
|
sdl_device_physical_effect_update,
|
2018-02-21 13:55:50 +01:00
|
|
|
};
|
|
|
|
|
2021-12-02 10:47:48 +01:00
|
|
|
static void check_device_effects_state(struct sdl_device *impl)
|
|
|
|
{
|
|
|
|
struct unix_device *iface = &impl->unix_device;
|
|
|
|
struct hid_effect_state *effect_state = &iface->hid_physical.effect_state;
|
|
|
|
ULONG effect_flags = InterlockedOr(&impl->effect_flags, 0);
|
|
|
|
unsigned int i, ret;
|
|
|
|
|
|
|
|
if (!impl->sdl_haptic) return;
|
|
|
|
if (!(impl->effect_support & SDL_HAPTIC_STATUS)) return;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(impl->effect_ids); ++i)
|
|
|
|
{
|
|
|
|
if (impl->effect_ids[i] == -1) continue;
|
|
|
|
ret = pSDL_HapticGetEffectStatus(impl->sdl_haptic, impl->effect_ids[i]);
|
|
|
|
if (impl->effect_state[i] == ret) continue;
|
|
|
|
impl->effect_state[i] = ret;
|
|
|
|
hid_device_set_effect_state(iface, i, effect_flags | (ret == 1 ? EFFECT_STATE_EFFECT_PLAYING : 0));
|
|
|
|
bus_event_queue_input_report(&event_queue, iface, effect_state->report_buf, effect_state->report_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_all_devices_effects_state(void)
|
|
|
|
{
|
|
|
|
static UINT last_ticks = 0;
|
|
|
|
UINT ticks = pSDL_GetTicks();
|
|
|
|
struct sdl_device *impl;
|
|
|
|
|
|
|
|
if (ticks - last_ticks < 10) return;
|
|
|
|
last_ticks = ticks;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&sdl_cs);
|
|
|
|
LIST_FOR_EACH_ENTRY(impl, &device_list, struct sdl_device, unix_device.entry)
|
|
|
|
check_device_effects_state(impl);
|
|
|
|
pthread_mutex_unlock(&sdl_cs);
|
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
static BOOL set_report_from_joystick_event(struct sdl_device *impl, SDL_Event *event)
|
2019-09-20 10:31:41 +02:00
|
|
|
{
|
2021-09-22 10:30:39 +02:00
|
|
|
struct unix_device *iface = &impl->unix_device;
|
2021-09-23 08:55:26 +02:00
|
|
|
struct hid_device_state *state = &iface->hid_device_state;
|
2021-09-15 09:04:41 +02:00
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
if (impl->sdl_controller) return TRUE; /* use controller events instead */
|
2018-02-21 13:56:46 +01:00
|
|
|
|
2021-12-02 10:47:48 +01:00
|
|
|
switch (event->type)
|
2018-02-21 13:56:46 +01:00
|
|
|
{
|
|
|
|
case SDL_JOYBUTTONDOWN:
|
|
|
|
case SDL_JOYBUTTONUP:
|
|
|
|
{
|
|
|
|
SDL_JoyButtonEvent *ie = &event->jbutton;
|
|
|
|
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_button(iface, ie->button, ie->state);
|
2021-09-23 08:55:26 +02:00
|
|
|
bus_event_queue_input_report(&event_queue, iface, state->report_buf, state->report_len);
|
2018-02-21 13:56:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_JOYAXISMOTION:
|
|
|
|
{
|
|
|
|
SDL_JoyAxisEvent *ie = &event->jaxis;
|
|
|
|
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_abs_axis(iface, ie->axis, ie->value);
|
|
|
|
bus_event_queue_input_report(&event_queue, iface, state->report_buf, state->report_len);
|
2018-02-21 13:56:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_JOYBALLMOTION:
|
|
|
|
{
|
|
|
|
SDL_JoyBallEvent *ie = &event->jball;
|
|
|
|
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_rel_axis(iface, 2 * ie->ball, ie->xrel);
|
|
|
|
hid_device_set_rel_axis(iface, 2 * ie->ball + 1, ie->yrel);
|
2021-09-23 08:55:26 +02:00
|
|
|
bus_event_queue_input_report(&event_queue, iface, state->report_buf, state->report_len);
|
2018-02-21 13:56:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_JOYHATMOTION:
|
|
|
|
{
|
|
|
|
SDL_JoyHatEvent *ie = &event->jhat;
|
|
|
|
|
2021-09-23 08:55:27 +02:00
|
|
|
set_hat_value(iface, ie->hat, ie->value);
|
2021-09-23 08:55:26 +02:00
|
|
|
bus_event_queue_input_report(&event_queue, iface, state->report_buf, state->report_len);
|
2018-02-21 13:56:46 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-02-21 13:57:05 +01:00
|
|
|
default:
|
|
|
|
ERR("TODO: Process Report (0x%x)\n",event->type);
|
|
|
|
}
|
2021-12-02 10:47:48 +01:00
|
|
|
|
|
|
|
check_device_effects_state(impl);
|
2018-02-21 13:57:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
static BOOL set_report_from_controller_event(struct sdl_device *impl, SDL_Event *event)
|
2018-02-21 13:57:05 +01:00
|
|
|
{
|
2021-09-22 10:30:39 +02:00
|
|
|
struct unix_device *iface = &impl->unix_device;
|
2021-09-23 08:55:26 +02:00
|
|
|
struct hid_device_state *state = &iface->hid_device_state;
|
2018-02-21 13:57:05 +01:00
|
|
|
|
2021-12-02 10:47:48 +01:00
|
|
|
switch (event->type)
|
2018-02-21 13:57:05 +01:00
|
|
|
{
|
|
|
|
case SDL_CONTROLLERBUTTONDOWN:
|
|
|
|
case SDL_CONTROLLERBUTTONUP:
|
|
|
|
{
|
|
|
|
SDL_ControllerButtonEvent *ie = &event->cbutton;
|
2021-09-21 08:36:44 +02:00
|
|
|
int button;
|
2018-02-21 13:57:05 +01:00
|
|
|
|
2021-09-21 08:36:44 +02:00
|
|
|
switch ((button = ie->button))
|
2018-02-21 13:57:05 +01:00
|
|
|
{
|
2021-09-21 08:36:44 +02:00
|
|
|
case SDL_CONTROLLER_BUTTON_DPAD_UP:
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_hatswitch_y(iface, 0, ie->state ? -1 : 0);
|
|
|
|
break;
|
2021-09-21 08:36:44 +02:00
|
|
|
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_hatswitch_y(iface, 0, ie->state ? +1 : 0);
|
|
|
|
break;
|
2021-09-21 08:36:44 +02:00
|
|
|
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_hatswitch_x(iface, 0, ie->state ? -1 : 0);
|
|
|
|
break;
|
2021-09-21 08:36:44 +02:00
|
|
|
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_hatswitch_x(iface, 0, ie->state ? +1 : 0);
|
2021-09-21 08:36:44 +02:00
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: button = 4; break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: button = 5; break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_BACK: button = 6; break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_START: button = 7; break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_LEFTSTICK: button = 8; break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_RIGHTSTICK: button = 9; break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_GUIDE: button = 10; break;
|
2018-02-21 13:57:05 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_button(iface, button, ie->state);
|
2021-09-23 08:55:26 +02:00
|
|
|
bus_event_queue_input_report(&event_queue, iface, state->report_buf, state->report_len);
|
2018-02-21 13:57:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_CONTROLLERAXISMOTION:
|
|
|
|
{
|
|
|
|
SDL_ControllerAxisEvent *ie = &event->caxis;
|
|
|
|
|
2021-09-23 08:55:27 +02:00
|
|
|
hid_device_set_abs_axis(iface, ie->axis, ie->value);
|
2021-09-23 08:55:26 +02:00
|
|
|
bus_event_queue_input_report(&event_queue, iface, state->report_buf, state->report_len);
|
2018-02-21 13:57:05 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-02-21 13:56:46 +01:00
|
|
|
default:
|
|
|
|
ERR("TODO: Process Report (%x)\n",event->type);
|
|
|
|
}
|
2021-12-02 10:47:48 +01:00
|
|
|
|
|
|
|
check_device_effects_state(impl);
|
2018-02-21 13:56:46 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
static void sdl_add_device(unsigned int index)
|
2018-02-21 13:55:50 +01:00
|
|
|
{
|
2021-09-03 09:30:48 +02:00
|
|
|
struct device_desc desc =
|
|
|
|
{
|
|
|
|
.input = -1,
|
2021-10-05 10:55:50 +02:00
|
|
|
.manufacturer = {'S','D','L',0},
|
|
|
|
.serialnumber = {'0','0','0','0',0},
|
2021-09-03 09:30:48 +02:00
|
|
|
};
|
2021-09-22 10:30:39 +02:00
|
|
|
struct sdl_device *impl;
|
2018-02-21 13:55:50 +01:00
|
|
|
|
|
|
|
SDL_Joystick* joystick;
|
|
|
|
SDL_JoystickID id;
|
|
|
|
SDL_JoystickGUID guid;
|
2018-02-21 13:57:05 +01:00
|
|
|
SDL_GameController *controller = NULL;
|
2021-10-05 10:55:50 +02:00
|
|
|
const char *str;
|
|
|
|
char guid_str[33];
|
2018-02-21 13:55:50 +01:00
|
|
|
|
|
|
|
if ((joystick = pSDL_JoystickOpen(index)) == NULL)
|
|
|
|
{
|
|
|
|
WARN("Unable to open sdl device %i: %s\n", index, pSDL_GetError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-23 10:49:40 +02:00
|
|
|
if (options.map_controllers && pSDL_IsGameController(index))
|
2018-02-21 13:57:05 +01:00
|
|
|
controller = pSDL_GameControllerOpen(index);
|
|
|
|
|
2021-10-05 10:55:50 +02:00
|
|
|
if (controller) str = pSDL_GameControllerName(controller);
|
|
|
|
else str = pSDL_JoystickName(joystick);
|
|
|
|
if (str) ntdll_umbstowcs(str, strlen(str) + 1, desc.product, ARRAY_SIZE(desc.product));
|
2021-09-13 13:01:47 +02:00
|
|
|
|
2018-05-08 17:57:29 +02:00
|
|
|
id = pSDL_JoystickInstanceID(joystick);
|
2018-11-22 00:56:01 +01:00
|
|
|
|
|
|
|
if (pSDL_JoystickGetProductVersion != NULL) {
|
2021-09-03 09:30:48 +02:00
|
|
|
desc.vid = pSDL_JoystickGetVendor(joystick);
|
|
|
|
desc.pid = pSDL_JoystickGetProduct(joystick);
|
|
|
|
desc.version = pSDL_JoystickGetProductVersion(joystick);
|
2018-02-21 13:55:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-03 09:30:48 +02:00
|
|
|
desc.vid = 0x01;
|
|
|
|
desc.pid = pSDL_JoystickInstanceID(joystick) + 1;
|
|
|
|
desc.version = 0;
|
2018-02-21 13:55:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
guid = pSDL_JoystickGetGUID(joystick);
|
2021-10-05 10:55:50 +02:00
|
|
|
pSDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str));
|
|
|
|
ntdll_umbstowcs(guid_str, strlen(guid_str) + 1, desc.serialnumber, ARRAY_SIZE(desc.serialnumber));
|
2018-02-21 13:55:50 +01:00
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
if (controller) desc.is_gamepad = TRUE;
|
2018-02-21 13:57:05 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int button_count, axis_count;
|
|
|
|
|
|
|
|
axis_count = pSDL_JoystickNumAxes(joystick);
|
2018-11-20 01:17:10 +01:00
|
|
|
button_count = pSDL_JoystickNumButtons(joystick);
|
2021-09-03 09:30:48 +02:00
|
|
|
desc.is_gamepad = (axis_count == 6 && button_count >= 14);
|
2018-02-21 13:57:05 +01:00
|
|
|
}
|
2018-02-21 13:55:50 +01:00
|
|
|
|
2021-09-03 09:30:48 +02:00
|
|
|
TRACE("%s id %d, desc %s.\n", controller ? "controller" : "joystick", id, debugstr_device_desc(&desc));
|
|
|
|
|
2021-09-22 10:30:42 +02:00
|
|
|
if (!(impl = hid_device_create(&sdl_device_vtbl, sizeof(struct sdl_device)))) return;
|
2021-09-22 10:30:39 +02:00
|
|
|
list_add_tail(&device_list, &impl->unix_device.entry);
|
|
|
|
impl->sdl_joystick = joystick;
|
|
|
|
impl->sdl_controller = controller;
|
|
|
|
impl->id = id;
|
2018-02-21 13:55:50 +01:00
|
|
|
|
2021-09-22 10:30:39 +02:00
|
|
|
bus_event_queue_device_created(&event_queue, &impl->unix_device, &desc);
|
2018-02-21 13:55:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void process_device_event(SDL_Event *event)
|
|
|
|
{
|
2021-09-22 10:30:39 +02:00
|
|
|
struct sdl_device *impl;
|
2021-08-16 08:56:20 +02:00
|
|
|
SDL_JoystickID id;
|
|
|
|
|
2021-10-27 10:39:11 +02:00
|
|
|
TRACE("Received action %x\n", event->type);
|
2018-02-21 13:55:50 +01:00
|
|
|
|
2021-09-17 08:50:33 +02:00
|
|
|
pthread_mutex_lock(&sdl_cs);
|
2021-09-15 09:04:41 +02:00
|
|
|
|
2018-02-21 13:55:50 +01:00
|
|
|
if (event->type == SDL_JOYDEVICEADDED)
|
2021-09-03 09:30:48 +02:00
|
|
|
sdl_add_device(((SDL_JoyDeviceEvent *)event)->which);
|
2018-02-21 13:55:50 +01:00
|
|
|
else if (event->type == SDL_JOYDEVICEREMOVED)
|
2021-08-16 08:56:20 +02:00
|
|
|
{
|
|
|
|
id = ((SDL_JoyDeviceEvent *)event)->which;
|
2021-09-22 10:30:39 +02:00
|
|
|
impl = find_device_from_id(id);
|
|
|
|
if (impl) bus_event_queue_device_removed(&event_queue, &impl->unix_device);
|
2021-09-16 10:17:52 +02:00
|
|
|
else WARN("failed to find device with id %d\n", id);
|
2021-08-16 08:56:20 +02:00
|
|
|
}
|
2018-02-21 13:56:46 +01:00
|
|
|
else if (event->type >= SDL_JOYAXISMOTION && event->type <= SDL_JOYBUTTONUP)
|
2021-08-16 08:56:20 +02:00
|
|
|
{
|
|
|
|
id = ((SDL_JoyButtonEvent *)event)->which;
|
2021-09-22 10:30:39 +02:00
|
|
|
impl = find_device_from_id(id);
|
|
|
|
if (impl) set_report_from_joystick_event(impl, event);
|
2021-08-16 08:56:20 +02:00
|
|
|
else WARN("failed to find device with id %d\n", id);
|
|
|
|
}
|
2018-02-21 13:57:05 +01:00
|
|
|
else if (event->type >= SDL_CONTROLLERAXISMOTION && event->type <= SDL_CONTROLLERBUTTONUP)
|
2021-08-16 08:56:20 +02:00
|
|
|
{
|
|
|
|
id = ((SDL_ControllerButtonEvent *)event)->which;
|
2021-09-22 10:30:39 +02:00
|
|
|
impl = find_device_from_id(id);
|
|
|
|
if (impl) set_report_from_controller_event(impl, event);
|
2021-08-16 08:56:20 +02:00
|
|
|
else WARN("failed to find device with id %d\n", id);
|
|
|
|
}
|
2021-09-15 09:04:41 +02:00
|
|
|
|
2021-09-17 08:50:33 +02:00
|
|
|
pthread_mutex_unlock(&sdl_cs);
|
2018-02-21 13:55:50 +01:00
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS sdl_bus_init(void *args)
|
2021-08-13 09:46:18 +02:00
|
|
|
{
|
|
|
|
const char *mapping;
|
2021-09-16 10:17:55 +02:00
|
|
|
int i;
|
2021-08-13 09:46:18 +02:00
|
|
|
|
2021-08-23 10:49:40 +02:00
|
|
|
TRACE("args %p\n", args);
|
|
|
|
|
|
|
|
options = *(struct sdl_bus_options *)args;
|
2018-09-12 18:22:09 +02:00
|
|
|
|
2021-08-13 09:46:17 +02:00
|
|
|
if (!(sdl_handle = dlopen(SONAME_LIBSDL2, RTLD_NOW)))
|
|
|
|
{
|
|
|
|
WARN("could not load %s\n", SONAME_LIBSDL2);
|
2021-08-23 10:49:36 +02:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-08-13 09:46:17 +02:00
|
|
|
}
|
|
|
|
#define LOAD_FUNCPTR(f) \
|
|
|
|
if ((p##f = dlsym(sdl_handle, #f)) == NULL) \
|
|
|
|
{ \
|
|
|
|
WARN("could not find symbol %s\n", #f); \
|
|
|
|
goto failed; \
|
|
|
|
}
|
|
|
|
LOAD_FUNCPTR(SDL_GetError);
|
|
|
|
LOAD_FUNCPTR(SDL_Init);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickClose);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickEventState);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickGetGUID);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickGetGUIDString);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickInstanceID);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickName);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickNumAxes);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickOpen);
|
2021-12-02 10:47:48 +01:00
|
|
|
LOAD_FUNCPTR(SDL_WaitEventTimeout);
|
2021-08-13 09:46:17 +02:00
|
|
|
LOAD_FUNCPTR(SDL_JoystickNumButtons);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickNumBalls);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickNumHats);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickGetAxis);
|
|
|
|
LOAD_FUNCPTR(SDL_JoystickGetHat);
|
|
|
|
LOAD_FUNCPTR(SDL_IsGameController);
|
|
|
|
LOAD_FUNCPTR(SDL_GameControllerClose);
|
|
|
|
LOAD_FUNCPTR(SDL_GameControllerGetAxis);
|
|
|
|
LOAD_FUNCPTR(SDL_GameControllerGetButton);
|
|
|
|
LOAD_FUNCPTR(SDL_GameControllerName);
|
|
|
|
LOAD_FUNCPTR(SDL_GameControllerOpen);
|
|
|
|
LOAD_FUNCPTR(SDL_GameControllerEventState);
|
|
|
|
LOAD_FUNCPTR(SDL_HapticClose);
|
|
|
|
LOAD_FUNCPTR(SDL_HapticDestroyEffect);
|
2021-12-02 10:47:48 +01:00
|
|
|
LOAD_FUNCPTR(SDL_HapticGetEffectStatus);
|
2021-08-13 09:46:17 +02:00
|
|
|
LOAD_FUNCPTR(SDL_HapticNewEffect);
|
|
|
|
LOAD_FUNCPTR(SDL_HapticOpenFromJoystick);
|
2021-10-01 09:31:07 +02:00
|
|
|
LOAD_FUNCPTR(SDL_HapticPause);
|
2021-08-13 09:46:17 +02:00
|
|
|
LOAD_FUNCPTR(SDL_HapticQuery);
|
|
|
|
LOAD_FUNCPTR(SDL_HapticRumbleInit);
|
|
|
|
LOAD_FUNCPTR(SDL_HapticRumblePlay);
|
2022-02-14 17:26:18 +01:00
|
|
|
LOAD_FUNCPTR(SDL_HapticRumbleStop);
|
2021-08-13 09:46:17 +02:00
|
|
|
LOAD_FUNCPTR(SDL_HapticRumbleSupported);
|
|
|
|
LOAD_FUNCPTR(SDL_HapticRunEffect);
|
2021-10-01 09:31:07 +02:00
|
|
|
LOAD_FUNCPTR(SDL_HapticSetGain);
|
2021-08-13 09:46:17 +02:00
|
|
|
LOAD_FUNCPTR(SDL_HapticStopAll);
|
2021-10-04 09:51:33 +02:00
|
|
|
LOAD_FUNCPTR(SDL_HapticStopEffect);
|
2021-10-01 09:31:07 +02:00
|
|
|
LOAD_FUNCPTR(SDL_HapticUnpause);
|
2021-10-05 08:43:24 +02:00
|
|
|
LOAD_FUNCPTR(SDL_HapticUpdateEffect);
|
2021-08-13 09:46:17 +02:00
|
|
|
LOAD_FUNCPTR(SDL_JoystickIsHaptic);
|
|
|
|
LOAD_FUNCPTR(SDL_GameControllerAddMapping);
|
|
|
|
LOAD_FUNCPTR(SDL_RegisterEvents);
|
|
|
|
LOAD_FUNCPTR(SDL_PushEvent);
|
2021-12-02 10:47:48 +01:00
|
|
|
LOAD_FUNCPTR(SDL_GetTicks);
|
2021-08-13 09:46:17 +02:00
|
|
|
#undef LOAD_FUNCPTR
|
2021-09-24 11:51:52 +02:00
|
|
|
pSDL_JoystickRumble = dlsym(sdl_handle, "SDL_JoystickRumble");
|
2021-08-13 09:46:17 +02:00
|
|
|
pSDL_JoystickGetProduct = dlsym(sdl_handle, "SDL_JoystickGetProduct");
|
|
|
|
pSDL_JoystickGetProductVersion = dlsym(sdl_handle, "SDL_JoystickGetProductVersion");
|
|
|
|
pSDL_JoystickGetVendor = dlsym(sdl_handle, "SDL_JoystickGetVendor");
|
2021-08-23 10:49:36 +02:00
|
|
|
|
|
|
|
if (pSDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) < 0)
|
|
|
|
{
|
|
|
|
ERR("could not init SDL: %s\n", pSDL_GetError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((quit_event = pSDL_RegisterEvents(1)) == -1)
|
|
|
|
{
|
|
|
|
ERR("error registering quit event\n");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
pSDL_JoystickEventState(SDL_ENABLE);
|
|
|
|
pSDL_GameControllerEventState(SDL_ENABLE);
|
|
|
|
|
|
|
|
/* Process mappings */
|
2021-09-16 10:17:55 +02:00
|
|
|
if (pSDL_GameControllerAddMapping)
|
|
|
|
{
|
|
|
|
if ((mapping = getenv("SDL_GAMECONTROLLERCONFIG")))
|
|
|
|
{
|
|
|
|
TRACE("Setting environment mapping %s\n", debugstr_a(mapping));
|
|
|
|
if (pSDL_GameControllerAddMapping(mapping) < 0)
|
|
|
|
WARN("Failed to add environment mapping %s\n", pSDL_GetError());
|
|
|
|
}
|
|
|
|
else for (i = 0; i < options.mappings_count; ++i)
|
|
|
|
{
|
|
|
|
TRACE("Setting registry mapping %s\n", debugstr_a(options.mappings[i]));
|
|
|
|
if (pSDL_GameControllerAddMapping(options.mappings[i]) < 0)
|
|
|
|
WARN("Failed to add registry mapping %s\n", pSDL_GetError());
|
|
|
|
}
|
|
|
|
}
|
2021-08-23 10:49:36 +02:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2021-08-13 09:46:17 +02:00
|
|
|
|
|
|
|
failed:
|
|
|
|
dlclose(sdl_handle);
|
|
|
|
sdl_handle = NULL;
|
2021-08-23 10:49:36 +02:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-08-13 09:46:17 +02:00
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS sdl_bus_wait(void *args)
|
2018-02-21 13:55:13 +01:00
|
|
|
{
|
2021-08-30 11:22:52 +02:00
|
|
|
struct bus_event *result = args;
|
2021-08-23 10:49:36 +02:00
|
|
|
SDL_Event event;
|
2018-02-21 13:57:05 +01:00
|
|
|
|
2021-09-15 09:04:41 +02:00
|
|
|
/* cleanup previously returned event */
|
|
|
|
bus_event_cleanup(result);
|
|
|
|
|
2021-08-23 10:49:36 +02:00
|
|
|
do
|
|
|
|
{
|
2021-08-30 11:22:52 +02:00
|
|
|
if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING;
|
2021-12-02 10:47:48 +01:00
|
|
|
if (pSDL_WaitEventTimeout(&event, 10) != 0) process_device_event(&event);
|
|
|
|
else check_all_devices_effects_state();
|
2021-08-23 10:49:36 +02:00
|
|
|
} while (event.type != quit_event);
|
2018-02-21 13:55:50 +01:00
|
|
|
|
2021-08-23 10:49:36 +02:00
|
|
|
TRACE("SDL main loop exiting\n");
|
2021-08-30 11:22:52 +02:00
|
|
|
bus_event_queue_destroy(&event_queue);
|
2021-08-23 10:49:36 +02:00
|
|
|
dlclose(sdl_handle);
|
|
|
|
sdl_handle = NULL;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2018-02-21 13:55:50 +01:00
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS sdl_bus_stop(void *args)
|
2021-08-23 10:49:36 +02:00
|
|
|
{
|
|
|
|
SDL_Event event;
|
2018-02-21 13:57:05 +01:00
|
|
|
|
2021-08-23 10:49:36 +02:00
|
|
|
if (!sdl_handle) return STATUS_SUCCESS;
|
2018-02-21 13:55:50 +01:00
|
|
|
|
2021-08-23 10:49:36 +02:00
|
|
|
event.type = quit_event;
|
|
|
|
if (pSDL_PushEvent(&event) != 1)
|
2018-02-21 13:55:50 +01:00
|
|
|
{
|
2021-08-23 10:49:36 +02:00
|
|
|
ERR("error pushing quit event\n");
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2018-02-21 13:55:50 +01:00
|
|
|
}
|
|
|
|
|
2021-08-23 10:49:36 +02:00
|
|
|
return STATUS_SUCCESS;
|
2018-02-21 13:55:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS sdl_bus_init(void *args)
|
2018-02-21 13:55:13 +01:00
|
|
|
{
|
2021-08-23 10:49:36 +02:00
|
|
|
WARN("SDL support not compiled in!\n");
|
2018-02-21 13:55:13 +01:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS sdl_bus_wait(void *args)
|
2018-09-12 18:22:09 +02:00
|
|
|
{
|
2021-08-23 10:49:36 +02:00
|
|
|
WARN("SDL support not compiled in!\n");
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:50:34 +02:00
|
|
|
NTSTATUS sdl_bus_stop(void *args)
|
2021-08-23 10:49:36 +02:00
|
|
|
{
|
|
|
|
WARN("SDL support not compiled in!\n");
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2018-09-12 18:22:09 +02:00
|
|
|
}
|
|
|
|
|
2018-02-21 13:55:13 +01:00
|
|
|
#endif /* SONAME_LIBSDL2 */
|