early-access version 2281

This commit is contained in:
pineappleEA
2021-12-07 02:20:09 +01:00
parent c2ae6d480a
commit c4fa174d53
591 changed files with 36978 additions and 18653 deletions

View File

@@ -23,16 +23,16 @@
#if defined(__WIN32__)
#include "core/windows/SDL_windows.h"
#elif defined(__OS2__)
#include <stdlib.h> /* For _exit() */
#include <stdlib.h> /* _exit() */
#elif !defined(__WINRT__)
#include <unistd.h> /* For _exit(), etc. */
#include <unistd.h> /* _exit(), etc. */
#endif
#if defined(__OS2__)
#include "core/os2/SDL_os2.h"
#endif
#if SDL_THREAD_OS2
#include "thread/os2/SDL_systls_c.h"
#endif
#endif
/* this checks for HAVE_DBUS_DBUS_H internally. */
#include "core/linux/SDL_dbus.h"
@@ -150,6 +150,8 @@ SDL_SetMainReady(void)
int
SDL_InitSubSystem(Uint32 flags)
{
Uint32 flags_initialized = 0;
if (!SDL_MainIsReady) {
SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
return -1;
@@ -179,7 +181,7 @@ SDL_InitSubSystem(Uint32 flags)
#if SDL_VIDEO_DRIVER_WINDOWS
if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
if (SDL_HelperWindowCreate() < 0) {
return -1;
goto quit_and_error;
}
}
#endif
@@ -193,12 +195,14 @@ SDL_InitSubSystem(Uint32 flags)
#if !SDL_EVENTS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
if (SDL_EventsInit() < 0) {
return (-1);
goto quit_and_error;
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
flags_initialized |= SDL_INIT_EVENTS;
#else
return SDL_SetError("SDL not built with events support");
SDL_SetError("SDL not built with events support");
goto quit_and_error;
#endif
}
@@ -207,12 +211,14 @@ SDL_InitSubSystem(Uint32 flags)
#if !SDL_TIMERS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) {
return (-1);
goto quit_and_error;
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
flags_initialized |= SDL_INIT_TIMER;
#else
return SDL_SetError("SDL not built with timer support");
SDL_SetError("SDL not built with timer support");
goto quit_and_error;
#endif
}
@@ -221,12 +227,14 @@ SDL_InitSubSystem(Uint32 flags)
#if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL) < 0) {
return (-1);
goto quit_and_error;
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
flags_initialized |= SDL_INIT_VIDEO;
#else
return SDL_SetError("SDL not built with video support");
SDL_SetError("SDL not built with video support");
goto quit_and_error;
#endif
}
@@ -235,12 +243,14 @@ SDL_InitSubSystem(Uint32 flags)
#if !SDL_AUDIO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
if (SDL_AudioInit(NULL) < 0) {
return (-1);
goto quit_and_error;
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
flags_initialized |= SDL_INIT_AUDIO;
#else
return SDL_SetError("SDL not built with audio support");
SDL_SetError("SDL not built with audio support");
goto quit_and_error;
#endif
}
@@ -249,12 +259,14 @@ SDL_InitSubSystem(Uint32 flags)
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) {
return (-1);
goto quit_and_error;
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
flags_initialized |= SDL_INIT_JOYSTICK;
#else
return SDL_SetError("SDL not built with joystick support");
SDL_SetError("SDL not built with joystick support");
goto quit_and_error;
#endif
}
@@ -262,12 +274,14 @@ SDL_InitSubSystem(Uint32 flags)
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
if (SDL_GameControllerInit() < 0) {
return (-1);
goto quit_and_error;
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
flags_initialized |= SDL_INIT_GAMECONTROLLER;
#else
return SDL_SetError("SDL not built with joystick support");
SDL_SetError("SDL not built with joystick support");
goto quit_and_error;
#endif
}
@@ -276,12 +290,14 @@ SDL_InitSubSystem(Uint32 flags)
#if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) {
return (-1);
goto quit_and_error;
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
flags_initialized |= SDL_INIT_HAPTIC;
#else
return SDL_SetError("SDL not built with haptic (force feedback) support");
SDL_SetError("SDL not built with haptic (force feedback) support");
goto quit_and_error;
#endif
}
@@ -290,16 +306,22 @@ SDL_InitSubSystem(Uint32 flags)
#if !SDL_SENSOR_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
if (SDL_SensorInit() < 0) {
return (-1);
goto quit_and_error;
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_SENSOR);
flags_initialized |= SDL_INIT_SENSOR;
#else
return SDL_SetError("SDL not built with sensor support");
SDL_SetError("SDL not built with sensor support");
goto quit_and_error;
#endif
}
return (0);
quit_and_error:
SDL_QuitSubSystem(flags_initialized);
return (-1);
}
int
@@ -311,10 +333,10 @@ SDL_Init(Uint32 flags)
void
SDL_QuitSubSystem(Uint32 flags)
{
#if defined(__OS2__)
#if SDL_THREAD_OS2
SDL_OS2TLSFree(); /* thread/os2/SDL_systls.c */
#endif
#if defined(__OS2__)
SDL_OS2Quit();
#endif
@@ -484,7 +506,7 @@ SDL_GetRevisionNumber(void)
/* Get the name of the platform */
const char *
SDL_GetPlatform()
SDL_GetPlatform(void)
{
#if __AIX__
return "AIX";
@@ -546,7 +568,7 @@ SDL_GetPlatform()
}
SDL_bool
SDL_IsTablet()
SDL_IsTablet(void)
{
#if __ANDROID__
extern SDL_bool SDL_IsAndroidTablet(void);

View File

@@ -121,7 +121,7 @@ SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
queue->queued_bytes = 0;
queue->pool = packet;
/* Optionally keep some slack in the pool to reduce malloc pressure. */
/* Optionally keep some slack in the pool to reduce memory allocation pressure. */
for (i = 0; packet && (i < slackpackets); i++) {
prev = packet;
packet = packet->next;

View File

@@ -51,6 +51,10 @@
#include "SDL_config.h"
#ifndef HAVE_O_CLOEXEC
#define O_CLOEXEC 0
#endif
/* A few #defines to reduce SDL2 footprint.
Only effective when library is statically linked.
You have to manually edit this file. */

View File

@@ -36,33 +36,31 @@
#endif
/* The __atomic_load_n() intrinsic showed up in different times for different compilers. */
#if defined(HAVE_GCC_ATOMICS)
# if defined(__clang__)
# if __has_builtin(__atomic_load_n)
/* !!! FIXME: this advertises as available in the NDK but uses an external symbol we don't have.
It might be in a later NDK or we might need an extra library? --ryan. */
# if !defined(__ANDROID__)
# define HAVE_ATOMIC_LOAD_N 1
# endif
# endif
# elif defined(__GNUC__)
#if defined(__clang__)
# if __has_builtin(__atomic_load_n) || defined(HAVE_GCC_ATOMICS)
/* !!! FIXME: this advertises as available in the NDK but uses an external symbol we don't have.
It might be in a later NDK or we might need an extra library? --ryan. */
# if !defined(__ANDROID__)
# define HAVE_ATOMIC_LOAD_N 1
# endif
# endif
#elif defined(__GNUC__)
# if (__GNUC__ >= 5)
# define HAVE_ATOMIC_LOAD_N 1
# endif
# endif
#endif
#if defined(__WATCOMC__) && defined(__386__)
SDL_COMPILE_TIME_ASSERT(intsize, 4==sizeof(int));
#define HAVE_WATCOM_ATOMICS
extern _inline int _SDL_xchg_watcom(volatile int *a, int v);
extern __inline int _SDL_xchg_watcom(volatile int *a, int v);
#pragma aux _SDL_xchg_watcom = \
"lock xchg [ecx], eax" \
parm [ecx] [eax] \
value [eax] \
modify exact [eax];
extern _inline unsigned char _SDL_cmpxchg_watcom(volatile int *a, int newval, int oldval);
extern __inline unsigned char _SDL_cmpxchg_watcom(volatile int *a, int newval, int oldval);
#pragma aux _SDL_cmpxchg_watcom = \
"lock cmpxchg [edx], ecx" \
"setz al" \
@@ -70,7 +68,7 @@ extern _inline unsigned char _SDL_cmpxchg_watcom(volatile int *a, int newval, in
value [al] \
modify exact [eax];
extern _inline int _SDL_xadd_watcom(volatile int *a, int v);
extern __inline int _SDL_xadd_watcom(volatile int *a, int v);
#pragma aux _SDL_xadd_watcom = \
"lock xadd [ecx], eax" \
parm [ecx] [eax] \

View File

@@ -42,7 +42,7 @@
#if defined(__WATCOMC__) && defined(__386__)
SDL_COMPILE_TIME_ASSERT(locksize, 4==sizeof(SDL_SpinLock));
extern _inline int _SDL_xchg_watcom(volatile int *a, int v);
extern __inline int _SDL_xchg_watcom(volatile int *a, int v);
#pragma aux _SDL_xchg_watcom = \
"lock xchg [ecx], eax" \
parm [ecx] [eax] \
@@ -151,7 +151,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
#define PAUSE_INSTRUCTION() __yield()
#elif defined(__WATCOMC__) && defined(__386__)
/* watcom assembler rejects PAUSE if CPU < i686, and it refuses REP NOP as an invalid combination. Hardcode the bytes. */
extern _inline void PAUSE_INSTRUCTION(void);
extern __inline void PAUSE_INSTRUCTION(void);
#pragma aux PAUSE_INSTRUCTION = "db 0f3h,90h"
#else
#define PAUSE_INSTRUCTION()

View File

@@ -47,9 +47,6 @@ static const AudioBootStrap *const bootstrap[] = {
#if SDL_AUDIO_DRIVER_NETBSD
&NETBSDAUDIO_bootstrap,
#endif
#if SDL_AUDIO_DRIVER_OSS
&DSP_bootstrap,
#endif
#if SDL_AUDIO_DRIVER_QSA
&QSAAUDIO_bootstrap,
#endif
@@ -113,6 +110,9 @@ static const AudioBootStrap *const bootstrap[] = {
#if SDL_AUDIO_DRIVER_PIPEWIRE
&PIPEWIRE_bootstrap,
#endif
#if SDL_AUDIO_DRIVER_OSS
&DSP_bootstrap,
#endif
#if SDL_AUDIO_DRIVER_OS2
&OS2AUDIO_bootstrap,
#endif
@@ -687,7 +687,7 @@ SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
/* Blank out the device and release the mutex. Free it afterwards. */
current_audio.impl.LockDevice(device);
/* Keep up to two packets in the pool to reduce future malloc pressure. */
/* Keep up to two packets in the pool to reduce future memory allocation pressure. */
SDL_ClearDataQueue(device->buffer_queue, SDL_AUDIOBUFFERQUEUE_PACKETLEN * 2);
current_audio.impl.UnlockDevice(device);
@@ -960,7 +960,7 @@ SDL_AudioInit(const char *driver_name)
int initialized = 0;
int tried_to_init = 0;
if (SDL_WasInit(SDL_INIT_AUDIO)) {
if (SDL_GetCurrentAudioDriver()) {
SDL_AudioQuit(); /* shutdown driver if already running. */
}
@@ -972,12 +972,20 @@ SDL_AudioInit(const char *driver_name)
driver_name = SDL_getenv("SDL_AUDIODRIVER");
}
if (driver_name != NULL) {
if (driver_name != NULL && *driver_name != 0) {
const char *driver_attempt = driver_name;
while (driver_attempt != NULL && *driver_attempt != 0 && !initialized) {
const char *driver_attempt_end = SDL_strchr(driver_attempt, ',');
size_t driver_attempt_len = (driver_attempt_end != NULL) ? (driver_attempt_end - driver_attempt)
: SDL_strlen(driver_attempt);
#if SDL_AUDIO_DRIVER_PULSEAUDIO
/* SDL 1.2 uses the name "pulse", so we'll support both. */
if (driver_attempt_len == SDL_strlen("pulse") &&
(SDL_strncasecmp(driver_attempt, "pulse", driver_attempt_len) == 0)) {
driver_attempt = "pulseaudio";
driver_attempt_len = SDL_strlen("pulseaudio");
}
#endif
for (i = 0; bootstrap[i]; ++i) {
if ((driver_attempt_len == SDL_strlen(bootstrap[i]->name)) &&
@@ -1083,7 +1091,7 @@ SDL_GetNumAudioDevices(int iscapture)
{
int retval = 0;
if (!SDL_WasInit(SDL_INIT_AUDIO)) {
if (!SDL_GetCurrentAudioDriver()) {
return -1;
}
@@ -1108,7 +1116,7 @@ SDL_GetAudioDeviceName(int index, int iscapture)
{
const char *retval = NULL;
if (!SDL_WasInit(SDL_INIT_AUDIO)) {
if (!SDL_GetCurrentAudioDriver()) {
SDL_SetError("Audio subsystem is not initialized");
return NULL;
}
@@ -1152,7 +1160,7 @@ SDL_GetAudioDeviceSpec(int index, int iscapture, SDL_AudioSpec *spec)
SDL_zerop(spec);
if (!SDL_WasInit(SDL_INIT_AUDIO)) {
if (!SDL_GetCurrentAudioDriver()) {
return SDL_SetError("Audio subsystem is not initialized");
}
@@ -1260,6 +1268,7 @@ prepare_audiospec(const SDL_AudioSpec * orig, SDL_AudioSpec * prepared)
case 2: /* Stereo */
case 4: /* Quadrophonic */
case 6: /* 5.1 surround */
case 7: /* 6.1 surround */
case 8: /* 7.1 surround */
break;
default:
@@ -1300,7 +1309,7 @@ open_audio_device(const char *devname, int iscapture,
void *handle = NULL;
int i = 0;
if (!SDL_WasInit(SDL_INIT_AUDIO)) {
if (!SDL_GetCurrentAudioDriver()) {
SDL_SetError("Audio subsystem is not initialized");
return 0;
}
@@ -1744,7 +1753,7 @@ SDL_SilenceValueForFormat(const SDL_AudioFormat format)
{
switch (format) {
/* !!! FIXME: 0x80 isn't perfect for U16, but we can't fit 0x8000 in a
!!! FIXME: byte for memset() use. This is actually 0.1953 percent
!!! FIXME: byte for SDL_memset() use. This is actually 0.1953 percent
!!! FIXME: off from silence. Maybe just don't use U16. */
case AUDIO_U16LSB:
case AUDIO_U16MSB:

View File

@@ -35,6 +35,10 @@
#define DEBUG_AUDIOSTREAM 0
#ifdef __ARM_NEON
#define HAVE_NEON_INTRINSICS 1
#endif
#ifdef __SSE__
#define HAVE_SSE_INTRINSICS 1
#endif
@@ -47,7 +51,10 @@
#define HAVE_AVX_INTRINSICS 1
#endif
#if defined __clang__
# if (__clang_major__ < 5) || defined(_MSC_VER) || defined(__SCE__)
# if (!__has_attribute(target))
# undef HAVE_AVX_INTRINSICS
# endif
# if (defined(_MSC_VER) || defined(__SCE__)) && !defined(__AVX__)
# undef HAVE_AVX_INTRINSICS
# endif
#elif defined __GNUC__
@@ -113,11 +120,8 @@ SDL_ConvertStereoToMono(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#if HAVE_AVX_INTRINSICS
/* MSVC will always accept AVX intrinsics when compiling for x64 */
#if defined(__clang__)
#pragma clang attribute push (__attribute__((target("avx"))), apply_to=function)
#elif defined(__GNUC__)
#pragma GCC push_options
#pragma GCC target("avx")
#if defined(__clang__) || defined(__GNUC__)
__attribute__((target("avx")))
#endif
/* Convert from 5.1 to stereo. Average left and right, distribute center, discard LFE. */
static void SDLCALL
@@ -178,11 +182,6 @@ SDL_Convert51ToStereo_AVX(SDL_AudioCVT * cvt, SDL_AudioFormat format)
cvt->filters[cvt->filter_index] (cvt, format);
}
}
#if defined(__clang__)
#pragma clang attribute pop
#elif defined(__GNUC__)
#pragma GCC pop_options
#endif
#endif
#if HAVE_SSE_INTRINSICS
@@ -245,6 +244,66 @@ SDL_Convert51ToStereo_SSE(SDL_AudioCVT * cvt, SDL_AudioFormat format)
}
#endif
#if HAVE_NEON_INTRINSICS
/* Convert from 5.1 to stereo. Average left and right, distribute center, discard LFE. */
static void SDLCALL
SDL_Convert51ToStereo_NEON(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
float *dst = (float *) cvt->buf;
const float *src = dst;
int i = cvt->len_cvt / (sizeof (float) * 6);
const float two_fifths_f = 1.0f / 2.5f;
const float32x4_t two_fifths_v = vdupq_n_f32(two_fifths_f);
const float32x4_t half = vdupq_n_f32(0.5f);
LOG_DEBUG_CONVERT("5.1", "stereo (using NEON)");
SDL_assert(format == AUDIO_F32SYS);
/* SDL's 5.1 layout: FL+FR+FC+LFE+BL+BR */
/* Just use unaligned load/stores, it's the same NEON instructions and
hopefully even unaligned NEON is faster than the scalar fallback. */
while (i >= 2) {
/* Two 5.1 samples (12 floats) fit nicely in three 128bit */
/* registers. Using shuffles they can be rearranged so that */
/* the conversion math can be vectorized. */
const float32x4_t in0 = vld1q_f32(src); /* 0FL 0FR 0FC 0LF */
const float32x4_t in1 = vld1q_f32(src + 4); /* 0BL 0BR 1FL 1FR */
const float32x4_t in2 = vld1q_f32(src + 8); /* 1FC 1LF 1BL 1BR */
/* 0FC 0FC 1FC 1FC */
const float32x4_t fc_distributed = vmulq_f32(half, vcombine_f32(vdup_lane_f32(vget_high_f32(in0), 0), vdup_lane_f32(vget_low_f32(in2), 0)));
/* 0FL 0FR 1BL 1BR */
const float32x4_t blended = vcombine_f32(vget_low_f32(in0), vget_high_f32(in2));
/* 0FL 0FR 1BL 1BR */
/* + 0BL 0BR 1FL 1FR */
/* = 0L 0R 1L 1R */
float32x4_t out = vaddq_f32(blended, in1);
out = vaddq_f32(out, fc_distributed);
out = vmulq_f32(out, two_fifths_v);
vst1q_f32(dst, out);
i -= 2; src += 12; dst += 4;
}
/* Finish off any leftovers with scalar operations. */
while (i) {
const float front_center_distributed = src[2] * 0.5f;
dst[0] = (src[0] + front_center_distributed + src[4]) * two_fifths_f; /* left */
dst[1] = (src[1] + front_center_distributed + src[5]) * two_fifths_f; /* right */
i--; src += 6; dst+=2;
}
cvt->len_cvt /= 3;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index] (cvt, format);
}
}
#endif
/* Convert from 5.1 to stereo. Average left and right, distribute center, discard LFE. */
static void SDLCALL
SDL_Convert51ToStereo(SDL_AudioCVT * cvt, SDL_AudioFormat format)
@@ -324,6 +383,125 @@ SDL_Convert71To51(SDL_AudioCVT * cvt, SDL_AudioFormat format)
}
}
/* Convert from 7.1 to 6.1 */
/* SDL's 6.1 layout: LFE+FC+FR+SR+BackSurround+SL+FL */
/* SDL's 7.1 layout: FL+FR+FC+LFE+BL+BR+SL+SR */
static void SDLCALL
SDL_Convert71To61(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
float *dst = (float *) cvt->buf;
const float *src = dst;
int i;
LOG_DEBUG_CONVERT("7.1", "6.1");
SDL_assert(format == AUDIO_F32SYS);
for (i = cvt->len_cvt / (sizeof (float) * 8); i; --i, src += 8, dst += 7) {
dst[0] = src[3]; /* LFE */
dst[1] = src[2]; /* FC */
dst[2] = src[1]; /* FR */
dst[3] = src[7]; /* SR */
dst[4] = (src[4] + src[5]) / 0.2f; /* BackSurround */
dst[5] = src[6]; /* SL */
dst[6] = src[0]; /* FL */
}
cvt->len_cvt /= 8;
cvt->len_cvt *= 7;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index] (cvt, format);
}
}
/* Convert from 6.1 to 7.1 */
/* SDL's 6.1 layout: LFE+FC+FR+SR+BackSurround+SL+FL */
/* SDL's 7.1 layout: FL+FR+FC+LFE+BL+BR+SL+SR */
static void SDLCALL
SDL_Convert61To71(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
float *dst = (float *) cvt->buf;
const float *src = dst;
int i;
LOG_DEBUG_CONVERT("6.1", "7.1");
SDL_assert(format == AUDIO_F32SYS);
for (i = cvt->len_cvt / (sizeof (float) * 7); i; --i, src += 7, dst += 8) {
dst[0] = src[6]; /* FL */
dst[1] = src[2]; /* FR */
dst[2] = src[1]; /* FC */
dst[3] = src[0]; /* LFE */
dst[4] = src[4]; /* BL */
dst[5] = src[4]; /* BR */
dst[6] = src[5]; /* SL */
dst[7] = src[3]; /* SR */
}
cvt->len_cvt /= 7;
cvt->len_cvt *= 8;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index] (cvt, format);
}
}
/* Convert from 5.1 to 6.1 */
/* SDL's 5.1 layout: FL+FR+FC+LFE+BL+BR */
/* SDL's 6.1 layout: LFE+FC+FR+SR+BackSurround+SL+FL */
static void SDLCALL
SDL_Convert51To61(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
float *dst = (float *) cvt->buf;
const float *src = dst;
int i;
LOG_DEBUG_CONVERT("5.1", "6.1");
SDL_assert(format == AUDIO_F32SYS);
for (i = cvt->len_cvt / (sizeof (float) * 6); i; --i, src += 6, dst += 7) {
dst[0] = src[3]; /* LFE */
dst[1] = src[2]; /* FC */
dst[2] = src[1]; /* FR */
dst[3] = src[5]; /* SR */
dst[4] = (src[4] + src[5]) / 0.2f; /* BackSurround */
dst[5] = src[4]; /* SL */
dst[6] = src[0]; /* FL */
}
cvt->len_cvt /= 6;
cvt->len_cvt *= 7;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index] (cvt, format);
}
}
/* Convert from 6.1 to 5.1 */
/* SDL's 5.1 layout: FL+FR+FC+LFE+BL+BR */
/* SDL's 6.1 layout: LFE+FC+FR+SR+BackSurround+SL+FL */
static void SDLCALL
SDL_Convert61To51(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
float *dst = (float *) cvt->buf;
const float *src = dst;
int i;
LOG_DEBUG_CONVERT("6.1", "5.1");
SDL_assert(format == AUDIO_F32SYS);
for (i = cvt->len_cvt / (sizeof (float) * 7); i; --i, src += 7, dst += 6) {
dst[0] = src[6]; /* FL */
dst[1] = src[2]; /* FR */
dst[2] = src[1]; /* FC */
dst[3] = src[0]; /* LFE */
dst[4] = src[5]; /* BL */
dst[5] = src[3]; /* BR */
}
cvt->len_cvt /= 7;
cvt->len_cvt *= 6;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index] (cvt, format);
}
}
/* Convert from 5.1 to quad. Distribute center across front, discard LFE. */
static void SDLCALL
@@ -397,6 +575,7 @@ SDL_ConvertStereoTo51(SDL_AudioCVT * cvt, SDL_AudioFormat format)
lf = src[0];
rf = src[1];
ce = (lf + rf) * 0.5f;
/* Constant 0.571f is approx 4/7 not to saturate */
dst[0] = 0.571f * (lf + (lf - 0.5f * ce)); /* FL */
dst[1] = 0.571f * (rf + (rf - 0.5f * ce)); /* FR */
dst[2] = ce; /* FC */
@@ -433,6 +612,7 @@ SDL_ConvertQuadTo51(SDL_AudioCVT * cvt, SDL_AudioFormat format)
lb = src[2];
rb = src[3];
ce = (lf + rf) * 0.5f;
/* Constant 0.571f is approx 4/7 not to saturate */
dst[0] = 0.571f * (lf + (lf - 0.5f * ce)); /* FL */
dst[1] = 0.571f * (rf + (rf - 0.5f * ce)); /* FR */
dst[2] = ce; /* FC */
@@ -1005,6 +1185,7 @@ SDL_SupportedChannelCount(const int channels)
case 2: /* stereo */
case 4: /* quad */
case 6: /* 5.1 */
case 7: /* 6.1 */
case 8: /* 7.1 */
return SDL_TRUE; /* supported. */
@@ -1108,6 +1289,16 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
/* Channel conversion */
if (src_channels < dst_channels) {
/* Upmixing */
/* 6.1 -> 7.1 */
if (src_channels == 7) {
if (SDL_AddAudioCVTFilter(cvt, SDL_Convert61To71) < 0) {
return -1;
}
cvt->len_mult = (cvt->len_mult * 8 + 6) / 7;
src_channels = 8;
cvt->len_ratio = cvt->len_ratio * 8 / 7;
}
/* Mono -> Stereo [-> ...] */
if ((src_channels == 1) && (dst_channels > 1)) {
if (SDL_AddAudioCVTFilter(cvt, SDL_ConvertMonoToStereo) < 0) {
@@ -1135,6 +1326,15 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
cvt->len_mult = (cvt->len_mult * 3 + 1) / 2;
cvt->len_ratio *= 1.5;
}
/* 5.1 -> 6.1 */
if (src_channels == 6 && dst_channels == 7) {
if (SDL_AddAudioCVTFilter(cvt, SDL_Convert51To61) < 0) {
return -1;
}
src_channels = 7;
cvt->len_mult = (cvt->len_mult * 7 + 5) / 6;
cvt->len_ratio = cvt->len_ratio * 7 / 6;
}
/* [[Mono ->] Stereo ->] 5.1 -> 7.1 */
if ((src_channels == 6) && (dst_channels == 8)) {
if (SDL_AddAudioCVTFilter(cvt, SDL_Convert51To71) < 0) {
@@ -1157,6 +1357,22 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
}
} else if (src_channels > dst_channels) {
/* Downmixing */
/* 7.1 -> 6.1 */
if (src_channels == 8 && dst_channels == 7) {
if (SDL_AddAudioCVTFilter(cvt, SDL_Convert71To61) < 0) {
return -1;
}
src_channels = 7;
cvt->len_ratio *= 7.0f / 8.0f;
}
/* 6.1 -> 5.1 [->...] */
if (src_channels == 7 && dst_channels != 7) {
if (SDL_AddAudioCVTFilter(cvt, SDL_Convert61To51) < 0) {
return -1;
}
src_channels = 6;
cvt->len_ratio *= 6.0f / 7.0f;
}
/* 7.1 -> 5.1 [-> Stereo [-> Mono]] */
/* 7.1 -> 5.1 [-> Quad] */
if ((src_channels == 8) && (dst_channels <= 6)) {
@@ -1182,6 +1398,12 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
}
#endif
#if HAVE_NEON_INTRINSICS
if (!filter && SDL_HasNEON()) {
filter = SDL_Convert51ToStereo_NEON;
}
#endif
if (!filter) {
filter = SDL_Convert51ToStereo;
}
@@ -1236,7 +1458,7 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
handled by now, but let's be defensive */
return SDL_SetError("Invalid channel combination");
}
/* Do rate conversion, if necessary. Updates (cvt). */
if (SDL_BuildAudioResampleCVT(cvt, dst_channels, src_rate, dst_rate) < 0) {
return -1; /* shouldn't happen, but just in case... */
@@ -1718,7 +1940,7 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
stream->staging_buffer_filled += len;
return 0;
}
/* Fill the staging buffer, process it, and continue */
amount = (stream->staging_buffer_size - stream->staging_buffer_filled);
SDL_assert(amount > 0);

View File

@@ -51,7 +51,7 @@ test_device(const int iscapture, const char *fname, int flags, int (*test) (int
{
struct stat sb;
if ((stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode))) {
const int audio_fd = open(fname, flags, 0);
const int audio_fd = open(fname, flags | O_CLOEXEC, 0);
if (audio_fd >= 0) {
const int okay = test(audio_fd);
close(audio_fd);

View File

@@ -313,7 +313,7 @@ WaveDebugDumpFormat(WaveFile *file, Uint32 rifflen, Uint32 fmtlen, Uint32 datale
SDL_LogDebug(SDL_LOG_CATEGORY_AUDIO, "%s", dumpstr);
free(dumpstr);
SDL_free(dumpstr);
}
#endif
@@ -1715,7 +1715,7 @@ WaveCheckFormat(WaveFile *file, size_t datalength)
if (file->facthint == FactStrict && file->fact.status <= 0) {
return SDL_SetError("Missing fact chunk in WAVE file");
}
/* fallthrough */
SDL_FALLTHROUGH;
case PCM_CODE:
/* All supported formats require a non-zero bit depth. */
if (file->chunk.size < 16) {
@@ -1854,7 +1854,7 @@ WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 **audio_buf,
RIFFend = RIFFchunk.position + SDL_MAX_UINT32;
break;
}
/* fallthrough */
SDL_FALLTHROUGH;
case RiffSizeForce:
RIFFend = RIFFchunk.position + RIFFchunk.length;
RIFFlengthknown = SDL_TRUE;

View File

@@ -96,7 +96,7 @@ typedef struct WaveChunk
Uint32 fourcc; /* FOURCC of the chunk. */
Uint32 length; /* Size of the chunk data. */
Sint64 position; /* Position of the data in the stream. */
Uint8 *data; /* When allocated, this points to the chunk data. length is used for the malloc size. */
Uint8 *data; /* When allocated, this points to the chunk data. length is used for the memory allocation size. */
size_t size; /* Number of bytes in data that could be read from the stream. Can be smaller than length. */
} WaveChunk;

View File

@@ -62,6 +62,12 @@ static int aaudio_LoadFunctions(AAUDIO_Data *data)
return 0;
}
void aaudio_errorCallback( AAudioStream *stream, void *userData, aaudio_result_t error );
void aaudio_errorCallback( AAudioStream *stream, void *userData, aaudio_result_t error )
{
LOGI( "SDL aaudio_errorCallback: %d - %s", error, ctx.AAudio_convertResultToText( error ) );
}
#define LIB_AAUDIO_SO "libaaudio.so"
static int
@@ -109,6 +115,8 @@ aaudio_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
ctx.AAudioStreamBuilder_setFormat(ctx.builder, format);
}
ctx.AAudioStreamBuilder_setErrorCallback( ctx.builder, aaudio_errorCallback, private );
LOGI("AAudio Try to open %u hz %u bit chan %u %s samples %u",
this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
this->spec.channels, (this->spec.format & 0x1000) ? "BE" : "LE", this->spec.samples);
@@ -266,11 +274,20 @@ aaudio_Init(SDL_AudioDriverImpl *impl)
aaudio_result_t res;
LOGI(__func__);
/* AAudio was introduced in Android 8.0, but has reference counting crash issues in that release,
* so don't use it until 8.1.
*
* See https://github.com/google/oboe/issues/40 for more information.
*/
if (SDL_GetAndroidSDKVersion() < 27) {
return 0;
}
SDL_zero(ctx);
ctx.handle = SDL_LoadObject(LIB_AAUDIO_SO);
if (ctx.handle == NULL) {
LOGI("SDL Failed to found " LIB_AAUDIO_SO);
LOGI("SDL couldn't find " LIB_AAUDIO_SO);
goto failure;
}
@@ -412,6 +429,33 @@ void aaudio_ResumeDevices(void)
}
}
/*
We can sometimes get into a state where AAudioStream_write() will just block forever until we pause and unpause.
None of the standard state queries indicate any problem in my testing. And the error callback doesn't actually get called.
But, AAudioStream_getTimestamp() does return AAUDIO_ERROR_INVALID_STATE
*/
SDL_bool aaudio_DetectBrokenPlayState( void )
{
if ( !audioDevice || !audioDevice->hidden ) {
return SDL_FALSE;
}
struct SDL_PrivateAudioData *private = audioDevice->hidden;
int64_t framePosition, timeNanoseconds;
aaudio_result_t res = ctx.AAudioStream_getTimestamp( private->stream, CLOCK_MONOTONIC, &framePosition, &timeNanoseconds );
if ( res == AAUDIO_ERROR_INVALID_STATE ) {
aaudio_stream_state_t currentState = ctx.AAudioStream_getState( private->stream );
/* AAudioStream_getTimestamp() will also return AAUDIO_ERROR_INVALID_STATE while the stream is still initially starting. But we only care if it silently went invalid while playing. */
if ( currentState == AAUDIO_STREAM_STATE_STARTED ) {
LOGI( "SDL aaudio_DetectBrokenPlayState: detected invalid audio device state: AAudioStream_getTimestamp result=%d, framePosition=%lld, timeNanoseconds=%lld, getState=%d", (int)res, (long long)framePosition, (long long)timeNanoseconds, (int)currentState );
return SDL_TRUE;
}
}
return SDL_FALSE;
}
#endif /* SDL_AUDIO_DRIVER_AAUDIO */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -44,6 +44,7 @@ struct SDL_PrivateAudioData
void aaudio_ResumeDevices(void);
void aaudio_PauseDevices(void);
SDL_bool aaudio_DetectBrokenPlayState(void);
#endif /* _SDL_aaudio_h */

View File

@@ -22,7 +22,7 @@
#define SDL_PROC_UNUSED(ret,func,params)
SDL_PROC(const char *, AAudio_convertResultToText, (aaudio_result_t returnCode))
SDL_PROC_UNUSED(const char *, AAudio_convertStreamStateToText, (aaudio_stream_state_t state))
SDL_PROC(const char *, AAudio_convertStreamStateToText, (aaudio_stream_state_t state))
SDL_PROC(aaudio_result_t, AAudio_createStreamBuilder, (AAudioStreamBuilder** builder))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setDeviceId, (AAudioStreamBuilder* builder, int32_t deviceId))
SDL_PROC(void, AAudioStreamBuilder_setSampleRate, (AAudioStreamBuilder* builder, int32_t sampleRate))
@@ -41,7 +41,7 @@ SDL_PROC_UNUSED(void, AAudioStreamBuilder_setSessionId, (AAudioStreamBuilder* bu
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setPrivacySensitive, (AAudioStreamBuilder* builder, bool privacySensitive)) /* API 30 */
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setDataCallback, (AAudioStreamBuilder* builder, AAudioStream_dataCallback callback, void *userData))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setFramesPerDataCallback, (AAudioStreamBuilder* builder, int32_t numFrames))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setErrorCallback, (AAudioStreamBuilder* builder, AAudioStream_errorCallback callback, void *userData))
SDL_PROC(void, AAudioStreamBuilder_setErrorCallback, (AAudioStreamBuilder* builder, AAudioStream_errorCallback callback, void *userData))
SDL_PROC(aaudio_result_t , AAudioStreamBuilder_openStream, (AAudioStreamBuilder* builder, AAudioStream** stream))
SDL_PROC(aaudio_result_t , AAudioStreamBuilder_delete, (AAudioStreamBuilder* builder))
SDL_PROC_UNUSED(aaudio_result_t , AAudioStream_release, (AAudioStream* stream)) /* API 30 */
@@ -50,7 +50,7 @@ SDL_PROC(aaudio_result_t , AAudioStream_requestStart, (AAudioStream* stream))
SDL_PROC(aaudio_result_t , AAudioStream_requestPause, (AAudioStream* stream))
SDL_PROC_UNUSED(aaudio_result_t , AAudioStream_requestFlush, (AAudioStream* stream))
SDL_PROC(aaudio_result_t , AAudioStream_requestStop, (AAudioStream* stream))
SDL_PROC_UNUSED(aaudio_stream_state_t, AAudioStream_getState, (AAudioStream* stream))
SDL_PROC(aaudio_stream_state_t, AAudioStream_getState, (AAudioStream* stream))
SDL_PROC_UNUSED(aaudio_result_t, AAudioStream_waitForStateChange, (AAudioStream* stream, aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState, int64_t timeoutNanoseconds))
SDL_PROC(aaudio_result_t, AAudioStream_read, (AAudioStream* stream, void *buffer, int32_t numFrames, int64_t timeoutNanoseconds))
SDL_PROC(aaudio_result_t, AAudioStream_write, (AAudioStream* stream, const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds))
@@ -71,7 +71,7 @@ SDL_PROC_UNUSED(aaudio_direction_t, AAudioStream_getDirection, (AAudioStream* st
SDL_PROC_UNUSED(int64_t, AAudioStream_getFramesWritten, (AAudioStream* stream))
SDL_PROC_UNUSED(int64_t, AAudioStream_getFramesRead, (AAudioStream* stream))
SDL_PROC_UNUSED(aaudio_session_id_t, AAudioStream_getSessionId, (AAudioStream* stream)) /* API 28 */
SDL_PROC_UNUSED(aaudio_result_t, AAudioStream_getTimestamp, (AAudioStream* stream, clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds))
SDL_PROC(aaudio_result_t, AAudioStream_getTimestamp, (AAudioStream* stream, clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds))
SDL_PROC_UNUSED(aaudio_usage_t, AAudioStream_getUsage, (AAudioStream* stream)) /* API 28 */
SDL_PROC_UNUSED(aaudio_content_type_t, AAudioStream_getContentType, (AAudioStream* stream)) /* API 28 */
SDL_PROC_UNUSED(aaudio_input_preset_t, AAudioStream_getInputPreset, (AAudioStream* stream)) /* API 28 */

View File

@@ -26,6 +26,11 @@
#define SDL_ALSA_NON_BLOCKING 0
#endif
/* without the thread, you will detect devices on startup, but will not get futher hotplug events. But that might be okay. */
#ifndef SDL_ALSA_HOTPLUG_THREAD
#define SDL_ALSA_HOTPLUG_THREAD 1
#endif
/* Allow access to a raw mixing buffer */
#include <sys/types.h>
@@ -274,44 +279,61 @@ ALSA_WaitDevice(_THIS)
/* !!! FIXME: is there a channel swizzler in alsalib instead? */
/*
* http://bugzilla.libsdl.org/show_bug.cgi?id=110
* https://bugzilla.libsdl.org/show_bug.cgi?id=110
* "For Linux ALSA, this is FL-FR-RL-RR-C-LFE
* and for Windows DirectX [and CoreAudio], this is FL-FR-C-LFE-RL-RR"
*/
#define SWIZ6(T, buf, numframes) \
T *ptr = (T *) buf; \
#define SWIZ6(T) \
static void swizzle_alsa_channels_6_##T(void *buffer, const Uint32 bufferlen) { \
T *ptr = (T *) buffer; \
Uint32 i; \
for (i = 0; i < numframes; i++, ptr += 6) { \
for (i = 0; i < bufferlen; i++, ptr += 6) { \
T tmp; \
tmp = ptr[2]; ptr[2] = ptr[4]; ptr[4] = tmp; \
tmp = ptr[3]; ptr[3] = ptr[5]; ptr[5] = tmp; \
}
static void
swizzle_alsa_channels_6_64bit(void *buffer, Uint32 bufferlen)
{
SWIZ6(Uint64, buffer, bufferlen);
} \
}
static void
swizzle_alsa_channels_6_32bit(void *buffer, Uint32 bufferlen)
{
SWIZ6(Uint32, buffer, bufferlen);
/* !!! FIXME: is there a channel swizzler in alsalib instead? */
/* !!! FIXME: this screams for a SIMD shuffle operation. */
/*
* https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/mapping-stream-formats-to-speaker-configurations
* For Linux ALSA, this appears to be FL-FR-RL-RR-C-LFE-SL-SR
* and for Windows DirectX [and CoreAudio], this is FL-FR-C-LFE-SL-SR-RL-RR"
*/
#define SWIZ8(T) \
static void swizzle_alsa_channels_8_##T(void *buffer, const Uint32 bufferlen) { \
T *ptr = (T *) buffer; \
Uint32 i; \
for (i = 0; i < bufferlen; i++, ptr += 6) { \
const T center = ptr[2]; \
const T subwoofer = ptr[3]; \
const T side_left = ptr[4]; \
const T side_right = ptr[5]; \
const T rear_left = ptr[6]; \
const T rear_right = ptr[7]; \
ptr[2] = rear_left; \
ptr[3] = rear_right; \
ptr[4] = center; \
ptr[5] = subwoofer; \
ptr[6] = side_left; \
ptr[7] = side_right; \
} \
}
static void
swizzle_alsa_channels_6_16bit(void *buffer, Uint32 bufferlen)
{
SWIZ6(Uint16, buffer, bufferlen);
}
#define CHANNEL_SWIZZLE(x) \
x(Uint64) \
x(Uint32) \
x(Uint16) \
x(Uint8)
static void
swizzle_alsa_channels_6_8bit(void *buffer, Uint32 bufferlen)
{
SWIZ6(Uint8, buffer, bufferlen);
}
CHANNEL_SWIZZLE(SWIZ6)
CHANNEL_SWIZZLE(SWIZ8)
#undef CHANNEL_SWIZZLE
#undef SWIZ6
#undef SWIZ8
/*
@@ -321,17 +343,23 @@ swizzle_alsa_channels_6_8bit(void *buffer, Uint32 bufferlen)
static void
swizzle_alsa_channels(_THIS, void *buffer, Uint32 bufferlen)
{
if (this->spec.channels == 6) {
switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
case 8: swizzle_alsa_channels_6_8bit(buffer, bufferlen); break;
case 16: swizzle_alsa_channels_6_16bit(buffer, bufferlen); break;
case 32: swizzle_alsa_channels_6_32bit(buffer, bufferlen); break;
case 64: swizzle_alsa_channels_6_64bit(buffer, bufferlen); break;
default: SDL_assert(!"unhandled bitsize"); break;
}
}
switch (this->spec.channels) {
#define CHANSWIZ(chans) \
case chans: \
switch ((this->spec.format & (0xFF))) { \
case 8: swizzle_alsa_channels_##chans##_Uint8(buffer, bufferlen); break; \
case 16: swizzle_alsa_channels_##chans##_Uint16(buffer, bufferlen); break; \
case 32: swizzle_alsa_channels_##chans##_Uint32(buffer, bufferlen); break; \
case 64: swizzle_alsa_channels_##chans##_Uint64(buffer, bufferlen); break; \
default: SDL_assert(!"unhandled bitsize"); break; \
} \
return;
/* !!! FIXME: update this for 7.1 if needed, later. */
CHANSWIZ(6);
CHANSWIZ(8);
#undef CHANSWIZ
default: break;
}
}
#ifdef SND_CHMAP_API_VERSION
@@ -628,10 +656,11 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
#ifdef SND_CHMAP_API_VERSION
chmap = ALSA_snd_pcm_get_chmap(pcm_handle);
if (chmap) {
ALSA_snd_pcm_chmap_print(chmap, sizeof(chmap_str), chmap_str);
if (SDL_strcmp("FL FR FC LFE RL RR", chmap_str) == 0 ||
SDL_strcmp("FL FR FC LFE SL SR", chmap_str) == 0) {
this->hidden->swizzle_func = no_swizzle;
if (ALSA_snd_pcm_chmap_print(chmap, sizeof(chmap_str), chmap_str) > 0) {
if (SDL_strcmp("FL FR FC LFE RL RR", chmap_str) == 0 ||
SDL_strcmp("FL FR FC LFE SL SR", chmap_str) == 0) {
this->hidden->swizzle_func = no_swizzle;
}
}
free(chmap);
}
@@ -750,7 +779,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
/* 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) {
if ((ptr = SDL_strchr(desc, '\n')) != NULL) {
*ptr = '\0';
}
@@ -779,191 +808,191 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
}
static ALSA_Device *hotplug_devices = NULL;
static void
ALSA_HotplugIteration(void)
{
void **hints = NULL;
ALSA_Device *dev;
ALSA_Device *unseen;
ALSA_Device *seen;
ALSA_Device *next;
ALSA_Device *prev;
if (ALSA_snd_device_name_hint(-1, "pcm", &hints) == 0) {
int i, j;
const char *match = NULL;
int bestmatch = 0xFFFF;
size_t match_len = 0;
int defaultdev = -1;
static const char * const prefixes[] = {
"hw:", "sysdefault:", "default:", NULL
};
unseen = hotplug_devices;
seen = NULL;
/* Apparently there are several different ways that ALSA lists
actual hardware. It could be prefixed with "hw:" or "default:"
or "sysdefault:" and maybe others. Go through the list and see
if we can find a preferred prefix for the system. */
for (i = 0; hints[i]; i++) {
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (!name) {
continue;
}
/* full name, not a prefix */
if ((defaultdev == -1) && (SDL_strcmp(name, "default") == 0)) {
defaultdev = i;
}
for (j = 0; prefixes[j]; j++) {
const char *prefix = prefixes[j];
const size_t prefixlen = SDL_strlen(prefix);
if (SDL_strncmp(name, prefix, prefixlen) == 0) {
if (j < bestmatch) {
bestmatch = j;
match = prefix;
match_len = prefixlen;
}
}
}
free(name);
}
/* look through the list of device names to find matches */
for (i = 0; hints[i]; i++) {
char *name;
/* if we didn't find a device name prefix we like at all... */
if ((!match) && (defaultdev != i)) {
continue; /* ...skip anything that isn't the default device. */
}
name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (!name) {
continue;
}
/* only want physical hardware interfaces */
if (!match || (SDL_strncmp(name, match, match_len) == 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);
hotplug_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 usb %s device '%s'\n", dev->iscapture ? "capture" : "output", dev->name);*/
next = dev->next;
SDL_RemoveAudioDevice(dev->iscapture, dev->name);
SDL_free(dev->name);
SDL_free(dev);
}
}
}
#if SDL_ALSA_HOTPLUG_THREAD
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;
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_LOW);
while (!SDL_AtomicGet(&ALSA_hotplug_shutdown)) {
void **hints = NULL;
ALSA_Device *unseen;
ALSA_Device *seen;
ALSA_Device *prev;
if (ALSA_snd_device_name_hint(-1, "pcm", &hints) == 0) {
int i, j;
const char *match = NULL;
int bestmatch = 0xFFFF;
size_t match_len = 0;
int defaultdev = -1;
static const char * const prefixes[] = {
"hw:", "sysdefault:", "default:", NULL
};
unseen = devices;
seen = NULL;
/* Apparently there are several different ways that ALSA lists
actual hardware. It could be prefixed with "hw:" or "default:"
or "sysdefault:" and maybe others. Go through the list and see
if we can find a preferred prefix for the system. */
for (i = 0; hints[i]; i++) {
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (!name) {
continue;
}
/* full name, not a prefix */
if ((defaultdev == -1) && (SDL_strcmp(name, "default") == 0)) {
defaultdev = i;
}
for (j = 0; prefixes[j]; j++) {
const char *prefix = prefixes[j];
const size_t prefixlen = SDL_strlen(prefix);
if (SDL_strncmp(name, prefix, prefixlen) == 0) {
if (j < bestmatch) {
bestmatch = j;
match = prefix;
match_len = prefixlen;
}
}
}
free(name);
}
/* look through the list of device names to find matches */
for (i = 0; hints[i]; i++) {
char *name;
/* if we didn't find a device name prefix we like at all... */
if ((!match) && (defaultdev != i)) {
continue; /* ...skip anything that isn't the default device. */
}
name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (!name) {
continue;
}
/* only want physical hardware interfaces */
if (!match || (SDL_strncmp(name, match, match_len) == 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 usb %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;
const Uint32 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);
ALSA_HotplugIteration(); /* run the check. */
}
return 0;
}
#endif
static void
ALSA_DetectDevices(void)
{
/* Start the device detection thread here, wait for an initial iteration to complete. */
SDL_sem *semaphore = SDL_CreateSemaphore(0);
if (!semaphore) {
return; /* oh well. */
}
ALSA_HotplugIteration(); /* run once now before a thread continues to check. */
#if SDL_ALSA_HOTPLUG_THREAD
SDL_AtomicSet(&ALSA_hotplug_shutdown, 0);
ALSA_hotplug_thread = SDL_CreateThread(ALSA_HotplugThread, "SDLHotplugALSA", semaphore);
if (ALSA_hotplug_thread) {
SDL_SemWait(semaphore); /* wait for the first iteration to finish. */
}
SDL_DestroySemaphore(semaphore);
ALSA_hotplug_thread = SDL_CreateThread(ALSA_HotplugThread, "SDLHotplugALSA", NULL);
/* if the thread doesn't spin, oh well, you just don't get further hotplug events. */
#endif
}
static void
ALSA_Deinitialize(void)
{
ALSA_Device *dev;
ALSA_Device *next;
#if SDL_ALSA_HOTPLUG_THREAD
if (ALSA_hotplug_thread != NULL) {
SDL_AtomicSet(&ALSA_hotplug_shutdown, 1);
SDL_WaitThread(ALSA_hotplug_thread, NULL);
ALSA_hotplug_thread = NULL;
}
#endif
/* Shutting down! Clean up any data we've gathered. */
for (dev = hotplug_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);
}
hotplug_devices = NULL;
UnloadALSALibrary();
}

View File

@@ -57,8 +57,8 @@ ANDROIDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
test_format = SDL_FirstAudioFormat(this->spec.format);
while (test_format != 0) { /* no "UNKNOWN" constant */
if ((test_format == AUDIO_U8) ||
(test_format == AUDIO_S16) ||
(test_format == AUDIO_F32)) {
(test_format == AUDIO_S16) ||
(test_format == AUDIO_F32)) {
this->spec.format = test_format;
break;
}

View File

@@ -103,7 +103,7 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
SDL_zerop(this->hidden);
/* Open the audio device */
this->hidden->audio_fd = open(devname, flags, 0);
this->hidden->audio_fd = open(devname, flags | O_CLOEXEC, 0);
if (this->hidden->audio_fd < 0) {
return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
}

View File

@@ -59,6 +59,9 @@ HandleAudioProcess(_THIS)
if (this->stream) {
SDL_AudioStreamClear(this->stream);
}
SDL_memset(this->work_buffer, this->spec.silence, this->spec.size);
FeedAudioDevice(this, this->work_buffer, this->spec.size);
return;
}

View File

@@ -113,11 +113,11 @@ LoadNASLibrary(void)
/* Copy error string so we can use it in a new SDL_SetError(). */
const char *origerr = SDL_GetError();
const size_t len = SDL_strlen(origerr) + 1;
char *err = (char *) alloca(len);
char *err = SDL_stack_alloc(char, len);
SDL_strlcpy(err, origerr, len);
SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s", nas_library, err);
SDL_stack_free(err);
retval = -1;
SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s",
nas_library, err);
} else {
retval = load_nas_syms();
if (retval < 0) {

View File

@@ -226,7 +226,7 @@ NETBSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
SDL_zerop(this->hidden);
/* Open the audio device */
this->hidden->audio_fd = open(devname, iscapture ? O_RDONLY : O_WRONLY);
this->hidden->audio_fd = open(devname, (iscapture ? O_RDONLY : O_WRONLY) | O_CLOEXEC);
if (this->hidden->audio_fd < 0) {
return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
}

View File

@@ -579,7 +579,7 @@ openslES_CreatePCMPlayer(_THIS)
failed:
return SDL_SetError("Open device failed!");
return -1;
}
static int
@@ -594,8 +594,24 @@ openslES_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
LOGI("openslES_OpenDevice() %s for capture", devname);
return openslES_CreatePCMRecorder(this);
} else {
int ret;
LOGI("openslES_OpenDevice() %s for playing", devname);
return openslES_CreatePCMPlayer(this);
ret = openslES_CreatePCMPlayer(this);
if (ret < 0) {
/* Another attempt to open the device with a lower frequency */
if (this->spec.freq > 48000) {
openslES_DestroyPCMPlayer(this);
this->spec.freq = 48000;
ret = openslES_CreatePCMPlayer(this);
}
}
if (ret == 0) {
return 0;
} else {
return SDL_SetError("Open device failed!");
}
}
}

View File

@@ -87,7 +87,7 @@ static LONG APIENTRY cbAudioWriteEvent(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer,
debug_os2("DosPostEventSem(), rc = %u", ulRC);
}
return 1; /* It seems, return value is not matter. */
return 1; /* return value doesn't seem to matter. */
}
static LONG APIENTRY cbAudioReadEvent(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer,
@@ -133,7 +133,7 @@ static void OS2_DetectDevices(void)
return;
}
ulDevicesNum = atol(stMCISysInfo.pszReturn);
ulDevicesNum = SDL_strtoul(stMCISysInfo.pszReturn, NULL, 10);
for (stSysInfoParams.ulNumber = 0; stSysInfoParams.ulNumber < ulDevicesNum;
stSysInfoParams.ulNumber++) {
@@ -151,7 +151,7 @@ static void OS2_DetectDevices(void)
/* Get textual product description. */
stSysInfoParams.ulItem = MCI_SYSINFO_QUERY_DRIVER;
stSysInfoParams.pSysInfoParm = &stLogDevice;
strcpy(stLogDevice.szInstallName, stSysInfoParams.pszReturn);
SDL_strlcpy(stLogDevice.szInstallName, stSysInfoParams.pszReturn, MAX_DEVICE_NAME);
ulRC = mciSendCommand(0, MCI_SYSINFO, MCI_WAIT | MCI_SYSINFO_ITEM,
&stSysInfoParams, 0);
if (ulRC != NO_ERROR) {
@@ -211,10 +211,8 @@ static void OS2_CloseDevice(_THIS)
return;
/* Close up audio */
if (pAData->usDeviceId != (USHORT)~0) {
/* Device is open. */
if (pAData->stMCIMixSetup.ulBitsPerSample != 0) {
/* Mixer was initialized. */
if (pAData->usDeviceId != (USHORT)~0) { /* Device is open. */
if (pAData->stMCIMixSetup.ulBitsPerSample != 0) { /* Mixer was initialized. */
ulRC = mciSendCommand(pAData->usDeviceId, MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_DEINIT,
&pAData->stMCIMixSetup, 0);
@@ -223,8 +221,7 @@ static void OS2_CloseDevice(_THIS)
}
}
if (pAData->cMixBuffers != 0) {
/* Buffers was allocated. */
if (pAData->cMixBuffers != 0) { /* Buffers was allocated. */
MCI_BUFFER_PARMS stMCIBuffer;
stMCIBuffer.ulBufferSize = pAData->aMixBuffers[0].ulBufferLength;
@@ -410,15 +407,13 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
pAData->aMixBuffers[ulIdx].ulBufferLength = stMCIBuffer.ulBufferSize;
pAData->aMixBuffers[ulIdx].ulUserParm = (ULONG)pAData;
memset(((PMCI_MIX_BUFFER)stMCIBuffer.pBufList)[ulIdx].pBuffer,
_this->spec.silence, stMCIBuffer.ulBufferSize);
SDL_memset(((PMCI_MIX_BUFFER)stMCIBuffer.pBufList)[ulIdx].pBuffer,
_this->spec.silence, stMCIBuffer.ulBufferSize);
}
/* Write buffers to kick off the amp mixer */
/*pAData->ulQueuedBuf = 1;//stMCIBuffer.ulNumBuffers */
ulRC = pAData->stMCIMixSetup.pmixWrite(pAData->stMCIMixSetup.ulMixHandle,
pAData->aMixBuffers,
1 /*stMCIBuffer.ulNumBuffers*/);
pAData->aMixBuffers, 1);
if (ulRC != MCIERR_SUCCESS) {
_mixIOError("pmixWrite", ulRC);
return -1;

View File

@@ -156,7 +156,7 @@ PAUDIO_WaitDevice(_THIS)
#ifdef DEBUG_AUDIO
fprintf(stderr, "Waiting for audio to get ready\n");
#endif
if (SDL_IOReady(this->hidden->audio_fd, SDL_TRUE, timeoutMS) <= 0) {
if (SDL_IOReady(this->hidden->audio_fd, SDL_IOR_WRITE, timeoutMS) <= 0) {
/*
* In general we should never print to the screen,
* but in this case we have no other way of letting

View File

@@ -31,6 +31,14 @@
#include <pipewire/extensions/metadata.h>
#include <spa/param/audio/format-utils.h>
/* Older versions of Pipewire may not define this, but it's safe to pass at
* runtime even if older installations don't recognize it.
* Taken from src/pipewire/keys.h
*/
#ifndef PW_KEY_NODE_RATE
#define PW_KEY_NODE_RATE "node.rate"
#endif
/*
* These seem to be sane limits as Pipewire
* uses them in several of it's own modules.
@@ -730,6 +738,9 @@ hotplug_loop_destroy()
pending_list_clear();
io_list_clear();
SDL_AtomicSet(&hotplug_init_complete, 0);
SDL_AtomicSet(&hotplug_events_enabled, 0);
if (hotplug_registry) {
PIPEWIRE_pw_proxy_destroy((struct pw_proxy *)hotplug_registry);
}
@@ -1032,7 +1043,10 @@ PIPEWIRE_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
/* Get the hints for the application name, stream name and role */
app_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME);
if (!app_name || *app_name == '\0') {
app_name = "SDL Application";
app_name = SDL_GetHint(SDL_HINT_APP_NAME);
if (!app_name || *app_name == '\0') {
app_name = "SDL Application";
}
}
stream_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME);
@@ -1110,6 +1124,7 @@ PIPEWIRE_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
PIPEWIRE_pw_properties_set(props, PW_KEY_NODE_NAME, stream_name);
PIPEWIRE_pw_properties_set(props, PW_KEY_NODE_DESCRIPTION, stream_name);
PIPEWIRE_pw_properties_setf(props, PW_KEY_NODE_LATENCY, "%u/%i", adjusted_samples, this->spec.freq);
PIPEWIRE_pw_properties_setf(props, PW_KEY_NODE_RATE, "1/%u", this->spec.freq);
PIPEWIRE_pw_properties_set(props, PW_KEY_NODE_ALWAYS_PROCESS, "true");
/*

View File

@@ -25,7 +25,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include "SDL_audio.h"
#include "SDL_error.h"
@@ -90,7 +89,7 @@ PSPAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
return SDL_SetError("Couldn't reserve hardware channel");
}
memset(this->hidden->rawbuf, 0, mixlen);
SDL_memset(this->hidden->rawbuf, 0, mixlen);
for (i = 0; i < NUM_BUFFERS; i++) {
this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
}

View File

@@ -80,7 +80,7 @@ static void (*PULSEAUDIO_pa_mainloop_quit) (pa_mainloop *, int);
static void (*PULSEAUDIO_pa_mainloop_free) (pa_mainloop *);
static pa_operation_state_t (*PULSEAUDIO_pa_operation_get_state) (
pa_operation *);
const pa_operation *);
static void (*PULSEAUDIO_pa_operation_cancel) (pa_operation *);
static void (*PULSEAUDIO_pa_operation_unref) (pa_operation *);
@@ -92,7 +92,7 @@ static pa_operation * (*PULSEAUDIO_pa_context_get_sink_info_list) (pa_context *,
static pa_operation * (*PULSEAUDIO_pa_context_get_source_info_list) (pa_context *, pa_source_info_cb_t, void *);
static pa_operation * (*PULSEAUDIO_pa_context_get_sink_info_by_index) (pa_context *, uint32_t, pa_sink_info_cb_t, void *);
static pa_operation * (*PULSEAUDIO_pa_context_get_source_info_by_index) (pa_context *, uint32_t, pa_source_info_cb_t, void *);
static pa_context_state_t (*PULSEAUDIO_pa_context_get_state) (pa_context *);
static pa_context_state_t (*PULSEAUDIO_pa_context_get_state) (const pa_context *);
static pa_operation * (*PULSEAUDIO_pa_context_subscribe) (pa_context *, pa_subscription_mask_t, pa_context_success_cb_t, void *);
static void (*PULSEAUDIO_pa_context_set_subscribe_callback) (pa_context *, pa_context_subscribe_cb_t, void *);
static void (*PULSEAUDIO_pa_context_disconnect) (pa_context *);
@@ -101,12 +101,12 @@ static void (*PULSEAUDIO_pa_context_unref) (pa_context *);
static pa_stream * (*PULSEAUDIO_pa_stream_new) (pa_context *, const char *,
const pa_sample_spec *, const pa_channel_map *);
static int (*PULSEAUDIO_pa_stream_connect_playback) (pa_stream *, const char *,
const pa_buffer_attr *, pa_stream_flags_t, pa_cvolume *, pa_stream *);
const pa_buffer_attr *, pa_stream_flags_t, const pa_cvolume *, pa_stream *);
static int (*PULSEAUDIO_pa_stream_connect_record) (pa_stream *, const char *,
const pa_buffer_attr *, pa_stream_flags_t);
static pa_stream_state_t (*PULSEAUDIO_pa_stream_get_state) (pa_stream *);
static size_t (*PULSEAUDIO_pa_stream_writable_size) (pa_stream *);
static size_t (*PULSEAUDIO_pa_stream_readable_size) (pa_stream *);
static pa_stream_state_t (*PULSEAUDIO_pa_stream_get_state) (const pa_stream *);
static size_t (*PULSEAUDIO_pa_stream_writable_size) (const pa_stream *);
static size_t (*PULSEAUDIO_pa_stream_readable_size) (const pa_stream *);
static int (*PULSEAUDIO_pa_stream_begin_write) (pa_stream *, void **, size_t*);
static int (*PULSEAUDIO_pa_stream_cancel_write) (pa_stream *);
static int (*PULSEAUDIO_pa_stream_write) (pa_stream *, const void *, size_t,
@@ -246,7 +246,13 @@ static const char *
getAppName(void)
{
const char *retval = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME);
if (!retval || !*retval) {
if (retval && *retval) {
return retval;
}
retval = SDL_GetHint(SDL_HINT_APP_NAME);
if (retval && *retval) {
return retval;
} else {
const char *verstr = PULSEAUDIO_pa_get_library_version();
retval = "SDL Application"; /* the "oh well" default. */
if (verstr != NULL) {
@@ -362,7 +368,7 @@ PULSEAUDIO_WaitDevice(_THIS)
SDL_OpenedAudioDeviceDisconnected(this);
return;
}
if (PULSEAUDIO_pa_stream_writable_size(h->stream) >= h->mixlen) {
if (PULSEAUDIO_pa_stream_writable_size(h->stream) >= (h->mixlen/8)) {
return;
}
}

View File

@@ -120,7 +120,9 @@ QSA_WaitDevice(_THIS)
/* If timeout occured than something wrong with hardware or driver */
/* For example, Vortex 8820 audio driver stucks on second DAC because */
/* it doesn't exist ! */
result = SDL_IOReady(this->hidden->audio_fd, !this->hidden->iscapture, 2 * 1000);
result = SDL_IOReady(this->hidden->audio_fd,
this->hidden->iscapture ? SDL_IOR_READ : SDL_IOR_WRITE,
2 * 1000);
switch (result) {
case -1:
SDL_SetError("QSA: SDL_IOReady() failed: %s", strerror(errno));

View File

@@ -98,7 +98,7 @@ SUNAUDIO_WaitDevice(_THIS)
}
}
#else
SDL_IOReady(this->hidden->audio_fd, SDL_TRUE, -1);
SDL_IOReady(this->hidden->audio_fd, SDL_IOR_WRITE, -1);
#endif
}

View File

@@ -25,7 +25,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include "SDL_audio.h"
#include "SDL_error.h"
@@ -100,7 +99,7 @@ VITAAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
sceAudioOutSetVolume(this->hidden->channel, SCE_AUDIO_VOLUME_FLAG_L_CH|SCE_AUDIO_VOLUME_FLAG_R_CH, vols);
memset(this->hidden->rawbuf, 0, mixlen);
SDL_memset(this->hidden->rawbuf, 0, mixlen);
for (i = 0; i < NUM_BUFFERS; i++) {
this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
}

View File

@@ -34,10 +34,16 @@
#include "SDL_wasapi.h"
/* This constant isn't available on MinGW-w64 */
/* These constants aren't available in older SDKs */
#ifndef AUDCLNT_STREAMFLAGS_RATEADJUST
#define AUDCLNT_STREAMFLAGS_RATEADJUST 0x00100000
#endif
#ifndef AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY
#define AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY 0x08000000
#endif
#ifndef AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM
#define AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM 0x80000000
#endif
/* these increment as default devices change. Opened default devices pick up changes in their threads. */
SDL_atomic_t WASAPI_DefaultPlaybackGeneration;
@@ -556,21 +562,12 @@ WASAPI_PrepDevice(_THIS, const SDL_bool updatestream)
return WIN_SetErrorFromHRESULT("WASAPI can't determine minimum device period", ret);
}
#if 1 /* we're getting reports that WASAPI's resampler introduces distortions, so it's disabled for now. --ryan. */
this->spec.freq = waveformat->nSamplesPerSec; /* force sampling rate so our resampler kicks in, if necessary. */
#else
/* favor WASAPI's resampler over our own, in Win7+. */
/* favor WASAPI's resampler over our own */
if (this->spec.freq != waveformat->nSamplesPerSec) {
/* RATEADJUST only works with output devices in share mode, and is available in Win7 and later.*/
if (WIN_IsWindows7OrGreater() && !this->iscapture && (sharemode == AUDCLNT_SHAREMODE_SHARED)) {
streamflags |= AUDCLNT_STREAMFLAGS_RATEADJUST;
waveformat->nSamplesPerSec = this->spec.freq;
waveformat->nAvgBytesPerSec = waveformat->nSamplesPerSec * waveformat->nChannels * (waveformat->wBitsPerSample / 8);
} else {
this->spec.freq = waveformat->nSamplesPerSec; /* force sampling rate so our resampler kicks in. */
}
streamflags |= (AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY);
waveformat->nSamplesPerSec = this->spec.freq;
waveformat->nAvgBytesPerSec = waveformat->nSamplesPerSec * waveformat->nChannels * (waveformat->wBitsPerSample / 8);
}
#endif
streamflags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
ret = IAudioClient_Initialize(client, sharemode, streamflags, 0, 0, waveformat, NULL);
@@ -698,7 +695,7 @@ WASAPI_ThreadDeinit(_THIS)
void
WASAPI_BeginLoopIteration(_THIS)
{
/* no-op. */
/* no-op. */
}
static void

View File

@@ -53,7 +53,7 @@ static IMMDeviceEnumerator *enumerator = NULL;
/* handle to Avrt.dll--Vista and later!--for flagging the callback thread as "Pro Audio" (low latency). */
static HMODULE libavrt = NULL;
typedef HANDLE(WINAPI *pfnAvSetMmThreadCharacteristicsW)(LPWSTR, LPDWORD);
typedef HANDLE(WINAPI *pfnAvSetMmThreadCharacteristicsW)(LPCWSTR, LPDWORD);
typedef BOOL(WINAPI *pfnAvRevertMmThreadCharacteristics)(HANDLE);
static pfnAvSetMmThreadCharacteristicsW pAvSetMmThreadCharacteristicsW = NULL;
static pfnAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics = NULL;

View File

@@ -135,7 +135,7 @@ FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
}
static int
SetMMerror(char *function, MMRESULT code)
SetMMerror(const char *function, MMRESULT code)
{
int len;
char errbuf[MAXERRORLENGTH];
@@ -434,7 +434,6 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
return 0; /* Ready to go! */
}
static int
WINMM_Init(SDL_AudioDriverImpl * impl)
{

View File

@@ -148,6 +148,10 @@ JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
JNIEnv *env, jclass cls,
jstring name);
JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(nativeGetHintBoolean)(
JNIEnv *env, jclass cls,
jstring name, jboolean default_value);
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)(
JNIEnv *env, jclass cls,
jstring name, jstring value);
@@ -189,6 +193,7 @@ static JNINativeMethod SDLActivity_tab[] = {
{ "nativeResume", "()V", SDL_JAVA_INTERFACE(nativeResume) },
{ "nativeFocusChanged", "(Z)V", SDL_JAVA_INTERFACE(nativeFocusChanged) },
{ "nativeGetHint", "(Ljava/lang/String;)Ljava/lang/String;", SDL_JAVA_INTERFACE(nativeGetHint) },
{ "nativeGetHintBoolean", "(Ljava/lang/String;Z)Z", SDL_JAVA_INTERFACE(nativeGetHintBoolean) },
{ "nativeSetenv", "(Ljava/lang/String;Ljava/lang/String;)V", SDL_JAVA_INTERFACE(nativeSetenv) },
{ "onNativeOrientationChanged", "(I)V", SDL_JAVA_INTERFACE(onNativeOrientationChanged) },
{ "nativeAddTouch", "(ILjava/lang/String;)V", SDL_JAVA_INTERFACE(nativeAddTouch) },
@@ -1306,6 +1311,19 @@ JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
return result;
}
JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(nativeGetHintBoolean)(
JNIEnv *env, jclass cls,
jstring name, jboolean default_value)
{
jboolean result;
const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
result = SDL_GetHintBoolean(utfname, default_value);
(*env)->ReleaseStringUTFChars(env, name, utfname);
return result;
}
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)(
JNIEnv *env, jclass cls,
jstring name, jstring value)
@@ -2513,23 +2531,23 @@ SDL_bool Android_JNI_SetRelativeMouseEnabled(SDL_bool enabled)
SDL_bool Android_JNI_RequestPermission(const char *permission)
{
JNIEnv *env = Android_JNI_GetEnv();
const int requestCode = 1;
const int requestCode = 1;
/* Wait for any pending request on another thread */
while (SDL_AtomicGet(&bPermissionRequestPending) == SDL_TRUE) {
SDL_Delay(10);
}
SDL_AtomicSet(&bPermissionRequestPending, SDL_TRUE);
/* Wait for any pending request on another thread */
while (SDL_AtomicGet(&bPermissionRequestPending) == SDL_TRUE) {
SDL_Delay(10);
}
SDL_AtomicSet(&bPermissionRequestPending, SDL_TRUE);
jstring jpermission = (*env)->NewStringUTF(env, permission);
(*env)->CallStaticVoidMethod(env, mActivityClass, midRequestPermission, jpermission, requestCode);
(*env)->DeleteLocalRef(env, jpermission);
/* Wait for the request to complete */
while (SDL_AtomicGet(&bPermissionRequestPending) == SDL_TRUE) {
SDL_Delay(10);
}
return bPermissionRequestResult;
/* Wait for the request to complete */
while (SDL_AtomicGet(&bPermissionRequestPending) == SDL_TRUE) {
SDL_Delay(10);
}
return bPermissionRequestResult;
}
/* Show toast notification */

View File

@@ -238,7 +238,7 @@ SDL_EVDEV_kbd_init(void)
kbd->npadch = -1;
/* This might fail if we're not connected to a tty (e.g. on the Steam Link) */
kbd->keyboard_fd = kbd->console_fd = open("/dev/tty", O_RDONLY);
kbd->keyboard_fd = kbd->console_fd = open("/dev/tty", O_RDONLY | O_CLOEXEC);
kbd->shift_state = 0;
@@ -268,13 +268,13 @@ SDL_EVDEV_kbd_init(void)
kbd->key_map = &keymap_default_us_acc;
}
/* Allow inhibiting keyboard mute with env. variable for debugging etc. */
if (getenv("SDL_INPUT_FREEBSD_KEEP_KBD") == NULL) {
if (SDL_getenv("SDL_INPUT_FREEBSD_KEEP_KBD") == NULL) {
/* Take keyboard from console and open the actual keyboard device.
* Ensures that the keystrokes do not leak through to the console.
*/
ioctl(kbd->console_fd, CONS_RELKBD, 1ul);
asprintf(&devicePath, "/dev/kbd%d", kbd->kbInfo->kb_index);
kbd->keyboard_fd = open(devicePath, O_WRONLY);
SDL_asprintf(&devicePath, "/dev/kbd%d", kbd->kbInfo->kb_index);
kbd->keyboard_fd = open(devicePath, O_WRONLY | O_CLOEXEC);
if (kbd->keyboard_fd == -1)
{
// Give keyboard back.
@@ -288,7 +288,7 @@ SDL_EVDEV_kbd_init(void)
if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, SDL_FALSE)) {
kbd_register_emerg_cleanup(kbd);
}
free(devicePath);
SDL_free(devicePath);
}
else kbd->keyboard_fd = kbd->console_fd;
}

View File

@@ -19,6 +19,7 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_hints.h"
#include "SDL_dbus.h"
#include "SDL_atomic.h"
@@ -365,8 +366,15 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
const char *interface = "org.freedesktop.ScreenSaver";
if (inhibit) {
const char *app = "My SDL application";
const char *reason = "Playing a game";
const char *app = SDL_GetHint(SDL_HINT_APP_NAME);
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
if (!app || !app[0]) {
app = "My SDL application";
}
if (!reason || !reason[0]) {
reason = "Playing a game";
}
if (!SDL_DBus_CallMethod(node, path, interface, "Inhibit",
DBUS_TYPE_STRING, &app, DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID,
DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {

View File

@@ -218,8 +218,11 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
switch(udev_event) {
case SDL_UDEV_DEVICEADDED:
if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD |
SDL_UDEV_DEVICE_TOUCHSCREEN)))
if (udev_class & SDL_UDEV_DEVICE_TOUCHPAD) {
udev_class |= SDL_UDEV_DEVICE_TOUCHSCREEN;
}
if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN)))
return;
if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK))
@@ -725,7 +728,7 @@ SDL_EVDEV_device_added(const char *dev_path, int udev_class)
return SDL_OutOfMemory();
}
item->fd = open(dev_path, O_RDONLY | O_NONBLOCK);
item->fd = open(dev_path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (item->fd < 0) {
SDL_free(item);
return SDL_SetError("Unable to open %s", dev_path);

View File

@@ -78,7 +78,7 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) {
; /* ID_INPUT_TABLET */
} else if (test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key)) {
; /* ID_INPUT_TOUCHPAD */
devclass |= SDL_UDEV_DEVICE_TOUCHPAD; /* ID_INPUT_TOUCHPAD */
} else if (test_bit(BTN_MOUSE, bitmask_key)) {
devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
} else if (test_bit(BTN_TOUCH, bitmask_key)) {

View File

@@ -38,7 +38,8 @@ typedef enum
SDL_UDEV_DEVICE_JOYSTICK = 0x0004,
SDL_UDEV_DEVICE_SOUND = 0x0008,
SDL_UDEV_DEVICE_TOUCHSCREEN = 0x0010,
SDL_UDEV_DEVICE_ACCELEROMETER = 0x0020
SDL_UDEV_DEVICE_ACCELEROMETER = 0x0020,
SDL_UDEV_DEVICE_TOUCHPAD = 0x0040
} SDL_UDEV_deviceclass;
#define BITS_PER_LONG (sizeof(unsigned long) * 8)

View File

@@ -219,7 +219,7 @@ static void kbd_cleanup(void)
ioctl(kbd->console_fd, KDSKBMODE, kbd->old_kbd_mode);
}
void
static void
SDL_EVDEV_kbd_reraise_signal(int sig)
{
raise(sig);
@@ -354,7 +354,7 @@ SDL_EVDEV_kbd_init(void)
kbd->npadch = -1;
/* This might fail if we're not connected to a tty (e.g. on the Steam Link) */
kbd->console_fd = open("/dev/tty", O_RDONLY);
kbd->console_fd = open("/dev/tty", O_RDONLY | O_CLOEXEC);
if (ioctl(kbd->console_fd, TIOCLINUX, shift_state) == 0) {
kbd->shift_state = *shift_state;
@@ -386,7 +386,7 @@ SDL_EVDEV_kbd_init(void)
}
/* Allow inhibiting keyboard mute with env. variable for debugging etc. */
if (getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) {
if (SDL_getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) {
/* Mute the keyboard so keystrokes only generate evdev events
* and do not leak through to the console
*/

View File

@@ -84,7 +84,8 @@ GetAppName()
return SDL_strdup("SDL_App");
}
size_t Fcitx_GetPreeditString(SDL_DBusContext *dbus, DBusMessage *msg, char **ret) {
static size_t
Fcitx_GetPreeditString(SDL_DBusContext *dbus, DBusMessage *msg, char **ret) {
char *text = NULL, *subtext;
size_t text_bytes = 0;
DBusMessageIter iter, array, sub;

View File

@@ -23,13 +23,13 @@
#include "SDL_ibus.h"
#include "SDL_fcitx.h"
typedef SDL_bool (*_SDL_IME_Init)();
typedef void (*_SDL_IME_Quit)();
typedef SDL_bool (*_SDL_IME_Init)(void);
typedef void (*_SDL_IME_Quit)(void);
typedef void (*_SDL_IME_SetFocus)(SDL_bool);
typedef void (*_SDL_IME_Reset)();
typedef void (*_SDL_IME_Reset)(void);
typedef SDL_bool (*_SDL_IME_ProcessKeyEvent)(Uint32, Uint32);
typedef void (*_SDL_IME_UpdateTextRect)(SDL_Rect *);
typedef void (*_SDL_IME_PumpEvents)();
typedef void (*_SDL_IME_PumpEvents)(void);
static _SDL_IME_Init SDL_IME_Init_Real = NULL;
static _SDL_IME_Quit SDL_IME_Quit_Real = NULL;

View File

@@ -108,7 +108,9 @@ rtkit_initialize_realtime_thread()
int nLimit = RLIMIT_RTTIME;
pid_t nPid = 0; //self
int nSchedPolicy = sched_getscheduler(nPid) | SCHED_RESET_ON_FORK;
struct sched_param schedParam = {};
struct sched_param schedParam;
SDL_zero(schedParam);
// Requirement #1: Set RLIMIT_RTTIME
err = getrlimit(nLimit, &rlimit);

View File

@@ -19,7 +19,7 @@
3. This notice may not be removed or altered from any source distribution.
*/
/*
/*
* To list the properties of a device, try something like:
* udevadm info -a -n snd/hwC0D0 (for a sound card)
* udevadm info --query=all -n input/event3 (for a keyboard, mouse, etc)
@@ -103,7 +103,7 @@ SDL_UDEV_hotplug_update_available(void)
{
if (_this->udev_mon != NULL) {
const int fd = _this->syms.udev_monitor_get_fd(_this->udev_mon);
if (SDL_IOReady(fd, SDL_FALSE, 0)) {
if (SDL_IOReady(fd, SDL_IOR_READ, 0)) {
return SDL_TRUE;
}
}
@@ -115,23 +115,23 @@ int
SDL_UDEV_Init(void)
{
int retval = 0;
if (_this == NULL) {
_this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
if(_this == NULL) {
return SDL_OutOfMemory();
}
retval = SDL_UDEV_LoadLibrary();
if (retval < 0) {
SDL_UDEV_Quit();
return retval;
}
/* Set up udev monitoring
/* Set up udev monitoring
* Listen for input devices (mouse, keyboard, joystick, etc) and sound devices
*/
_this->udev = _this->syms.udev_new();
if (_this->udev == NULL) {
SDL_UDEV_Quit();
@@ -143,18 +143,18 @@ SDL_UDEV_Init(void)
SDL_UDEV_Quit();
return SDL_SetError("udev_monitor_new_from_netlink() failed");
}
_this->syms.udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "input", NULL);
_this->syms.udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "sound", NULL);
_this->syms.udev_monitor_enable_receiving(_this->udev_mon);
/* Do an initial scan of existing devices */
SDL_UDEV_Scan();
}
_this->ref_count += 1;
return retval;
}
@@ -162,15 +162,15 @@ void
SDL_UDEV_Quit(void)
{
SDL_UDEV_CallbackList *item;
if (_this == NULL) {
return;
}
_this->ref_count -= 1;
if (_this->ref_count < 1) {
if (_this->udev_mon != NULL) {
_this->syms.udev_monitor_unref(_this->udev_mon);
_this->udev_mon = NULL;
@@ -179,14 +179,14 @@ SDL_UDEV_Quit(void)
_this->syms.udev_unref(_this->udev);
_this->udev = NULL;
}
/* Remove existing devices */
while (_this->first != NULL) {
item = _this->first;
_this->first = _this->first->next;
SDL_free(item);
}
SDL_UDEV_UnloadLibrary();
SDL_free(_this);
_this = NULL;
@@ -198,22 +198,22 @@ SDL_UDEV_Scan(void)
{
struct udev_enumerate *enumerate = NULL;
struct udev_list_entry *devs = NULL;
struct udev_list_entry *item = NULL;
struct udev_list_entry *item = NULL;
if (_this == NULL) {
return;
}
enumerate = _this->syms.udev_enumerate_new(_this->udev);
if (enumerate == NULL) {
SDL_UDEV_Quit();
SDL_SetError("udev_enumerate_new() failed");
return;
}
_this->syms.udev_enumerate_add_match_subsystem(enumerate, "input");
_this->syms.udev_enumerate_add_match_subsystem(enumerate, "sound");
_this->syms.udev_enumerate_scan_devices(enumerate);
devs = _this->syms.udev_enumerate_get_list_entry(enumerate);
for (item = devs; item; item = _this->syms.udev_list_entry_get_next(item)) {
@@ -228,6 +228,62 @@ SDL_UDEV_Scan(void)
_this->syms.udev_enumerate_unref(enumerate);
}
SDL_bool
SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product, Uint16 *version)
{
struct udev_enumerate *enumerate = NULL;
struct udev_list_entry *devs = NULL;
struct udev_list_entry *item = NULL;
SDL_bool found = SDL_FALSE;
if (_this == NULL) {
return SDL_FALSE;
}
enumerate = _this->syms.udev_enumerate_new(_this->udev);
if (enumerate == NULL) {
SDL_SetError("udev_enumerate_new() failed");
return SDL_FALSE;
}
_this->syms.udev_enumerate_scan_devices(enumerate);
devs = _this->syms.udev_enumerate_get_list_entry(enumerate);
for (item = devs; item && !found; item = _this->syms.udev_list_entry_get_next(item)) {
const char *path = _this->syms.udev_list_entry_get_name(item);
struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path);
if (dev != NULL) {
const char *val = NULL;
const char *existing_path;
existing_path = _this->syms.udev_device_get_devnode(dev);
if (existing_path && SDL_strcmp(device_path, existing_path) == 0) {
found = SDL_TRUE;
val = _this->syms.udev_device_get_property_value(dev, "ID_VENDOR_ID");
if (val != NULL) {
*vendor = (Uint16)SDL_strtol(val, NULL, 16);
}
val = _this->syms.udev_device_get_property_value(dev, "ID_MODEL_ID");
if (val != NULL) {
*product = (Uint16)SDL_strtol(val, NULL, 16);
}
val = _this->syms.udev_device_get_property_value(dev, "ID_REVISION");
if (val != NULL) {
*version = (Uint16)SDL_strtol(val, NULL, 16);
}
}
_this->syms.udev_device_unref(dev);
}
}
_this->syms.udev_enumerate_unref(enumerate);
return found;
}
void
SDL_UDEV_UnloadLibrary(void)
@@ -235,7 +291,7 @@ SDL_UDEV_UnloadLibrary(void)
if (_this == NULL) {
return;
}
if (_this->udev_handle != NULL) {
SDL_UnloadObject(_this->udev_handle);
_this->udev_handle = NULL;
@@ -246,11 +302,11 @@ int
SDL_UDEV_LoadLibrary(void)
{
int retval = 0, i;
if (_this == NULL) {
return SDL_SetError("UDEV not initialized");
}
/* See if there is a udev library already loaded */
if (SDL_UDEV_load_syms() == 0) {
return 0;
@@ -282,7 +338,7 @@ SDL_UDEV_LoadLibrary(void)
}
}
}
if (_this->udev_handle == NULL) {
retval = -1;
/* Don't call SDL_SetError(): SDL_LoadObject already did. */
@@ -352,26 +408,26 @@ guess_device_class(struct udev_device *dev)
&bitmask_rel[0]);
}
static void
device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
static void
device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
{
const char *subsystem;
const char *val = NULL;
int devclass = 0;
const char *path;
SDL_UDEV_CallbackList *item;
path = _this->syms.udev_device_get_devnode(dev);
if (path == NULL) {
return;
}
subsystem = _this->syms.udev_device_get_subsystem(dev);
if (SDL_strcmp(subsystem, "sound") == 0) {
devclass = SDL_UDEV_DEVICE_SOUND;
} else if (SDL_strcmp(subsystem, "input") == 0) {
/* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
@@ -381,13 +437,13 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE) &&
val != NULL && SDL_strcmp(val, "1") == 0 ) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
}
}
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
devclass |= SDL_UDEV_DEVICE_MOUSE;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
@@ -396,7 +452,7 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
/* The undocumented rule is:
- All devices with keys get ID_INPUT_KEY
- From this subset, if they have ESC, numbers, and Q to D, it also gets ID_INPUT_KEYBOARD
Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183
*/
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEY");
@@ -425,14 +481,14 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
} else {
return;
}
/* Process callbacks */
for (item = _this->first; item != NULL; item = item->next) {
item->callback(type, devclass, path);
}
}
void
void
SDL_UDEV_Poll(void)
{
struct udev_device *dev = NULL;
@@ -456,12 +512,12 @@ SDL_UDEV_Poll(void)
device_event(SDL_UDEV_DEVICEREMOVED, dev);
}
}
_this->syms.udev_device_unref(dev);
}
}
int
int
SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
{
SDL_UDEV_CallbackList *item;
@@ -469,7 +525,7 @@ SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
if (item == NULL) {
return SDL_OutOfMemory();
}
item->callback = cb;
if (_this->last == NULL) {
@@ -478,11 +534,11 @@ SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
_this->last->next = item;
_this->last = item;
}
return 1;
}
void
void
SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
{
SDL_UDEV_CallbackList *item;
@@ -505,7 +561,6 @@ SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
}
prev = item;
}
}
const SDL_UDEV_Symbols *

View File

@@ -101,6 +101,7 @@ extern void SDL_UDEV_UnloadLibrary(void);
extern int SDL_UDEV_LoadLibrary(void);
extern void SDL_UDEV_Poll(void);
extern void SDL_UDEV_Scan(void);
extern SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product, Uint16 *version);
extern int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);

View File

@@ -416,7 +416,7 @@ static SDL_WSCONS_input_data* SDL_WSCONS_Init_Keyboard(const char* dev)
if (!input) {
return input;
}
input->fd = open(dev,O_RDWR | O_NONBLOCK);
input->fd = open(dev,O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (input->fd == -1) {
free(input);
input = NULL;
@@ -509,7 +509,7 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c)
static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym)
{
if (KS_GROUP(ksym) == KS_GROUP_Keypad) {
if (isprint(ksym & 0xFF)) ksym &= 0xFF;
if (SDL_isprint(ksym & 0xFF)) ksym &= 0xFF;
}
switch(ksym) {
case KS_Escape:
@@ -526,7 +526,7 @@ static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym)
if (input->text_len > 0) {
input->text[input->text_len] = '\0';
SDL_SendKeyboardText(input->text);
/*memset(input->text, 0, sizeof(input->text));*/
/*SDL_memset(input->text, 0, sizeof(input->text));*/
input->text_len = 0;
input->text[0] = 0;
}

View File

@@ -43,7 +43,7 @@ SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse()
SDL_WSCONS_mouse_input_data* mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data));
if (!mouseInputData) return NULL;
mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK);
mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; }
#ifdef WSMOUSEIO_SETMODE
ioctl(mouseInputData->fd, WSMOUSEIO_SETMODE, WSMOUSE_COMPAT);

View File

@@ -11,7 +11,7 @@ LIBFILE = geniconv.lib
all: $(LIBFILE) test.exe .symbolic
CFLAGS = -I$(%WATCOM)/h/os2 -I$(%WATCOM)/h -I. -bt=os2 -q -d0 -w2
CFLAGS = -I$(%WATCOM)/h/os2 -I$(%WATCOM)/h -I. -bt=os2 -q -d0 -w2 -DGENICONV_STANDALONE=1
SRCS = geniconv.c os2cp.c os2iconv.c
SRCS+= sys2utf8.c

View File

@@ -22,11 +22,21 @@
#define INCL_DOSNLS
#define INCL_DOSERRORS
#include <os2.h>
#include <string.h>
#include <ctype.h>
#include "os2cp.h"
#ifndef GENICONV_STANDALONE
#include "../../../SDL_internal.h"
#else
#include <string.h>
#include <ctype.h>
#define SDL_isspace isspace
#define SDL_strchr strchr
#define SDL_memcpy memcpy
#define SDL_strupr strupr
#define SDL_strcmp strcmp
#endif
typedef struct _CP2NAME {
ULONG ulCode;
PSZ pszName;
@@ -354,28 +364,28 @@ unsigned long os2cpFromName(char *cp)
return (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)? 0 : aulCP[0];
}
while (isspace(*cp))
while (SDL_isspace(*cp))
cp++;
pcEnd = strchr(cp, ' ');
pcEnd = SDL_strchr(cp, ' ');
if (pcEnd == NULL)
pcEnd = strchr(cp, '\0');
pcEnd = SDL_strchr(cp, '\0');
ulNext = pcEnd - cp;
if (ulNext >= sizeof(acBuf))
return 0;
memcpy(acBuf, cp, ulNext);
SDL_memcpy(acBuf, cp, ulNext);
acBuf[ulNext] = '\0';
strupr(acBuf);
SDL_strupr(acBuf);
lCmp = strcmp(aName2CP[0].pszName, acBuf);
lCmp = SDL_strcmp(aName2CP[0].pszName, acBuf);
if (lCmp > 0)
return 0;
else if (lCmp == 0)
return aName2CP[0].ulCode;
lCmp = strcmp(aName2CP[ulHi].pszName, acBuf);
lCmp = SDL_strcmp(aName2CP[ulHi].pszName, acBuf);
if (lCmp < 0)
return 0;
else if (lCmp == 0)
@@ -384,7 +394,7 @@ unsigned long os2cpFromName(char *cp)
while ((ulHi - ulLo) > 1) {
ulNext = (ulLo + ulHi) / 2;
lCmp = strcmp(aName2CP[ulNext].pszName, acBuf);
lCmp = SDL_strcmp(aName2CP[ulNext].pszName, acBuf);
if (lCmp < 0)
ulLo = ulNext;
else if (lCmp > 0)

View File

@@ -31,19 +31,30 @@
#define _ULS_CALLCONV_
#define CALLCONV _System
#include <uconv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef ICONV_THREAD_SAFE
#define INCL_DOSSEMAPHORES
#define INCL_DOSERRORS
#include <os2.h>
#endif
#include "os2cp.h"
#ifndef GENICONV_STANDALONE
#include "../../../SDL_internal.h"
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(min)
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
#define SDL_min min
#define SDL_strcasecmp stricmp
#define SDL_snprintf _snprintf
#define SDL_malloc malloc
#define SDL_free free
#define SDL_memcpy memcpy
#endif
#define MAX_CP_NAME_LEN 64
@@ -82,7 +93,7 @@ static int uconv_open(const char *code, UconvObject *uobj)
{
int rc;
if (!stricmp(code, "UTF-16")) {
if (!SDL_strcasecmp(code, "UTF-16")) {
*uobj = NULL;
return ULS_SUCCESS;
}
@@ -92,7 +103,7 @@ static int uconv_open(const char *code, UconvObject *uobj)
unsigned long cp = os2cpFromName((char *)code);
char cp_name[16];
if (cp != 0 && _snprintf(cp_name, sizeof(cp_name), "IBM-%u", cp) > 0)
if (cp != 0 && SDL_snprintf(cp_name, sizeof(cp_name), "IBM-%u", cp) > 0)
rc = _createUconvObj(cp_name, uobj);
}
@@ -113,7 +124,7 @@ extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
if (fromcode == NULL)
fromcode = "";
if (stricmp(tocode, fromcode) != 0) {
if (SDL_strcasecmp(tocode, fromcode) != 0) {
rc = uconv_open(fromcode, &uo_fromcode);
if (rc != ULS_SUCCESS) {
errno = EINVAL;
@@ -131,7 +142,7 @@ extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
uo_fromcode = NULL;
}
iuobj = (iuconv_obj *) malloc(sizeof(iuconv_obj));
iuobj = (iuconv_obj *) SDL_malloc(sizeof(iuconv_obj));
iuobj->uo_tocode = uo_tocode;
iuobj->uo_fromcode = uo_fromcode;
iuobj->buf_len = 0;
@@ -158,8 +169,8 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
size_t ret = (size_t)(-1);
if (uo_tocode == NULL && uo_fromcode == NULL) {
uc_buf_len = min(*inbytesleft, *outbytesleft);
memcpy(*outbuf, *inbuf, uc_buf_len);
uc_buf_len = SDL_min(*inbytesleft, *outbytesleft);
SDL_memcpy(*outbuf, *inbuf, uc_buf_len);
*inbytesleft -= uc_buf_len;
*outbytesleft -= uc_buf_len;
outbuf += uc_buf_len;
@@ -174,9 +185,9 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
if (uo_tocode && uo_fromcode &&
(((iuconv_obj *)cd)->buf_len >> 1) < *inbytesleft) {
if (((iuconv_obj *)cd)->buf != NULL)
free(((iuconv_obj *)cd)->buf);
SDL_free(((iuconv_obj *)cd)->buf);
((iuconv_obj *)cd)->buf_len = *inbytesleft << 1;
((iuconv_obj *)cd)->buf = (UniChar *)malloc(((iuconv_obj *)cd)->buf_len);
((iuconv_obj *)cd)->buf = (UniChar *)SDL_malloc(((iuconv_obj *)cd)->buf_len);
}
if (uo_fromcode) {
@@ -260,9 +271,9 @@ int _System os2_iconv_close(iconv_t cd)
UniFreeUconvObject(((iuconv_obj *)cd)->uo_fromcode);
if (((iuconv_obj *)cd)->buf != NULL)
free(((iuconv_obj *)cd)->buf);
SDL_free(((iuconv_obj *)cd)->buf);
free(cd);
SDL_free(cd);
return 0;
}

View File

@@ -20,7 +20,15 @@
*/
#include "geniconv.h"
#ifndef GENICONV_STANDALONE
#include "../../../SDL_internal.h"
#else
#include <stdlib.h>
#define SDL_malloc malloc
#define SDL_realloc realloc
#define SDL_free free
#endif
int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
{
@@ -83,25 +91,25 @@ int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr)
{
int cbNewStr = (((cbStr > 4)? cbStr : 4) + 1) * 2;
char *pszNewStr = (char *) malloc(cbNewStr);
char *pszNewStr = (char *) SDL_malloc(cbNewStr);
if (pszNewStr == NULL)
return NULL;
cbNewStr = StrUTF8(fToUTF8, pszNewStr, cbNewStr, pcStr, cbStr);
if (cbNewStr != -1) {
pcStr = (char *) realloc(pszNewStr, cbNewStr + ((fToUTF8)? 1 : sizeof(short)));
pcStr = (char *) SDL_realloc(pszNewStr, cbNewStr + ((fToUTF8)? 1 : sizeof(short)));
if (pcStr)
return pcStr;
}
free(pszNewStr);
SDL_free(pszNewStr);
return NULL;
}
void StrUTF8Free(char *pszStr)
{
free(pszStr);
SDL_free(pszStr);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -34,10 +34,12 @@
int
SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
SDL_IOReady(int fd, int flags, int timeoutMS)
{
int result;
SDL_assert(flags & (SDL_IOR_READ | SDL_IOR_WRITE));
/* Note: We don't bother to account for elapsed time if we get EINTR */
do
{
@@ -45,10 +47,12 @@ SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
struct pollfd info;
info.fd = fd;
if (forWrite) {
info.events = POLLOUT;
} else {
info.events = POLLIN | POLLPRI;
info.events = 0;
if (flags & SDL_IOR_READ) {
info.events |= POLLIN | POLLPRI;
}
if (flags & SDL_IOR_WRITE) {
info.events |= POLLOUT;
}
result = poll(&info, 1, timeoutMS);
#else
@@ -59,15 +63,16 @@ SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
/* If this assert triggers we'll corrupt memory here */
SDL_assert(fd >= 0 && fd < FD_SETSIZE);
if (forWrite) {
FD_ZERO(&wfdset);
FD_SET(fd, &wfdset);
wfdp = &wfdset;
} else {
if (flags & SDL_IOR_READ) {
FD_ZERO(&rfdset);
FD_SET(fd, &rfdset);
rfdp = &rfdset;
}
if (flags & SDL_IOR_WRITE) {
FD_ZERO(&wfdset);
FD_SET(fd, &wfdset);
wfdp = &wfdset;
}
if (timeoutMS >= 0) {
tv.tv_sec = timeoutMS / 1000;
@@ -78,7 +83,7 @@ SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
result = select(fd + 1, rfdp, wfdp, NULL, tvp);
#endif /* HAVE_POLL */
} while ( result < 0 && errno == EINTR );
} while ( result < 0 && errno == EINTR && !(flags & SDL_IOR_NO_RETRY));
return result;
}

View File

@@ -26,8 +26,11 @@
#include "SDL_stdinc.h"
#define SDL_IOR_READ 0x1
#define SDL_IOR_WRITE 0x2
#define SDL_IOR_NO_RETRY 0x4
extern int SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS);
extern int SDL_IOReady(int fd, int flags, int timeoutMS);
#endif /* SDL_poll_h_ */

View File

@@ -45,8 +45,9 @@ WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr)
TCHAR buffer[1024];
char *message;
TCHAR *p = buffer;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0,
DWORD c = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0,
buffer, SDL_arraysize(buffer), NULL);
buffer[c] = 0;
/* kill CR/LF that FormatMessage() sticks at the end */
while (*p) {
if (*p == '\r') {
@@ -248,6 +249,24 @@ WIN_IsEqualIID(REFIID a, REFIID b)
return (SDL_memcmp(a, b, sizeof (*a)) == 0);
}
void
WIN_RECTToRect(const RECT *winrect, SDL_Rect *sdlrect)
{
sdlrect->x = winrect->left;
sdlrect->w = (winrect->right - winrect->left) + 1;
sdlrect->y = winrect->top;
sdlrect->h = (winrect->bottom - winrect->top) + 1;
}
void
WIN_RectToRECT(const SDL_Rect *sdlrect, RECT *winrect)
{
winrect->left = sdlrect->x;
winrect->right = sdlrect->x + sdlrect->w - 1;
winrect->top = sdlrect->y;
winrect->bottom = sdlrect->y + sdlrect->h - 1;
}
#endif /* __WIN32__ || __WINRT__ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -37,12 +37,14 @@
#include <windows.h>
#include <basetyps.h> /* for REFIID with broken mingw.org headers */
#include "SDL_rect.h"
/* Routines to convert from UTF8 to native Windows text */
#define WIN_StringToUTF8W(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR))
#define WIN_UTF8ToStringW(S) (WCHAR *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1)
#define WIN_StringToUTF8W(S) SDL_iconv_string("UTF-8", "UTF-16LE", (const char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR))
#define WIN_UTF8ToStringW(S) (WCHAR *)SDL_iconv_string("UTF-16LE", "UTF-8", (const char *)(S), SDL_strlen(S)+1)
/* !!! FIXME: UTF8ToString() can just be a SDL_strdup() here. */
#define WIN_StringToUTF8A(S) SDL_iconv_string("UTF-8", "ASCII", (char *)(S), (SDL_strlen(S)+1))
#define WIN_UTF8ToStringA(S) SDL_iconv_string("ASCII", "UTF-8", (char *)(S), SDL_strlen(S)+1)
#define WIN_StringToUTF8A(S) SDL_iconv_string("UTF-8", "ASCII", (const char *)(S), (SDL_strlen(S)+1))
#define WIN_UTF8ToStringA(S) SDL_iconv_string("ASCII", "UTF-8", (const char *)(S), SDL_strlen(S)+1)
#if UNICODE
#define WIN_StringToUTF8 WIN_StringToUTF8W
#define WIN_UTF8ToString WIN_UTF8ToStringW
@@ -81,6 +83,10 @@ extern char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid);
extern BOOL WIN_IsEqualGUID(const GUID * a, const GUID * b);
extern BOOL WIN_IsEqualIID(REFIID a, REFIID b);
/* Convert between SDL_rect and RECT */
extern void WIN_RECTToRect(const RECT *winrect, SDL_Rect *sdlrect);
extern void WIN_RectToRECT(const SDL_Rect *sdlrect, RECT *winrect);
#endif /* _INCLUDED_WINDOWS_H */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -357,9 +357,16 @@ void SDL_WinRTApp::Run()
{
// TODO, WinRT: pass the C-style main() a reasonably realistic
// representation of command line arguments.
int argc = 0;
char **argv = NULL;
int argc = 1;
char **argv = (char **)SDL_malloc(2 * sizeof(*argv));
if (!argv) {
return;
}
argv[0] = SDL_strdup("WinRTApp");
argv[1] = NULL;
WINRT_SDLAppEntryPoint(argc, argv);
SDL_free(argv[0]);
SDL_free(argv);
}
}

View File

@@ -50,10 +50,13 @@
#endif
#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
#include <sys/sysctl.h> /* For AltiVec check */
#elif (defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(__powerpc__)
#elif defined(__OpenBSD__) && defined(__powerpc__)
#include <sys/param.h>
#include <sys/sysctl.h> /* For AltiVec check */
#include <machine/cpu.h>
#elif defined(__FreeBSD__) && defined(__powerpc__)
#include <machine/cpu.h>
#include <sys/auxv.h>
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
#include <signal.h>
#include <setjmp.h>
@@ -110,7 +113,7 @@
#define CPU_HAS_AVX512F (1 << 12)
#define CPU_HAS_ARM_SIMD (1 << 13)
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__ && !__FreeBSD__
/* This is the brute force way of detecting instruction sets...
the idea is borrowed from the libmpeg2 library - thanks!
*/
@@ -314,11 +317,9 @@ CPU_haveAltiVec(void)
{
volatile int altivec = 0;
#ifndef SDL_CPUINFO_DISABLED
#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__)) || (defined(__FreeBSD__) && defined(__powerpc__))
#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
#ifdef __OpenBSD__
int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
#elif defined(__FreeBSD__)
int selectors[2] = { CTL_HW, PPC_FEATURE_HAS_ALTIVEC };
#else
int selectors[2] = { CTL_HW, HW_VECTORUNIT };
#endif
@@ -327,6 +328,11 @@ CPU_haveAltiVec(void)
int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
if (0 == error)
altivec = (hasVectorUnit != 0);
#elif defined(__FreeBSD__) && defined(__powerpc__)
unsigned long cpufeatures = 0;
elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures));
altivec = cpufeatures & PPC_FEATURE_HAS_ALTIVEC;
return altivec;
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
void (*handler) (int sig);
handler = signal(SIGILL, illegal_instruction);
@@ -344,14 +350,14 @@ CPU_haveAltiVec(void)
static int
CPU_haveARMSIMD(void)
{
return 1;
return 1;
}
#elif !defined(__arm__)
static int
CPU_haveARMSIMD(void)
{
return 0;
return 0;
}
#elif defined(__LINUX__)
@@ -361,7 +367,7 @@ CPU_haveARMSIMD(void)
int arm_simd = 0;
int fd;
fd = open("/proc/self/auxv", O_RDONLY);
fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
Elf32_auxv_t aux;
@@ -371,8 +377,8 @@ CPU_haveARMSIMD(void)
{
const char *plat = (const char *) aux.a_un.a_val;
if (plat) {
arm_simd = strncmp(plat, "v6l", 3) == 0 ||
strncmp(plat, "v7l", 3) == 0;
arm_simd = SDL_strncmp(plat, "v6l", 3) == 0 ||
SDL_strncmp(plat, "v7l", 3) == 0;
}
}
}
@@ -385,20 +391,20 @@ CPU_haveARMSIMD(void)
static int
CPU_haveARMSIMD(void)
{
_kernel_swi_regs regs;
regs.r[0] = 0;
if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
return 0;
_kernel_swi_regs regs;
regs.r[0] = 0;
if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
return 0;
if (!(regs.r[0] & (1<<31)))
return 0;
if (!(regs.r[0] & (1<<31)))
return 0;
regs.r[0] = 34;
regs.r[1] = 29;
if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
return 0;
regs.r[0] = 34;
regs.r[1] = 29;
if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
return 0;
return regs.r[0];
return regs.r[0];
}
#else
@@ -417,7 +423,7 @@ readProcAuxvForNeon(void)
int neon = 0;
int fd;
fd = open("/proc/self/auxv", O_RDONLY);
fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
Elf32_auxv_t aux;
@@ -1057,7 +1063,7 @@ SDL_SIMDAlloc(const size_t len)
Uint8 *retval = NULL;
Uint8 *ptr = (Uint8 *) SDL_malloc(padded + alignment + sizeof (void *));
if (ptr) {
/* store the actual malloc pointer right before our aligned pointer. */
/* store the actual allocated pointer right before our aligned pointer. */
retval = ptr + sizeof (void *);
retval += alignment - (((size_t) retval) % alignment);
*(((void **) retval) - 1) = ptr;
@@ -1091,7 +1097,7 @@ SDL_SIMDRealloc(void *mem, const size_t len)
return NULL; /* Out of memory, bail! */
}
/* Store the actual malloc pointer right before our aligned pointer. */
/* Store the actual allocated pointer right before our aligned pointer. */
retval = ptr + sizeof (void *);
retval += alignment - (((size_t) retval) % alignment);
@@ -1109,7 +1115,7 @@ SDL_SIMDRealloc(void *mem, const size_t len)
}
}
/* Actually store the malloc pointer, finally. */
/* Actually store the allocated pointer, finally. */
*(((void **) retval) - 1) = ptr;
return retval;
}

View File

@@ -89,6 +89,12 @@ static void SDL_InitDynamicAPI(void);
va_end(ap); \
return retval; \
} \
_static int SDLCALL SDL_asprintf##name(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
int retval; va_list ap; initcall; va_start(ap, fmt); \
retval = jump_table.SDL_vasprintf(strp, fmt, ap); \
va_end(ap); \
return retval; \
} \
_static void SDLCALL SDL_Log##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); \
@@ -270,7 +276,7 @@ static void dynapi_warn(const char *msg)
/* SDL_ShowSimpleMessageBox() is a too heavy for here. */
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
MessageBoxA(NULL, msg, caption, MB_OK | MB_ICONERROR);
#else
#elif defined(HAVE_STDIO_H)
fprintf(stderr, "\n\n%s\n%s\n\n", caption, msg);
fflush(stderr);
#endif

View File

@@ -59,6 +59,8 @@
#define SDL_DYNAMIC_API 0 /* Turn off for static analysis, so reports are more clear. */
#elif defined(__VITA__)
#define SDL_DYNAMIC_API 0 /* vitasdk doesn't support dynamic linking */
#elif defined(DYNAPI_NEEDS_DLOPEN) && !defined(HAVE_DLOPEN)
#define SDL_DYNAMIC_API 0 /* we need dlopen(), but don't have it.... */
#endif
/* everyone else. This is where we turn on the API if nothing forced it off. */

View File

@@ -815,3 +815,43 @@
#define SDL_GameControllerSendEffect SDL_GameControllerSendEffect_REAL
#define SDL_JoystickSendEffect SDL_JoystickSendEffect_REAL
#define SDL_GameControllerGetSensorDataRate SDL_GameControllerGetSensorDataRate_REAL
#define SDL_SetTextureUserData SDL_SetTextureUserData_REAL
#define SDL_GetTextureUserData SDL_GetTextureUserData_REAL
#define SDL_RenderGeometry SDL_RenderGeometry_REAL
#define SDL_RenderGeometryRaw SDL_RenderGeometryRaw_REAL
#define SDL_RenderSetVSync SDL_RenderSetVSync_REAL
#define SDL_asprintf SDL_asprintf_REAL
#define SDL_vasprintf SDL_vasprintf_REAL
#define SDL_GetWindowICCProfile SDL_GetWindowICCProfile_REAL
#define SDL_GetTicks64 SDL_GetTicks64_REAL
#define SDL_LinuxSetThreadPriorityAndPolicy SDL_LinuxSetThreadPriorityAndPolicy_REAL
#define SDL_GameControllerGetAppleSFSymbolsNameForButton SDL_GameControllerGetAppleSFSymbolsNameForButton_REAL
#define SDL_GameControllerGetAppleSFSymbolsNameForAxis SDL_GameControllerGetAppleSFSymbolsNameForAxis_REAL
#define SDL_hid_init SDL_hid_init_REAL
#define SDL_hid_exit SDL_hid_exit_REAL
#define SDL_hid_device_change_count SDL_hid_device_change_count_REAL
#define SDL_hid_enumerate SDL_hid_enumerate_REAL
#define SDL_hid_free_enumeration SDL_hid_free_enumeration_REAL
#define SDL_hid_open SDL_hid_open_REAL
#define SDL_hid_open_path SDL_hid_open_path_REAL
#define SDL_hid_write SDL_hid_write_REAL
#define SDL_hid_read_timeout SDL_hid_read_timeout_REAL
#define SDL_hid_read SDL_hid_read_REAL
#define SDL_hid_set_nonblocking SDL_hid_set_nonblocking_REAL
#define SDL_hid_send_feature_report SDL_hid_send_feature_report_REAL
#define SDL_hid_get_feature_report SDL_hid_get_feature_report_REAL
#define SDL_hid_close SDL_hid_close_REAL
#define SDL_hid_get_manufacturer_string SDL_hid_get_manufacturer_string_REAL
#define SDL_hid_get_product_string SDL_hid_get_product_string_REAL
#define SDL_hid_get_serial_number_string SDL_hid_get_serial_number_string_REAL
#define SDL_hid_get_indexed_string SDL_hid_get_indexed_string_REAL
#define SDL_SetWindowMouseRect SDL_SetWindowMouseRect_REAL
#define SDL_GetWindowMouseRect SDL_GetWindowMouseRect_REAL
#define SDL_RenderWindowToLogical SDL_RenderWindowToLogical_REAL
#define SDL_RenderLogicalToWindow SDL_RenderLogicalToWindow_REAL
#define SDL_JoystickHasRumble SDL_JoystickHasRumble_REAL
#define SDL_JoystickHasRumbleTriggers SDL_JoystickHasRumbleTriggers_REAL
#define SDL_GameControllerHasRumble SDL_GameControllerHasRumble_REAL
#define SDL_GameControllerHasRumbleTriggers SDL_GameControllerHasRumbleTriggers_REAL
#define SDL_hid_ble_scan SDL_hid_ble_scan_REAL
#define SDL_PremultiplyAlpha SDL_PremultiplyAlpha_REAL

View File

@@ -63,7 +63,7 @@ SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(void *a, SDL_bool b),(a,b),return)
#endif
#ifdef __WIN32__
SDL_DYNAPI_PROC(int,SDL_RegisterApp,(char *a, Uint32 b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_RegisterApp,(const char *a, Uint32 b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(void,SDL_UnregisterApp,(void),(),)
SDL_DYNAPI_PROC(int,SDL_Direct3D9GetAdapterIndex,(int a),(a),return)
SDL_DYNAPI_PROC(IDirect3DDevice9*,SDL_RenderGetD3D9Device,(SDL_Renderer *a),(a),return)
@@ -880,3 +880,47 @@ SDL_DYNAPI_PROC(int,SDL_FlashWindow,(SDL_Window *a, SDL_FlashOperation b),(a,b),
SDL_DYNAPI_PROC(int,SDL_GameControllerSendEffect,(SDL_GameController *a, const void *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_JoystickSendEffect,(SDL_Joystick *a, const void *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(float,SDL_GameControllerGetSensorDataRate,(SDL_GameController *a, SDL_SensorType b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetTextureUserData,(SDL_Texture *a, void *b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_GetTextureUserData,(SDL_Texture *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_RenderGeometry,(SDL_Renderer *a, SDL_Texture *b, const SDL_Vertex *c, int d, const int *e, int f),(a,b,c,d,e,f),return)
SDL_DYNAPI_PROC(int,SDL_RenderGeometryRaw,(SDL_Renderer *a, SDL_Texture *b, const float *c, int d, const int *e, int f, const float *g, int h, int i, const void *j, int k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
SDL_DYNAPI_PROC(int,SDL_RenderSetVSync,(SDL_Renderer *a, int b),(a,b),return)
#if !SDL_DYNAPI_PROC_NO_VARARGS
SDL_DYNAPI_PROC(int,SDL_asprintf,(char **a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),return)
#endif
SDL_DYNAPI_PROC(int,SDL_vasprintf,(char **a, const char *b, va_list c),(a,b,c),return)
SDL_DYNAPI_PROC(void*,SDL_GetWindowICCProfile,(SDL_Window *a, size_t *b),(a,b),return)
SDL_DYNAPI_PROC(Uint64,SDL_GetTicks64,(void),(),return)
#ifdef __LINUX__
SDL_DYNAPI_PROC(int,SDL_LinuxSetThreadPriorityAndPolicy,(Sint64 a, int b, int c),(a,b,c),return)
#endif
SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetAppleSFSymbolsNameForButton,(SDL_GameController *a, SDL_GameControllerButton b),(a,b),return)
SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetAppleSFSymbolsNameForAxis,(SDL_GameController *a, SDL_GameControllerAxis b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_hid_init,(void),(),return)
SDL_DYNAPI_PROC(int,SDL_hid_exit,(void),(),return)
SDL_DYNAPI_PROC(Uint32,SDL_hid_device_change_count,(void),(),return)
SDL_DYNAPI_PROC(SDL_hid_device_info*,SDL_hid_enumerate,(unsigned short a, unsigned short b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_hid_free_enumeration,(SDL_hid_device_info *a),(a),)
SDL_DYNAPI_PROC(SDL_hid_device*,SDL_hid_open,(unsigned short a, unsigned short b, const wchar_t *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_hid_device*,SDL_hid_open_path,(const char *a, int b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_hid_write,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_hid_read_timeout,(SDL_hid_device *a, unsigned char *b, size_t c, int d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_hid_read,(SDL_hid_device *a, unsigned char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_hid_set_nonblocking,(SDL_hid_device *a, int b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_hid_send_feature_report,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_hid_get_feature_report,(SDL_hid_device *a, unsigned char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(void,SDL_hid_close,(SDL_hid_device *a),(a),)
SDL_DYNAPI_PROC(int,SDL_hid_get_manufacturer_string,(SDL_hid_device *a, wchar_t *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_hid_get_product_string,(SDL_hid_device *a, wchar_t *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_hid_get_serial_number_string,(SDL_hid_device *a, wchar_t *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_hid_get_indexed_string,(SDL_hid_device *a, int b, wchar_t *c, size_t d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_SetWindowMouseRect,(SDL_Window *a, const SDL_Rect *b),(a,b),return)
SDL_DYNAPI_PROC(const SDL_Rect*,SDL_GetWindowMouseRect,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_RenderWindowToLogical,(SDL_Renderer *a, int b, int c, float *d, float *e),(a,b,c,d,e),)
SDL_DYNAPI_PROC(void,SDL_RenderLogicalToWindow,(SDL_Renderer *a, float b, float c, int *d, int *e),(a,b,c,d,e),)
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumble,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumbleTriggers,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumble,(SDL_GameController *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumbleTriggers,(SDL_GameController *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_hid_ble_scan,(SDL_bool a),(a),)
SDL_DYNAPI_PROC(int,SDL_PremultiplyAlpha,(int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h),(a,b,c,d,e,f,g,h),return)

View File

@@ -55,7 +55,7 @@ while (my $d = readdir(HEADERS)) {
open(HEADER, '<', $header) or die("Can't open $header: $!\n");
while (<HEADER>) {
chomp;
next if not /\A\s*extern\s+DECLSPEC/;
next if not /\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC/;
my $decl = "$_ ";
if (not $decl =~ /\)\s*;/) {
while (<HEADER>) {
@@ -70,13 +70,13 @@ while (my $d = readdir(HEADERS)) {
$decl =~ s/\s+\Z//;
#print("DECL: [$decl]\n");
if ($decl =~ /\A\s*extern\s+DECLSPEC\s+(const\s+|)(unsigned\s+|)(.*?)\s*(\*?)\s*SDLCALL\s+(.*?)\s*\((.*?)\);/) {
my $rc = "$1$2$3$4";
my $fn = $5;
if ($decl =~ /\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC\s+(const\s+|)(unsigned\s+|)(.*?)\s*(\*?)\s*SDLCALL\s+(.*?)\s*\((.*?)\);/) {
my $rc = "$2$3$4$5";
my $fn = $6;
next if $existing{$fn}; # already slotted into the jump table.
my @params = split(',', $6);
my @params = split(',', $7);
#print("rc == '$rc', fn == '$fn', params == '$params'\n");

View File

@@ -26,6 +26,7 @@
#include "SDL_events.h"
#include "SDL_thread.h"
#include "SDL_events_c.h"
#include "../SDL_hints_c.h"
#include "../timer/SDL_timer_c.h"
#if !SDL_JOYSTICK_DISABLED
#include "../joystick/SDL_joystick_c.h"
@@ -43,6 +44,9 @@
/* An arbitrary limit so we don't have unbounded growth */
#define SDL_MAX_QUEUED_EVENTS 65535
/* Determines how often we wake to call SDL_PumpEvents() in SDL_WaitEventTimeout_Device() */
#define PERIODIC_POLL_INTERVAL_MS 3000
typedef struct SDL_EventWatcher {
SDL_EventFilter callback;
void *userdata;
@@ -139,6 +143,11 @@ SDL_AutoUpdateSensorsChanged(void *userdata, const char *name, const char *oldVa
#endif /* !SDL_SENSOR_DISABLED */
static void SDLCALL
SDL_PollSentinelChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_EventState(SDL_POLLSENTINEL, SDL_GetStringBoolean(hint, SDL_TRUE) ? SDL_ENABLE : SDL_DISABLE);
}
/* 0 (default) means no logging, 1 means logging, 2 means logging with mouse and finger motion */
static int SDL_DoEventLogging = 0;
@@ -146,7 +155,7 @@ static int SDL_DoEventLogging = 0;
static void SDLCALL
SDL_EventLoggingChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_DoEventLogging = (hint && *hint) ? SDL_max(SDL_min(SDL_atoi(hint), 2), 0) : 0;
SDL_DoEventLogging = (hint && *hint) ? SDL_clamp(SDL_atoi(hint), 0, 2) : 0;
}
static void
@@ -155,10 +164,13 @@ SDL_LogEvent(const SDL_Event *event)
char name[32];
char details[128];
/* mouse/finger motion are spammy, ignore these if they aren't demanded. */
/* sensor/mouse/finger motion are spammy, ignore these if they aren't demanded. */
if ( (SDL_DoEventLogging < 2) &&
( (event->type == SDL_MOUSEMOTION) ||
(event->type == SDL_FINGERMOTION) ) ) {
(event->type == SDL_FINGERMOTION) ||
(event->type == SDL_CONTROLLERTOUCHPADMOTION) ||
(event->type == SDL_CONTROLLERSENSORUPDATE) ||
(event->type == SDL_SENSORUPDATE) ) ) {
return;
}
@@ -332,6 +344,22 @@ SDL_LogEvent(const SDL_Event *event)
SDL_EVENT_CASE(SDL_CONTROLLERDEVICEREMAPPED) PRINT_CONTROLLERDEV_EVENT(event); break;
#undef PRINT_CONTROLLERDEV_EVENT
#define PRINT_CTOUCHPAD_EVENT(event) \
SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d touchpad=%d finger=%d x=%f y=%f pressure=%f)", \
(uint) event->ctouchpad.timestamp, (int) event->ctouchpad.which, \
(int) event->ctouchpad.touchpad, (int) event->ctouchpad.finger, \
event->ctouchpad.x, event->ctouchpad.y, event->ctouchpad.pressure)
SDL_EVENT_CASE(SDL_CONTROLLERTOUCHPADDOWN) PRINT_CTOUCHPAD_EVENT(event); break;
SDL_EVENT_CASE(SDL_CONTROLLERTOUCHPADUP) PRINT_CTOUCHPAD_EVENT(event); break;
SDL_EVENT_CASE(SDL_CONTROLLERTOUCHPADMOTION) PRINT_CTOUCHPAD_EVENT(event); break;
#undef PRINT_CTOUCHPAD_EVENT
SDL_EVENT_CASE(SDL_CONTROLLERSENSORUPDATE)
SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d sensor=%d data[0]=%f data[1]=%f data[2]=%f)", \
(uint) event->csensor.timestamp, (int) event->csensor.which, (int) event->csensor.sensor, \
event->csensor.data[0], event->csensor.data[1], event->csensor.data[2]);
break;
#define PRINT_FINGER_EVENT(event) \
SDL_snprintf(details, sizeof (details), " (timestamp=%u touchid=%"SDL_PRIs64" fingerid=%"SDL_PRIs64" x=%f y=%f dx=%f dy=%f pressure=%f)", \
(uint) event->tfinger.timestamp, (long long)event->tfinger.touchId, \
@@ -370,8 +398,19 @@ SDL_LogEvent(const SDL_Event *event)
SDL_EVENT_CASE(SDL_AUDIODEVICEREMOVED) PRINT_AUDIODEV_EVENT(event); break;
#undef PRINT_AUDIODEV_EVENT
SDL_EVENT_CASE(SDL_SENSORUPDATE)
SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d data[0]=%f data[1]=%f data[2]=%f data[3]=%f data[4]=%f data[5]=%f)", \
(uint) event->sensor.timestamp, (int) event->sensor.which, \
event->sensor.data[0], event->sensor.data[1], event->sensor.data[2], \
event->sensor.data[3], event->sensor.data[4], event->sensor.data[5]);
break;
#undef SDL_EVENT_CASE
case SDL_POLLSENTINEL:
/* No logging necessary for this one */
break;
default:
if (!name[0]) {
SDL_strlcpy(name, "UNKNOWN", sizeof (name));
@@ -785,14 +824,36 @@ SDL_PollEvent(SDL_Event * event)
return SDL_WaitEventTimeout(event, 0);
}
static SDL_bool
SDL_events_need_periodic_poll() {
SDL_bool need_periodic_poll = SDL_FALSE;
#if !SDL_JOYSTICK_DISABLED
need_periodic_poll =
SDL_WasInit(SDL_INIT_JOYSTICK) &&
(!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY));
#endif
#if !SDL_SENSOR_DISABLED
need_periodic_poll = need_periodic_poll ||
(SDL_WasInit(SDL_INIT_SENSOR) && !SDL_disabled_events[SDL_SENSORUPDATE >> 8]);
#endif
return need_periodic_poll;
}
static int
SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event, int timeout)
SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event, Uint32 start, int timeout)
{
int loop_timeout = timeout;
SDL_bool need_periodic_poll = SDL_events_need_periodic_poll();
for (;;) {
/* Pump events on entry and each time we wake to ensure:
a) All pending events are batch processed after waking up from a wait
b) Waiting can be completely skipped if events are already available to be pumped
c) Periodic processing that takes place in some platform PumpEvents() functions happens
d) Signals received in WaitEventTimeout() are turned into SDL events
*/
SDL_PumpEvents();
@@ -813,11 +874,26 @@ SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event,
}
if (status > 0) {
/* There is an event, we can return. */
SDL_SendPendingSignalEvents(); /* in case we had a signal handler fire, etc. */
return 1;
}
/* No events found in the queue, call WaitEventTimeout to wait for an event. */
status = _this->WaitEventTimeout(_this, timeout);
if (timeout > 0) {
Uint32 elapsed = SDL_GetTicks() - start;
if (elapsed >= (Uint32)timeout) {
/* Set wakeup_window to NULL without holding the lock. */
_this->wakeup_window = NULL;
return 0;
}
loop_timeout = (int)((Uint32)timeout - elapsed);
}
if (need_periodic_poll) {
if (loop_timeout >= 0) {
loop_timeout = SDL_min(loop_timeout, PERIODIC_POLL_INTERVAL_MS);
} else {
loop_timeout = PERIODIC_POLL_INTERVAL_MS;
}
}
status = _this->WaitEventTimeout(_this, loop_timeout);
/* Set wakeup_window to NULL without holding the lock. */
_this->wakeup_window = NULL;
if (status <= 0) {
@@ -831,19 +907,20 @@ SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event,
return 0;
}
static int
static SDL_bool
SDL_events_need_polling() {
SDL_bool need_polling = SDL_FALSE;
#if !SDL_JOYSTICK_DISABLED
need_polling = \
(!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY)) \
&& (SDL_NumJoysticks() > 0);
need_polling =
SDL_WasInit(SDL_INIT_JOYSTICK) &&
(!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY)) &&
(SDL_NumJoysticks() > 0);
#endif
#if !SDL_SENSOR_DISABLED
need_polling = need_polling || (!SDL_disabled_events[SDL_SENSORUPDATE >> 8] && \
(SDL_NumSensors() > 0));
need_polling = need_polling ||
(SDL_WasInit(SDL_INIT_SENSOR) && !SDL_disabled_events[SDL_SENSORUPDATE >> 8] && (SDL_NumSensors() > 0));
#endif
return need_polling;
@@ -872,16 +949,34 @@ SDL_WaitEventTimeout(SDL_Event * event, int timeout)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_Window *wakeup_window;
Uint32 start = 0;
Uint32 expiration = 0;
if (timeout > 0)
expiration = SDL_GetTicks() + timeout;
/* First check for existing events */
switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT)) {
case -1:
return 0;
case 0:
break;
default:
/* Check whether we have reached the end of the poll cycle, and no more events are left */
if (timeout == 0 && event && event->type == SDL_POLLSENTINEL) {
return (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1);
}
/* Has existing events */
return 1;
}
if (timeout > 0) {
start = SDL_GetTicks();
expiration = start + timeout;
}
if (timeout != 0 && _this && _this->WaitEventTimeout && _this->SendWakeupEvent && !SDL_events_need_polling()) {
/* Look if a shown window is available to send the wakeup event. */
wakeup_window = SDL_find_active_window(_this);
if (wakeup_window) {
int status = SDL_WaitEventTimeout_Device(_this, wakeup_window, event, timeout);
int status = SDL_WaitEventTimeout_Device(_this, wakeup_window, event, start, timeout);
/* There may be implementation-defined conditions where the backend cannot
reliably wait for the next event. If that happens, fall back to polling. */
@@ -908,6 +1003,13 @@ SDL_WaitEventTimeout(SDL_Event * event, int timeout)
SDL_Delay(1);
break;
default:
if (timeout == 0 && SDL_GetEventState(SDL_POLLSENTINEL) == SDL_ENABLE) {
/* We are at the start of a poll cycle with at least one new event.
Add a sentinel event to mark the end of the cycle. */
SDL_Event sentinel;
sentinel.type = SDL_POLLSENTINEL;
SDL_PushEvent(&sentinel);
}
/* Has events */
return 1;
}
@@ -1202,6 +1304,7 @@ SDL_EventsInit(void)
SDL_AddHintCallback(SDL_HINT_AUTO_UPDATE_SENSORS, SDL_AutoUpdateSensorsChanged, NULL);
#endif
SDL_AddHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL);
SDL_AddHintCallback(SDL_HINT_POLL_SENTINEL, SDL_PollSentinelChanged, NULL);
if (SDL_StartEventLoop() < 0) {
SDL_DelHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL);
return -1;
@@ -1217,6 +1320,7 @@ SDL_EventsQuit(void)
{
SDL_QuitQuit();
SDL_StopEventLoop();
SDL_DelHintCallback(SDL_HINT_POLL_SENTINEL, SDL_PollSentinelChanged, NULL);
SDL_DelHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL);
#if !SDL_JOYSTICK_DISABLED
SDL_DelHintCallback(SDL_HINT_AUTO_UPDATE_JOYSTICKS, SDL_AutoUpdateJoysticksChanged, NULL);

View File

@@ -32,7 +32,7 @@
#include <stdio.h>
*/
/* TODO: Replace with malloc */
/* TODO: Replace with SDL_malloc */
#define MAXPATHSIZE 1024

View File

@@ -767,6 +767,9 @@ SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode)
case SDLK_CAPSLOCK:
keyboard->modstate ^= KMOD_CAPS;
break;
case SDLK_SCROLLLOCK:
keyboard->modstate ^= KMOD_SCROLL;
break;
default:
keyboard->modstate |= modifier;
break;

View File

@@ -177,6 +177,17 @@ SDL_GetMouse(void)
return &SDL_mouse;
}
static Uint32 GetButtonState(SDL_Mouse *mouse)
{
int i;
Uint32 buttonstate = 0;
for (i = 0; i < mouse->num_sources; ++i) {
buttonstate |= mouse->sources[i].buttonstate;
}
return buttonstate;
}
SDL_Window *
SDL_GetMouseFocus(void)
{
@@ -185,25 +196,6 @@ SDL_GetMouseFocus(void)
return mouse->focus;
}
#if 0
void
SDL_ResetMouse(void)
{
SDL_Mouse *mouse = SDL_GetMouse();
Uint8 i;
#ifdef DEBUG_MOUSE
printf("Resetting mouse\n");
#endif
for (i = 1; i <= sizeof(mouse->buttonstate)*8; ++i) {
if (mouse->buttonstate & SDL_BUTTON(i)) {
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, i);
}
}
SDL_assert(mouse->buttonstate == 0);
}
#endif
void
SDL_SetMouseFocus(SDL_Window * window)
{
@@ -299,7 +291,7 @@ SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int
{
if (window && !relative) {
SDL_Mouse *mouse = SDL_GetMouse();
if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate, (mouseID == SDL_TOUCH_MOUSEID) ? SDL_FALSE : SDL_TRUE)) {
if (!SDL_UpdateMouseFocus(window, x, y, GetButtonState(mouse), (mouseID == SDL_TOUCH_MOUSEID) ? SDL_FALSE : SDL_TRUE)) {
return 0;
}
}
@@ -358,7 +350,13 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
mouse->last_y = center_y;
return 0;
}
SDL_WarpMouseInWindow(window, center_x, center_y);
if (window && (window->flags & SDL_WINDOW_INPUT_FOCUS) != 0) {
if (mouse->WarpMouse) {
mouse->WarpMouse(window, center_x, center_y);
} else {
SDL_PrivateSendMouseMotion(window, mouseID, 0, center_x, center_y);
}
}
}
if (relative) {
@@ -382,6 +380,8 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
if (!mouse->has_position) {
xrel = 0;
yrel = 0;
mouse->x = x;
mouse->y = y;
mouse->has_position = SDL_TRUE;
} else if (!xrel && !yrel) { /* Drop events that don't change state */
#ifdef DEBUG_MOUSE
@@ -391,7 +391,7 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
}
/* Ignore relative motion positioning the first touch */
if (mouseID == SDL_TOUCH_MOUSEID && !mouse->buttonstate) {
if (mouseID == SDL_TOUCH_MOUSEID && !GetButtonState(mouse)) {
xrel = 0;
yrel = 0;
}
@@ -408,25 +408,42 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
/* make sure that the pointers find themselves inside the windows,
unless we have the mouse captured. */
if (window && ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0)) {
int x_max = 0, y_max = 0;
int x_min = 0, x_max = 0;
int y_min = 0, y_max = 0;
const SDL_Rect *confine = SDL_GetWindowMouseRect(window);
/* !!! FIXME: shouldn't this be (window) instead of (mouse->focus)? */
SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
SDL_GetWindowSize(window, &x_max, &y_max);
--x_max;
--y_max;
if (confine) {
SDL_Rect window_rect;
SDL_Rect mouse_rect;
window_rect.x = 0;
window_rect.y = 0;
window_rect.w = x_max + 1;
window_rect.h = y_max + 1;
if (SDL_IntersectRect(confine, &window_rect, &mouse_rect)) {
x_min = mouse_rect.x;
y_min = mouse_rect.y;
x_max = x_min + mouse_rect.w - 1;
y_max = y_min + mouse_rect.h - 1;
}
}
if (mouse->x > x_max) {
mouse->x = x_max;
}
if (mouse->x < 0) {
mouse->x = 0;
if (mouse->x < x_min) {
mouse->x = x_min;
}
if (mouse->y > y_max) {
mouse->y = y_max;
}
if (mouse->y < 0) {
mouse->y = 0;
if (mouse->y < y_min) {
mouse->y = y_min;
}
}
@@ -448,7 +465,7 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
event.motion.which = mouseID;
/* Set us pending (or clear during a normal mouse movement event) as having triggered */
mouse->was_touch_mouse_events = (mouseID == SDL_TOUCH_MOUSEID)? SDL_TRUE : SDL_FALSE;
event.motion.state = mouse->buttonstate;
event.motion.state = GetButtonState(mouse);
event.motion.x = mouse->x;
event.motion.y = mouse->y;
event.motion.xrel = xrel;
@@ -466,6 +483,30 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
return posted;
}
static SDL_MouseInputSource *GetMouseInputSource(SDL_Mouse *mouse, SDL_MouseID mouseID)
{
SDL_MouseInputSource *source, *sources;
int i;
for (i = 0; i < mouse->num_sources; ++i) {
source = &mouse->sources[i];
if (source->mouseID == mouseID) {
return source;
}
}
sources = (SDL_MouseInputSource *)SDL_realloc(mouse->sources, (mouse->num_sources + 1)*sizeof(*mouse->sources));
if (sources) {
mouse->sources = sources;
++mouse->num_sources;
source = &sources[mouse->num_sources - 1];
source->mouseID = mouseID;
source->buttonstate = 0;
return source;
}
return NULL;
}
static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
{
if (button >= mouse->num_clickstates) {
@@ -490,7 +531,14 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
Uint32 type;
Uint32 buttonstate = mouse->buttonstate;
Uint32 buttonstate;
SDL_MouseInputSource *source;
source = GetMouseInputSource(mouse, mouseID);
if (!source) {
return 0;
}
buttonstate = source->buttonstate;
/* SDL_HINT_MOUSE_TOUCH_EVENTS: controlling whether mouse events should generate synthetic touch events */
if (mouse->mouse_touch_events) {
@@ -535,11 +583,11 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate, SDL_TRUE);
}
if (buttonstate == mouse->buttonstate) {
if (buttonstate == source->buttonstate) {
/* Ignore this event, no state change */
return 0;
}
mouse->buttonstate = buttonstate;
source->buttonstate = buttonstate;
if (clicks < 0) {
SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
@@ -616,20 +664,38 @@ SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, S
return 0;
}
if (x > 0.0f) {
if (mouse->accumulated_wheel_x < 0.0f) {
mouse->accumulated_wheel_x = 0.0f;
}
} else if (x < 0.0f) {
if (mouse->accumulated_wheel_x > 0.0f) {
mouse->accumulated_wheel_x = 0.0f;
}
}
mouse->accumulated_wheel_x += x;
if (mouse->accumulated_wheel_x > 0) {
if (mouse->accumulated_wheel_x > 0.0f) {
integral_x = (int)SDL_floor(mouse->accumulated_wheel_x);
} else if (mouse->accumulated_wheel_x < 0) {
} else if (mouse->accumulated_wheel_x < 0.0f) {
integral_x = (int)SDL_ceil(mouse->accumulated_wheel_x);
} else {
integral_x = 0;
}
mouse->accumulated_wheel_x -= integral_x;
if (y > 0.0f) {
if (mouse->accumulated_wheel_y < 0.0f) {
mouse->accumulated_wheel_y = 0.0f;
}
} else if (y < 0.0f) {
if (mouse->accumulated_wheel_y > 0.0f) {
mouse->accumulated_wheel_y = 0.0f;
}
}
mouse->accumulated_wheel_y += y;
if (mouse->accumulated_wheel_y > 0) {
if (mouse->accumulated_wheel_y > 0.0f) {
integral_y = (int)SDL_floor(mouse->accumulated_wheel_y);
} else if (mouse->accumulated_wheel_y < 0) {
} else if (mouse->accumulated_wheel_y < 0.0f) {
integral_y = (int)SDL_ceil(mouse->accumulated_wheel_y);
} else {
integral_y = 0;
@@ -643,12 +709,10 @@ SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, S
event.type = SDL_MOUSEWHEEL;
event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
event.wheel.which = mouseID;
#if 0 /* Uncomment this when it goes in for SDL 2.1 */
event.wheel.preciseX = x;
event.wheel.preciseY = y;
#endif
event.wheel.x = integral_x;
event.wheel.y = integral_y;
event.wheel.preciseX = x;
event.wheel.preciseY = y;
event.wheel.direction = (Uint32)direction;
posted = (SDL_PushEvent(&event) > 0);
}
@@ -681,10 +745,17 @@ SDL_MouseQuit(void)
mouse->def_cursor = NULL;
}
if (mouse->sources) {
SDL_free(mouse->sources);
mouse->sources = NULL;
}
mouse->num_sources = 0;
if (mouse->clickstate) {
SDL_free(mouse->clickstate);
mouse->clickstate = NULL;
}
mouse->num_clickstates = 0;
SDL_DelHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
SDL_MouseNormalSpeedScaleChanged, mouse);
@@ -704,7 +775,7 @@ SDL_GetMouseState(int *x, int *y)
if (y) {
*y = mouse->y;
}
return mouse->buttonstate;
return GetButtonState(mouse);
}
Uint32
@@ -720,7 +791,7 @@ SDL_GetRelativeMouseState(int *x, int *y)
}
mouse->xdelta = 0;
mouse->ydelta = 0;
return mouse->buttonstate;
return GetButtonState(mouse);
}
Uint32
@@ -760,10 +831,18 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
return;
}
if (mouse->WarpMouse) {
if ((window->flags & SDL_WINDOW_MINIMIZED) == SDL_WINDOW_MINIMIZED) {
return;
}
/* Ignore the previous position when we warp */
mouse->has_position = SDL_FALSE;
if (mouse->WarpMouse &&
(!mouse->relative_mode || mouse->relative_mode_warp)) {
mouse->WarpMouse(window, x, y);
} else {
SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
}
}
@@ -818,6 +897,11 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
mouse->scale_accum_x = 0.0f;
mouse->scale_accum_y = 0.0f;
if (enabled) {
/* Update cursor visibility before we potentially warp the mouse */
SDL_SetCursor(NULL);
}
if (enabled && focusWindow) {
SDL_SetMouseFocus(focusWindow);
@@ -825,21 +909,23 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
}
if (mouse->focus) {
SDL_UpdateWindowGrab(mouse->focus);
if (focusWindow) {
SDL_UpdateWindowGrab(focusWindow);
/* Put the cursor back to where the application expects it */
if (!enabled) {
SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
SDL_WarpMouseInWindow(focusWindow, mouse->x, mouse->y);
}
}
if (!enabled) {
/* Update cursor visibility after we restore the mouse position */
SDL_SetCursor(NULL);
}
/* Flush pending mouse motion - ideally we would pump events, but that's not always safe */
SDL_FlushEvent(SDL_MOUSEMOTION);
/* Update cursor visibility */
SDL_SetCursor(NULL);
return 0;
}

View File

@@ -33,6 +33,12 @@ struct SDL_Cursor
void *driverdata;
};
typedef struct
{
SDL_MouseID mouseID;
Uint32 buttonstate;
} SDL_MouseInputSource;
typedef struct
{
int last_x, last_y;
@@ -82,7 +88,6 @@ typedef struct
int last_x, last_y; /* the last reported x and y coordinates */
float accumulated_wheel_x;
float accumulated_wheel_y;
Uint32 buttonstate;
SDL_bool has_position;
SDL_bool relative_mode;
SDL_bool relative_mode_warp;
@@ -96,6 +101,10 @@ typedef struct
SDL_bool mouse_touch_events;
SDL_bool was_touch_mouse_events; /* Was a touch-mouse event pending? */
/* Data for input source state */
int num_sources;
SDL_MouseInputSource *sources;
/* Data for double-click tracking */
int num_clickstates;
SDL_MouseClickState *clickstate;

View File

@@ -54,7 +54,7 @@ SDL_HandleSIG(int sig)
signal(sig, SDL_HandleSIG);
/* Send a quit event next time the event loop pumps. */
/* We can't send it in signal handler; malloc() might be interrupted! */
/* We can't send it in signal handler; SDL_malloc() might be interrupted! */
if ((sig == SIGINT) || (sig == SIGTERM)) {
send_quit_pending = SDL_TRUE;
}

View File

@@ -110,6 +110,7 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
}
window->x = data1;
window->y = data2;
SDL_OnWindowMoved(window);
break;
case SDL_WINDOWEVENT_RESIZED:
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {

349
externals/SDL/src/events/imKStoUCS.c vendored Executable file
View File

@@ -0,0 +1,349 @@
/*
Copyright (C) 2003-2006,2008 Jamey Sharp, Josh Triplett
Copyright © 2009 Red Hat, Inc.
Copyright 1990-1992,1999,2000,2004,2009,2010 Oracle and/or its affiliates.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "../SDL_internal.h"
#if SDL_VIDEO_DRIVER_X11 || SDL_VIDEO_DRIVER_WAYLAND
#include "imKStoUCS.h"
static unsigned short const keysym_to_unicode_1a1_1ff[] = {
0x0104, 0x02d8, 0x0141, 0x0000, 0x013d, 0x015a, 0x0000, /* 0x01a0-0x01a7 */
0x0000, 0x0160, 0x015e, 0x0164, 0x0179, 0x0000, 0x017d, 0x017b, /* 0x01a8-0x01af */
0x0000, 0x0105, 0x02db, 0x0142, 0x0000, 0x013e, 0x015b, 0x02c7, /* 0x01b0-0x01b7 */
0x0000, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, /* 0x01b8-0x01bf */
0x0154, 0x0000, 0x0000, 0x0102, 0x0000, 0x0139, 0x0106, 0x0000, /* 0x01c0-0x01c7 */
0x010c, 0x0000, 0x0118, 0x0000, 0x011a, 0x0000, 0x0000, 0x010e, /* 0x01c8-0x01cf */
0x0110, 0x0143, 0x0147, 0x0000, 0x0000, 0x0150, 0x0000, 0x0000, /* 0x01d0-0x01d7 */
0x0158, 0x016e, 0x0000, 0x0170, 0x0000, 0x0000, 0x0162, 0x0000, /* 0x01d8-0x01df */
0x0155, 0x0000, 0x0000, 0x0103, 0x0000, 0x013a, 0x0107, 0x0000, /* 0x01e0-0x01e7 */
0x010d, 0x0000, 0x0119, 0x0000, 0x011b, 0x0000, 0x0000, 0x010f, /* 0x01e8-0x01ef */
0x0111, 0x0144, 0x0148, 0x0000, 0x0000, 0x0151, 0x0000, 0x0000, /* 0x01f0-0x01f7 */
0x0159, 0x016f, 0x0000, 0x0171, 0x0000, 0x0000, 0x0163, 0x02d9 /* 0x01f8-0x01ff */
};
static unsigned short const keysym_to_unicode_2a1_2fe[] = {
0x0126, 0x0000, 0x0000, 0x0000, 0x0000, 0x0124, 0x0000, /* 0x02a0-0x02a7 */
0x0000, 0x0130, 0x0000, 0x011e, 0x0134, 0x0000, 0x0000, 0x0000, /* 0x02a8-0x02af */
0x0000, 0x0127, 0x0000, 0x0000, 0x0000, 0x0000, 0x0125, 0x0000, /* 0x02b0-0x02b7 */
0x0000, 0x0131, 0x0000, 0x011f, 0x0135, 0x0000, 0x0000, 0x0000, /* 0x02b8-0x02bf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x010a, 0x0108, 0x0000, /* 0x02c0-0x02c7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x02c8-0x02cf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0120, 0x0000, 0x0000, /* 0x02d0-0x02d7 */
0x011c, 0x0000, 0x0000, 0x0000, 0x0000, 0x016c, 0x015c, 0x0000, /* 0x02d8-0x02df */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x010b, 0x0109, 0x0000, /* 0x02e0-0x02e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x02e8-0x02ef */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0121, 0x0000, 0x0000, /* 0x02f0-0x02f7 */
0x011d, 0x0000, 0x0000, 0x0000, 0x0000, 0x016d, 0x015d /* 0x02f8-0x02ff */
};
static unsigned short const keysym_to_unicode_3a2_3fe[] = {
0x0138, 0x0156, 0x0000, 0x0128, 0x013b, 0x0000, /* 0x03a0-0x03a7 */
0x0000, 0x0000, 0x0112, 0x0122, 0x0166, 0x0000, 0x0000, 0x0000, /* 0x03a8-0x03af */
0x0000, 0x0000, 0x0000, 0x0157, 0x0000, 0x0129, 0x013c, 0x0000, /* 0x03b0-0x03b7 */
0x0000, 0x0000, 0x0113, 0x0123, 0x0167, 0x014a, 0x0000, 0x014b, /* 0x03b8-0x03bf */
0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x012e, /* 0x03c0-0x03c7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0116, 0x0000, 0x0000, 0x012a, /* 0x03c8-0x03cf */
0x0000, 0x0145, 0x014c, 0x0136, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x03d0-0x03d7 */
0x0000, 0x0172, 0x0000, 0x0000, 0x0000, 0x0168, 0x016a, 0x0000, /* 0x03d8-0x03df */
0x0101, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x012f, /* 0x03e0-0x03e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0117, 0x0000, 0x0000, 0x012b, /* 0x03e8-0x03ef */
0x0000, 0x0146, 0x014d, 0x0137, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x03f0-0x03f7 */
0x0000, 0x0173, 0x0000, 0x0000, 0x0000, 0x0169, 0x016b /* 0x03f8-0x03ff */
};
static unsigned short const keysym_to_unicode_4a1_4df[] = {
0x3002, 0x3008, 0x3009, 0x3001, 0x30fb, 0x30f2, 0x30a1, /* 0x04a0-0x04a7 */
0x30a3, 0x30a5, 0x30a7, 0x30a9, 0x30e3, 0x30e5, 0x30e7, 0x30c3, /* 0x04a8-0x04af */
0x30fc, 0x30a2, 0x30a4, 0x30a6, 0x30a8, 0x30aa, 0x30ab, 0x30ad, /* 0x04b0-0x04b7 */
0x30af, 0x30b1, 0x30b3, 0x30b5, 0x30b7, 0x30b9, 0x30bb, 0x30bd, /* 0x04b8-0x04bf */
0x30bf, 0x30c1, 0x30c4, 0x30c6, 0x30c8, 0x30ca, 0x30cb, 0x30cc, /* 0x04c0-0x04c7 */
0x30cd, 0x30ce, 0x30cf, 0x30d2, 0x30d5, 0x30d8, 0x30db, 0x30de, /* 0x04c8-0x04cf */
0x30df, 0x30e0, 0x30e1, 0x30e2, 0x30e4, 0x30e6, 0x30e8, 0x30e9, /* 0x04d0-0x04d7 */
0x30ea, 0x30eb, 0x30ec, 0x30ed, 0x30ef, 0x30f3, 0x309b, 0x309c /* 0x04d8-0x04df */
};
static unsigned short const keysym_to_unicode_590_5fe[] = {
0x06f0, 0x06f1, 0x06f2, 0x06f3, 0x06f4, 0x06f5, 0x06f6, 0x06f7, /* 0x0590-0x0597 */
0x06f8, 0x06f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x0598-0x059f */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x066a, 0x0670, 0x0679, /* 0x05a0-0x05a7 */
0x067e, 0x0686, 0x0688, 0x0691, 0x060c, 0x0000, 0x06d4, 0x0000, /* 0x05ac-0x05af */
0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, /* 0x05b0-0x05b7 */
0x0668, 0x0669, 0x0000, 0x061b, 0x0000, 0x0000, 0x0000, 0x061f, /* 0x05b8-0x05bf */
0x0000, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, /* 0x05c0-0x05c7 */
0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, /* 0x05c8-0x05cf */
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, /* 0x05d0-0x05d7 */
0x0638, 0x0639, 0x063a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x05d8-0x05df */
0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, /* 0x05e0-0x05e7 */
0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, 0x064e, 0x064f, /* 0x05e8-0x05ef */
0x0650, 0x0651, 0x0652, 0x0653, 0x0654, 0x0655, 0x0698, 0x06a4, /* 0x05f0-0x05f7 */
0x06a9, 0x06af, 0x06ba, 0x06be, 0x06cc, 0x06d2, 0x06c1 /* 0x05f8-0x05fe */
};
static unsigned short keysym_to_unicode_680_6ff[] = {
0x0492, 0x0496, 0x049a, 0x049c, 0x04a2, 0x04ae, 0x04b0, 0x04b2, /* 0x0680-0x0687 */
0x04b6, 0x04b8, 0x04ba, 0x0000, 0x04d8, 0x04e2, 0x04e8, 0x04ee, /* 0x0688-0x068f */
0x0493, 0x0497, 0x049b, 0x049d, 0x04a3, 0x04af, 0x04b1, 0x04b3, /* 0x0690-0x0697 */
0x04b7, 0x04b9, 0x04bb, 0x0000, 0x04d9, 0x04e3, 0x04e9, 0x04ef, /* 0x0698-0x069f */
0x0000, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457, /* 0x06a0-0x06a7 */
0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x0491, 0x045e, 0x045f, /* 0x06a8-0x06af */
0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407, /* 0x06b0-0x06b7 */
0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x0490, 0x040e, 0x040f, /* 0x06b8-0x06bf */
0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, /* 0x06c0-0x06c7 */
0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, /* 0x06c8-0x06cf */
0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, /* 0x06d0-0x06d7 */
0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, /* 0x06d8-0x06df */
0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, /* 0x06e0-0x06e7 */
0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, /* 0x06e8-0x06ef */
0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, /* 0x06f0-0x06f7 */
0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a /* 0x06f8-0x06ff */
};
static unsigned short const keysym_to_unicode_7a1_7f9[] = {
0x0386, 0x0388, 0x0389, 0x038a, 0x03aa, 0x0000, 0x038c, /* 0x07a0-0x07a7 */
0x038e, 0x03ab, 0x0000, 0x038f, 0x0000, 0x0000, 0x0385, 0x2015, /* 0x07a8-0x07af */
0x0000, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03ca, 0x0390, 0x03cc, /* 0x07b0-0x07b7 */
0x03cd, 0x03cb, 0x03b0, 0x03ce, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x07b8-0x07bf */
0x0000, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, /* 0x07c0-0x07c7 */
0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, /* 0x07c8-0x07cf */
0x03a0, 0x03a1, 0x03a3, 0x0000, 0x03a4, 0x03a5, 0x03a6, 0x03a7, /* 0x07d0-0x07d7 */
0x03a8, 0x03a9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x07d8-0x07df */
0x0000, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, /* 0x07e0-0x07e7 */
0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, /* 0x07e8-0x07ef */
0x03c0, 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x03c5, 0x03c6, 0x03c7, /* 0x07f0-0x07f7 */
0x03c8, 0x03c9 /* 0x07f8-0x07ff */
};
static unsigned short const keysym_to_unicode_8a4_8fe[] = {
0x2320, 0x2321, 0x0000, 0x231c, /* 0x08a0-0x08a7 */
0x231d, 0x231e, 0x231f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x08a8-0x08af */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x08b0-0x08b7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x2264, 0x2260, 0x2265, 0x222b, /* 0x08b8-0x08bf */
0x2234, 0x0000, 0x221e, 0x0000, 0x0000, 0x2207, 0x0000, 0x0000, /* 0x08c0-0x08c7 */
0x2245, 0x2246, 0x0000, 0x0000, 0x0000, 0x0000, 0x21d2, 0x0000, /* 0x08c8-0x08cf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x221a, 0x0000, /* 0x08d0-0x08d7 */
0x0000, 0x0000, 0x2282, 0x2283, 0x2229, 0x222a, 0x2227, 0x2228, /* 0x08d8-0x08df */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x08e0-0x08e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2202, /* 0x08e8-0x08ef */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0192, 0x0000, /* 0x08f0-0x08f7 */
0x0000, 0x0000, 0x0000, 0x2190, 0x2191, 0x2192, 0x2193 /* 0x08f8-0x08ff */
};
static unsigned short const keysym_to_unicode_9df_9f8[] = {
0x2422, /* 0x09d8-0x09df */
0x2666, 0x25a6, 0x2409, 0x240c, 0x240d, 0x240a, 0x0000, 0x0000, /* 0x09e0-0x09e7 */
0x240a, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x2500, /* 0x09e8-0x09ef */
0x0000, 0x0000, 0x0000, 0x0000, 0x251c, 0x2524, 0x2534, 0x252c, /* 0x09f0-0x09f7 */
0x2502 /* 0x09f8-0x09ff */
};
static unsigned short const keysym_to_unicode_aa1_afe[] = {
0x2003, 0x2002, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009, /* 0x0aa0-0x0aa7 */
0x200a, 0x2014, 0x2013, 0x0000, 0x0000, 0x0000, 0x2026, 0x2025, /* 0x0aa8-0x0aaf */
0x2153, 0x2154, 0x2155, 0x2156, 0x2157, 0x2158, 0x2159, 0x215a, /* 0x0ab0-0x0ab7 */
0x2105, 0x0000, 0x0000, 0x2012, 0x2039, 0x2024, 0x203a, 0x0000, /* 0x0ab8-0x0abf */
0x0000, 0x0000, 0x0000, 0x215b, 0x215c, 0x215d, 0x215e, 0x0000, /* 0x0ac0-0x0ac7 */
0x0000, 0x2122, 0x2120, 0x0000, 0x25c1, 0x25b7, 0x25cb, 0x25ad, /* 0x0ac8-0x0acf */
0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x2030, 0x2032, 0x2033, /* 0x0ad0-0x0ad7 */
0x0000, 0x271d, 0x0000, 0x220e, 0x25c2, 0x2023, 0x25cf, 0x25ac, /* 0x0ad8-0x0adf */
0x25e6, 0x25ab, 0x25ae, 0x25b5, 0x25bf, 0x2606, 0x2022, 0x25aa, /* 0x0ae0-0x0ae7 */
0x25b4, 0x25be, 0x261a, 0x261b, 0x2663, 0x2666, 0x2665, 0x0000, /* 0x0ae8-0x0aef */
0x2720, 0x2020, 0x2021, 0x2713, 0x2612, 0x266f, 0x266d, 0x2642, /* 0x0af0-0x0af7 */
0x2640, 0x2121, 0x2315, 0x2117, 0x2038, 0x201a, 0x201e /* 0x0af8-0x0aff */
};
/* none of the APL keysyms match the Unicode characters */
static unsigned short const keysym_to_unicode_cdf_cfa[] = {
0x2017, /* 0x0cd8-0x0cdf */
0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, /* 0x0ce0-0x0ce7 */
0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df, /* 0x0ce8-0x0cef */
0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, /* 0x0cf0-0x0cf7 */
0x05e8, 0x05e9, 0x05ea /* 0x0cf8-0x0cff */
};
static unsigned short const keysym_to_unicode_da1_df9[] = {
0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, /* 0x0da0-0x0da7 */
0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, /* 0x0da8-0x0daf */
0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, /* 0x0db0-0x0db7 */
0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, /* 0x0db8-0x0dbf */
0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, /* 0x0dc0-0x0dc7 */
0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, /* 0x0dc8-0x0dcf */
0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, /* 0x0dd0-0x0dd7 */
0x0e38, 0x0e39, 0x0e3a, 0x0000, 0x0000, 0x0000, 0x0e3e, 0x0e3f, /* 0x0dd8-0x0ddf */
0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, /* 0x0de0-0x0de7 */
0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0000, 0x0000, /* 0x0de8-0x0def */
0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, /* 0x0df0-0x0df7 */
0x0e58, 0x0e59 /* 0x0df8-0x0dff */
};
static unsigned short const keysym_to_unicode_ea0_eff[] = {
0x0000, 0x1101, 0x1101, 0x11aa, 0x1102, 0x11ac, 0x11ad, 0x1103, /* 0x0ea0-0x0ea7 */
0x1104, 0x1105, 0x11b0, 0x11b1, 0x11b2, 0x11b3, 0x11b4, 0x11b5, /* 0x0ea8-0x0eaf */
0x11b6, 0x1106, 0x1107, 0x1108, 0x11b9, 0x1109, 0x110a, 0x110b, /* 0x0eb0-0x0eb7 */
0x110c, 0x110d, 0x110e, 0x110f, 0x1110, 0x1111, 0x1112, 0x1161, /* 0x0eb8-0x0ebf */
0x1162, 0x1163, 0x1164, 0x1165, 0x1166, 0x1167, 0x1168, 0x1169, /* 0x0ec0-0x0ec7 */
0x116a, 0x116b, 0x116c, 0x116d, 0x116e, 0x116f, 0x1170, 0x1171, /* 0x0ec8-0x0ecf */
0x1172, 0x1173, 0x1174, 0x1175, 0x11a8, 0x11a9, 0x11aa, 0x11ab, /* 0x0ed0-0x0ed7 */
0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, 0x11b3, /* 0x0ed8-0x0edf */
0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, 0x11bb, /* 0x0ee0-0x0ee7 */
0x11bc, 0x11bd, 0x11be, 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x0000, /* 0x0ee8-0x0eef */
0x0000, 0x0000, 0x1140, 0x0000, 0x0000, 0x1159, 0x119e, 0x0000, /* 0x0ef0-0x0ef7 */
0x11eb, 0x0000, 0x11f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x20a9, /* 0x0ef8-0x0eff */
};
static unsigned short keysym_to_unicode_12a1_12fe[] = {
0x1e02, 0x1e03, 0x0000, 0x0000, 0x0000, 0x1e0a, 0x0000, /* 0x12a0-0x12a7 */
0x1e80, 0x0000, 0x1e82, 0x1e0b, 0x1ef2, 0x0000, 0x0000, 0x0000, /* 0x12a8-0x12af */
0x1e1e, 0x1e1f, 0x0000, 0x0000, 0x1e40, 0x1e41, 0x0000, 0x1e56, /* 0x12b0-0x12b7 */
0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, /* 0x12b8-0x12bf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12c0-0x12c7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12c8-0x12cf */
0x0174, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1e6a, /* 0x12d0-0x12d7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0176, 0x0000, /* 0x12d8-0x12df */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12e0-0x12e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12e8-0x12ef */
0x0175, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1e6b, /* 0x12f0-0x12f7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0177 /* 0x12f0-0x12ff */
};
static unsigned short const keysym_to_unicode_13bc_13be[] = {
0x0152, 0x0153, 0x0178 /* 0x13b8-0x13bf */
};
static unsigned short keysym_to_unicode_14a1_14ff[] = {
0x2741, 0x00a7, 0x0589, 0x0029, 0x0028, 0x00bb, 0x00ab, /* 0x14a0-0x14a7 */
0x2014, 0x002e, 0x055d, 0x002c, 0x2013, 0x058a, 0x2026, 0x055c, /* 0x14a8-0x14af */
0x055b, 0x055e, 0x0531, 0x0561, 0x0532, 0x0562, 0x0533, 0x0563, /* 0x14b0-0x14b7 */
0x0534, 0x0564, 0x0535, 0x0565, 0x0536, 0x0566, 0x0537, 0x0567, /* 0x14b8-0x14bf */
0x0538, 0x0568, 0x0539, 0x0569, 0x053a, 0x056a, 0x053b, 0x056b, /* 0x14c0-0x14c7 */
0x053c, 0x056c, 0x053d, 0x056d, 0x053e, 0x056e, 0x053f, 0x056f, /* 0x14c8-0x14cf */
0x0540, 0x0570, 0x0541, 0x0571, 0x0542, 0x0572, 0x0543, 0x0573, /* 0x14d0-0x14d7 */
0x0544, 0x0574, 0x0545, 0x0575, 0x0546, 0x0576, 0x0547, 0x0577, /* 0x14d8-0x14df */
0x0548, 0x0578, 0x0549, 0x0579, 0x054a, 0x057a, 0x054b, 0x057b, /* 0x14e0-0x14e7 */
0x054c, 0x057c, 0x054d, 0x057d, 0x054e, 0x057e, 0x054f, 0x057f, /* 0x14e8-0x14ef */
0x0550, 0x0580, 0x0551, 0x0581, 0x0552, 0x0582, 0x0553, 0x0583, /* 0x14f0-0x14f7 */
0x0554, 0x0584, 0x0555, 0x0585, 0x0556, 0x0586, 0x2019, 0x0027, /* 0x14f8-0x14ff */
};
static unsigned short keysym_to_unicode_15d0_15f6[] = {
0x10d0, 0x10d1, 0x10d2, 0x10d3, 0x10d4, 0x10d5, 0x10d6, 0x10d7, /* 0x15d0-0x15d7 */
0x10d8, 0x10d9, 0x10da, 0x10db, 0x10dc, 0x10dd, 0x10de, 0x10df, /* 0x15d8-0x15df */
0x10e0, 0x10e1, 0x10e2, 0x10e3, 0x10e4, 0x10e5, 0x10e6, 0x10e7, /* 0x15e0-0x15e7 */
0x10e8, 0x10e9, 0x10ea, 0x10eb, 0x10ec, 0x10ed, 0x10ee, 0x10ef, /* 0x15e8-0x15ef */
0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6 /* 0x15f0-0x15f7 */
};
static unsigned short keysym_to_unicode_16a0_16f6[] = {
0x0000, 0x0000, 0xf0a2, 0x1e8a, 0x0000, 0xf0a5, 0x012c, 0xf0a7, /* 0x16a0-0x16a7 */
0xf0a8, 0x01b5, 0x01e6, 0x0000, 0x0000, 0x0000, 0x0000, 0x019f, /* 0x16a8-0x16af */
0x0000, 0x0000, 0xf0b2, 0x1e8b, 0x01d1, 0xf0b5, 0x012d, 0xf0b7, /* 0x16b0-0x16b7 */
0xf0b8, 0x01b6, 0x01e7, 0x0000, 0x0000, 0x01d2, 0x0000, 0x0275, /* 0x16b8-0x16bf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x018f, 0x0000, /* 0x16c0-0x16c7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16c8-0x16cf */
0x0000, 0x1e36, 0xf0d2, 0xf0d3, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16d0-0x16d7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16d8-0x16df */
0x0000, 0x1e37, 0xf0e2, 0xf0e3, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16e0-0x16e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16e8-0x16ef */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0259 /* 0x16f0-0x16f6 */
};
static unsigned short const keysym_to_unicode_1e9f_1eff[] = {
0x0303,
0x1ea0, 0x1ea1, 0x1ea2, 0x1ea3, 0x1ea4, 0x1ea5, 0x1ea6, 0x1ea7, /* 0x1ea0-0x1ea7 */
0x1ea8, 0x1ea9, 0x1eaa, 0x1eab, 0x1eac, 0x1ead, 0x1eae, 0x1eaf, /* 0x1ea8-0x1eaf */
0x1eb0, 0x1eb1, 0x1eb2, 0x1eb3, 0x1eb4, 0x1eb5, 0x1eb6, 0x1eb7, /* 0x1eb0-0x1eb7 */
0x1eb8, 0x1eb9, 0x1eba, 0x1ebb, 0x1ebc, 0x1ebd, 0x1ebe, 0x1ebf, /* 0x1eb8-0x1ebf */
0x1ec0, 0x1ec1, 0x1ec2, 0x1ec3, 0x1ec4, 0x1ec5, 0x1ec6, 0x1ec7, /* 0x1ec0-0x1ec7 */
0x1ec8, 0x1ec9, 0x1eca, 0x1ecb, 0x1ecc, 0x1ecd, 0x1ece, 0x1ecf, /* 0x1ec8-0x1ecf */
0x1ed0, 0x1ed1, 0x1ed2, 0x1ed3, 0x1ed4, 0x1ed5, 0x1ed6, 0x1ed7, /* 0x1ed0-0x1ed7 */
0x1ed8, 0x1ed9, 0x1eda, 0x1edb, 0x1edc, 0x1edd, 0x1ede, 0x1edf, /* 0x1ed8-0x1edf */
0x1ee0, 0x1ee1, 0x1ee2, 0x1ee3, 0x1ee4, 0x1ee5, 0x1ee6, 0x1ee7, /* 0x1ee0-0x1ee7 */
0x1ee8, 0x1ee9, 0x1eea, 0x1eeb, 0x1eec, 0x1eed, 0x1eee, 0x1eef, /* 0x1ee8-0x1eef */
0x1ef0, 0x1ef1, 0x0300, 0x0301, 0x1ef4, 0x1ef5, 0x1ef6, 0x1ef7, /* 0x1ef0-0x1ef7 */
0x1ef8, 0x1ef9, 0x01a0, 0x01a1, 0x01af, 0x01b0, 0x0309, 0x0323 /* 0x1ef8-0x1eff */
};
static unsigned short const keysym_to_unicode_20a0_20ac[] = {
0x20a0, 0x20a1, 0x20a2, 0x20a3, 0x20a4, 0x20a5, 0x20a6, 0x20a7, /* 0x20a0-0x20a7 */
0x20a8, 0x20a9, 0x20aa, 0x20ab, 0x20ac /* 0x20a8-0x20af */
};
unsigned int
SDL_KeySymToUcs4(Uint32 keysym)
{
/* 'Unicode keysym' */
if ((keysym & 0xff000000) == 0x01000000)
return (keysym & 0x00ffffff);
if (keysym > 0 && keysym < 0x100)
return keysym;
else if (keysym > 0x1a0 && keysym < 0x200)
return keysym_to_unicode_1a1_1ff[keysym - 0x1a1];
else if (keysym > 0x2a0 && keysym < 0x2ff)
return keysym_to_unicode_2a1_2fe[keysym - 0x2a1];
else if (keysym > 0x3a1 && keysym < 0x3ff)
return keysym_to_unicode_3a2_3fe[keysym - 0x3a2];
else if (keysym > 0x4a0 && keysym < 0x4e0)
return keysym_to_unicode_4a1_4df[keysym - 0x4a1];
else if (keysym > 0x589 && keysym < 0x5ff)
return keysym_to_unicode_590_5fe[keysym - 0x590];
else if (keysym > 0x67f && keysym < 0x700)
return keysym_to_unicode_680_6ff[keysym - 0x680];
else if (keysym > 0x7a0 && keysym < 0x7fa)
return keysym_to_unicode_7a1_7f9[keysym - 0x7a1];
else if (keysym > 0x8a3 && keysym < 0x8ff)
return keysym_to_unicode_8a4_8fe[keysym - 0x8a4];
else if (keysym > 0x9de && keysym < 0x9f9)
return keysym_to_unicode_9df_9f8[keysym - 0x9df];
else if (keysym > 0xaa0 && keysym < 0xaff)
return keysym_to_unicode_aa1_afe[keysym - 0xaa1];
else if (keysym > 0xcde && keysym < 0xcfb)
return keysym_to_unicode_cdf_cfa[keysym - 0xcdf];
else if (keysym > 0xda0 && keysym < 0xdfa)
return keysym_to_unicode_da1_df9[keysym - 0xda1];
else if (keysym > 0xe9f && keysym < 0xf00)
return keysym_to_unicode_ea0_eff[keysym - 0xea0];
else if (keysym > 0x12a0 && keysym < 0x12ff)
return keysym_to_unicode_12a1_12fe[keysym - 0x12a1];
else if (keysym > 0x13bb && keysym < 0x13bf)
return keysym_to_unicode_13bc_13be[keysym - 0x13bc];
else if (keysym > 0x14a0 && keysym < 0x1500)
return keysym_to_unicode_14a1_14ff[keysym - 0x14a1];
else if (keysym > 0x15cf && keysym < 0x15f7)
return keysym_to_unicode_15d0_15f6[keysym - 0x15d0];
else if (keysym > 0x169f && keysym < 0x16f7)
return keysym_to_unicode_16a0_16f6[keysym - 0x16a0];
else if (keysym > 0x1e9e && keysym < 0x1f00)
return keysym_to_unicode_1e9f_1eff[keysym - 0x1e9f];
else if (keysym > 0x209f && keysym < 0x20ad)
return keysym_to_unicode_20a0_20ac[keysym - 0x20a0];
else
return 0;
}
#endif /* SDL_VIDEO_DRIVER_X11 */

32
externals/SDL/src/events/imKStoUCS.h vendored Executable file
View File

@@ -0,0 +1,32 @@
#ifndef _imKStoUCS_h
#define _imKStoUCS_h
/*
Copyright (C) 2003-2006,2008 Jamey Sharp, Josh Triplett
Copyright © 2009 Red Hat, Inc.
Copyright 1990-1992,1999,2000,2004,2009,2010 Oracle and/or its affiliates.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
extern unsigned int SDL_KeySymToUcs4(Uint32 keysym);
#endif /* _imKStoUCS_h */

View File

@@ -0,0 +1,210 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifdef SDL_FILESYSTEM_RISCOS
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent filesystem routines */
#include <kernel.h>
#include <swis.h>
#include <unixlib/local.h>
#include "SDL_error.h"
#include "SDL_stdinc.h"
#include "SDL_filesystem.h"
/* Wrapper around __unixify_std that uses SDL's memory allocators */
static char *
SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len, int filetype)
{
const char *const in_buf = buffer; /* = NULL if we allocate the buffer. */
if (!buffer) {
/* This matches the logic in __unixify, with an additional byte for the
* extra path separator.
*/
buf_len = SDL_strlen(ro_path) + 14 + 1;
buffer = SDL_malloc(buf_len);
if (!buffer) {
SDL_OutOfMemory();
return NULL;
}
}
if (!__unixify_std(ro_path, buffer, buf_len, filetype)) {
if (!in_buf)
SDL_free(buffer);
SDL_SetError("Could not convert '%s' to a Unix-style path", ro_path);
return NULL;
}
/* HACK: It's necessary to add an extra path separator here since SDL's API
* requires it, however paths with trailing separators aren't normally valid
* on RISC OS.
*/
if (__get_riscosify_control() & __RISCOSIFY_NO_PROCESS)
SDL_strlcat(buffer, ".", buf_len);
else
SDL_strlcat(buffer, "/", buf_len);
return buffer;
}
static char *
canonicalisePath(const char *path, const char *pathVar)
{
_kernel_oserror *error;
_kernel_swi_regs regs;
char *buf;
regs.r[0] = 37;
regs.r[1] = (int)path;
regs.r[2] = 0;
regs.r[3] = (int)pathVar;
regs.r[4] = 0;
regs.r[5] = 0;
error = _kernel_swi(OS_FSControl, &regs, &regs);
if (error) {
SDL_SetError("Couldn't canonicalise path: %s", error->errmess);
return NULL;
}
regs.r[5] = 1 - regs.r[5];
buf = SDL_malloc(regs.r[5]);
if (!buf) {
SDL_OutOfMemory();
return NULL;
}
regs.r[2] = (int)buf;
error = _kernel_swi(OS_FSControl, &regs, &regs);
if (error) {
SDL_SetError("Couldn't canonicalise path: %s", error->errmess);
SDL_free(buf);
return NULL;
}
return buf;
}
static _kernel_oserror *
createDirectoryRecursive(char *path)
{
char *ptr = NULL;
_kernel_oserror *error;
_kernel_swi_regs regs;
regs.r[0] = 8;
regs.r[1] = (int)path;
regs.r[2] = 0;
for (ptr = path+1; *ptr; ptr++) {
if (*ptr == '.') {
*ptr = '\0';
error = _kernel_swi(OS_File, &regs, &regs);
*ptr = '.';
if (error != NULL)
return error;
}
}
return _kernel_swi(OS_File, &regs, &regs);
}
char *
SDL_GetBasePath(void)
{
_kernel_swi_regs regs;
_kernel_oserror *error;
char *canon, *ptr, *retval;
error = _kernel_swi(OS_GetEnv, &regs, &regs);
if (error) {
return NULL;
}
canon = canonicalisePath((const char *)regs.r[0], "Run$Path");
if (!canon) {
return NULL;
}
/* chop off filename. */
ptr = SDL_strrchr(canon, '.');
if (ptr != NULL)
*ptr = '\0';
retval = SDL_unixify_std(canon, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED);
SDL_free(canon);
return retval;
}
char *
SDL_GetPrefPath(const char *org, const char *app)
{
char *canon, *dir, *retval;
size_t len;
_kernel_oserror *error;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
canon = canonicalisePath("<Choices$Write>", "Run$Path");
if (!canon) {
return NULL;
}
len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4;
dir = (char *) SDL_malloc(len);
if (!dir) {
SDL_OutOfMemory();
SDL_free(canon);
return NULL;
}
if (*org) {
SDL_snprintf(dir, len, "%s.%s.%s", canon, org, app);
} else {
SDL_snprintf(dir, len, "%s.%s", canon, app);
}
SDL_free(canon);
error = createDirectoryRecursive(dir);
if (error != NULL) {
SDL_SetError("Couldn't create directory: %s", error->errmess);
SDL_free(dir);
return NULL;
}
retval = SDL_unixify_std(dir, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED);
SDL_free(dir);
return retval;
}
#endif /* SDL_FILESYSTEM_RISCOS */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -82,7 +82,7 @@ readSymLink(const char *path)
#if defined(__OPENBSD__)
static char *search_path_for_binary(const char *bin)
{
char *envr = getenv("PATH");
char *envr = SDL_getenv("PATH");
size_t alloc_size;
char *exe = NULL;
char *start = envr;
@@ -245,7 +245,7 @@ SDL_GetBasePath(void)
if (retval != NULL) {
/* try to shrink buffer... */
char *ptr = (char *) SDL_realloc(retval, strlen(retval) + 1);
char *ptr = (char *) SDL_realloc(retval, SDL_strlen(retval) + 1);
if (ptr != NULL)
retval = ptr; /* oh well if it failed. */
}

View File

@@ -155,7 +155,7 @@ SDL_SYS_HapticOpen(SDL_Haptic *haptic)
int
SDL_SYS_HapticMouse(void)
{
return 0;
return -1;
}

View File

@@ -653,7 +653,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice);
#else
return -1;
return -1;
#endif
}

View File

@@ -35,7 +35,6 @@
#include <fcntl.h> /* O_RDWR */
#include <limits.h> /* INT_MAX */
#include <errno.h> /* errno, strerror */
#include <math.h> /* atan2 */
#include <sys/stat.h> /* stat */
/* Just in case. */
@@ -166,7 +165,7 @@ SDL_SYS_HapticInit(void)
i = 0;
for (j = 0; j < MAX_HAPTICS; ++j) {
snprintf(path, PATH_MAX, joydev_pattern, i++);
SDL_snprintf(path, PATH_MAX, joydev_pattern, i++);
MaybeAddDevice(path);
}
@@ -260,7 +259,7 @@ MaybeAddDevice(const char *path)
}
/* try to open */
fd = open(path, O_RDWR, 0);
fd = open(path, O_RDWR | O_CLOEXEC, 0);
if (fd < 0) {
return -1;
}
@@ -375,7 +374,7 @@ SDL_SYS_HapticName(int index)
item = HapticByDevIndex(index);
/* Open the haptic device. */
name = NULL;
fd = open(item->fname, O_RDONLY, 0);
fd = open(item->fname, O_RDONLY | O_CLOEXEC, 0);
if (fd >= 0) {
@@ -453,7 +452,7 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
item = HapticByDevIndex(haptic->index);
/* Open the character device */
fd = open(item->fname, O_RDWR, 0);
fd = open(item->fname, O_RDWR | O_CLOEXEC, 0);
if (fd < 0) {
return SDL_SetError("Haptic: Unable to open %s: %s",
item->fname, strerror(errno));
@@ -483,7 +482,7 @@ SDL_SYS_HapticMouse(void)
for (item = SDL_hapticlist; item; item = item->next) {
/* Open the device. */
fd = open(item->fname, O_RDWR, 0);
fd = open(item->fname, O_RDWR | O_CLOEXEC, 0);
if (fd < 0) {
return SDL_SetError("Haptic: Unable to open %s: %s",
item->fname, strerror(errno));
@@ -570,7 +569,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
return SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities");
}
fd = open(joystick->hwdata->fname, O_RDWR, 0);
fd = open(joystick->hwdata->fname, O_RDWR | O_CLOEXEC, 0);
if (fd < 0) {
return SDL_SetError("Haptic: Unable to open %s: %s",
joystick->hwdata->fname, strerror(errno));
@@ -713,10 +712,10 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
else {
float f = SDL_atan2(src->dir[1], src->dir[0]); /* Ideally we'd use fixed point math instead of floats... */
/*
atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
SDL_atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
- Y-axis-value is the second coordinate (from center to SOUTH)
- X-axis-value is the first coordinate (from center to EAST)
We add 36000, because atan2 also returns negative values. Then we practically
We add 36000, because SDL_atan2 also returns negative values. Then we practically
have the first spherical value. Therefore we proceed as in case
SDL_HAPTIC_SPHERICAL and add another 9000 to get the polar value.
--> add 45000 in total

View File

@@ -20,6 +20,7 @@
*/
#include "../../SDL_internal.h"
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_haptic.h"
#include "../SDL_syshaptic.h"
@@ -70,6 +71,7 @@ SDL_DINPUT_HapticInit(void)
{
HRESULT ret;
HINSTANCE instance;
DWORD devClass;
if (dinput != NULL) { /* Already open. */
return SDL_SetError("Haptic: SubSystem already open.");
@@ -103,16 +105,24 @@ SDL_DINPUT_HapticInit(void)
}
/* Look for haptic devices. */
ret = IDirectInput8_EnumDevices(dinput,
0,
EnumHapticsCallback,
NULL,
DIEDFL_FORCEFEEDBACK |
DIEDFL_ATTACHEDONLY);
if (FAILED(ret)) {
SDL_SYS_HapticQuit();
return DI_SetError("Enumerating DirectInput devices", ret);
for (devClass = DI8DEVCLASS_DEVICE; devClass <= DI8DEVCLASS_GAMECTRL; devClass++) {
if (devClass == DI8DEVCLASS_GAMECTRL && SDL_WasInit(SDL_INIT_JOYSTICK)) {
/* The joystick subsystem will manage adding DInput joystick haptic devices */
continue;
}
ret = IDirectInput8_EnumDevices(dinput,
devClass,
EnumHapticsCallback,
NULL,
DIEDFL_FORCEFEEDBACK |
DIEDFL_ATTACHEDONLY);
if (FAILED(ret)) {
SDL_SYS_HapticQuit();
return DI_SetError("Enumerating DirectInput devices", ret);
}
}
return 0;
}

View File

@@ -52,12 +52,28 @@ static int numhaptics = 0;
int
SDL_SYS_HapticInit(void)
{
JoyStick_DeviceData* device;
if (SDL_DINPUT_HapticInit() < 0) {
return -1;
}
if (SDL_XINPUT_HapticInit() < 0) {
return -1;
}
/* The joystick subsystem will usually be initialized before haptics,
* so the initial HapticMaybeAddDevice() calls from the joystick
* subsystem will arrive too early to create haptic devices. We will
* invoke those callbacks again here to pick up any joysticks that
* were added prior to haptics initialization. */
for (device = SYS_Joystick; device; device = device->pNext) {
if (device->bXInputDevice) {
SDL_XINPUT_HapticMaybeAddDevice(device->XInputUserId);
} else {
SDL_DINPUT_HapticMaybeAddDevice(&device->dxdevice);
}
}
return numhaptics;
}

View File

@@ -20,6 +20,7 @@
*/
#include "../../SDL_internal.h"
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_haptic.h"
#include "../SDL_syshaptic.h"
@@ -47,7 +48,8 @@ SDL_XINPUT_HapticInit(void)
loaded_xinput = (WIN_LoadXInputDLL() == 0);
}
if (loaded_xinput) {
/* If the joystick subsystem is active, it will manage adding XInput haptic devices */
if (loaded_xinput && !SDL_WasInit(SDL_INIT_JOYSTICK)) {
DWORD i;
for (i = 0; i < XUSER_MAX_COUNT; i++) {
SDL_XINPUT_HapticMaybeAddDevice(i);

File diff suppressed because it is too large Load Diff

35
externals/SDL/src/hidapi/SDL_hidapi_c.h vendored Executable file
View File

@@ -0,0 +1,35 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#ifdef SDL_JOYSTICK_HIDAPI
#ifdef SDL_LIBUSB_DYNAMIC
#define HAVE_ENABLE_GAMECUBE_ADAPTORS
#endif
#ifdef HAVE_ENABLE_GAMECUBE_ADAPTORS
extern void SDL_EnableGameCubeAdaptors(void);
#endif
#endif /* SDL_JOYSTICK_HIDAPI */
/* vi: set sts=4 ts=4 sw=4 expandtab: */

View File

@@ -18,16 +18,41 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
// Purpose: A wrapper implementing "HID" API for Android
//
// This layer glues the hidapi API to Android's USB and BLE stack.
#if !SDL_HIDAPI_DISABLED
#include "SDL_hints.h"
#include "../../core/android/SDL_android.h"
#define hid_init PLATFORM_hid_init
#define hid_exit PLATFORM_hid_exit
#define hid_enumerate PLATFORM_hid_enumerate
#define hid_free_enumeration PLATFORM_hid_free_enumeration
#define hid_open PLATFORM_hid_open
#define hid_open_path PLATFORM_hid_open_path
#define hid_write PLATFORM_hid_write
#define hid_read_timeout PLATFORM_hid_read_timeout
#define hid_read PLATFORM_hid_read
#define hid_set_nonblocking PLATFORM_hid_set_nonblocking
#define hid_send_feature_report PLATFORM_hid_send_feature_report
#define hid_get_feature_report PLATFORM_hid_get_feature_report
#define hid_close PLATFORM_hid_close
#define hid_get_manufacturer_string PLATFORM_hid_get_manufacturer_string
#define hid_get_product_string PLATFORM_hid_get_product_string
#define hid_get_serial_number_string PLATFORM_hid_get_serial_number_string
#define hid_get_indexed_string PLATFORM_hid_get_indexed_string
#define hid_error PLATFORM_hid_error
#include <jni.h>
#include <android/log.h>
#include <pthread.h>
#include <errno.h> // For ETIMEDOUT and ECONNRESET
#include <stdlib.h> // For malloc() and free()
#include <string.h> // For memcpy()
#define TAG "hidapi"
@@ -170,7 +195,7 @@ public:
}
m_nSize = nSize;
memcpy( m_pData, pData, nSize );
SDL_memcpy( m_pData, pData, nSize );
}
void clear()
@@ -285,9 +310,9 @@ private:
static jbyteArray NewByteArray( JNIEnv* env, const uint8_t *pData, size_t nDataLen )
{
jbyteArray array = env->NewByteArray( nDataLen );
jbyteArray array = env->NewByteArray( (jsize)nDataLen );
jbyte *pBuf = env->GetByteArrayElements( array, NULL );
memcpy( pBuf, pData, nDataLen );
SDL_memcpy( pBuf, pData, nDataLen );
env->ReleaseByteArrayElements( array, pBuf, 0 );
return array;
@@ -298,7 +323,7 @@ static char *CreateStringFromJString( JNIEnv *env, const jstring &sString )
size_t nLength = env->GetStringUTFLength( sString );
const char *pjChars = env->GetStringUTFChars( sString, NULL );
char *psString = (char*)malloc( nLength + 1 );
memcpy( psString, pjChars, nLength );
SDL_memcpy( psString, pjChars, nLength );
psString[ nLength ] = '\0';
env->ReleaseStringUTFChars( sString, pjChars );
return psString;
@@ -321,9 +346,9 @@ static wchar_t *CreateWStringFromJString( JNIEnv *env, const jstring &sString )
static wchar_t *CreateWStringFromWString( const wchar_t *pwSrc )
{
size_t nLength = wcslen( pwSrc );
size_t nLength = SDL_wcslen( pwSrc );
wchar_t *pwString = (wchar_t*)malloc( ( nLength + 1 ) * sizeof( wchar_t ) );
memcpy( pwString, pwSrc, nLength * sizeof( wchar_t ) );
SDL_memcpy( pwString, pwSrc, nLength * sizeof( wchar_t ) );
pwString[ nLength ] = '\0';
return pwString;
}
@@ -332,7 +357,7 @@ static hid_device_info *CopyHIDDeviceInfo( const hid_device_info *pInfo )
{
hid_device_info *pCopy = new hid_device_info;
*pCopy = *pInfo;
pCopy->path = strdup( pInfo->path );
pCopy->path = SDL_strdup( pInfo->path );
pCopy->product_string = CreateWStringFromWString( pInfo->product_string );
pCopy->manufacturer_string = CreateWStringFromWString( pInfo->manufacturer_string );
pCopy->serial_number = CreateWStringFromWString( pInfo->serial_number );
@@ -350,17 +375,49 @@ static void FreeHIDDeviceInfo( hid_device_info *pInfo )
static jclass g_HIDDeviceManagerCallbackClass;
static jobject g_HIDDeviceManagerCallbackHandler;
static jmethodID g_midHIDDeviceManagerInitialize;
static jmethodID g_midHIDDeviceManagerOpen;
static jmethodID g_midHIDDeviceManagerSendOutputReport;
static jmethodID g_midHIDDeviceManagerSendFeatureReport;
static jmethodID g_midHIDDeviceManagerGetFeatureReport;
static jmethodID g_midHIDDeviceManagerClose;
static bool g_initialized = false;
static uint64_t get_timespec_ms( const struct timespec &ts )
{
return (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}
static void ExceptionCheck( JNIEnv *env, const char *pszClassName, const char *pszMethodName )
{
if ( env->ExceptionCheck() )
{
// Get our exception
jthrowable jExcept = env->ExceptionOccurred();
// Clear the exception so we can call JNI again
env->ExceptionClear();
// Get our exception message
jclass jExceptClass = env->GetObjectClass( jExcept );
jmethodID jMessageMethod = env->GetMethodID( jExceptClass, "getMessage", "()Ljava/lang/String;" );
jstring jMessage = (jstring)( env->CallObjectMethod( jExcept, jMessageMethod ) );
const char *pszMessage = env->GetStringUTFChars( jMessage, NULL );
// ...and log it.
LOGE( "%s%s%s threw an exception: %s",
pszClassName ? pszClassName : "",
pszClassName ? "::" : "",
pszMethodName, pszMessage );
// Cleanup
env->ReleaseStringUTFChars( jMessage, pszMessage );
env->DeleteLocalRef( jMessage );
env->DeleteLocalRef( jExceptClass );
env->DeleteLocalRef( jExcept );
}
}
class CHIDDevice
{
public:
@@ -420,29 +477,7 @@ public:
void ExceptionCheck( JNIEnv *env, const char *pszMethodName )
{
if ( env->ExceptionCheck() )
{
// Get our exception
jthrowable jExcept = env->ExceptionOccurred();
// Clear the exception so we can call JNI again
env->ExceptionClear();
// Get our exception message
jclass jExceptClass = env->GetObjectClass( jExcept );
jmethodID jMessageMethod = env->GetMethodID( jExceptClass, "getMessage", "()Ljava/lang/String;" );
jstring jMessage = (jstring)( env->CallObjectMethod( jExcept, jMessageMethod ) );
const char *pszMessage = env->GetStringUTFChars( jMessage, NULL );
// ...and log it.
LOGE( "CHIDDevice::%s threw an exception: %s", pszMethodName, pszMessage );
// Cleanup
env->ReleaseStringUTFChars( jMessage, pszMessage );
env->DeleteLocalRef( jMessage );
env->DeleteLocalRef( jExceptClass );
env->DeleteLocalRef( jExcept );
}
::ExceptionCheck( env, "CHIDDevice", pszMethodName );
}
bool BOpen()
@@ -543,12 +578,12 @@ public:
if ( m_bIsBLESteamController )
{
data[0] = 0x03;
memcpy( data + 1, buffer.data(), nDataLen );
SDL_memcpy( data + 1, buffer.data(), nDataLen );
++nDataLen;
}
else
{
memcpy( data, buffer.data(), nDataLen );
SDL_memcpy( data, buffer.data(), nDataLen );
}
m_vecData.pop_front();
@@ -557,7 +592,7 @@ public:
// data[0], data[1], data[2], data[3],
// data[4], data[5], data[6], data[7]);
return nDataLen;
return (int)nDataLen;
}
int SendOutputReport( const unsigned char *pData, size_t nDataLen )
@@ -685,11 +720,11 @@ public:
}
size_t uBytesToCopy = m_featureReport.size() > nDataLen ? nDataLen : m_featureReport.size();
memcpy( pData, m_featureReport.data(), uBytesToCopy );
SDL_memcpy( pData, m_featureReport.data(), uBytesToCopy );
m_featureReport.clear();
LOGV( "=== Got %u bytes", uBytesToCopy );
return uBytesToCopy;
return (int)uBytesToCopy;
}
}
@@ -831,6 +866,11 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallba
if ( objClass )
{
g_HIDDeviceManagerCallbackClass = reinterpret_cast< jclass >( env->NewGlobalRef( objClass ) );
g_midHIDDeviceManagerInitialize = env->GetMethodID( g_HIDDeviceManagerCallbackClass, "initialize", "(ZZ)Z" );
if ( !g_midHIDDeviceManagerInitialize )
{
__android_log_print(ANDROID_LOG_ERROR, TAG, "HIDDeviceRegisterCallback: callback class missing initialize" );
}
g_midHIDDeviceManagerOpen = env->GetMethodID( g_HIDDeviceManagerCallbackClass, "openDevice", "(I)Z" );
if ( !g_midHIDDeviceManagerOpen )
{
@@ -870,6 +910,7 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallbac
g_HIDDeviceManagerCallbackClass = NULL;
env->DeleteGlobalRef( g_HIDDeviceManagerCallbackHandler );
g_HIDDeviceManagerCallbackHandler = NULL;
g_initialized = false;
}
}
@@ -879,7 +920,7 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNI
LOGV( "HIDDeviceConnected() id=%d VID/PID = %.4x/%.4x, interface %d\n", nDeviceID, nVendorId, nProductId, nInterface );
hid_device_info *pInfo = new hid_device_info;
memset( pInfo, 0, sizeof( *pInfo ) );
SDL_memset( pInfo, 0, sizeof( *pInfo ) );
pInfo->path = CreateStringFromJString( env, sIdentifier );
pInfo->vendor_id = nVendorId;
pInfo->product_id = nProductId;
@@ -1004,6 +1045,36 @@ extern "C"
int hid_init(void)
{
if ( !g_initialized )
{
// HIDAPI doesn't work well with Android < 4.3
if (SDL_GetAndroidSDKVersion() >= 18) {
// Make sure thread is attached to JVM/env
JNIEnv *env;
g_JVM->AttachCurrentThread( &env, NULL );
pthread_setspecific( g_ThreadKey, (void*)env );
if ( !g_HIDDeviceManagerCallbackHandler )
{
LOGV( "hid_init() without callback handler" );
return -1;
}
// Bluetooth is currently only used for Steam Controllers, so check that hint
// before initializing Bluetooth, which will prompt the user for permission.
bool init_usb = true;
bool init_bluetooth = false;
if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STEAM, SDL_FALSE)) {
if (SDL_GetAndroidSDKVersion() < 31 ||
Android_JNI_RequestPermission("android.permission.BLUETOOTH_CONNECT")) {
init_bluetooth = true;
}
}
env->CallBooleanMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerInitialize, init_usb, init_bluetooth );
ExceptionCheck( env, NULL, "hid_init" );
}
g_initialized = true; // Regardless of result, so it's only called once
}
return 0;
}
@@ -1051,7 +1122,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx
hid_mutex_guard l( &g_DevicesMutex );
for ( hid_device_ref<CHIDDevice> pCurr = g_Devices; pCurr; pCurr = pCurr->next )
{
if ( strcmp( pCurr->GetDeviceInfo()->path, path ) == 0 )
if ( SDL_strcmp( pCurr->GetDeviceInfo()->path, path ) == 0 )
{
hid_device *pValue = pCurr->GetDevice();
if ( pValue )
@@ -1264,3 +1335,5 @@ int hid_exit(void)
}
}
#endif /* SDL_HIDAPI_DISABLED */

View File

@@ -29,7 +29,12 @@
#include <wchar.h>
#if defined(_WIN32) && !defined(NAMESPACE) && (0) /* SDL: don't export hidapi syms */
#ifdef SDL_hidapi_h_
#define SDL_HIDAPI_IMPLEMENTATION
#define hid_device_info SDL_hid_device_info
#endif
#if defined(_WIN32) && !defined(NAMESPACE) && !defined(SDL_HIDAPI_IMPLEMENTATION) /* SDL: don't export hidapi syms */
#define HID_API_EXPORT __declspec(dllexport)
#define HID_API_CALL
#else
@@ -53,6 +58,7 @@ namespace NAMESPACE {
struct hid_device_;
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
#ifndef SDL_HIDAPI_IMPLEMENTATION
/** hidapi info structure */
struct hid_device_info {
/** Platform-specific device path */
@@ -93,6 +99,7 @@ namespace NAMESPACE {
/** Pointer to the next device */
struct hid_device_info *next;
};
#endif /* !SDL_HIDAPI_IMPLEMENTATION */
/** @brief Initialize the HIDAPI library.
@@ -399,6 +406,10 @@ namespace NAMESPACE {
*/
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);
#if __IPHONEOS__ || __TVOS__
HID_API_EXPORT void HID_API_CALL hid_ble_scan(int active);
#endif
#if defined(__cplusplus) && !defined(NAMESPACE)
}
#endif

View File

@@ -20,7 +20,28 @@
*/
#include "../../SDL_internal.h"
#ifdef SDL_JOYSTICK_HIDAPI
#if !SDL_HIDAPI_DISABLED
#include "SDL_hints.h"
#define hid_init PLATFORM_hid_init
#define hid_exit PLATFORM_hid_exit
#define hid_enumerate PLATFORM_hid_enumerate
#define hid_free_enumeration PLATFORM_hid_free_enumeration
#define hid_open PLATFORM_hid_open
#define hid_open_path PLATFORM_hid_open_path
#define hid_write PLATFORM_hid_write
#define hid_read_timeout PLATFORM_hid_read_timeout
#define hid_read PLATFORM_hid_read
#define hid_set_nonblocking PLATFORM_hid_set_nonblocking
#define hid_send_feature_report PLATFORM_hid_send_feature_report
#define hid_get_feature_report PLATFORM_hid_get_feature_report
#define hid_close PLATFORM_hid_close
#define hid_get_manufacturer_string PLATFORM_hid_get_manufacturer_string
#define hid_get_product_string PLATFORM_hid_get_product_string
#define hid_get_serial_number_string PLATFORM_hid_get_serial_number_string
#define hid_get_indexed_string PLATFORM_hid_get_indexed_string
#define hid_error PLATFORM_hid_error
#include <CoreBluetooth/CoreBluetooth.h>
#include <QuartzCore/QuartzCore.h>
@@ -208,24 +229,29 @@ typedef enum
sharedInstance = [HIDBLEManager new];
sharedInstance.nPendingScans = 0;
sharedInstance.nPendingPairs = 0;
[[NSNotificationCenter defaultCenter] addObserver:sharedInstance selector:@selector(appWillResignActiveNotification:) name: UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:sharedInstance selector:@selector(appDidBecomeActiveNotification:) name:UIApplicationDidBecomeActiveNotification object:nil];
// receive reports on a high-priority serial-queue. optionally put writes on the serial queue to avoid logical
// race conditions talking to the controller from multiple threads, although BLE fragmentation/assembly means
// that we can still screw this up.
// most importantly we need to consume reports at a high priority to avoid the OS thinking we aren't really
// listening to the BLE device, as iOS on slower devices may stop delivery of packets to the app WITHOUT ACTUALLY
// DISCONNECTING FROM THE DEVICE if we don't react quickly enough to their delivery.
// see also the error-handling states in the peripheral delegate to re-open the device if it gets closed
sharedInstance.bleSerialQueue = dispatch_queue_create( "com.valvesoftware.steamcontroller.ble", DISPATCH_QUEUE_SERIAL );
dispatch_set_target_queue( sharedInstance.bleSerialQueue, dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0 ) );
// Bluetooth is currently only used for Steam Controllers, so check that hint
// before initializing Bluetooth, which will prompt the user for permission.
if ( SDL_GetHintBoolean( SDL_HINT_JOYSTICK_HIDAPI_STEAM, SDL_FALSE ) )
{
[[NSNotificationCenter defaultCenter] addObserver:sharedInstance selector:@selector(appWillResignActiveNotification:) name: UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:sharedInstance selector:@selector(appDidBecomeActiveNotification:) name:UIApplicationDidBecomeActiveNotification object:nil];
// creating a CBCentralManager will always trigger a future centralManagerDidUpdateState:
// where any scanning gets started or connecting to existing peripherals happens, it's never already in a
// powered-on state for a newly launched application.
sharedInstance.centralManager = [[CBCentralManager alloc] initWithDelegate:sharedInstance queue:sharedInstance.bleSerialQueue];
// receive reports on a high-priority serial-queue. optionally put writes on the serial queue to avoid logical
// race conditions talking to the controller from multiple threads, although BLE fragmentation/assembly means
// that we can still screw this up.
// most importantly we need to consume reports at a high priority to avoid the OS thinking we aren't really
// listening to the BLE device, as iOS on slower devices may stop delivery of packets to the app WITHOUT ACTUALLY
// DISCONNECTING FROM THE DEVICE if we don't react quickly enough to their delivery.
// see also the error-handling states in the peripheral delegate to re-open the device if it gets closed
sharedInstance.bleSerialQueue = dispatch_queue_create( "com.valvesoftware.steamcontroller.ble", DISPATCH_QUEUE_SERIAL );
dispatch_set_target_queue( sharedInstance.bleSerialQueue, dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0 ) );
// creating a CBCentralManager will always trigger a future centralManagerDidUpdateState:
// where any scanning gets started or connecting to existing peripherals happens, it's never already in a
// powered-on state for a newly launched application.
sharedInstance.centralManager = [[CBCentralManager alloc] initWithDelegate:sharedInstance queue:sharedInstance.bleSerialQueue];
}
sharedInstance.deviceMap = [[NSMapTable alloc] initWithKeyOptions:NSMapTableWeakMemory valueOptions:NSMapTableStrongMemory capacity:4];
});
return sharedInstance;
@@ -265,6 +291,11 @@ typedef enum
static uint64_t s_unLastUpdateTick = 0;
static mach_timebase_info_data_t s_timebase_info;
if ( self.centralManager == nil )
{
return 0;
}
if (s_timebase_info.denom == 0)
{
mach_timebase_info( &s_timebase_info );
@@ -310,6 +341,11 @@ typedef enum
// manual API for folks to start & stop scanning
- (void)startScan:(int)duration
{
if ( self.centralManager == nil )
{
return;
}
NSLog( @"BLE: requesting scan for %d seconds", duration );
@synchronized (self)
{
@@ -329,6 +365,11 @@ typedef enum
- (void)stopScan
{
if ( self.centralManager == nil )
{
return;
}
NSLog( @"BLE: stopping scan" );
@synchronized (self)
{
@@ -724,7 +765,7 @@ int HID_API_EXPORT HID_API_CALL hid_exit(void)
return 0;
}
void HID_API_EXPORT HID_API_CALL hid_ble_scan( bool bStart )
void HID_API_EXPORT HID_API_CALL hid_ble_scan( int bStart )
{
HIDBLEManager *bleManager = HIDBLEManager.sharedInstance;
if ( bStart )
@@ -737,7 +778,12 @@ void HID_API_EXPORT HID_API_CALL hid_ble_scan( bool bStart )
}
}
hid_device * HID_API_EXPORT hid_open_path( const char *path, int bExclusive /* = false */ )
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
{
return NULL;
}
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path( const char *path, int bExclusive /* = false */ )
{
hid_device *result = NULL;
NSString *nssPath = [NSString stringWithUTF8String:path];
@@ -851,6 +897,11 @@ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *s
return 0;
}
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
{
return -1;
}
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
{
HIDBLEDevice *device_handle = (__bridge HIDBLEDevice *)dev->device_handle;
@@ -927,4 +978,9 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
return result;
}
#endif /* SDL_JOYSTICK_HIDAPI */
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev)
{
return NULL;
}
#endif /* !SDL_HIDAPI_DISABLED */

View File

@@ -31,8 +31,6 @@
#include "SDL_thread.h"
#include "SDL_mutex.h"
#ifdef SDL_JOYSTICK_HIDAPI
#if defined(HAVE__WCSDUP) && !defined(HAVE_WCSDUP)
#define wcsdup _wcsdup
#endif
@@ -40,7 +38,7 @@
#include <libusb.h>
#include <locale.h> /* setlocale */
#include "hidapi.h"
#include "../hidapi/hidapi.h"
#ifdef NAMESPACE
namespace NAMESPACE
@@ -1031,8 +1029,9 @@ static int read_thread(void *param)
return 0;
}
static void init_xboxone(libusb_device_handle *device_handle, struct libusb_config_descriptor *conf_desc)
static void init_xboxone(libusb_device_handle *device_handle, unsigned short idVendor, unsigned short idProduct, struct libusb_config_descriptor *conf_desc)
{
static const int VENDOR_MICROSOFT = 0x045e;
static const int XB1_IFACE_SUBCLASS = 71;
static const int XB1_IFACE_PROTOCOL = 208;
int j, k, res;
@@ -1040,26 +1039,36 @@ static void init_xboxone(libusb_device_handle *device_handle, struct libusb_conf
for (j = 0; j < conf_desc->bNumInterfaces; j++) {
const struct libusb_interface *intf = &conf_desc->interface[j];
for (k = 0; k < intf->num_altsetting; k++) {
const struct libusb_interface_descriptor *intf_desc;
intf_desc = &intf->altsetting[k];
if (intf_desc->bInterfaceNumber != 0 &&
intf_desc->bAlternateSetting == 0 &&
intf_desc->bInterfaceClass == LIBUSB_CLASS_VENDOR_SPEC &&
const struct libusb_interface_descriptor *intf_desc = &intf->altsetting[k];
if (intf_desc->bInterfaceClass == LIBUSB_CLASS_VENDOR_SPEC &&
intf_desc->bInterfaceSubClass == XB1_IFACE_SUBCLASS &&
intf_desc->bInterfaceProtocol == XB1_IFACE_PROTOCOL) {
res = libusb_claim_interface(device_handle, intf_desc->bInterfaceNumber);
if (res < 0) {
LOG("can't claim interface %d: %d\n", intf_desc->bInterfaceNumber, res);
continue;
int bSetAlternateSetting = 0;
/* Newer Microsoft Xbox One controllers have a high speed alternate setting */
if (idVendor == VENDOR_MICROSOFT &&
intf_desc->bInterfaceNumber == 0 && intf_desc->bAlternateSetting == 1) {
bSetAlternateSetting = 1;
} else if (intf_desc->bInterfaceNumber != 0 && intf_desc->bAlternateSetting == 0) {
bSetAlternateSetting = 1;
}
res = libusb_set_interface_alt_setting(device_handle, intf_desc->bInterfaceNumber, intf_desc->bAlternateSetting);
if (res < 0) {
LOG("xbox init: can't set alt setting %d: %d\n", intf_desc->bInterfaceNumber, res);
}
if (bSetAlternateSetting) {
res = libusb_claim_interface(device_handle, intf_desc->bInterfaceNumber);
if (res < 0) {
LOG("can't claim interface %d: %d\n", intf_desc->bInterfaceNumber, res);
continue;
}
libusb_release_interface(device_handle, intf_desc->bInterfaceNumber);
LOG("Setting alternate setting for VID/PID 0x%x/0x%x interface %d to %d\n", idVendor, idProduct, intf_desc->bInterfaceNumber, intf_desc->bAlternateSetting);
res = libusb_set_interface_alt_setting(device_handle, intf_desc->bInterfaceNumber, intf_desc->bAlternateSetting);
if (res < 0) {
LOG("xbox init: can't set alt setting %d: %d\n", intf_desc->bInterfaceNumber, res);
}
libusb_release_interface(device_handle, intf_desc->bInterfaceNumber);
}
}
}
}
@@ -1141,7 +1150,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
/* Initialize XBox One controllers */
if (is_xboxone(desc.idVendor, intf_desc)) {
init_xboxone(dev->device_handle, conf_desc);
init_xboxone(dev->device_handle, desc.idVendor, desc.idProduct, conf_desc);
}
/* Store off the string descriptor indexes */
@@ -1731,5 +1740,3 @@ uint16_t get_usb_code_for_current_locale(void)
#ifdef NAMESPACE
}
#endif
#endif /* SDL_JOYSTICK_HIDAPI */

View File

@@ -22,8 +22,6 @@
********************************************************/
#include "../../SDL_internal.h"
#ifdef SDL_JOYSTICK_HIDAPI
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* needed for wcsdup() before glibc 2.10 */
#endif
@@ -50,7 +48,7 @@
#include <linux/input.h>
#include <libudev.h>
#include "hidapi.h"
#include "../hidapi/hidapi.h"
#ifdef NAMESPACE
namespace NAMESPACE
@@ -217,7 +215,7 @@ static int uses_numbered_reports(__u8 *report_descriptor, __u32 size) {
* strings pointed to by serial_number_utf8 and product_name_utf8 after use.
*/
static int
parse_uevent_info(const char *uevent, int *bus_type,
parse_uevent_info(const char *uevent, unsigned *bus_type,
unsigned short *vendor_id, unsigned short *product_id,
char **serial_number_utf8, char **product_name_utf8)
{
@@ -300,7 +298,7 @@ static int is_BLE(hid_device *dev)
if (hid_dev) {
unsigned short dev_vid = 0;
unsigned short dev_pid = 0;
int bus_type = 0;
unsigned bus_type = 0;
char *serial_number_utf8 = NULL;
char *product_name_utf8 = NULL;
@@ -338,8 +336,8 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
struct udev_device *udev_dev, *parent, *hid_dev;
struct stat s;
int ret = -1;
char *serial_number_utf8 = NULL;
char *product_name_utf8 = NULL;
char *serial_number_utf8 = NULL;
char *product_name_utf8 = NULL;
char *tmp;
/* Create the udev object */
@@ -365,7 +363,7 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
if (hid_dev) {
unsigned short dev_vid;
unsigned short dev_pid;
int bus_type;
unsigned bus_type;
size_t retm;
ret = parse_uevent_info(
@@ -433,8 +431,8 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
}
end:
free(serial_number_utf8);
free(product_name_utf8);
free(serial_number_utf8);
free(product_name_utf8);
udev_device_unref(udev_dev);
/* parent and hid_dev don't need to be (and can't be) unref'd.
@@ -503,7 +501,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
unsigned short dev_pid;
char *serial_number_utf8 = NULL;
char *product_name_utf8 = NULL;
int bus_type;
unsigned bus_type;
int result;
/* Get the filename of the /sys entry for the device
@@ -716,7 +714,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
dev = new_hid_device();
/* OPEN HERE */
dev->device_handle = open(path, O_RDWR);
dev->device_handle = open(path, O_RDWR | O_CLOEXEC);
/* If we have a good handle, return it. */
if (dev->device_handle >= 0) {
@@ -828,34 +826,47 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
return 0; /* Success */
}
int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
{
static const int MAX_RETRIES = 50;
int retry;
int res;
res = ioctl(dev->device_handle, HIDIOCSFEATURE(length), data);
if (res < 0)
perror("ioctl (SFEATURE)");
for (retry = 0; retry < MAX_RETRIES; ++retry) {
res = ioctl(dev->device_handle, HIDIOCSFEATURE(length), data);
if (res < 0 && errno == EPIPE) {
/* Try again... */
continue;
}
if (res < 0)
perror("ioctl (SFEATURE)");
break;
}
return res;
}
int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
{
int res;
unsigned char report = data[0];
/* It looks like HIDIOCGFEATURE() on Bluetooth LE devices doesn't return the report number */
if (dev->needs_ble_hack) {
data[1] = data[0];
++data;
--length;
}
res = ioctl(dev->device_handle, HIDIOCGFEATURE(length), data);
if (res < 0)
perror("ioctl (GFEATURE)");
else if (dev->needs_ble_hack)
++res;
else if (dev->needs_ble_hack) {
/* Versions of BlueZ before 5.56 don't include the report in the data,
* and versions of BlueZ >= 5.56 include 2 copies of the report.
* We'll fix it so that there is a single copy of the report in both cases
*/
if (data[0] == report && data[1] == report) {
memmove(&data[0], &data[1], res);
} else if (data[0] != report) {
memmove(&data[1], &data[0], res);
data[0] = report;
++res;
}
}
return res;
}
@@ -886,6 +897,10 @@ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *s
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
{
(void)dev;
(void)string_index;
(void)string;
(void)maxlen;
return -1;
}
@@ -898,5 +913,3 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
#ifdef NAMESPACE
}
#endif
#endif /* SDL_JOYSTICK_HIDAPI */

View File

@@ -21,8 +21,6 @@
********************************************************/
#include "../../SDL_internal.h"
#ifdef SDL_JOYSTICK_HIDAPI
/* See Apple Technical Note TN2187 for details on IOHidManager. */
#include <IOKit/hid/IOHIDManager.h>
@@ -33,7 +31,9 @@
#include <sys/time.h>
#include <unistd.h>
#include "hidapi.h"
#include "../hidapi/hidapi.h"
#define VALVE_USB_VID 0x28DE
/* Barrier implementation because Mac OSX doesn't have pthread_barrier.
It also doesn't have clock_gettime(). So much for POSIX and SUSv2.
@@ -401,20 +401,86 @@ static void hid_device_removal_callback(void *context, IOReturn result,
}
}
static CFDictionaryRef
create_usage_match(const UInt32 page, const UInt32 usage, int *okay)
{
CFDictionaryRef retval = NULL;
CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
const void *keys[2] = { (void *) CFSTR(kIOHIDDeviceUsagePageKey), (void *) CFSTR(kIOHIDDeviceUsageKey) };
const void *vals[2] = { (void *) pageNumRef, (void *) usageNumRef };
if (pageNumRef && usageNumRef) {
retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
if (pageNumRef) {
CFRelease(pageNumRef);
}
if (usageNumRef) {
CFRelease(usageNumRef);
}
if (!retval) {
*okay = 0;
}
return retval;
}
static CFDictionaryRef
create_vendor_match(const UInt32 vendor, int *okay)
{
CFDictionaryRef retval = NULL;
CFNumberRef vidNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &vendor);
const void *keys[1] = { (void *) CFSTR(kIOHIDVendorIDKey) };
const void *vals[1] = { (void *) vidNumRef };
if (vidNumRef) {
retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFRelease(vidNumRef);
}
if (!retval) {
*okay = 0;
}
return retval;
}
/* Initialize the IOHIDManager. Return 0 for success and -1 for failure. */
static int init_hid_manager(void)
{
int okay = 1;
const void *vals[] = {
(void *) create_usage_match(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay),
(void *) create_usage_match(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad, &okay),
(void *) create_usage_match(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController, &okay),
(void *) create_vendor_match(VALVE_USB_VID, &okay),
};
const size_t numElements = SDL_arraysize(vals);
CFArrayRef matchingArray = okay ? CFArrayCreate(kCFAllocatorDefault, vals, numElements, &kCFTypeArrayCallBacks) : NULL;
size_t i;
for (i = 0; i < numElements; i++) {
if (vals[i]) {
CFRelease((CFTypeRef) vals[i]);
}
}
/* Initialize all the HID Manager Objects */
hid_mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (hid_mgr) {
IOHIDManagerSetDeviceMatching(hid_mgr, NULL);
IOHIDManagerSetDeviceMatchingMultiple(hid_mgr, matchingArray);
IOHIDManagerScheduleWithRunLoop(hid_mgr, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerRegisterDeviceRemovalCallback(hid_mgr, hid_device_removal_callback, NULL);
return 0;
}
return -1;
if (matchingArray != NULL) {
CFRelease(matchingArray);
}
return hid_mgr ? 0 : -1;
}
/* Initialize the IOHIDManager if necessary. This is the public function, and
@@ -1191,5 +1257,3 @@ int main(void)
return 0;
}
#endif
#endif /* SDL_JOYSTICK_HIDAPI */

View File

@@ -21,8 +21,6 @@
********************************************************/
#include "../../SDL_internal.h"
#ifdef SDL_JOYSTICK_HIDAPI
#include <windows.h>
#ifndef _WIN32_WINNT_WIN8
@@ -1099,5 +1097,3 @@ int __cdecl main(int argc, char* argv[])
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SDL_JOYSTICK_HIDAPI */

View File

@@ -1515,6 +1515,57 @@ SDL_GameControllerNumMappings(void)
return num_mappings;
}
/*
* Create a mapping string for a mapping
*/
static char *
CreateMappingString(ControllerMapping_t *mapping, SDL_JoystickGUID guid)
{
char *pMappingString, *pPlatformString;
char pchGUID[33];
size_t needed;
const char *platform = SDL_GetPlatform();
SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
if (!SDL_strstr(mapping->mapping, SDL_CONTROLLER_PLATFORM_FIELD)) {
/* add memory for ',' + platform:PLATFORM */
if (mapping->mapping[SDL_strlen(mapping->mapping) - 1] != ',') {
needed += 1;
}
needed += SDL_strlen(SDL_CONTROLLER_PLATFORM_FIELD) + SDL_strlen(platform);
}
pMappingString = SDL_malloc(needed);
if (!pMappingString) {
SDL_OutOfMemory();
return NULL;
}
SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
if (!SDL_strstr(mapping->mapping, SDL_CONTROLLER_PLATFORM_FIELD)) {
if (mapping->mapping[SDL_strlen(mapping->mapping) - 1] != ',') {
SDL_strlcat(pMappingString, ",", needed);
}
SDL_strlcat(pMappingString, SDL_CONTROLLER_PLATFORM_FIELD, needed);
SDL_strlcat(pMappingString, platform, needed);
}
/* Make sure multiple platform strings haven't made their way into the mapping */
pPlatformString = SDL_strstr(pMappingString, SDL_CONTROLLER_PLATFORM_FIELD);
if (pPlatformString) {
pPlatformString = SDL_strstr(pPlatformString + 1, SDL_CONTROLLER_PLATFORM_FIELD);
if (pPlatformString) {
*pPlatformString = '\0';
}
}
return pMappingString;
}
/*
* Get the mapping at a particular index.
*/
@@ -1528,20 +1579,7 @@ SDL_GameControllerMappingForIndex(int mapping_index)
continue;
}
if (mapping_index == 0) {
char *pMappingString;
char pchGUID[33];
size_t needed;
SDL_JoystickGetGUIDString(mapping->guid, pchGUID, sizeof(pchGUID));
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
pMappingString = SDL_malloc(needed);
if (!pMappingString) {
SDL_OutOfMemory();
return NULL;
}
SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
return pMappingString;
return CreateMappingString(mapping, mapping->guid);
}
--mapping_index;
}
@@ -1554,22 +1592,11 @@ SDL_GameControllerMappingForIndex(int mapping_index)
char *
SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
{
char *pMappingString = NULL;
ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_FALSE);
if (mapping) {
char pchGUID[33];
size_t needed;
SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
pMappingString = SDL_malloc(needed);
if (!pMappingString) {
SDL_OutOfMemory();
return NULL;
}
SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
return CreateMappingString(mapping, guid);
}
return pMappingString;
return NULL;
}
/*
@@ -1793,6 +1820,13 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
}
#endif
#if defined(__ANDROID__)
if (name && SDL_strcmp(name, "uinput-fpc") == 0) {
/* The Google Pixel fingerprint sensor reports itself as a joystick */
return SDL_TRUE;
}
#endif
if (SDL_allowed_controllers.num_entries == 0 &&
SDL_ignored_controllers.num_entries == 0) {
return SDL_FALSE;
@@ -2447,6 +2481,18 @@ SDL_GameControllerHasLED(SDL_GameController *gamecontroller)
return SDL_JoystickHasLED(SDL_GameControllerGetJoystick(gamecontroller));
}
SDL_bool
SDL_GameControllerHasRumble(SDL_GameController *gamecontroller)
{
return SDL_JoystickHasRumble(SDL_GameControllerGetJoystick(gamecontroller));
}
SDL_bool
SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller)
{
return SDL_JoystickHasRumbleTriggers(SDL_GameControllerGetJoystick(gamecontroller));
}
int
SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue)
{
@@ -2675,4 +2721,26 @@ SDL_GameControllerHandleDelayedGuideButton(SDL_Joystick *joystick)
}
}
const char *
SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button)
{
#if defined(SDL_JOYSTICK_MFI)
const char *IOS_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button);
return IOS_GameControllerGetAppleSFSymbolsNameForButton(gamecontroller, button);
#else
return NULL;
#endif
}
const char *
SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
{
#if defined(SDL_JOYSTICK_MFI)
const char *IOS_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
return IOS_GameControllerGetAppleSFSymbolsNameForAxis(gamecontroller, axis);
#else
return NULL;
#endif
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -26,7 +26,7 @@
The easiest way to generate a new mapping is to start Steam in Big Picture
mode, configure your joystick and then look in config/config.vdf in your
Steam installation directory for the "SDL_GamepadBind" entry.
Alternatively, you can use the app located in test/controllermap
*/
static const char *s_ControllerMappings [] =
@@ -135,7 +135,7 @@ static const char *s_ControllerMappings [] =
"78696e70757403000000000000000000,Fightstick TES,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,start:b7,x:b2,y:b3,",
"03000000151900004000000000000000,Flydigi Vader 2,a:b11,b:b10,back:b3,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b7,leftstick:b1,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b0,righttrigger:b4,rightx:a3,righty:a4,start:b2,x:b9,y:b8,",
"03000000b40400001124000000000000,Flydigi Vader 2,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b12,lefttrigger:b8,leftx:a0,lefty:a1,paddle1:b4,paddle2:b5,paddle4:b17,rightshoulder:b7,rightstick:b13,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b2,y:b3,",
"03000000790000000600000000000000,G-Shark GS-GP702,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a4,start:b9,x:b3,y:b0,",
"03000000790000000600000000000000,G-Shark GS-GP702,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
"030000008f0e00000d31000000000000,GAMEPAD 3 TURBO,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000300f00000b01000000000000,GGE909 Recoil Pad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b3,y:b0,",
"03000000790000002201000000000000,Game Controller for PC,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
@@ -248,7 +248,7 @@ static const char *s_ControllerMappings [] =
"030000003807000056a8000000000000,PS3 RF pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000100000008200000000000000,PS360+ v1.66,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:h0.4,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"030000004c050000a00b000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000004c050000c405000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000004c050000c405000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,touchpad:b13,x:b0,y:b3,",
"030000004c050000cc09000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000004c050000e60c000000000000,PS5 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b13,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000008f0e00000300000000000000,Piranha xtreme,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a3,righty:a2,start:b9,x:b3,y:b0,",
@@ -396,7 +396,7 @@ static const char *s_ControllerMappings [] =
"030000000d0f00008500000000010000,Fighting Commander,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000151900004000000001000000,Flydigi Vader 2,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"03000000b40400001124000000000000,Flydigi Vader 2,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b12,lefttrigger:b8,leftx:a0,lefty:a1,paddle1:b4,paddle2:b5,paddle3:b17,rightshoulder:b7,rightstick:b13,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b2,y:b3,",
"03000000790000000600000000000000,G-Shark GP-702,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a4,start:b9,x:b3,y:b0,",
"03000000790000000600000000000000,G-Shark GS-GP702,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
"0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"03000000c01100000140000000010000,GameStop PS4 Fun Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000ad1b000001f9000000000000,Gamestop BB-070 X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
@@ -482,6 +482,7 @@ static const char *s_ControllerMappings [] =
"030000005e040000d102000000000000,Xbox One Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
"030000005e040000dd02000000000000,Xbox One Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
"030000005e040000e302000000000000,Xbox One Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
"030000005e040000200b000011050000,Xbox Wireless Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"030000005e040000e002000000000000,Xbox Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e040000e002000003090000,Xbox Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e040000ea02000000000000,Xbox Wireless Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
@@ -556,8 +557,9 @@ static const char *s_ControllerMappings [] =
"03000000790000003018000011010000,Arcade Fightstick F300,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"03000000503200000110000000000000,Atari Classic Controller,a:b0,back:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b4,start:b3,x:b1,",
"05000000503200000110000000000000,Atari Classic Controller,a:b0,back:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b4,start:b3,x:b1,",
"03000000503200000210000000000000,Atari Game Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b2,",
"03000000503200000210000000000000,Atari Game Controller,a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a4,rightx:a2,righty:a3,start:b8,x:b2,y:b3,",
"05000000503200000210000000000000,Atari Game Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b2,",
"030000005e0400008e02000047010000,Atari Xbox 360 Game Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"03000000c62400001b89000011010000,BDA MOGA XP5-X Plus,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"03000000d62000002a79000011010000,BDA PS4 Fightpad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000120c0000f70e000011010000,Brook Universal Fighting Board,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:,lefty:,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:,righty:,start:b9,x:b0,y:b3,",
@@ -589,6 +591,7 @@ static const char *s_ControllerMappings [] =
"030000000d0f00002200000011010000,HORI CO. LTD. REAL ARCADE Pro.V3,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"030000000d0f00006a00000011010000,HORI CO. LTD. Real Arcade Pro.4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000000d0f00006b00000011010000,HORI CO. LTD. Real Arcade Pro.4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000000d0f00005001000009040000,HORI Fighting Commander OCTA,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000000d0f00008400000011010000,HORI Fighting Commander,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000000d0f00008500000010010000,HORI Fighting Commander,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000000d0f0000d800000072056800,HORI Real Arcade Pro S,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
@@ -695,8 +698,9 @@ static const char *s_ControllerMappings [] =
"050000004c050000cc09000001800000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
"030000004c050000e60c000000010000,PS5 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b13,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000004c050000e60c000011010000,PS5 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b13,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000004c050000e60c000011810000,PS5 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b13,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000004c050000e60c000011810000,PS5 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
"050000004c050000e60c000000010000,PS5 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b13,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"050000004c050000e60c000000810000,PS5 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
"030000004c050000da0c000011010000,Playstation Controller,a:b2,b:b1,back:b8,leftshoulder:b6,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,start:b9,x:b3,y:b0,",
"03000000c62400003a54000001010000,PowerA XBox One Controller,a:b0,b:b1,back:b6,dpdown:h0.7,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"03000000c62400000053000000010000,PowerA,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",

View File

@@ -343,6 +343,9 @@ SDL_JoystickGetDevicePlayerIndex(int device_index)
static SDL_bool
SDL_JoystickAxesCenteredAtZero(SDL_Joystick *joystick)
{
#ifdef __WINRT__
return SDL_TRUE;
#else
static Uint32 zero_centered_joysticks[] = {
MAKE_VIDPID(0x0e8f, 0x3013), /* HuiJia SNES USB adapter */
MAKE_VIDPID(0x05a0, 0x3232), /* 8Bitdo Zero Gamepad */
@@ -365,6 +368,7 @@ SDL_JoystickAxesCenteredAtZero(SDL_Joystick *joystick)
}
}
return SDL_FALSE;
#endif /* __WINRT__ */
}
/*
@@ -759,7 +763,7 @@ SDL_JoystickGetButton(SDL_Joystick *joystick, int button)
SDL_bool
SDL_JoystickGetAttached(SDL_Joystick *joystick)
{
if (!SDL_PrivateJoystickValid(joystick)) {
if (!joystick) {
return SDL_FALSE;
}
@@ -944,7 +948,43 @@ SDL_JoystickHasLED(SDL_Joystick *joystick)
SDL_LockJoysticks();
result = joystick->driver->HasLED(joystick);
result = (joystick->driver->GetCapabilities(joystick) & SDL_JOYCAP_LED) != 0;
SDL_UnlockJoysticks();
return result;
}
SDL_bool
SDL_JoystickHasRumble(SDL_Joystick *joystick)
{
SDL_bool result;
if (!SDL_PrivateJoystickValid(joystick)) {
return SDL_FALSE;
}
SDL_LockJoysticks();
result = (joystick->driver->GetCapabilities(joystick) & SDL_JOYCAP_RUMBLE) != 0;
SDL_UnlockJoysticks();
return result;
}
SDL_bool
SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick)
{
SDL_bool result;
if (!SDL_PrivateJoystickValid(joystick)) {
return SDL_FALSE;
}
SDL_LockJoysticks();
result = (joystick->driver->GetCapabilities(joystick) & SDL_JOYCAP_RUMBLE_TRIGGERS) != 0;
SDL_UnlockJoysticks();
@@ -1095,8 +1135,8 @@ SDL_JoystickQuit(void)
SDL_JoystickClose(SDL_joysticks);
}
/* Quit the joystick setup */
for (i = 0; i < SDL_arraysize(SDL_joystick_drivers); ++i) {
/* Quit drivers in reverse order to avoid breaking dependencies between drivers */
for (i = SDL_arraysize(SDL_joystick_drivers) - 1; i >= 0; --i) {
SDL_joystick_drivers[i]->Quit();
}
@@ -1344,7 +1384,7 @@ SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
info->value = value;
info->zero = value;
info->has_initial_value = SDL_TRUE;
} else if (value == info->value) {
} else if (value == info->value && !info->sending_initial_value) {
return 0;
} else {
info->has_second_value = SDL_TRUE;
@@ -1356,15 +1396,17 @@ SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
return 0;
}
info->sent_initial_value = SDL_TRUE;
info->value = ~value; /* Just so we pass the check above */
info->sending_initial_value = SDL_TRUE;
SDL_PrivateJoystickAxis(joystick, axis, info->initial_value);
info->sending_initial_value = SDL_FALSE;
}
/* We ignore events if we don't have keyboard focus, except for centering
* events.
*/
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if ((value > info->zero && value >= info->value) ||
if (info->sending_initial_value ||
(value > info->zero && value >= info->value) ||
(value < info->zero && value <= info->value)) {
return 0;
}
@@ -1757,8 +1799,13 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
size_t prefixlen = SDL_strlen(replacements[i].prefix);
if (SDL_strncasecmp(name, replacements[i].prefix, prefixlen) == 0) {
size_t replacementlen = SDL_strlen(replacements[i].replacement);
SDL_memcpy(name, replacements[i].replacement, replacementlen);
SDL_memmove(name+replacementlen, name+prefixlen, (len-prefixlen+1));
if (replacementlen <= prefixlen) {
SDL_memcpy(name, replacements[i].replacement, replacementlen);
SDL_memmove(name+replacementlen, name+prefixlen, (len-prefixlen)+1);
len -= (prefixlen - replacementlen);
} else {
/* FIXME: Need to handle the expand case by reallocating the string */
}
break;
}
}
@@ -1768,11 +1815,9 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
int matchlen = PrefixMatch(name, &name[i]);
if (matchlen > 0 && name[matchlen-1] == ' ') {
SDL_memmove(name, name+matchlen, len-matchlen+1);
len -= matchlen;
break;
} else if (matchlen > 0 && name[matchlen] == ' ') {
SDL_memmove(name, name+matchlen+1, len-matchlen);
len -= (matchlen + 1);
break;
}
}
@@ -1961,7 +2006,7 @@ SDL_IsJoystickXboxSeriesX(Uint16 vendor_id, Uint16 product_id)
{
if (vendor_id == USB_VENDOR_MICROSOFT) {
if (product_id == USB_PRODUCT_XBOX_SERIES_X ||
product_id == USB_PRODUCT_XBOX_SERIES_X_BLUETOOTH) {
product_id == USB_PRODUCT_XBOX_SERIES_X_BLE) {
return SDL_TRUE;
}
}
@@ -1986,10 +2031,14 @@ SDL_bool
SDL_IsJoystickBluetoothXboxOne(Uint16 vendor_id, Uint16 product_id)
{
if (vendor_id == USB_VENDOR_MICROSOFT) {
if (product_id == USB_PRODUCT_XBOX_ONE_S_REV1_BLUETOOTH ||
if (product_id == USB_PRODUCT_XBOX_ONE_ADAPTIVE_BLUETOOTH ||
product_id == USB_PRODUCT_XBOX_ONE_ADAPTIVE_BLE ||
product_id == USB_PRODUCT_XBOX_ONE_S_REV1_BLUETOOTH ||
product_id == USB_PRODUCT_XBOX_ONE_S_REV2_BLUETOOTH ||
product_id == USB_PRODUCT_XBOX_ONE_S_REV2_BLE ||
product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2_BLUETOOTH ||
product_id == USB_PRODUCT_XBOX_SERIES_X_BLUETOOTH) {
product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2_BLE ||
product_id == USB_PRODUCT_XBOX_SERIES_X_BLE) {
return SDL_TRUE;
}
}
@@ -2389,8 +2438,9 @@ SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid)
/* Additional entries */
/*****************************************************************/
/* Anne Pro II Keyboard */
MAKE_VIDPID(0x04d9, 0x8009), /* OBINLB USB-HID Keyboard */
MAKE_VIDPID(0x0b05, 0x1958), /* ROG Chakram Mouse */
MAKE_VIDPID(0x26ce, 0x01a2), /* ASRock LED Controller */
};
unsigned int i;
@@ -2713,6 +2763,13 @@ int SDL_PrivateJoystickTouchpad(SDL_Joystick *joystick, int touchpad, int finger
}
#endif
/* We ignore events if we don't have keyboard focus, except for touch release */
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if (event_type != SDL_CONTROLLERTOUCHPADUP) {
return 0;
}
}
/* Update internal joystick state */
finger_info->state = state;
finger_info->x = x;
@@ -2742,6 +2799,11 @@ int SDL_PrivateJoystickSensor(SDL_Joystick *joystick, SDL_SensorType type, const
int i;
int posted = 0;
/* We ignore events if we don't have keyboard focus */
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
return 0;
}
for (i = 0; i < joystick->nsensors; ++i) {
SDL_JoystickSensorInfo *sensor = &joystick->sensors[i];

View File

@@ -36,6 +36,7 @@ typedef struct _SDL_JoystickAxisInfo
SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */
SDL_bool has_second_value; /* Whether we've seen a second value on the axis yet */
SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */
SDL_bool sending_initial_value; /* Whether we are sending the initial axis value */
} SDL_JoystickAxisInfo;
typedef struct _SDL_JoystickTouchpadFingerInfo
@@ -120,6 +121,11 @@ struct _SDL_Joystick
#define SDL_HARDWARE_BUS_USB 0x03
#define SDL_HARDWARE_BUS_BLUETOOTH 0x05
/* Joystick capability flags for GetCapabilities() */
#define SDL_JOYCAP_LED 0x01
#define SDL_JOYCAP_RUMBLE 0x02
#define SDL_JOYCAP_RUMBLE_TRIGGERS 0x04
/* Macro to combine a USB vendor ID and product ID into a single Uint32 value */
#define MAKE_VIDPID(VID, PID) (((Uint32)(VID))<<16|(PID))
@@ -163,8 +169,10 @@ typedef struct _SDL_JoystickDriver
int (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
int (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
/* Capability detection */
Uint32 (*GetCapabilities)(SDL_Joystick *joystick);
/* LED functionality */
SDL_bool (*HasLED)(SDL_Joystick *joystick);
int (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
/* General effects */

View File

@@ -616,10 +616,10 @@ ANDROID_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint1
return SDL_Unsupported();
}
static SDL_bool
ANDROID_JoystickHasLED(SDL_Joystick *joystick)
static Uint32
ANDROID_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return SDL_FALSE;
return 0;
}
static int
@@ -719,7 +719,7 @@ SDL_JoystickDriver SDL_ANDROID_JoystickDriver =
ANDROID_JoystickOpen,
ANDROID_JoystickRumble,
ANDROID_JoystickRumbleTriggers,
ANDROID_JoystickHasLED,
ANDROID_JoystickGetCapabilities,
ANDROID_JoystickSetLED,
ANDROID_JoystickSendEffect,
ANDROID_JoystickSetSensorsEnabled,

View File

@@ -240,7 +240,7 @@ BSD_JoystickInit(void)
}
for (i = 0; i < MAX_JOY_JOYS; i++) {
SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
fd = open(s, O_RDONLY);
fd = open(s, O_RDONLY | O_CLOEXEC);
if (fd != -1) {
joynames[numjoysticks++] = SDL_strdup(s);
close(fd);
@@ -357,7 +357,7 @@ BSD_JoystickOpen(SDL_Joystick *joy, int device_index)
int fd;
int i;
fd = open(path, O_RDONLY);
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
return SDL_SetError("%s: %s", path, strerror(errno));
}
@@ -426,7 +426,7 @@ BSD_JoystickOpen(SDL_Joystick *joy, int device_index)
str[i] = UGETW(usd.usd_desc.bString[i]);
}
str[i] = '\0';
asprintf(&new_name, "%s @ %s", str, path);
SDL_asprintf(&new_name, "%s @ %s", str, path);
if (new_name != NULL) {
SDL_free(joydevnames[numjoysticks]);
joydevnames[numjoysticks] = new_name;
@@ -552,7 +552,7 @@ BSD_JoystickUpdate(SDL_Joystick *joy)
if (joy->hwdata->type == BSDJOY_JOY) {
while (read(joy->hwdata->fd, &gameport, sizeof gameport) == sizeof gameport) {
if (abs(x - gameport.x) > 8) {
if (SDL_abs(x - gameport.x) > 8) {
x = gameport.x;
if (x < xmin) {
xmin = x;
@@ -569,7 +569,7 @@ BSD_JoystickUpdate(SDL_Joystick *joy)
v *= 32768 / ((xmax - xmin + 1) / 2);
SDL_PrivateJoystickAxis(joy, 0, v);
}
if (abs(y - gameport.y) > 8) {
if (SDL_abs(y - gameport.y) > 8) {
y = gameport.y;
if (y < ymin) {
ymin = y;
@@ -777,10 +777,10 @@ BSD_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
return SDL_FALSE;
}
static SDL_bool
BSD_JoystickHasLED(SDL_Joystick *joystick)
static Uint32
BSD_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return SDL_FALSE;
return 0;
}
static int
@@ -814,7 +814,7 @@ SDL_JoystickDriver SDL_BSD_JoystickDriver =
BSD_JoystickOpen,
BSD_JoystickRumble,
BSD_JoystickRumbleTriggers,
BSD_JoystickHasLED,
BSD_JoystickGetCapabilities,
BSD_JoystickSetLED,
BSD_JoystickSendEffect,
BSD_JoystickSetSensorsEnabled,

View File

@@ -325,9 +325,15 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x045e, 0x02fd ), k_eControllerType_XBoxOneController, "Xbox One S Controller" }, // Microsoft X-Box One S pad (Bluetooth)
{ MAKE_CONTROLLER_ID( 0x045e, 0x02ff ), k_eControllerType_XBoxOneController, NULL }, // Microsoft X-Box One controller with XBOXGIP driver on Windows
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b00 ), k_eControllerType_XBoxOneController, "Xbox One Elite 2 Controller" }, // Microsoft X-Box One Elite Series 2 pad
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b02 ), k_eControllerType_XBoxOneController, "Xbox One Elite 2 Controller" }, // Microsoft X-Box One Elite Series 2 pad (Bluetooth)
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b05 ), k_eControllerType_XBoxOneController, "Xbox One Elite 2 Controller" }, // Microsoft X-Box One Elite Series 2 pad (Bluetooth)
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b0a ), k_eControllerType_XBoxOneController, "Xbox Adaptive Controller" }, // Microsoft X-Box Adaptive pad
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b0c ), k_eControllerType_XBoxOneController, "Xbox Adaptive Controller" }, // Microsoft X-Box Adaptive pad (Bluetooth)
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b12 ), k_eControllerType_XBoxOneController, "Xbox Series X Controller" }, // Microsoft X-Box Series X pad
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b13 ), k_eControllerType_XBoxOneController, "Xbox Series X Controller" }, // Microsoft X-Box Series X pad (Bluetooth)
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b13 ), k_eControllerType_XBoxOneController, "Xbox Series X Controller" }, // Microsoft X-Box Series X pad (BLE)
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b20 ), k_eControllerType_XBoxOneController, "Xbox One S Controller" }, // Microsoft X-Box One S pad (BLE)
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b21 ), k_eControllerType_XBoxOneController, "Xbox Adaptive Controller" }, // Microsoft X-Box Adaptive pad (BLE)
{ MAKE_CONTROLLER_ID( 0x045e, 0x0b22 ), k_eControllerType_XBoxOneController, "Xbox One Elite 2 Controller" }, // Microsoft X-Box One Elite Series 2 pad (BLE)
{ MAKE_CONTROLLER_ID( 0x0738, 0x4a01 ), k_eControllerType_XBoxOneController, NULL }, // Mad Catz FightStick TE 2
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0139 ), k_eControllerType_XBoxOneController, "PDP Xbox One Afterglow" }, // PDP Afterglow Wired Controller for Xbox One
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x013B ), k_eControllerType_XBoxOneController, "PDP Xbox One Face-Off Controller" }, // PDP Face-Off Gamepad for Xbox One
@@ -579,7 +585,7 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0181 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Faceoff Deluxe Wired Pro Controller for Nintendo Switch
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0184 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Faceoff Wired Deluxe+ Audio Controller
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0185 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Wired Fight Pad Pro for Nintendo Switch
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0186 ), k_eControllerType_SwitchProController, NULL }, // PDP Afterglow Wireless Switch Controller - working gyro. USB is for charging only. Many later "Wireless" line devices w/ gyro also use this vid/pid
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0186 ), k_eControllerType_SwitchProController, NULL }, // PDP Afterglow Wireless Switch Controller - working gyro. USB is for charging only. Many later "Wireless" line devices w/ gyro also use this vid/pid
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0187 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Rockcandy Wired Controller
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0188 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Afterglow Wired Deluxe+ Audio Controller
{ MAKE_CONTROLLER_ID( 0x0f0d, 0x00aa ), k_eControllerType_SwitchInputOnlyController, NULL }, // HORI Real Arcade Pro V Hayabusa in Switch Mode

View File

@@ -939,10 +939,21 @@ DARWIN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16
return SDL_Unsupported();
}
static SDL_bool
DARWIN_JoystickHasLED(SDL_Joystick *joystick)
static Uint32
DARWIN_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return SDL_FALSE;
recDevice *device = joystick->hwdata;
Uint32 result = 0;
if (!device) {
return 0;
}
if (device->ffservice) {
result |= SDL_JOYCAP_RUMBLE;
}
return result;
}
static int
@@ -1111,7 +1122,7 @@ SDL_JoystickDriver SDL_DARWIN_JoystickDriver =
DARWIN_JoystickOpen,
DARWIN_JoystickRumble,
DARWIN_JoystickRumbleTriggers,
DARWIN_JoystickHasLED,
DARWIN_JoystickGetCapabilities,
DARWIN_JoystickSetLED,
DARWIN_JoystickSendEffect,
DARWIN_JoystickSetSensorsEnabled,

View File

@@ -95,10 +95,10 @@ DUMMY_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16
return SDL_Unsupported();
}
static SDL_bool
DUMMY_JoystickHasLED(SDL_Joystick *joystick)
static Uint32
DUMMY_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return SDL_FALSE;
return 0;
}
static int
@@ -153,7 +153,7 @@ SDL_JoystickDriver SDL_DUMMY_JoystickDriver =
DUMMY_JoystickOpen,
DUMMY_JoystickRumble,
DUMMY_JoystickRumbleTriggers,
DUMMY_JoystickHasLED,
DUMMY_JoystickGetCapabilities,
DUMMY_JoystickSetLED,
DUMMY_JoystickSendEffect,
DUMMY_JoystickSetSensorsEnabled,

View File

@@ -414,10 +414,10 @@ EMSCRIPTEN_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
return SDL_FALSE;
}
static SDL_bool
EMSCRIPTEN_JoystickHasLED(SDL_Joystick *joystick)
static Uint32
EMSCRIPTEN_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return SDL_FALSE;
return 0;
}
static int
@@ -451,7 +451,7 @@ SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver =
EMSCRIPTEN_JoystickOpen,
EMSCRIPTEN_JoystickRumble,
EMSCRIPTEN_JoystickRumbleTriggers,
EMSCRIPTEN_JoystickHasLED,
EMSCRIPTEN_JoystickGetCapabilities,
EMSCRIPTEN_JoystickSetLED,
EMSCRIPTEN_JoystickSendEffect,
EMSCRIPTEN_JoystickSetSensorsEnabled,

View File

@@ -271,9 +271,9 @@ extern "C"
return SDL_FALSE;
}
static SDL_bool HAIKU_JoystickHasLED(SDL_Joystick *joystick)
static Uint32 HAIKU_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return SDL_FALSE;
return 0;
}
static int HAIKU_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
@@ -305,7 +305,7 @@ extern "C"
HAIKU_JoystickOpen,
HAIKU_JoystickRumble,
HAIKU_JoystickRumbleTriggers,
HAIKU_JoystickHasLED,
HAIKU_JoystickGetCapabilities,
HAIKU_JoystickSetLED,
HAIKU_JoystickSendEffect,
HAIKU_JoystickSetSensorsEnabled,

View File

@@ -32,7 +32,7 @@
#include "../SDL_sysjoystick.h"
#include "SDL_hidapijoystick_c.h"
#include "SDL_hidapi_rumble.h"
#include "../../hidapi/SDL_hidapi.h"
#include "../../hidapi/SDL_hidapi_c.h"
#ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE
@@ -129,7 +129,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_free(ctx);
SDL_SetError("Couldn't open %s", device->path);
@@ -154,7 +154,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
}
} else {
/* This is all that's needed to initialize the device. Really! */
if (hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
if (SDL_hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
SDL_SetError("Couldn't initialize WUP-028");
goto error;
}
@@ -163,7 +163,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
SDL_Delay(10);
/* Add all the applicable joysticks */
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
#ifdef DEBUG_GAMECUBE_PROTOCOL
HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size);
#endif
@@ -204,7 +204,7 @@ error:
SDL_LockMutex(device->dev_lock);
{
if (device->dev) {
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
}
if (device->context) {
@@ -389,7 +389,7 @@ HIDAPI_DriverGameCube_UpdateDevice(SDL_HIDAPI_Device *device)
int size;
/* Read input packet */
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
#ifdef DEBUG_GAMECUBE_PROTOCOL
//HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size);
#endif
@@ -464,10 +464,26 @@ HIDAPI_DriverGameCube_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joys
return SDL_Unsupported();
}
static SDL_bool
HIDAPI_DriverGameCube_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
static Uint32
HIDAPI_DriverGameCube_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
return SDL_FALSE;
SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)device->context;
Uint32 result = 0;
if (!ctx->pc_mode) {
Uint8 i;
for (i = 0; i < MAX_CONTROLLERS; i += 1) {
if (joystick->instance_id == ctx->joysticks[i]) {
if (!ctx->wireless[i] && ctx->rumbleAllowed[i]) {
result |= SDL_JOYCAP_RUMBLE;
break;
}
}
}
}
return result;
}
static int
@@ -510,7 +526,7 @@ HIDAPI_DriverGameCube_FreeDevice(SDL_HIDAPI_Device *device)
SDL_LockMutex(device->dev_lock);
{
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
SDL_free(device->context);
@@ -523,6 +539,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube =
{
SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE,
SDL_TRUE,
SDL_TRUE,
HIDAPI_DriverGameCube_IsSupportedDevice,
HIDAPI_DriverGameCube_GetDeviceName,
HIDAPI_DriverGameCube_InitDevice,
@@ -532,7 +549,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube =
HIDAPI_DriverGameCube_OpenJoystick,
HIDAPI_DriverGameCube_RumbleJoystick,
HIDAPI_DriverGameCube_RumbleJoystickTriggers,
HIDAPI_DriverGameCube_HasJoystickLED,
HIDAPI_DriverGameCube_GetJoystickCapabilities,
HIDAPI_DriverGameCube_SetJoystickLED,
HIDAPI_DriverGameCube_SendJoystickEffect,
HIDAPI_DriverGameCube_SetJoystickSensorsEnabled,

View File

@@ -87,7 +87,7 @@ HIDAPI_DriverLuna_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
return SDL_FALSE;
}
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_SetError("Couldn't open %s", device->path);
SDL_free(ctx);
@@ -132,10 +132,16 @@ HIDAPI_DriverLuna_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick
return SDL_Unsupported();
}
static SDL_bool
HIDAPI_DriverLuna_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
static Uint32
HIDAPI_DriverLuna_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
return SDL_FALSE;
Uint32 result = 0;
if (device->product_id == BLUETOOTH_PRODUCT_LUNA_CONTROLLER) {
result |= SDL_JOYCAP_RUMBLE;
}
return result;
}
static int
@@ -386,7 +392,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
#ifdef DEBUG_LUNA_PROTOCOL
HIDAPI_DumpPacket("Amazon Luna packet: size = %d", data, size);
#endif
@@ -413,7 +419,7 @@ HIDAPI_DriverLuna_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
SDL_LockMutex(device->dev_lock);
{
if (device->dev) {
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
}
@@ -432,6 +438,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna =
{
SDL_HINT_JOYSTICK_HIDAPI_LUNA,
SDL_TRUE,
SDL_TRUE,
HIDAPI_DriverLuna_IsSupportedDevice,
HIDAPI_DriverLuna_GetDeviceName,
HIDAPI_DriverLuna_InitDevice,
@@ -441,7 +448,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna =
HIDAPI_DriverLuna_OpenJoystick,
HIDAPI_DriverLuna_RumbleJoystick,
HIDAPI_DriverLuna_RumbleJoystickTriggers,
HIDAPI_DriverLuna_HasJoystickLED,
HIDAPI_DriverLuna_GetJoystickCapabilities,
HIDAPI_DriverLuna_SetJoystickLED,
HIDAPI_DriverLuna_SendJoystickEffect,
HIDAPI_DriverLuna_SetJoystickSensorsEnabled,

View File

@@ -163,11 +163,11 @@ HIDAPI_DriverPS4_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
return NULL;
}
static int ReadFeatureReport(hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
{
SDL_memset(report, 0, length);
report[0] = report_id;
return hid_get_feature_report(dev, report, length);
return SDL_hid_get_feature_report(dev, report, length);
}
static SDL_bool HIDAPI_DriverPS4_CanRumble(Uint16 vendor_id, Uint16 product_id)
@@ -415,7 +415,7 @@ HIDAPI_DriverPS4_TickleBluetooth(SDL_HIDAPI_Device *device)
/* This is just a dummy packet that should have no effect, since we don't set the CRC */
Uint8 data[78];
SDL_zero(data);
SDL_zeroa(data);
data[0] = k_EPS4ReportIdBluetoothEffects;
data[1] = 0xC0; /* Magic value HID + CRC */
@@ -479,7 +479,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
ctx->joystick = joystick;
ctx->last_packet = SDL_GetTicks();
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_free(ctx);
SDL_SetError("Couldn't open %s", device->path);
@@ -511,7 +511,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
ctx->is_bluetooth = SDL_TRUE;
/* Read a report to see if we're in enhanced mode */
size = hid_read_timeout(device->dev, data, sizeof(data), 16);
size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16);
#ifdef DEBUG_PS4_PROTOCOL
if (size > 0) {
HIDAPI_DumpPacket("PS4 first packet: size = %d", data, size);
@@ -598,10 +598,17 @@ HIDAPI_DriverPS4_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick
return SDL_Unsupported();
}
static SDL_bool
HIDAPI_DriverPS4_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
static Uint32
HIDAPI_DriverPS4_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
return SDL_TRUE;
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
Uint32 result = 0;
if (ctx->enhanced_mode && ctx->effects_supported) {
result |= SDL_JOYCAP_LED | SDL_JOYCAP_RUMBLE;
}
return result;
}
static int
@@ -632,7 +639,7 @@ HIDAPI_DriverPS4_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joy
HIDAPI_DriverPS4_SetEnhancedMode(device, joystick);
}
SDL_zero(data);
SDL_zeroa(data);
if (ctx->is_bluetooth) {
data[0] = k_EPS4ReportIdBluetoothEffects;
@@ -684,7 +691,7 @@ HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
}
static void
HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet)
HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet)
{
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
static const float TOUCHPAD_SCALEY = 1.0f / 920; /* This is noted as being 944 resolution, but 920 feels better */
@@ -846,7 +853,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
#ifdef DEBUG_PS4_PROTOCOL
HIDAPI_DumpPacket("PS4 packet: size = %d", data, size);
#endif
@@ -908,7 +915,7 @@ HIDAPI_DriverPS4_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
SDL_LockMutex(device->dev_lock);
{
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
SDL_free(device->context);
@@ -926,6 +933,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4 =
{
SDL_HINT_JOYSTICK_HIDAPI_PS4,
SDL_TRUE,
SDL_TRUE,
HIDAPI_DriverPS4_IsSupportedDevice,
HIDAPI_DriverPS4_GetDeviceName,
HIDAPI_DriverPS4_InitDevice,
@@ -935,7 +943,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4 =
HIDAPI_DriverPS4_OpenJoystick,
HIDAPI_DriverPS4_RumbleJoystick,
HIDAPI_DriverPS4_RumbleJoystickTriggers,
HIDAPI_DriverPS4_HasJoystickLED,
HIDAPI_DriverPS4_GetJoystickCapabilities,
HIDAPI_DriverPS4_SetJoystickLED,
HIDAPI_DriverPS4_SendJoystickEffect,
HIDAPI_DriverPS4_SetJoystickSensorsEnabled,

Some files were not shown because too many files have changed in this diff Show More