early-access version 1617

This commit is contained in:
pineappleEA
2021-04-20 21:40:33 +02:00
parent 242b6f6b49
commit f46563104f
510 changed files with 141726 additions and 62846 deletions

View File

@@ -19,11 +19,10 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_stdinc.h"
#include "SDL_assert.h"
#include "SDL_atomic.h"
#include "SDL_hints.h"
#include "SDL_log.h"
#include "SDL_main.h"
#include "SDL_timer.h"
@@ -44,6 +43,8 @@
#include "../../haptic/android/SDL_syshaptic_c.h"
#include <android/log.h>
#include <android/configuration.h>
#include <android/asset_manager_jni.h>
#include <sys/system_properties.h>
#include <pthread.h>
#include <sys/types.h>
@@ -125,6 +126,9 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeClipboardChanged)(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeLocaleChanged)(
JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)(
JNIEnv *env, jclass cls);
@@ -178,6 +182,7 @@ static JNINativeMethod SDLActivity_tab[] = {
{ "onNativeAccel", "(FFF)V", SDL_JAVA_INTERFACE(onNativeAccel) },
{ "onNativeClipboardChanged", "()V", SDL_JAVA_INTERFACE(onNativeClipboardChanged) },
{ "nativeLowMemory", "()V", SDL_JAVA_INTERFACE(nativeLowMemory) },
{ "onNativeLocaleChanged", "()V", SDL_JAVA_INTERFACE(onNativeLocaleChanged) },
{ "nativeSendQuit", "()V", SDL_JAVA_INTERFACE(nativeSendQuit) },
{ "nativeQuit", "()V", SDL_JAVA_INTERFACE(nativeQuit) },
{ "nativePause", "()V", SDL_JAVA_INTERFACE(nativePause) },
@@ -305,7 +310,7 @@ static jmethodID midIsScreenKeyboardShown;
static jmethodID midIsTablet;
static jmethodID midManualBackButton;
static jmethodID midMinimizeWindow;
static jmethodID midOpenAPKExpansionInputStream;
static jmethodID midOpenURL;
static jmethodID midRequestPermission;
static jmethodID midSendMessage;
static jmethodID midSetActivityTitle;
@@ -354,6 +359,12 @@ static SDL_bool bHasEnvironmentVariables;
static SDL_atomic_t bPermissionRequestPending;
static SDL_bool bPermissionRequestResult;
/* Android AssetManager */
static void Internal_Android_Create_AssetManager(void);
static void Internal_Android_Destroy_AssetManager(void);
static AAssetManager *asset_manager = NULL;
static jobject javaAssetManagerRef = 0;
/*******************************************************************************
Functions called by JNI
*******************************************************************************/
@@ -578,7 +589,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
midIsTablet = (*env)->GetStaticMethodID(env, mActivityClass, "isTablet", "()Z");
midManualBackButton = (*env)->GetStaticMethodID(env, mActivityClass, "manualBackButton", "()V");
midMinimizeWindow = (*env)->GetStaticMethodID(env, mActivityClass, "minimizeWindow","()V");
midOpenAPKExpansionInputStream = (*env)->GetStaticMethodID(env, mActivityClass, "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
midOpenURL = (*env)->GetStaticMethodID(env, mActivityClass, "openURL", "(Ljava/lang/String;)I");
midRequestPermission = (*env)->GetStaticMethodID(env, mActivityClass, "requestPermission", "(Ljava/lang/String;I)V");
midSendMessage = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z");
midSetActivityTitle = (*env)->GetStaticMethodID(env, mActivityClass, "setActivityTitle","(Ljava/lang/String;)Z");
@@ -608,7 +619,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
!midIsTablet ||
!midManualBackButton ||
!midMinimizeWindow ||
!midOpenAPKExpansionInputStream ||
!midOpenURL ||
!midRequestPermission ||
!midSendMessage ||
!midSetActivityTitle ||
@@ -1134,6 +1145,15 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
SDL_SendAppEvent(SDL_APP_LOWMEMORY);
}
/* Locale
* requires android:configChanges="layoutDirection|locale" in AndroidManifest.xml */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeLocaleChanged)(
JNIEnv *env, jclass cls)
{
SDL_SendAppEvent(SDL_LOCALECHANGED);
}
/* Send Quit event to "SDLThread" thread */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)(
JNIEnv *env, jclass cls)
@@ -1175,6 +1195,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
Android_ResumeSem = NULL;
}
Internal_Android_Destroy_AssetManager();
str = SDL_GetError();
if (str && str[0]) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "SDLActivity thread ends (error=%s)", str);
@@ -1797,245 +1819,90 @@ static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
return SDL_FALSE;
}
static int Internal_Android_JNI_FileOpen(SDL_RWops *ctx)
{
static void Internal_Android_Create_AssetManager() {
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
int result = 0;
JNIEnv *env = Android_JNI_GetEnv();
jmethodID mid;
jobject context;
jobject assetManager;
jobject inputStream;
jclass channels;
jobject readableByteChannel;
jstring fileNameJString;
jobject fd;
jclass fdCls;
jfieldID descriptor;
jobject javaAssetManager;
JNIEnv *env = Android_JNI_GetEnv();
if (!LocalReferenceHolder_Init(&refs, env)) {
goto failure;
LocalReferenceHolder_Cleanup(&refs);
return;
}
fileNameJString = (jstring)ctx->hidden.androidio.fileNameRef;
ctx->hidden.androidio.position = 0;
/* context = SDLActivity.getContext(); */
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
/* assetManager = context.getAssets(); */
/* javaAssetManager = context.getAssets(); */
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
"getAssets", "()Landroid/content/res/AssetManager;");
assetManager = (*env)->CallObjectMethod(env, context, mid);
javaAssetManager = (*env)->CallObjectMethod(env, context, mid);
/* First let's try opening the file to obtain an AssetFileDescriptor.
* This method reads the files directly from the APKs using standard *nix calls
*/
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;");
inputStream = (*env)->CallObjectMethod(env, assetManager, mid, fileNameJString);
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback;
}
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream), "getStartOffset", "()J");
ctx->hidden.androidio.offset = (long)(*env)->CallLongMethod(env, inputStream, mid);
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback;
}
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream), "getDeclaredLength", "()J");
ctx->hidden.androidio.size = (long)(*env)->CallLongMethod(env, inputStream, mid);
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback;
}
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream), "getFileDescriptor", "()Ljava/io/FileDescriptor;");
fd = (*env)->CallObjectMethod(env, inputStream, mid);
fdCls = (*env)->GetObjectClass(env, fd);
descriptor = (*env)->GetFieldID(env, fdCls, "descriptor", "I");
ctx->hidden.androidio.fd = (*env)->GetIntField(env, fd, descriptor);
ctx->hidden.androidio.assetFileDescriptorRef = (*env)->NewGlobalRef(env, inputStream);
/* Seek to the correct offset in the file. */
lseek(ctx->hidden.androidio.fd, (off_t)ctx->hidden.androidio.offset, SEEK_SET);
if (0) {
fallback:
/* Disabled log message because of spam on the Nexus 7 */
/* __android_log_print(ANDROID_LOG_DEBUG, "SDL", "Falling back to legacy InputStream method for opening file"); */
/* Try the old method using InputStream */
ctx->hidden.androidio.assetFileDescriptorRef = NULL;
/* inputStream = assetManager.open(<filename>); */
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, assetManager),
"open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
inputStream = (*env)->CallObjectMethod(env, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
/* Try fallback to APK expansion files */
inputStream = (*env)->CallStaticObjectMethod(env, mActivityClass, midOpenAPKExpansionInputStream, fileNameJString);
/* Exception is checked first because it always needs to be cleared.
* If no exception occurred then the last SDL error message is kept.
*/
if (Android_JNI_ExceptionOccurred(SDL_FALSE) || !inputStream) {
goto failure;
}
}
ctx->hidden.androidio.inputStreamRef = (*env)->NewGlobalRef(env, inputStream);
/* Despite all the visible documentation on [Asset]InputStream claiming
* that the .available() method is not guaranteed to return the entire file
* size, comments in <sdk>/samples/<ver>/ApiDemos/src/com/example/ ...
* android/apis/content/ReadAsset.java imply that Android's
* AssetInputStream.available() /will/ always return the total file size
*/
/* size = inputStream.available(); */
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream),
"available", "()I");
ctx->hidden.androidio.size = (long)(*env)->CallIntMethod(env, inputStream, mid);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure;
}
/* readableByteChannel = Channels.newChannel(inputStream); */
channels = (*env)->FindClass(env, "java/nio/channels/Channels");
mid = (*env)->GetStaticMethodID(env, channels,
"newChannel",
"(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
readableByteChannel = (*env)->CallStaticObjectMethod(
env, channels, mid, inputStream);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure;
}
ctx->hidden.androidio.readableByteChannelRef =
(*env)->NewGlobalRef(env, readableByteChannel);
/* Store .read id for reading purposes */
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, readableByteChannel),
"read", "(Ljava/nio/ByteBuffer;)I");
ctx->hidden.androidio.readMethod = mid;
}
if (0) {
failure:
result = -1;
(*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.fileNameRef);
if(ctx->hidden.androidio.inputStreamRef != NULL) {
(*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.inputStreamRef);
}
if(ctx->hidden.androidio.readableByteChannelRef != NULL) {
(*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.readableByteChannelRef);
}
if(ctx->hidden.androidio.assetFileDescriptorRef != NULL) {
(*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
}
/**
* Given a Dalvik AssetManager object, obtain the corresponding native AAssetManager
* object. Note that the caller is responsible for obtaining and holding a VM reference
* to the jobject to prevent its being garbage collected while the native object is
* in use.
*/
javaAssetManagerRef = (*env)->NewGlobalRef(env, javaAssetManager);
asset_manager = AAssetManager_fromJava(env, javaAssetManagerRef);
if (asset_manager == NULL) {
(*env)->DeleteGlobalRef(env, javaAssetManagerRef);
Android_JNI_ExceptionOccurred(SDL_TRUE);
}
LocalReferenceHolder_Cleanup(&refs);
return result;
}
static void Internal_Android_Destroy_AssetManager() {
JNIEnv *env = Android_JNI_GetEnv();
if (asset_manager) {
(*env)->DeleteGlobalRef(env, javaAssetManagerRef);
asset_manager = NULL;
}
}
int Android_JNI_FileOpen(SDL_RWops *ctx,
const char *fileName, const char *mode)
{
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
JNIEnv *env = Android_JNI_GetEnv();
int retval;
jstring fileNameJString;
AAsset *asset = NULL;
ctx->hidden.androidio.asset = NULL;
if (!LocalReferenceHolder_Init(&refs, env)) {
LocalReferenceHolder_Cleanup(&refs);
if (asset_manager == NULL) {
Internal_Android_Create_AssetManager();
}
if (asset_manager == NULL) {
return -1;
}
if (!ctx) {
LocalReferenceHolder_Cleanup(&refs);
asset = AAssetManager_open(asset_manager, fileName, AASSET_MODE_UNKNOWN);
if (asset == NULL) {
return -1;
}
fileNameJString = (*env)->NewStringUTF(env, fileName);
ctx->hidden.androidio.fileNameRef = (*env)->NewGlobalRef(env, fileNameJString);
ctx->hidden.androidio.inputStreamRef = NULL;
ctx->hidden.androidio.readableByteChannelRef = NULL;
ctx->hidden.androidio.readMethod = NULL;
ctx->hidden.androidio.assetFileDescriptorRef = NULL;
retval = Internal_Android_JNI_FileOpen(ctx);
LocalReferenceHolder_Cleanup(&refs);
return retval;
ctx->hidden.androidio.asset = (void*) asset;
return 0;
}
size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer,
size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
size_t size, size_t maxnum)
{
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
size_t result;
AAsset *asset = (AAsset*) ctx->hidden.androidio.asset;
result = AAsset_read(asset, buffer, size * maxnum);
if (ctx->hidden.androidio.assetFileDescriptorRef) {
size_t bytesMax = size * maxnum;
size_t result;
if (ctx->hidden.androidio.size != -1 /* UNKNOWN_LENGTH */ && ctx->hidden.androidio.position + bytesMax > ctx->hidden.androidio.size) {
bytesMax = ctx->hidden.androidio.size - ctx->hidden.androidio.position;
}
result = read(ctx->hidden.androidio.fd, buffer, bytesMax );
if (result > 0) {
ctx->hidden.androidio.position += result;
LocalReferenceHolder_Cleanup(&refs);
return result / size;
}
LocalReferenceHolder_Cleanup(&refs);
return 0;
if (result > 0) {
/* Number of chuncks */
return (result / size);
} else {
jlong bytesRemaining = (jlong) (size * maxnum);
jlong bytesMax = (jlong) (ctx->hidden.androidio.size - ctx->hidden.androidio.position);
int bytesRead = 0;
JNIEnv *env;
jobject readableByteChannel;
jmethodID readMethod;
jobject byteBuffer;
/* Don't read more bytes than those that remain in the file, otherwise we get an exception */
if (bytesRemaining > bytesMax) bytesRemaining = bytesMax;
env = Android_JNI_GetEnv();
if (!LocalReferenceHolder_Init(&refs, env)) {
LocalReferenceHolder_Cleanup(&refs);
return 0;
}
readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannelRef;
readMethod = (jmethodID)ctx->hidden.androidio.readMethod;
byteBuffer = (*env)->NewDirectByteBuffer(env, buffer, bytesRemaining);
while (bytesRemaining > 0) {
/* result = readableByteChannel.read(...); */
int result = (*env)->CallIntMethod(env, readableByteChannel, readMethod, byteBuffer);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
LocalReferenceHolder_Cleanup(&refs);
return 0;
}
if (result < 0) {
break;
}
bytesRemaining -= result;
bytesRead += result;
ctx->hidden.androidio.position += result;
}
LocalReferenceHolder_Cleanup(&refs);
return bytesRead / size;
/* Error or EOF */
return result;
}
}
@@ -2046,148 +1913,27 @@ size_t Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer,
return 0;
}
static int Internal_Android_JNI_FileClose(SDL_RWops *ctx, SDL_bool release)
Sint64 Android_JNI_FileSize(SDL_RWops *ctx)
{
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
int result = 0;
JNIEnv *env = Android_JNI_GetEnv();
if (!LocalReferenceHolder_Init(&refs, env)) {
LocalReferenceHolder_Cleanup(&refs);
return SDL_SetError("Failed to allocate enough JVM local references");
}
if (ctx) {
if (release) {
(*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.fileNameRef);
}
if (ctx->hidden.androidio.assetFileDescriptorRef) {
jobject inputStream = (jobject)ctx->hidden.androidio.assetFileDescriptorRef;
jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream),
"close", "()V");
(*env)->CallVoidMethod(env, inputStream, mid);
(*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
result = -1;
}
}
else {
jobject inputStream = (jobject)ctx->hidden.androidio.inputStreamRef;
/* inputStream.close(); */
jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream),
"close", "()V");
(*env)->CallVoidMethod(env, inputStream, mid);
(*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.inputStreamRef);
(*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.readableByteChannelRef);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
result = -1;
}
}
if (release) {
SDL_FreeRW(ctx);
}
}
LocalReferenceHolder_Cleanup(&refs);
off64_t result;
AAsset *asset = (AAsset*) ctx->hidden.androidio.asset;
result = AAsset_getLength64(asset);
return result;
}
Sint64 Android_JNI_FileSize(SDL_RWops *ctx)
Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
{
return ctx->hidden.androidio.size;
}
Sint64 Android_JNI_FileSeek(SDL_RWops *ctx, Sint64 offset, int whence)
{
if (ctx->hidden.androidio.assetFileDescriptorRef) {
off_t ret;
switch (whence) {
case RW_SEEK_SET:
if (ctx->hidden.androidio.size != -1 /* UNKNOWN_LENGTH */ && offset > ctx->hidden.androidio.size) offset = ctx->hidden.androidio.size;
offset += ctx->hidden.androidio.offset;
break;
case RW_SEEK_CUR:
offset += ctx->hidden.androidio.position;
if (ctx->hidden.androidio.size != -1 /* UNKNOWN_LENGTH */ && offset > ctx->hidden.androidio.size) offset = ctx->hidden.androidio.size;
offset += ctx->hidden.androidio.offset;
break;
case RW_SEEK_END:
offset = ctx->hidden.androidio.offset + ctx->hidden.androidio.size + offset;
break;
default:
return SDL_SetError("Unknown value for 'whence'");
}
ret = lseek(ctx->hidden.androidio.fd, (off_t)offset, SEEK_SET);
if (ret == -1) return -1;
ctx->hidden.androidio.position = ret - ctx->hidden.androidio.offset;
} else {
Sint64 newPosition;
Sint64 movement;
switch (whence) {
case RW_SEEK_SET:
newPosition = offset;
break;
case RW_SEEK_CUR:
newPosition = ctx->hidden.androidio.position + offset;
break;
case RW_SEEK_END:
newPosition = ctx->hidden.androidio.size + offset;
break;
default:
return SDL_SetError("Unknown value for 'whence'");
}
/* Validate the new position */
if (newPosition < 0) {
return SDL_Error(SDL_EFSEEK);
}
if (newPosition > ctx->hidden.androidio.size) {
newPosition = ctx->hidden.androidio.size;
}
movement = newPosition - ctx->hidden.androidio.position;
if (movement > 0) {
unsigned char buffer[4096];
/* The easy case where we're seeking forwards */
while (movement > 0) {
Sint64 amount = sizeof (buffer);
size_t result;
if (amount > movement) {
amount = movement;
}
result = Android_JNI_FileRead(ctx, buffer, 1, (size_t)amount);
if (result <= 0) {
/* Failed to read/skip the required amount, so fail */
return -1;
}
movement -= result;
}
} else if (movement < 0) {
/* We can't seek backwards so we have to reopen the file and seek */
/* forwards which obviously isn't very efficient */
Internal_Android_JNI_FileClose(ctx, SDL_FALSE);
Internal_Android_JNI_FileOpen(ctx);
Android_JNI_FileSeek(ctx, newPosition, RW_SEEK_SET);
}
}
return ctx->hidden.androidio.position;
off64_t result;
AAsset *asset = (AAsset*) ctx->hidden.androidio.asset;
result = AAsset_seek64(asset, offset, whence);
return result;
}
int Android_JNI_FileClose(SDL_RWops *ctx)
{
return Internal_Android_JNI_FileClose(ctx, SDL_TRUE);
AAsset *asset = (AAsset*) ctx->hidden.androidio.asset;
AAsset_close(asset);
return 0;
}
int Android_JNI_SetClipboardText(const char *text)
@@ -2717,6 +2463,11 @@ const char * SDL_AndroidGetExternalStoragePath(void)
return s_AndroidExternalFilesPath;
}
SDL_bool SDL_AndroidRequestPermission(const char *permission)
{
return Android_JNI_RequestPermission(permission);
}
void Android_JNI_GetManifestEnvironmentVariables(void)
{
if (!mActivityClass || !midGetManifestEnvironmentVariables) {
@@ -2796,6 +2547,74 @@ SDL_bool Android_JNI_RequestPermission(const char *permission)
return bPermissionRequestResult;
}
int Android_JNI_GetLocale(char *buf, size_t buflen)
{
AConfiguration *cfg;
SDL_assert(buflen > 6);
/* Need to re-create the asset manager if locale has changed (SDL_LOCALECHANGED) */
Internal_Android_Destroy_AssetManager();
if (asset_manager == NULL) {
Internal_Android_Create_AssetManager();
}
if (asset_manager == NULL) {
return -1;
}
cfg = AConfiguration_new();
if (cfg == NULL) {
return -1;
}
{
char language[2] = {};
char country[2] = {};
size_t id = 0;
AConfiguration_fromAssetManager(cfg, asset_manager);
AConfiguration_getLanguage(cfg, language);
AConfiguration_getCountry(cfg, country);
/* copy language (not null terminated) */
if (language[0]) {
buf[id++] = language[0];
if (language[1]) {
buf[id++] = language[1];
}
}
buf[id++] = '_';
/* copy country (not null terminated) */
if (country[0]) {
buf[id++] = country[0];
if (country[1]) {
buf[id++] = country[1];
}
}
buf[id++] = '\0';
SDL_assert(id <= buflen);
}
AConfiguration_delete(cfg);
return 0;
}
int
Android_JNI_OpenURL(const char *url)
{
JNIEnv *env = Android_JNI_GetEnv();
jstring jurl = (*env)->NewStringUTF(env, url);
const int ret = (*env)->CallStaticIntMethod(env, mActivityClass, midOpenURL, jurl);
(*env)->DeleteLocalRef(env, jurl);
return ret;
}
#endif /* __ANDROID__ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -104,6 +104,9 @@ void Android_JNI_InitTouch(void);
JNIEnv *Android_JNI_GetEnv(void);
int Android_JNI_SetupThread(void);
/* Locale */
int Android_JNI_GetLocale(char *buf, size_t buflen);
/* Generic messages */
int Android_JNI_SendMessage(int command, int param);
@@ -126,6 +129,8 @@ SDL_bool Android_JNI_SetRelativeMouseEnabled(SDL_bool enabled);
/* Request permission */
SDL_bool Android_JNI_RequestPermission(const char *permission);
int Android_JNI_OpenURL(const char *url);
int SDL_GetAndroidSDKVersion(void);
SDL_bool SDL_IsAndroidTablet(void);

View File

@@ -0,0 +1,165 @@
#include <sys/kbio.h>
/*
* Automatically generated from /usr/share/vt/keymaps/us.acc.kbd.
* DO NOT EDIT!
*/
static keymap_t keymap_default_us_acc = { 0x6d, {
/* alt
* scan cntrl alt alt cntrl
* code base shift cntrl shift alt shift cntrl shift spcl flgs
* ---------------------------------------------------------------------------
*/
/*00*/{{ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, }, 0xFF,0x00 },
/*01*/{{ 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, DBG, DBG, }, 0x03,0x00 },
/*02*/{{ '1', '!', NOP, NOP, '1', '!', NOP, NOP, }, 0x33,0x00 },
/*03*/{{ '2', '@', 0x00, 0x00, '2', '@', 0x00, 0x00, }, 0x00,0x00 },
/*04*/{{ '3', '#', NOP, NOP, '3', '#', NOP, NOP, }, 0x33,0x00 },
/*05*/{{ '4', '$', NOP, NOP, '4', '$', NOP, NOP, }, 0x33,0x00 },
/*06*/{{ '5', '%', NOP, NOP, '5', '%', NOP, NOP, }, 0x33,0x00 },
/*07*/{{ '6', '^', 0x1E, 0x1E, '6', DCIR, 0x1E, 0x1E, }, 0x04,0x00 },
/*08*/{{ '7', '&', NOP, NOP, '7', '&', NOP, NOP, }, 0x33,0x00 },
/*09*/{{ '8', '*', NOP, NOP, '8', DRIN, NOP, NOP, }, 0x37,0x00 },
/*0a*/{{ '9', '(', NOP, NOP, '9', '(', NOP, NOP, }, 0x33,0x00 },
/*0b*/{{ '0', ')', NOP, NOP, '0', ')', NOP, NOP, }, 0x33,0x00 },
/*0c*/{{ '-', '_', 0x1F, 0x1F, '-', '_', 0x1F, 0x1F, }, 0x00,0x00 },
/*0d*/{{ '=', '+', NOP, NOP, '=', '+', NOP, NOP, }, 0x33,0x00 },
/*0e*/{{ 0x08, 0x08, 0x7F, 0x7F, 0x08, 0x08, 0x7F, 0x7F, }, 0x00,0x00 },
/*0f*/{{ 0x09, BTAB, NEXT, NEXT, 0x09, BTAB, NOP, NOP, }, 0x77,0x00 },
/*10*/{{ 'q', 'Q', 0x11, 0x11, 'q', 'Q', 0x11, 0x11, }, 0x00,0x01 },
/*11*/{{ 'w', 'W', 0x17, 0x17, 'w', 'W', 0x17, 0x17, }, 0x00,0x01 },
/*12*/{{ 'e', 'E', 0x05, 0x05, 'e', 'E', 0x05, 0x05, }, 0x00,0x01 },
/*13*/{{ 'r', 'R', 0x12, 0x12, 'r', 'R', 0x12, 0x12, }, 0x00,0x01 },
/*14*/{{ 't', 'T', 0x14, 0x14, 't', 'T', 0x14, 0x14, }, 0x00,0x01 },
/*15*/{{ 'y', 'Y', 0x19, 0x19, 'y', 'Y', 0x19, 0x19, }, 0x00,0x01 },
/*16*/{{ 'u', 'U', 0x15, 0x15, 'u', 'U', 0x15, 0x15, }, 0x00,0x01 },
/*17*/{{ 'i', 'I', 0x09, 0x09, 'i', 'I', 0x09, 0x09, }, 0x00,0x01 },
/*18*/{{ 'o', 'O', 0x0F, 0x0F, 'o', 'O', 0x0F, 0x0F, }, 0x00,0x01 },
/*19*/{{ 'p', 'P', 0x10, 0x10, 'p', 'P', 0x10, 0x10, }, 0x00,0x01 },
/*1a*/{{ '[', '{', 0x1B, 0x1B, '[', '{', 0x1B, 0x1B, }, 0x00,0x00 },
/*1b*/{{ ']', '}', 0x1D, 0x1D, ']', '}', 0x1D, 0x1D, }, 0x00,0x00 },
/*1c*/{{ 0x0D, 0x0D, 0x0A, 0x0A, 0x0D, 0x0D, 0x0A, 0x0A, }, 0x00,0x00 },
/*1d*/{{ LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, }, 0xFF,0x00 },
/*1e*/{{ 'a', 'A', 0x01, 0x01, 'a', 'A', 0x01, 0x01, }, 0x00,0x01 },
/*1f*/{{ 's', 'S', 0x13, 0x13, 's', 'S', 0x13, 0x13, }, 0x00,0x01 },
/*20*/{{ 'd', 'D', 0x04, 0x04, 'd', 'D', 0x04, 0x04, }, 0x00,0x01 },
/*21*/{{ 'f', 'F', 0x06, 0x06, 'f', 'F', 0x06, 0x06, }, 0x00,0x01 },
/*22*/{{ 'g', 'G', 0x07, 0x07, 'g', 'G', 0x07, 0x07, }, 0x00,0x01 },
/*23*/{{ 'h', 'H', 0x08, 0x08, 'h', 'H', 0x08, 0x08, }, 0x00,0x01 },
/*24*/{{ 'j', 'J', 0x0A, 0x0A, 'j', 'J', 0x0A, 0x0A, }, 0x00,0x01 },
/*25*/{{ 'k', 'K', 0x0B, 0x0B, 'k', 'K', 0x0B, 0x0B, }, 0x00,0x01 },
/*26*/{{ 'l', 'L', 0x0C, 0x0C, 'l', 'L', 0x0C, 0x0C, }, 0x00,0x01 },
/*27*/{{ ';', ':', NOP, NOP, ';', ':', NOP, NOP, }, 0x33,0x00 },
/*28*/{{ '\'', '"', NOP, NOP, DACU, DUML, NOP, NOP, }, 0x3F,0x00 },
/*29*/{{ '`', '~', NOP, NOP, DGRA, DTIL, NOP, NOP, }, 0x3F,0x00 },
/*2a*/{{ LSH, LSH, LSH, LSH, LSH, LSH, LSH, LSH, }, 0xFF,0x00 },
/*2b*/{{ '\\', '|', 0x1C, 0x1C, '\\', '|', 0x1C, 0x1C, }, 0x00,0x00 },
/*2c*/{{ 'z', 'Z', 0x1A, 0x1A, 'z', 'Z', 0x1A, 0x1A, }, 0x00,0x01 },
/*2d*/{{ 'x', 'X', 0x18, 0x18, 'x', 'X', 0x18, 0x18, }, 0x00,0x01 },
/*2e*/{{ 'c', 'C', 0x03, 0x03, 'c', 'C', 0x03, 0x03, }, 0x00,0x01 },
/*2f*/{{ 'v', 'V', 0x16, 0x16, 'v', 'V', 0x16, 0x16, }, 0x00,0x01 },
/*30*/{{ 'b', 'B', 0x02, 0x02, 'b', 'B', 0x02, 0x02, }, 0x00,0x01 },
/*31*/{{ 'n', 'N', 0x0E, 0x0E, 'n', 'N', 0x0E, 0x0E, }, 0x00,0x01 },
/*32*/{{ 'm', 'M', 0x0D, 0x0D, 'm', 'M', 0x0D, 0x0D, }, 0x00,0x01 },
/*33*/{{ ',', '<', NOP, NOP, DCED, '<', NOP, NOP, }, 0x3B,0x00 },
/*34*/{{ '.', '>', NOP, NOP, '.', '>', NOP, NOP, }, 0x33,0x00 },
/*35*/{{ '/', '?', NOP, NOP, '/', '?', NOP, NOP, }, 0x33,0x00 },
/*36*/{{ RSH, RSH, RSH, RSH, RSH, RSH, RSH, RSH, }, 0xFF,0x00 },
/*37*/{{ '*', '*', '*', '*', '*', '*', '*', '*', }, 0x00,0x00 },
/*38*/{{ LALT, LALT, LALT, LALT, LALT, LALT, LALT, LALT, }, 0xFF,0x00 },
/*39*/{{ ' ', ' ', 0x00, 0x00, ' ', ' ', SUSP, SUSP, }, 0x03,0x00 },
/*3a*/{{ CLK, CLK, CLK, CLK, CLK, CLK, CLK, CLK, }, 0xFF,0x00 },
/*3b*/{{ F( 1), F(13), F(25), F(37), S( 1), S(11), S( 1), S(11),}, 0xFF,0x00 },
/*3c*/{{ F( 2), F(14), F(26), F(38), S( 2), S(12), S( 2), S(12),}, 0xFF,0x00 },
/*3d*/{{ F( 3), F(15), F(27), F(39), S( 3), S(13), S( 3), S(13),}, 0xFF,0x00 },
/*3e*/{{ F( 4), F(16), F(28), F(40), S( 4), S(14), S( 4), S(14),}, 0xFF,0x00 },
/*3f*/{{ F( 5), F(17), F(29), F(41), S( 5), S(15), S( 5), S(15),}, 0xFF,0x00 },
/*40*/{{ F( 6), F(18), F(30), F(42), S( 6), S(16), S( 6), S(16),}, 0xFF,0x00 },
/*41*/{{ F( 7), F(19), F(31), F(43), S( 7), S( 7), S( 7), S( 7),}, 0xFF,0x00 },
/*42*/{{ F( 8), F(20), F(32), F(44), S( 8), S( 8), S( 8), S( 8),}, 0xFF,0x00 },
/*43*/{{ F( 9), F(21), F(33), F(45), S( 9), S( 9), S( 9), S( 9),}, 0xFF,0x00 },
/*44*/{{ F(10), F(22), F(34), F(46), S(10), S(10), S(10), S(10),}, 0xFF,0x00 },
/*45*/{{ NLK, NLK, NLK, NLK, NLK, NLK, NLK, NLK, }, 0xFF,0x00 },
/*46*/{{ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, }, 0xFF,0x00 },
/*47*/{{ F(49), '7', '7', '7', '7', '7', '7', '7', }, 0x80,0x02 },
/*48*/{{ F(50), '8', '8', '8', '8', '8', '8', '8', }, 0x80,0x02 },
/*49*/{{ F(51), '9', '9', '9', '9', '9', '9', '9', }, 0x80,0x02 },
/*4a*/{{ F(52), '-', '-', '-', '-', '-', '-', '-', }, 0x80,0x02 },
/*4b*/{{ F(53), '4', '4', '4', '4', '4', '4', '4', }, 0x80,0x02 },
/*4c*/{{ F(54), '5', '5', '5', '5', '5', '5', '5', }, 0x80,0x02 },
/*4d*/{{ F(55), '6', '6', '6', '6', '6', '6', '6', }, 0x80,0x02 },
/*4e*/{{ F(56), '+', '+', '+', '+', '+', '+', '+', }, 0x80,0x02 },
/*4f*/{{ F(57), '1', '1', '1', '1', '1', '1', '1', }, 0x80,0x02 },
/*50*/{{ F(58), '2', '2', '2', '2', '2', '2', '2', }, 0x80,0x02 },
/*51*/{{ F(59), '3', '3', '3', '3', '3', '3', '3', }, 0x80,0x02 },
/*52*/{{ F(60), '0', '0', '0', '0', '0', '0', '0', }, 0x80,0x02 },
/*53*/{{ 0x7F, '.', '.', '.', '.', '.', RBT, RBT, }, 0x03,0x02 },
/*54*/{{ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, }, 0xFF,0x00 },
/*55*/{{ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, }, 0xFF,0x00 },
/*56*/{{ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, }, 0xFF,0x00 },
/*57*/{{ F(11), F(23), F(35), F(47), S(11), S(11), S(11), S(11),}, 0xFF,0x00 },
/*58*/{{ F(12), F(24), F(36), F(48), S(12), S(12), S(12), S(12),}, 0xFF,0x00 },
/*59*/{{ 0x0D, 0x0D, 0x0A, 0x0A, 0x0D, 0x0D, 0x0A, 0x0A, }, 0x00,0x00 },
/*5a*/{{ RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, }, 0xFF,0x00 },
/*5b*/{{ '/', '/', '/', '/', '/', '/', '/', '/', }, 0x00,0x02 },
/*5c*/{{ NEXT, NEXT, NOP, NOP, DBG, DBG, DBG, DBG, }, 0xFF,0x00 },
/*5d*/{{ RALT, RALT, RALT, RALT, RALT, RALT, RALT, RALT, }, 0xFF,0x00 },
/*5e*/{{ F(49), F(49), F(49), F(49), F(49), F(49), F(49), F(49),}, 0xFF,0x00 },
/*5f*/{{ F(50), F(50), F(50), F(50), F(50), F(50), F(50), F(50),}, 0xFF,0x00 },
/*60*/{{ F(51), F(51), F(51), F(51), F(51), F(51), F(51), F(51),}, 0xFF,0x00 },
/*61*/{{ F(53), F(53), F(53), F(53), F(53), F(53), F(53), F(53),}, 0xFF,0x00 },
/*62*/{{ F(55), F(55), F(55), F(55), F(55), F(55), F(55), F(55),}, 0xFF,0x00 },
/*63*/{{ F(57), F(57), F(57), F(57), F(57), F(57), F(57), F(57),}, 0xFF,0x00 },
/*64*/{{ F(58), F(58), F(58), F(58), F(58), F(58), F(58), F(58),}, 0xFF,0x00 },
/*65*/{{ F(59), F(59), F(59), F(59), F(59), F(59), F(59), F(59),}, 0xFF,0x00 },
/*66*/{{ F(60), F(60), F(60), F(60), F(60), F(60), F(60), F(60),}, 0xFF,0x00 },
/*67*/{{ F(61), F(61), F(61), F(61), F(61), F(61), RBT, F(61),}, 0xFF,0x00 },
/*68*/{{ SPSC, SPSC, SUSP, SUSP, NOP, NOP, SUSP, SUSP, }, 0xFF,0x00 },
/*69*/{{ F(62), F(62), F(62), F(62), F(62), F(62), F(62), F(62),}, 0xFF,0x00 },
/*6a*/{{ F(63), F(63), F(63), F(63), F(63), F(63), F(63), F(63),}, 0xFF,0x00 },
/*6b*/{{ F(64), F(64), F(64), F(64), F(64), F(64), F(64), F(64),}, 0xFF,0x00 },
/*6c*/{{ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, }, 0xFF,0x00 },
} };
static accentmap_t accentmap_default_us_acc = { 11, {
/* dgra=0 */
{ '`', { { 'a',0xe0 }, { 'A',0xc0 }, { 'e',0xe8 }, { 'E',0xc8 },
{ 'i',0xec }, { 'I',0xcc }, { 'o',0xf2 }, { 'O',0xd2 },
{ 'u',0xf9 }, { 'U',0xd9 }, }, },
/* dacu=1 */
{ 0xb4, { { 'a',0xe1 }, { 'A',0xc1 }, { 'e',0xe9 }, { 'E',0xc9 },
{ 'i',0xed }, { 'I',0xcd }, { 'o',0xf3 }, { 'O',0xd3 },
{ 'u',0xfa }, { 'U',0xda }, { 'y',0xfd }, { 'Y',0xdd }, }, },
/* dcir=2 */
{ '^', { { 'a',0xe2 }, { 'A',0xc2 }, { 'e',0xea }, { 'E',0xca },
{ 'i',0xee }, { 'I',0xce }, { 'o',0xf4 }, { 'O',0xd4 },
{ 'u',0xfb }, { 'U',0xdb }, }, },
/* dtil=3 */
{ '~', { { 'a',0xe3 }, { 'A',0xc3 }, { 'n',0xf1 }, { 'N',0xd1 },
{ 'o',0xf5 }, { 'O',0xd5 }, }, },
/* dmac=4 */
{ 0x00 },
/* dbre=5 */
{ 0x00 },
/* ddot=6 */
{ 0x00 },
/* duml=7 */
{ 0xa8, { { 'a',0xe4 }, { 'A',0xc4 }, { 'e',0xeb }, { 'E',0xcb },
{ 'i',0xef }, { 'I',0xcf }, { 'o',0xf6 }, { 'O',0xd6 },
{ 'u',0xfc }, { 'U',0xdc }, { 'y',0xff }, }, },
/* dsla=8 */
{ 0x00 },
/* drin=9 */
{ 0xb0, { { 'a',0xe5 }, { 'A',0xc5 }, }, },
/* dced=10 */
{ 0xb8, { { 'c',0xe7 }, { 'C',0xc7 }, }, },
/* dapo=11 */
{ 0x00 },
/* ddac=12 */
{ 0x00 },
/* dogo=13 */
{ 0x00 },
/* dcar=14 */
{ 0x00 },
} };

View File

@@ -0,0 +1,572 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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"
#include "../linux/SDL_evdev_kbd.h"
#include "SDL_hints.h"
#ifdef SDL_INPUT_FBSDKBIO
/* This logic is adapted from drivers/tty/vt/keyboard.c in the Linux kernel source, slightly modified to work with FreeBSD */
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/kbio.h>
#include <sys/consio.h>
#include <signal.h>
#include "../../events/SDL_events_c.h"
#include "SDL_evdev_kbd_default_keyaccmap.h"
typedef void (fn_handler_fn)(SDL_EVDEV_keyboard_state *kbd);
/*
* Keyboard State
*/
struct SDL_EVDEV_keyboard_state
{
int console_fd;
int keyboard_fd;
unsigned long old_kbd_mode;
unsigned short **key_maps;
keymap_t* key_map;
keyboard_info_t* kbInfo;
unsigned char shift_down[4]; /* shift state counters.. */
SDL_bool dead_key_next;
int npadch; /* -1 or number assembled on pad */
accentmap_t *accents;
unsigned int diacr;
SDL_bool rep; /* flag telling character repeat */
unsigned char lockstate;
unsigned char ledflagstate;
char shift_state;
char text[128];
unsigned int text_len;
};
static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd)
{
return (ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0);
}
static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL;
static int kbd_cleanup_sigactions_installed = 0;
static int kbd_cleanup_atexit_installed = 0;
static struct sigaction old_sigaction[NSIG];
static int fatal_signals[] =
{
/* Handlers for SIGTERM and SIGINT are installed in SDL_QuitInit. */
SIGHUP, SIGQUIT, SIGILL, SIGABRT,
SIGFPE, SIGSEGV, SIGPIPE, SIGBUS,
SIGSYS
};
static void kbd_cleanup(void)
{
SDL_EVDEV_keyboard_state* kbd = kbd_cleanup_state;
if (kbd == NULL) {
return;
}
kbd_cleanup_state = NULL;
ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
if (kbd->keyboard_fd != kbd->console_fd) close(kbd->keyboard_fd);
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
}
void
SDL_EVDEV_kbd_reraise_signal(int sig)
{
raise(sig);
}
siginfo_t* SDL_EVDEV_kdb_cleanup_siginfo = NULL;
void* SDL_EVDEV_kdb_cleanup_ucontext = NULL;
static void kbd_cleanup_signal_action(int signum, siginfo_t* info, void* ucontext)
{
struct sigaction* old_action_p = &(old_sigaction[signum]);
sigset_t sigset;
/* Restore original signal handler before going any further. */
sigaction(signum, old_action_p, NULL);
/* Unmask current signal. */
sigemptyset(&sigset);
sigaddset(&sigset, signum);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
/* Save original signal info and context for archeologists. */
SDL_EVDEV_kdb_cleanup_siginfo = info;
SDL_EVDEV_kdb_cleanup_ucontext = ucontext;
/* Restore keyboard. */
kbd_cleanup();
/* Reraise signal. */
SDL_EVDEV_kbd_reraise_signal(signum);
}
static void kbd_unregister_emerg_cleanup()
{
int tabidx, signum;
kbd_cleanup_state = NULL;
if (!kbd_cleanup_sigactions_installed) {
return;
}
kbd_cleanup_sigactions_installed = 0;
for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) {
struct sigaction* old_action_p;
struct sigaction cur_action;
signum = fatal_signals[tabidx];
old_action_p = &(old_sigaction[signum]);
/* Examine current signal action */
if (sigaction(signum, NULL, &cur_action))
continue;
/* Check if action installed and not modifed */
if (!(cur_action.sa_flags & SA_SIGINFO)
|| cur_action.sa_sigaction != &kbd_cleanup_signal_action)
continue;
/* Restore original action */
sigaction(signum, old_action_p, NULL);
}
}
static void kbd_cleanup_atexit(void)
{
/* Restore keyboard. */
kbd_cleanup();
/* Try to restore signal handlers in case shared library is being unloaded */
kbd_unregister_emerg_cleanup();
}
static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
{
int tabidx, signum;
if (kbd_cleanup_state != NULL) {
return;
}
kbd_cleanup_state = kbd;
if (!kbd_cleanup_atexit_installed) {
/* Since glibc 2.2.3, atexit() (and on_exit(3)) can be used within a shared library to establish
* functions that are called when the shared library is unloaded.
* -- man atexit(3)
*/
atexit(kbd_cleanup_atexit);
kbd_cleanup_atexit_installed = 1;
}
if (kbd_cleanup_sigactions_installed) {
return;
}
kbd_cleanup_sigactions_installed = 1;
for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) {
struct sigaction* old_action_p;
struct sigaction new_action;
signum = fatal_signals[tabidx];
old_action_p = &(old_sigaction[signum]);
if (sigaction(signum, NULL, old_action_p))
continue;
/* Skip SIGHUP and SIGPIPE if handler is already installed
* - assume the handler will do the cleanup
*/
if ((signum == SIGHUP || signum == SIGPIPE)
&& (old_action_p->sa_handler != SIG_DFL
|| (void (*)(int))old_action_p->sa_sigaction != SIG_DFL))
continue;
new_action = *old_action_p;
new_action.sa_flags |= SA_SIGINFO;
new_action.sa_sigaction = &kbd_cleanup_signal_action;
sigaction(signum, &new_action, NULL);
}
}
SDL_EVDEV_keyboard_state *
SDL_EVDEV_kbd_init(void)
{
SDL_EVDEV_keyboard_state *kbd;
char flag_state;
char* devicePath;
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
if (!kbd) {
return NULL;
}
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->shift_state = 0;
kbd->accents = SDL_calloc(sizeof(accentmap_t), 1);
kbd->key_map = SDL_calloc(sizeof(keymap_t), 1);
kbd->kbInfo = SDL_calloc(sizeof(keyboard_info_t), 1);
ioctl(kbd->console_fd, KDGKBINFO, kbd->kbInfo);
if (ioctl(kbd->console_fd, KDGKBSTATE, &flag_state) == 0) {
kbd->ledflagstate = flag_state;
}
if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0)
{
SDL_free(kbd->accents);
kbd->accents = &accentmap_default_us_acc;
}
if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) {
/* Set the keyboard in XLATE mode and load the keymaps */
ioctl(kbd->console_fd, KDSKBMODE, (unsigned long)(K_XLATE));
if(!SDL_EVDEV_kbd_load_keymaps(kbd))
{
SDL_free(kbd->key_map);
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) {
/* 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);
if (kbd->keyboard_fd == -1)
{
// Give keyboard back.
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
kbd->keyboard_fd = kbd->console_fd;
}
/* Make sure to restore keyboard if application fails to call
* SDL_Quit before exit or fatal signal is raised.
*/
if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, SDL_FALSE)) {
kbd_register_emerg_cleanup(kbd);
}
free(devicePath);
}
else kbd->keyboard_fd = kbd->console_fd;
}
return kbd;
}
void
SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
{
if (!kbd) {
return;
}
kbd_unregister_emerg_cleanup();
if (kbd->keyboard_fd >= 0) {
/* Restore the original keyboard mode */
ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
close(kbd->keyboard_fd);
if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0)
{
// Give back keyboard.
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
}
kbd->console_fd = kbd->keyboard_fd = -1;
}
SDL_free(kbd);
}
/*
* Helper Functions.
*/
static void put_queue(SDL_EVDEV_keyboard_state *kbd, uint c)
{
/* c is already part of a UTF-8 sequence and safe to add as a character */
if (kbd->text_len < (sizeof(kbd->text)-1)) {
kbd->text[kbd->text_len++] = (char)c;
}
}
static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
{
if (c < 0x80)
/* 0******* */
put_queue(kbd, c);
else if (c < 0x800) {
/* 110***** 10****** */
put_queue(kbd, 0xc0 | (c >> 6));
put_queue(kbd, 0x80 | (c & 0x3f));
} else if (c < 0x10000) {
if (c >= 0xD800 && c < 0xE000)
return;
if (c == 0xFFFF)
return;
/* 1110**** 10****** 10****** */
put_queue(kbd, 0xe0 | (c >> 12));
put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
put_queue(kbd, 0x80 | (c & 0x3f));
} else if (c < 0x110000) {
/* 11110*** 10****** 10****** 10****** */
put_queue(kbd, 0xf0 | (c >> 18));
put_queue(kbd, 0x80 | ((c >> 12) & 0x3f));
put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
put_queue(kbd, 0x80 | (c & 0x3f));
}
}
/*
* We have a combining character DIACR here, followed by the character CH.
* If the combination occurs in the table, return the corresponding value.
* Otherwise, if CH is a space or equals DIACR, return DIACR.
* Otherwise, conclude that DIACR was not combining after all,
* queue it and return CH.
*/
static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
{
unsigned int d = kbd->diacr;
unsigned int i, j;
kbd->diacr = 0;
for (i = 0; i < kbd->accents->n_accs; i++) {
if (kbd->accents->acc[i].accchar == d)
{
for (j = 0; j < NUM_ACCENTCHARS; ++j) {
if (kbd->accents->acc[i].map[j][0] == 0) /* end of table */
break;
if (kbd->accents->acc[i].map[j][0] == ch)
return kbd->accents->acc[i].map[j][1];
}
}
}
if (ch == ' ' || ch == d) {
put_utf8(kbd, d);
return 0;
}
put_utf8(kbd, d);
return ch;
}
static int vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
{
return (kbd->ledflagstate & flag) != 0;
}
static void chg_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
{
kbd->ledflagstate ^= flag;
ioctl(kbd->keyboard_fd, KDSKBSTATE, (unsigned long)(kbd->ledflagstate));
}
/*
* Special function handlers
*/
static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag)
{
if (up_flag)
return; /* no action, if this is a key release */
if (kbd->diacr)
value = handle_diacr(kbd, value);
if (kbd->dead_key_next) {
kbd->dead_key_next = SDL_FALSE;
kbd->diacr = value;
return;
}
put_utf8(kbd, value);
}
static void k_deadunicode(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag)
{
if (up_flag)
return;
kbd->diacr = (kbd->diacr ? handle_diacr(kbd, value) : value);
}
static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
{
int old_state = kbd->shift_state;
if (kbd->rep)
return;
if (up_flag) {
/*
* handle the case that two shift or control
* keys are depressed simultaneously
*/
if (kbd->shift_down[value])
kbd->shift_down[value]--;
} else
kbd->shift_down[value]++;
if (kbd->shift_down[value])
kbd->shift_state |= (1 << value);
else
kbd->shift_state &= ~(1 << value);
/* kludge */
if (up_flag && kbd->shift_state != old_state && kbd->npadch != -1) {
put_utf8(kbd, kbd->npadch);
kbd->npadch = -1;
}
}
void
SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down)
{
keymap_t key_map;
struct keyent_t keysym;
unsigned int final_key_state;
unsigned int map_from_key_sym;
key_map = *kbd->key_map;
if (!kbd) {
return;
}
kbd->rep = (down == 2);
if (keycode < NUM_KEYS) {
if (keycode >= 89 && keycode <= 95) {
/* These constitute unprintable language-related keys, so ignore them. */
return;
}
if (keycode > 95)
keycode -= 7;
if (vc_kbd_led(kbd, ALKED) || (kbd->shift_state & 0x8))
{
keycode += ALTGR_OFFSET;
}
keysym = key_map.key[keycode];
} else {
return;
}
final_key_state = kbd->shift_state & 0x7;
if ((keysym.flgs & FLAG_LOCK_C) && vc_kbd_led(kbd, LED_CAP))
final_key_state ^= 0x1;
if ((keysym.flgs & FLAG_LOCK_N) && vc_kbd_led(kbd, LED_NUM))
final_key_state ^= 0x1;
map_from_key_sym = keysym.map[final_key_state];
if ((keysym.spcl & (0x80 >> final_key_state)) || (map_from_key_sym & SPCLKEY)) {
/* Special function.*/
if (map_from_key_sym == 0)
return; /* Nothing to do. */
if (map_from_key_sym & SPCLKEY)
map_from_key_sym &= ~SPCLKEY;
if (map_from_key_sym >= F_ACC && map_from_key_sym <= L_ACC) {
/* Accent function.*/
unsigned int accent_index = map_from_key_sym - F_ACC;
if (kbd->accents->acc[accent_index].accchar != 0) {
k_deadunicode(kbd, kbd->accents->acc[accent_index].accchar, !down);
}
} else {
switch(map_from_key_sym) {
case ASH: /* alt/meta shift */
k_shift(kbd, 3, down == 0);
break;
case LSHA: /* left shift + alt lock */
case RSHA: /* right shift + alt lock */
if (down == 0) chg_vc_kbd_led(kbd, ALKED);
case LSH: /* left shift */
case RSH: /* right shift */
k_shift(kbd, 0, down == 0);
break;
case LCTRA: /* left ctrl + alt lock */
case RCTRA: /* right ctrl + alt lock */
if (down == 0) chg_vc_kbd_led(kbd, ALKED);
case LCTR: /* left ctrl */
case RCTR: /* right ctrl */
k_shift(kbd, 1, down == 0);
break;
case LALTA: /* left alt + alt lock */
case RALTA: /* right alt + alt lock */
if (down == 0) chg_vc_kbd_led(kbd, ALKED);
case LALT: /* left alt */
case RALT: /* right alt */
k_shift(kbd, 2, down == 0);
break;
case ALK: /* alt lock */
if (down == 1) chg_vc_kbd_led(kbd, ALKED);
break;
case CLK: /* caps lock*/
if (down == 1) chg_vc_kbd_led(kbd, CLKED);
break;
case NLK: /* num lock */
if (down == 1) chg_vc_kbd_led(kbd, NLKED);
break;
case SLK: /* scroll lock */
if (down == 1) chg_vc_kbd_led(kbd, SLKED);
break;
default:
return;
}
}
} else {
if (map_from_key_sym == '\n' || map_from_key_sym == '\r') {
if (kbd->diacr) {
kbd->diacr = 0;
return;
}
}
if (map_from_key_sym >= ' ' && map_from_key_sym != 127) {
k_self(kbd, map_from_key_sym, !down);
}
}
if (kbd->text_len > 0) {
kbd->text[kbd->text_len] = '\0';
SDL_SendKeyboardText(kbd->text);
kbd->text_len = 0;
}
}
#endif /* SDL_INPUT_FBSDKBIO */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -57,6 +57,10 @@ LoadDBUSSyms(void)
SDL_DBUS_SYM(message_new_method_call);
SDL_DBUS_SYM(message_append_args);
SDL_DBUS_SYM(message_append_args_valist);
SDL_DBUS_SYM(message_iter_init_append);
SDL_DBUS_SYM(message_iter_open_container);
SDL_DBUS_SYM(message_iter_append_basic);
SDL_DBUS_SYM(message_iter_close_container);
SDL_DBUS_SYM(message_get_args);
SDL_DBUS_SYM(message_get_args_valist);
SDL_DBUS_SYM(message_iter_init);
@@ -65,6 +69,7 @@ LoadDBUSSyms(void)
SDL_DBUS_SYM(message_iter_get_arg_type);
SDL_DBUS_SYM(message_iter_recurse);
SDL_DBUS_SYM(message_unref);
SDL_DBUS_SYM(threads_init_default);
SDL_DBUS_SYM(error_init);
SDL_DBUS_SYM(error_is_set);
SDL_DBUS_SYM(error_free);
@@ -124,19 +129,30 @@ SDL_DBus_Init(void)
return; /* oh well */
}
dbus.error_init(&err);
dbus.session_conn = dbus.bus_get_private(DBUS_BUS_SESSION, &err);
if (!dbus.error_is_set(&err)) {
dbus.system_conn = dbus.bus_get_private(DBUS_BUS_SYSTEM, &err);
if (!dbus.threads_init_default()) {
is_dbus_available = SDL_FALSE;
return;
}
dbus.error_init(&err);
/* session bus is required */
dbus.session_conn = dbus.bus_get_private(DBUS_BUS_SESSION, &err);
if (dbus.error_is_set(&err)) {
dbus.error_free(&err);
SDL_DBus_Quit();
is_dbus_available = SDL_FALSE;
return; /* oh well */
}
dbus.connection_set_exit_on_disconnect(dbus.system_conn, 0);
dbus.connection_set_exit_on_disconnect(dbus.session_conn, 0);
/* system bus is optional */
dbus.system_conn = dbus.bus_get_private(DBUS_BUS_SYSTEM, &err);
if (!dbus.error_is_set(&err)) {
dbus.connection_set_exit_on_disconnect(dbus.system_conn, 0);
}
dbus.error_free(&err);
}
}

View File

@@ -54,6 +54,10 @@ typedef struct SDL_DBusContext {
DBusMessage *(*message_new_method_call)(const char *, const char *, const char *, const char *);
dbus_bool_t (*message_append_args)(DBusMessage *, int, ...);
dbus_bool_t (*message_append_args_valist)(DBusMessage *, int, va_list);
void (*message_iter_init_append)(DBusMessage *, DBusMessageIter *);
dbus_bool_t (*message_iter_open_container)(DBusMessageIter *, int, const char *, DBusMessageIter *);
dbus_bool_t (*message_iter_append_basic)(DBusMessageIter *, int, const void *);
dbus_bool_t (*message_iter_close_container)(DBusMessageIter *, DBusMessageIter *);
dbus_bool_t (*message_get_args)(DBusMessage *, DBusError *, int, ...);
dbus_bool_t (*message_get_args_valist)(DBusMessage *, DBusError *, int, va_list);
dbus_bool_t (*message_iter_init)(DBusMessage *, DBusMessageIter *);
@@ -62,6 +66,7 @@ typedef struct SDL_DBusContext {
int (*message_iter_get_arg_type)(DBusMessageIter *);
void (*message_iter_recurse)(DBusMessageIter *, DBusMessageIter *);
void (*message_unref)(DBusMessage *);
dbus_bool_t (*threads_init_default)(void);
void (*error_init)(DBusError *);
dbus_bool_t (*error_is_set)(const DBusError *);
void (*error_free)(DBusError *);

View File

@@ -39,11 +39,11 @@
#include <linux/input.h>
#include "SDL.h"
#include "SDL_assert.h"
#include "SDL_endian.h"
#include "SDL_scancode.h"
#include "../../events/SDL_events_c.h"
#include "../../events/scancodes_linux.h" /* adds linux_scancode_table */
#include "../../core/linux/SDL_evdev_capabilities.h"
#include "../../core/linux/SDL_udev.h"
/* These are not defined in older Linux kernel headers */

View File

@@ -0,0 +1,98 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 2020 Collabora Ltd.
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_evdev_capabilities.h"
#if HAVE_LIBUDEV_H || defined(SDL_JOYSTICK_LINUX)
extern int
SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
unsigned long bitmask_abs[NBITS(ABS_MAX)],
unsigned long bitmask_key[NBITS(KEY_MAX)],
unsigned long bitmask_rel[NBITS(REL_MAX)])
{
int devclass = 0;
unsigned long keyboard_mask;
/* X, Y, Z axes but no buttons probably means an accelerometer */
if (test_bit(EV_ABS, bitmask_ev) &&
test_bit(ABS_X, bitmask_abs) &&
test_bit(ABS_Y, bitmask_abs) &&
test_bit(ABS_Z, bitmask_abs) &&
!test_bit(EV_KEY, bitmask_ev)) {
return SDL_UDEV_DEVICE_ACCELEROMETER;
}
/* RX, RY, RZ axes but no buttons also probably means an accelerometer */
if (test_bit(EV_ABS, bitmask_ev) &&
test_bit(ABS_RX, bitmask_abs) &&
test_bit(ABS_RY, bitmask_abs) &&
test_bit(ABS_RZ, bitmask_abs) &&
!test_bit(EV_KEY, bitmask_ev)) {
return SDL_UDEV_DEVICE_ACCELEROMETER;
}
if (test_bit(EV_ABS, bitmask_ev) &&
test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) {
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 */
} else if (test_bit(BTN_MOUSE, bitmask_key)) {
devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
} else if (test_bit(BTN_TOUCH, bitmask_key)) {
/* TODO: better determining between touchscreen and multitouch touchpad,
see https://github.com/systemd/systemd/blob/master/src/udev/udev-builtin-input_id.c */
devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN; /* ID_INPUT_TOUCHSCREEN */
}
if (test_bit(BTN_TRIGGER, bitmask_key) ||
test_bit(BTN_A, bitmask_key) ||
test_bit(BTN_1, bitmask_key) ||
test_bit(ABS_RX, bitmask_abs) ||
test_bit(ABS_RY, bitmask_abs) ||
test_bit(ABS_RZ, bitmask_abs) ||
test_bit(ABS_THROTTLE, bitmask_abs) ||
test_bit(ABS_RUDDER, bitmask_abs) ||
test_bit(ABS_WHEEL, bitmask_abs) ||
test_bit(ABS_GAS, bitmask_abs) ||
test_bit(ABS_BRAKE, bitmask_abs)) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK; /* ID_INPUT_JOYSTICK */
}
}
if (test_bit(EV_REL, bitmask_ev) &&
test_bit(REL_X, bitmask_rel) && test_bit(REL_Y, bitmask_rel) &&
test_bit(BTN_MOUSE, bitmask_key)) {
devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
}
/* the first 32 bits are ESC, numbers, and Q to D; if we have any of
* those, consider it a keyboard device; do not test KEY_RESERVED, though */
keyboard_mask = 0xFFFFFFFE;
if ((bitmask_key[0] & keyboard_mask) != 0)
devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */
return devclass;
}
#endif

View File

@@ -0,0 +1,59 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 2020 Collabora Ltd.
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"
#ifndef SDL_evdev_capabilities_h_
#define SDL_evdev_capabilities_h_
#if HAVE_LIBUDEV_H || defined(SDL_JOYSTICK_LINUX)
#include <linux/input.h>
/* A device can be any combination of these classes */
typedef enum
{
SDL_UDEV_DEVICE_UNKNOWN = 0x0000,
SDL_UDEV_DEVICE_MOUSE = 0x0001,
SDL_UDEV_DEVICE_KEYBOARD = 0x0002,
SDL_UDEV_DEVICE_JOYSTICK = 0x0004,
SDL_UDEV_DEVICE_SOUND = 0x0008,
SDL_UDEV_DEVICE_TOUCHSCREEN = 0x0010,
SDL_UDEV_DEVICE_ACCELEROMETER = 0x0020
} SDL_UDEV_deviceclass;
#define BITS_PER_LONG (sizeof(unsigned long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define EVDEV_OFF(x) ((x)%BITS_PER_LONG)
#define EVDEV_LONG(x) ((x)/BITS_PER_LONG)
#define test_bit(bit, array) ((array[EVDEV_LONG(bit)] >> EVDEV_OFF(bit)) & 1)
extern int SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
unsigned long bitmask_abs[NBITS(ABS_MAX)],
unsigned long bitmask_key[NBITS(KEY_MAX)],
unsigned long bitmask_rel[NBITS(REL_MAX)]);
#endif /* HAVE_LIBUDEV_H || defined(SDL_JOYSTICK_LINUX) */
#endif /* SDL_evdev_capabilities_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -819,7 +819,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
}
}
#else /* !SDL_INPUT_LINUXKD */
#elif !defined(SDL_INPUT_FBSDKBIO) /* !SDL_INPUT_LINUXKD */
SDL_EVDEV_keyboard_state *
SDL_EVDEV_kbd_init(void)

View File

@@ -20,9 +20,6 @@
*/
#include "../../SDL_internal.h"
#ifdef HAVE_FCITX_FRONTEND_H
#include <fcitx/frontend.h>
#include <unistd.h>
#include "SDL_fcitx.h"
@@ -36,23 +33,20 @@
#endif
#include "SDL_hints.h"
#define FCITX_DBUS_SERVICE "org.fcitx.Fcitx"
#define FCITX_DBUS_SERVICE "org.freedesktop.portal.Fcitx"
#define FCITX_IM_DBUS_PATH "/inputmethod"
#define FCITX_IC_DBUS_PATH "/inputcontext_%d"
#define FCITX_IM_DBUS_PATH "/org/freedesktop/portal/inputmethod"
#define FCITX_IM_DBUS_INTERFACE "org.fcitx.Fcitx.InputMethod"
#define FCITX_IC_DBUS_INTERFACE "org.fcitx.Fcitx.InputContext"
#define FCITX_IM_DBUS_INTERFACE "org.fcitx.Fcitx.InputMethod1"
#define FCITX_IC_DBUS_INTERFACE "org.fcitx.Fcitx.InputContext1"
#define IC_NAME_MAX 64
#define DBUS_TIMEOUT 500
typedef struct _FcitxClient
{
SDL_DBusContext *dbus;
char servicename[IC_NAME_MAX];
char icname[IC_NAME_MAX];
char *ic_path;
int id;
@@ -61,34 +55,6 @@ typedef struct _FcitxClient
static FcitxClient fcitx_client;
static int
GetDisplayNumber()
{
const char *display = SDL_getenv("DISPLAY");
const char *p = NULL;
int number = 0;
if (display == NULL)
return 0;
display = SDL_strchr(display, ':');
if (display == NULL)
return 0;
display++;
p = SDL_strchr(display, '.');
if (p == NULL && display != NULL) {
number = SDL_strtod(display, NULL);
} else {
char *buffer = SDL_strdup(display);
buffer[p - display] = '\0';
number = SDL_strtod(buffer, NULL);
SDL_free(buffer);
}
return number;
}
static char*
GetAppName()
{
@@ -118,6 +84,54 @@ GetAppName()
return SDL_strdup("SDL_App");
}
size_t Fcitx_GetPreeditString(SDL_DBusContext *dbus, DBusMessage *msg, char **ret) {
char *text = NULL, *subtext;
size_t text_bytes = 0;
DBusMessageIter iter, array, sub;
dbus->message_iter_init(msg, &iter);
/* Message type is a(si)i, we only need string part */
if (dbus->message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY) {
/* First pass: calculate string length */
dbus->message_iter_recurse(&iter, &array);
while (dbus->message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
dbus->message_iter_recurse(&array, &sub);
if (dbus->message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING) {
dbus->message_iter_get_basic(&sub, &subtext);
if (subtext && *subtext) {
text_bytes += SDL_strlen(subtext);
}
}
dbus->message_iter_next(&array);
}
if (text_bytes) {
text = SDL_malloc(text_bytes + 1);
}
if (text) {
char* pivot = text;
/* Second pass: join all the sub string */
dbus->message_iter_recurse(&iter, &array);
while (dbus->message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
dbus->message_iter_recurse(&array, &sub);
if (dbus->message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING) {
dbus->message_iter_get_basic(&sub, &subtext);
if (subtext && *subtext) {
size_t length = SDL_strlen(subtext);
SDL_strlcpy(pivot, subtext, length + 1);
pivot += length;
}
}
dbus->message_iter_next(&array);
}
} else {
text_bytes = 0;
}
}
*ret= text;
return text_bytes;
}
static DBusHandlerResult
DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
{
@@ -130,22 +144,27 @@ DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
dbus->message_iter_init(msg, &iter);
dbus->message_iter_get_basic(&iter, &text);
if (text)
SDL_SendKeyboardText(text);
if (text && *text) {
char buf[SDL_TEXTINPUTEVENT_TEXT_SIZE];
size_t text_bytes = SDL_strlen(text), i = 0;
while (i < text_bytes) {
size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
SDL_SendKeyboardText(buf);
i += sz;
}
}
return DBUS_HANDLER_RESULT_HANDLED;
}
if (dbus->message_is_signal(msg, FCITX_IC_DBUS_INTERFACE, "UpdatePreedit")) {
DBusMessageIter iter;
const char *text;
dbus->message_iter_init(msg, &iter);
dbus->message_iter_get_basic(&iter, &text);
if (text && *text) {
if (dbus->message_is_signal(msg, FCITX_IC_DBUS_INTERFACE, "UpdateFormattedPreedit")) {
char *text = NULL;
size_t text_bytes = Fcitx_GetPreeditString(dbus, msg, &text);
if (text_bytes) {
char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
size_t text_bytes = SDL_strlen(text), i = 0;
size_t i = 0;
size_t cursor = 0;
while (i < text_bytes) {
@@ -157,6 +176,9 @@ DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
i += sz;
cursor += chars;
}
SDL_free(text);
} else {
SDL_SendEditingText("", 0, 0);
}
SDL_Fcitx_UpdateTextRect(NULL);
@@ -169,7 +191,10 @@ DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
static void
FcitxClientICCallMethod(FcitxClient *client, const char *method)
{
SDL_DBus_CallVoidMethod(client->servicename, client->icname, FCITX_IC_DBUS_INTERFACE, method, DBUS_TYPE_INVALID);
if (!client->ic_path) {
return;
}
SDL_DBus_CallVoidMethod(FCITX_DBUS_SERVICE, client->ic_path, FCITX_IC_DBUS_INTERFACE, method, DBUS_TYPE_INVALID);
}
static void SDLCALL
@@ -179,40 +204,68 @@ Fcitx_SetCapabilities(void *data,
const char *internal_editing)
{
FcitxClient *client = (FcitxClient *)data;
Uint32 caps = CAPACITY_NONE;
if (!(internal_editing && *internal_editing == '1')) {
caps |= CAPACITY_PREEDIT;
Uint32 caps = 0;
if (!client->ic_path) {
return;
}
SDL_DBus_CallVoidMethod(client->servicename, client->icname, FCITX_IC_DBUS_INTERFACE, "SetCapacity", DBUS_TYPE_UINT32, &caps, DBUS_TYPE_INVALID);
if (!(internal_editing && *internal_editing == '1')) {
caps |= (1 << 1); /* Preedit Flag */
caps |= (1 << 4); /* Formatted Preedit Flag */
}
SDL_DBus_CallVoidMethod(FCITX_DBUS_SERVICE, client->ic_path, FCITX_IC_DBUS_INTERFACE, "SetCapability", DBUS_TYPE_UINT64, &caps, DBUS_TYPE_INVALID);
}
static SDL_bool
FcitxCreateInputContext(SDL_DBusContext* dbus, const char *appname, char **ic_path) {
const char *program = "program";
SDL_bool retval = SDL_FALSE;
if (dbus->session_conn) {
DBusMessage *msg = dbus->message_new_method_call(FCITX_DBUS_SERVICE, FCITX_IM_DBUS_PATH, FCITX_IM_DBUS_INTERFACE, "CreateInputContext");
if (msg) {
DBusMessage *reply = NULL;
DBusMessageIter args, array, sub;
dbus->message_iter_init_append(msg, &args);
dbus->message_iter_open_container(&args, DBUS_TYPE_ARRAY, "(ss)", &array);
dbus->message_iter_open_container(&array, DBUS_TYPE_STRUCT, 0, &sub);
dbus->message_iter_append_basic(&sub, DBUS_TYPE_STRING, &program);
dbus->message_iter_append_basic(&sub, DBUS_TYPE_STRING, &appname);
dbus->message_iter_close_container(&array, &sub);
dbus->message_iter_close_container(&args, &array);
reply = dbus->connection_send_with_reply_and_block(dbus->session_conn, msg, 300, NULL);
if (reply) {
if (dbus->message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH, ic_path, DBUS_TYPE_INVALID)) {
retval = SDL_TRUE;
}
dbus->message_unref(reply);
}
dbus->message_unref(msg);
}
}
return retval;
}
static SDL_bool
FcitxClientCreateIC(FcitxClient *client)
{
char *appname = GetAppName();
pid_t pid = getpid();
int id = -1;
Uint32 enable, arg1, arg2, arg3, arg4;
char *ic_path = NULL;
SDL_DBusContext *dbus = client->dbus;
if (!SDL_DBus_CallMethod(client->servicename, FCITX_IM_DBUS_PATH, FCITX_IM_DBUS_INTERFACE, "CreateICv3",
DBUS_TYPE_STRING, &appname, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID,
DBUS_TYPE_INT32, &id, DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_UINT32, &arg1, DBUS_TYPE_UINT32, &arg2, DBUS_TYPE_UINT32, &arg3, DBUS_TYPE_UINT32, &arg4, DBUS_TYPE_INVALID)) {
id = -1; /* just in case. */
/* SDL_DBus_CallMethod cannot handle a(ss) type, call dbus function directly */
if (!FcitxCreateInputContext(dbus, appname, &ic_path)) {
ic_path = NULL; /* just in case. */
}
SDL_free(appname);
if (id >= 0) {
SDL_DBusContext *dbus = client->dbus;
client->id = id;
SDL_snprintf(client->icname, IC_NAME_MAX, FCITX_IC_DBUS_PATH, client->id);
if (ic_path) {
SDL_free(client->ic_path);
client->ic_path = SDL_strdup(ic_path);
dbus->bus_add_match(dbus->session_conn,
"type='signal', interface='org.fcitx.Fcitx.InputContext'",
"type='signal', interface='org.fcitx.Fcitx.InputContext1'",
NULL);
dbus->connection_add_filter(dbus->session_conn,
&DBus_MessageFilter, dbus,
@@ -232,13 +285,14 @@ Fcitx_ModState(void)
Uint32 fcitx_mods = 0;
SDL_Keymod sdl_mods = SDL_GetModState();
if (sdl_mods & KMOD_SHIFT) fcitx_mods |= FcitxKeyState_Shift;
if (sdl_mods & KMOD_CAPS) fcitx_mods |= FcitxKeyState_CapsLock;
if (sdl_mods & KMOD_CTRL) fcitx_mods |= FcitxKeyState_Ctrl;
if (sdl_mods & KMOD_ALT) fcitx_mods |= FcitxKeyState_Alt;
if (sdl_mods & KMOD_NUM) fcitx_mods |= FcitxKeyState_NumLock;
if (sdl_mods & KMOD_LGUI) fcitx_mods |= FcitxKeyState_Super;
if (sdl_mods & KMOD_RGUI) fcitx_mods |= FcitxKeyState_Meta;
if (sdl_mods & KMOD_SHIFT) fcitx_mods |= (1 << 0);
if (sdl_mods & KMOD_CAPS) fcitx_mods |= (1 << 1);
if (sdl_mods & KMOD_CTRL) fcitx_mods |= (1 << 2);
if (sdl_mods & KMOD_ALT) fcitx_mods |= (1 << 3);
if (sdl_mods & KMOD_NUM) fcitx_mods |= (1 << 4);
if (sdl_mods & KMOD_MODE) fcitx_mods |= (1 << 7);
if (sdl_mods & KMOD_LGUI) fcitx_mods |= (1 << 6);
if (sdl_mods & KMOD_RGUI) fcitx_mods |= (1 << 28);
return fcitx_mods;
}
@@ -253,10 +307,6 @@ SDL_Fcitx_Init()
fcitx_client.cursor_rect.w = 0;
fcitx_client.cursor_rect.h = 0;
SDL_snprintf(fcitx_client.servicename, IC_NAME_MAX,
"%s-%d",
FCITX_DBUS_SERVICE, GetDisplayNumber());
return FcitxClientCreateIC(&fcitx_client);
}
@@ -264,6 +314,10 @@ void
SDL_Fcitx_Quit()
{
FcitxClientICCallMethod(&fcitx_client, "DestroyIC");
if (fcitx_client.ic_path) {
SDL_free(fcitx_client.ic_path);
fcitx_client.ic_path = NULL;
}
}
void
@@ -288,12 +342,16 @@ SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
{
Uint32 state = Fcitx_ModState();
Uint32 handled = SDL_FALSE;
int type = FCITX_PRESS_KEY;
Uint32 is_release = SDL_FALSE;
Uint32 event_time = 0;
if (SDL_DBus_CallMethod(fcitx_client.servicename, fcitx_client.icname, FCITX_IC_DBUS_INTERFACE, "ProcessKeyEvent",
DBUS_TYPE_UINT32, &keysym, DBUS_TYPE_UINT32, &keycode, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INT32, &type, DBUS_TYPE_UINT32, &event_time, DBUS_TYPE_INVALID,
DBUS_TYPE_INT32, &handled, DBUS_TYPE_INVALID)) {
if (!fcitx_client.ic_path) {
return SDL_FALSE;
}
if (SDL_DBus_CallMethod(FCITX_DBUS_SERVICE, fcitx_client.ic_path, FCITX_IC_DBUS_INTERFACE, "ProcessKeyEvent",
DBUS_TYPE_UINT32, &keysym, DBUS_TYPE_UINT32, &keycode, DBUS_TYPE_UINT32, &state, DBUS_TYPE_BOOLEAN, &is_release, DBUS_TYPE_UINT32, &event_time, DBUS_TYPE_INVALID,
DBUS_TYPE_BOOLEAN, &handled, DBUS_TYPE_INVALID)) {
if (handled) {
SDL_Fcitx_UpdateTextRect(NULL);
return SDL_TRUE;
@@ -350,7 +408,7 @@ SDL_Fcitx_UpdateTextRect(SDL_Rect *rect)
x += cursor->x;
y += cursor->y;
SDL_DBus_CallVoidMethod(fcitx_client.servicename, fcitx_client.icname, FCITX_IC_DBUS_INTERFACE, "SetCursorRect",
SDL_DBus_CallVoidMethod(FCITX_DBUS_SERVICE, fcitx_client.ic_path, FCITX_IC_DBUS_INTERFACE, "SetCursorRect",
DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_INT32, &cursor->w, DBUS_TYPE_INT32, &cursor->h, DBUS_TYPE_INVALID);
}
@@ -368,6 +426,4 @@ SDL_Fcitx_PumpEvents(void)
}
}
#endif /* HAVE_FCITX_FRONTEND_H */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -43,7 +43,7 @@ static void
InitIME()
{
static SDL_bool inited = SDL_FALSE;
#ifdef HAVE_FCITX_FRONTEND_H
#ifdef HAVE_FCITX
const char *im_module = SDL_getenv("SDL_IM_MODULE");
const char *xmodifiers = SDL_getenv("XMODIFIERS");
#endif
@@ -54,7 +54,7 @@ InitIME()
inited = SDL_TRUE;
/* See if fcitx IME support is being requested */
#ifdef HAVE_FCITX_FRONTEND_H
#ifdef HAVE_FCITX
if (!SDL_IME_Init_Real &&
((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
(!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
@@ -66,7 +66,7 @@ InitIME()
SDL_IME_UpdateTextRect_Real = SDL_Fcitx_UpdateTextRect;
SDL_IME_PumpEvents_Real = SDL_Fcitx_PumpEvents;
}
#endif /* HAVE_FCITX_FRONTEND_H */
#endif /* HAVE_FCITX */
/* default to IBus */
#ifdef HAVE_IBUS_IBUS_H

View File

@@ -24,6 +24,7 @@
#include "SDL_error.h"
#include "SDL_stdinc.h"
#include "SDL_thread.h"
#if !SDL_THREADS_DISABLED
#include <sys/time.h>
@@ -31,9 +32,20 @@
#include <pthread.h>
#include "SDL_system.h"
/* RLIMIT_RTTIME requires kernel >= 2.6.25 and is in glibc >= 2.14 */
#ifndef RLIMIT_RTTIME
#define RLIMIT_RTTIME 15
#endif
/* SCHED_RESET_ON_FORK is in kernel >= 2.6.32. */
#ifndef SCHED_RESET_ON_FORK
#define SCHED_RESET_ON_FORK 0x40000000
#endif
#include "SDL_dbus.h"
#if SDL_USE_LIBDBUS
#include <sched.h>
/* d-bus queries to org.freedesktop.RealtimeKit1. */
#define RTKIT_DBUS_NODE "org.freedesktop.RealtimeKit1"
#define RTKIT_DBUS_PATH "/org/freedesktop/RealtimeKit1"
@@ -41,6 +53,8 @@
static pthread_once_t rtkit_initialize_once = PTHREAD_ONCE_INIT;
static Sint32 rtkit_min_nice_level = -20;
static Sint32 rtkit_max_realtime_priority = 99;
static Sint64 rtkit_max_rttime_usec = 200000;
static void
rtkit_initialize()
@@ -52,10 +66,84 @@ rtkit_initialize()
DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
rtkit_min_nice_level = -20;
}
/* Try getting maximum realtime priority: this can be less than the POSIX default (99). */
if (!dbus || !SDL_DBus_QueryPropertyOnConnection(dbus->system_conn, RTKIT_DBUS_NODE, RTKIT_DBUS_PATH, RTKIT_DBUS_INTERFACE, "MaxRealtimePriority",
DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
rtkit_max_realtime_priority = 99;
}
/* Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL */
if (!dbus || !SDL_DBus_QueryPropertyOnConnection(dbus->system_conn, RTKIT_DBUS_NODE, RTKIT_DBUS_PATH, RTKIT_DBUS_INTERFACE, "RTTimeUSecMax",
DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
rtkit_max_rttime_usec = 200000;
}
}
static SDL_bool
rtkit_setpriority(pid_t thread, int nice_level)
rtkit_initialize_realtime_thread()
{
// Following is an excerpt from rtkit README that outlines the requirements
// a thread must meet before making rtkit requests:
//
// * Only clients with RLIMIT_RTTIME set will get RT scheduling
//
// * RT scheduling will only be handed out to processes with
// SCHED_RESET_ON_FORK set to guarantee that the scheduling
// settings cannot 'leak' to child processes, thus making sure
// that 'RT fork bombs' cannot be used to bypass RLIMIT_RTTIME
// and take the system down.
//
// * Limits are enforced on all user controllable resources, only
// a maximum number of users, processes, threads can request RT
// scheduling at the same time.
//
// * Only a limited number of threads may be made RT in a
// specific time frame.
//
// * Client authorization is verified with PolicyKit
int err;
struct rlimit rlimit;
int nLimit = RLIMIT_RTTIME;
pid_t nPid = 0; //self
int nSchedPolicy = sched_getscheduler(nPid) | SCHED_RESET_ON_FORK;
struct sched_param schedParam = {};
// Requirement #1: Set RLIMIT_RTTIME
err = getrlimit(nLimit, &rlimit);
if (err)
{
return SDL_FALSE;
}
// Current rtkit allows a max of 200ms right now
rlimit.rlim_max = rtkit_max_rttime_usec;
rlimit.rlim_cur = rlimit.rlim_max / 2;
err = setrlimit(nLimit, &rlimit);
if (err)
{
return SDL_FALSE;
}
// Requirement #2: Add SCHED_RESET_ON_FORK to the scheduler policy
err = sched_getparam(nPid, &schedParam);
if (err)
{
return SDL_FALSE;
}
err = sched_setscheduler(nPid, nSchedPolicy, &schedParam);
if (err)
{
return SDL_FALSE;
}
return SDL_TRUE;
}
static SDL_bool
rtkit_setpriority_nice(pid_t thread, int nice_level)
{
Uint64 ui64 = (Uint64)thread;
Sint32 si32 = (Sint32)nice_level;
@@ -74,10 +162,42 @@ rtkit_setpriority(pid_t thread, int nice_level)
}
return SDL_TRUE;
}
static SDL_bool
rtkit_setpriority_realtime(pid_t thread, int rt_priority)
{
Uint64 ui64 = (Uint64)thread;
Uint32 ui32 = (Uint32)rt_priority;
SDL_DBusContext *dbus = SDL_DBus_GetContext();
pthread_once(&rtkit_initialize_once, rtkit_initialize);
if (ui32 > rtkit_max_realtime_priority)
ui32 = rtkit_max_realtime_priority;
// We always perform the thread state changes necessary for rtkit.
// This wastes some system calls if the state is already set but
// typically code sets a thread priority and leaves it so it's
// not expected that this wasted effort will be an issue.
// We also do not quit if this fails, we let the rtkit request
// go through to determine whether it really needs to fail or not.
rtkit_initialize_realtime_thread();
if (!dbus || !SDL_DBus_CallMethodOnConnection(dbus->system_conn,
RTKIT_DBUS_NODE, RTKIT_DBUS_PATH, RTKIT_DBUS_INTERFACE, "MakeThreadRealtime",
DBUS_TYPE_UINT64, &ui64, DBUS_TYPE_UINT32, &ui32, DBUS_TYPE_INVALID,
DBUS_TYPE_INVALID)) {
return SDL_FALSE;
}
return SDL_TRUE;
}
#else
#define rtkit_max_realtime_priority 99
#endif /* dbus */
#endif /* threads */
/* this is a public symbol, so it has to exist even if threads are disabled. */
int
SDL_LinuxSetThreadPriority(Sint64 threadID, int priority)
@@ -102,7 +222,7 @@ SDL_LinuxSetThreadPriority(Sint64 threadID, int priority)
README and sample code at: http://git.0pointer.net/rtkit.git
*/
if (rtkit_setpriority((pid_t)threadID, priority)) {
if (rtkit_setpriority_nice((pid_t)threadID, priority)) {
return 0;
}
#endif
@@ -111,6 +231,69 @@ SDL_LinuxSetThreadPriority(Sint64 threadID, int priority)
#endif
}
/* this is a public symbol, so it has to exist even if threads are disabled. */
int
SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy)
{
#if SDL_THREADS_DISABLED
return SDL_Unsupported();
#else
int osPriority;
if (schedPolicy == SCHED_RR || schedPolicy == SCHED_FIFO) {
if (sdlPriority == SDL_THREAD_PRIORITY_LOW) {
osPriority = 1;
} else if (sdlPriority == SDL_THREAD_PRIORITY_HIGH) {
osPriority = rtkit_max_realtime_priority * 3 / 4;
} else if (sdlPriority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
osPriority = rtkit_max_realtime_priority;
} else {
osPriority = rtkit_max_realtime_priority / 2;
}
} else {
if (sdlPriority == SDL_THREAD_PRIORITY_LOW) {
osPriority = 19;
} else if (sdlPriority == SDL_THREAD_PRIORITY_HIGH) {
osPriority = -10;
} else if (sdlPriority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
osPriority = -20;
} else {
osPriority = 0;
}
if (setpriority(PRIO_PROCESS, (id_t)threadID, osPriority) == 0) {
return 0;
}
}
#if SDL_USE_LIBDBUS
/* Note that this fails you most likely:
* Have your process's scheduler incorrectly configured.
See the requirements at:
http://git.0pointer.net/rtkit.git/tree/README#n16
* Encountered dbus/polkit security restrictions. Note
that the RealtimeKit1 dbus endpoint is inaccessible
over ssh connections for most common distro configs.
You might want to check your local config for details:
/usr/share/polkit-1/actions/org.freedesktop.RealtimeKit1.policy
README and sample code at: http://git.0pointer.net/rtkit.git
*/
if (schedPolicy == SCHED_RR || schedPolicy == SCHED_FIFO) {
if (rtkit_setpriority_realtime((pid_t)threadID, osPriority)) {
return 0;
}
} else {
if (rtkit_setpriority_nice((pid_t)threadID, osPriority)) {
return 0;
}
}
#endif
return SDL_SetError("setpriority() failed");
#endif
}
#endif /* __LINUX__ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -32,6 +32,7 @@
#include <linux/input.h>
#include "SDL_assert.h"
#include "SDL_evdev_capabilities.h"
#include "SDL_loadso.h"
#include "SDL_timer.h"
#include "SDL_hints.h"
@@ -291,12 +292,6 @@ SDL_UDEV_LoadLibrary(void)
return retval;
}
#define BITS_PER_LONG (sizeof(unsigned long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define OFF(x) ((x)%BITS_PER_LONG)
#define LONG(x) ((x)/BITS_PER_LONG)
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
static void get_caps(struct udev_device *dev, struct udev_device *pdev, const char *attr, unsigned long *bitmask, size_t bitmask_len)
{
const char *value;
@@ -330,13 +325,11 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
static int
guess_device_class(struct udev_device *dev)
{
int devclass = 0;
struct udev_device *pdev;
unsigned long bitmask_ev[NBITS(EV_MAX)];
unsigned long bitmask_abs[NBITS(ABS_MAX)];
unsigned long bitmask_key[NBITS(KEY_MAX)];
unsigned long bitmask_rel[NBITS(REL_MAX)];
unsigned long keyboard_mask;
/* walk up the parental chain until we find the real input device; the
* argument is very likely a subdevice of this, like eventN */
@@ -353,48 +346,10 @@ guess_device_class(struct udev_device *dev)
get_caps(dev, pdev, "capabilities/rel", bitmask_rel, SDL_arraysize(bitmask_rel));
get_caps(dev, pdev, "capabilities/key", bitmask_key, SDL_arraysize(bitmask_key));
if (test_bit(EV_ABS, bitmask_ev) &&
test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) {
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 */
} else if (test_bit(BTN_MOUSE, bitmask_key)) {
devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
} else if (test_bit(BTN_TOUCH, bitmask_key)) {
/* TODO: better determining between touchscreen and multitouch touchpad,
see https://github.com/systemd/systemd/blob/master/src/udev/udev-builtin-input_id.c */
devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN; /* ID_INPUT_TOUCHSCREEN */
}
if (test_bit(BTN_TRIGGER, bitmask_key) ||
test_bit(BTN_A, bitmask_key) ||
test_bit(BTN_1, bitmask_key) ||
test_bit(ABS_RX, bitmask_abs) ||
test_bit(ABS_RY, bitmask_abs) ||
test_bit(ABS_RZ, bitmask_abs) ||
test_bit(ABS_THROTTLE, bitmask_abs) ||
test_bit(ABS_RUDDER, bitmask_abs) ||
test_bit(ABS_WHEEL, bitmask_abs) ||
test_bit(ABS_GAS, bitmask_abs) ||
test_bit(ABS_BRAKE, bitmask_abs)) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK; /* ID_INPUT_JOYSTICK */
}
}
if (test_bit(EV_REL, bitmask_ev) &&
test_bit(REL_X, bitmask_rel) && test_bit(REL_Y, bitmask_rel) &&
test_bit(BTN_MOUSE, bitmask_key)) {
devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
}
/* the first 32 bits are ESC, numbers, and Q to D; if we have any of
* those, consider it a keyboard device; do not test KEY_RESERVED, though */
keyboard_mask = 0xFFFFFFFE;
if ((bitmask_key[0] & keyboard_mask) != 0)
devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */
return devclass;
return SDL_EVDEV_GuessDeviceClass(&bitmask_ev[0],
&bitmask_abs[0],
&bitmask_key[0],
&bitmask_rel[0]);
}
static void

View File

@@ -46,17 +46,6 @@ typedef enum
SDL_UDEV_DEVICEREMOVED
} SDL_UDEV_deviceevent;
/* A device can be any combination of these classes */
typedef enum
{
SDL_UDEV_DEVICE_UNKNOWN = 0x0000,
SDL_UDEV_DEVICE_MOUSE = 0x0001,
SDL_UDEV_DEVICE_KEYBOARD = 0x0002,
SDL_UDEV_DEVICE_JOYSTICK = 0x0004,
SDL_UDEV_DEVICE_SOUND = 0x0008,
SDL_UDEV_DEVICE_TOUCHSCREEN = 0x0010
} SDL_UDEV_deviceclass;
typedef void (*SDL_UDEV_Callback)(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
typedef struct SDL_UDEV_CallbackList {

38
externals/SDL/src/core/os2/SDL_os2.c vendored Executable file
View File

@@ -0,0 +1,38 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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"
#if defined(__OS2__)
#include "geniconv/geniconv.h"
/* SDL_OS2Quit() will be called from SDL_QuitSubSystem() */
void SDL_OS2Quit(void)
{
/* Unload DLL used for iconv. We can do it at any time and use iconv again -
* dynamic library will be loaded on first call iconv_open() (see geniconv). */
libiconv_clean();
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

52
externals/SDL/src/core/os2/SDL_os2.h vendored Executable file
View File

@@ -0,0 +1,52 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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.
*/
#ifndef SDL_os2_h_
#define SDL_os2_h_
#include "SDL_log.h"
#include "SDL_stdinc.h"
#include "geniconv/geniconv.h"
#ifdef OS2DEBUG
#if (OS2DEBUG-0 >= 2)
# define debug_os2(s,...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, \
__func__ "(): " ##s, ##__VA_ARGS__)
#else
# define debug_os2(s,...) printf(__func__ "(): " ##s "\n", ##__VA_ARGS__)
#endif
#else /* no debug */
# define debug_os2(s,...) do {} while (0)
#endif /* OS2DEBUG */
/* StrUTF8New() - geniconv/sys2utf8.c */
#define OS2_SysToUTF8(S) StrUTF8New(1, (S), SDL_strlen((S)) + 1)
#define OS2_UTF8ToSys(S) StrUTF8New(0, (char *)(S), SDL_strlen((S)) + 1)
/* SDL_OS2Quit() will be called from SDL_QuitSubSystem() */
void SDL_OS2Quit(void);
#endif /* SDL_os2_h_ */
/* vi: set ts=4 sw=4 expandtab: */

157
externals/SDL/src/core/os2/geniconv/geniconv.c vendored Executable file
View File

@@ -0,0 +1,157 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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.
*/
/*
Universal iconv implementation for OS/2.
Andrey Vasilkin, 2016.
*/
#define INCL_DOSMODULEMGR /* Module Manager values */
#define INCL_DOSERRORS /* Error values */
#include <os2.h>
#include "geniconv.h"
/*#define DEBUG*/
#ifdef DEBUG
# include <stdio.h>
# define debug(s,...) printf(__func__"(): "##s"\n" ,##__VA_ARGS__)
#else
# define debug(s,...) do {} while (0)
#endif
/* Exports from os2iconv.c */
extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode);
extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
size_t *inbytesleft, char* * outbuf,
size_t *outbytesleft);
extern int _System os2_iconv_close(iconv_t cd);
/* Functions pointers types */
typedef iconv_t _System (*FNICONV_OPEN)(const char* tocode, const char* fromcode);
typedef size_t _System (*FNICONV)(iconv_t cd, char* * inbuf,
size_t *inbytesleft, char* * outbuf,
size_t *outbytesleft);
typedef int _System (*FNICONV_CLOSE)(iconv_t cd);
/* Used DLL module handle */
static HMODULE hmIconv = NULLHANDLE;
/* Functions pointers */
static FNICONV_OPEN fn_iconv_open = NULL;
static FNICONV fn_iconv = NULL;
static FNICONV_CLOSE fn_iconv_close = NULL;
static BOOL _loadDLL(PSZ pszName, PSZ pszIconvOpen, PSZ pszIconv,
PSZ pszIconvClose)
{
ULONG ulRC;
CHAR acError[256];
ulRC = DosLoadModule(acError, sizeof(acError), pszName, &hmIconv);
if (ulRC != NO_ERROR) {
debug("DLL not loaded: %s", &acError);
return FALSE;
}
do {
ulRC = DosQueryProcAddr(hmIconv, 0, pszIconvOpen, (PFN *)&fn_iconv_open);
if (ulRC != NO_ERROR) {
debug("Error: cannot find entry %s in %s", pszIconvOpen, pszName);
break;
}
ulRC = DosQueryProcAddr(hmIconv, 0, pszIconv, (PFN *)&fn_iconv);
if (ulRC != NO_ERROR) {
debug("Error: cannot find entry %s in %s", pszIconv, pszName);
break;
}
ulRC = DosQueryProcAddr(hmIconv, 0, pszIconvClose, (PFN *)&fn_iconv_close);
if (ulRC != NO_ERROR) {
debug("Error: cannot find entry %s in %s", pszIconvClose, pszName);
break;
}
debug("DLL %s used", pszName);
return TRUE;
} while (FALSE);
DosFreeModule(hmIconv);
hmIconv = NULLHANDLE;
return FALSE;
}
static void _init(void)
{
if (fn_iconv_open != NULL) /* Already was initialized */
return;
/* Try to load kiconv.dll, iconv2.dll or iconv.dll */
if (!_loadDLL("KICONV", "_libiconv_open", "_libiconv", "_libiconv_close") &&
!_loadDLL("ICONV2", "_libiconv_open", "_libiconv", "_libiconv_close") &&
!_loadDLL("ICONV", "_iconv_open", "_iconv", "_iconv_close") ) {
/* No DLL was loaded - use OS/2 conversion objects API */
debug("Uni*() API used");
fn_iconv_open = os2_iconv_open;
fn_iconv = os2_iconv;
fn_iconv_close = os2_iconv_close;
}
}
/* Public routines.
* ----------------
*/
/* Non-standard function for iconv to unload the used dynamic library */
void libiconv_clean(void)
{
if (hmIconv != NULLHANDLE) {
DosFreeModule(hmIconv);
hmIconv = NULLHANDLE;
fn_iconv_open = NULL;
fn_iconv = NULL;
fn_iconv_close = NULL;
}
}
iconv_t libiconv_open(const char* tocode, const char* fromcode)
{
_init();
return fn_iconv_open(tocode, fromcode);
}
size_t libiconv(iconv_t cd, char* * inbuf, size_t *inbytesleft,
char* * outbuf, size_t *outbytesleft)
{
return fn_iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
}
int libiconv_close(iconv_t cd)
{
return fn_iconv_close(cd);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,85 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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.
*/
/*
Universal iconv implementation for OS/2.
Andrey Vasilkin, 2016.
*/
#ifndef GENICONV_H
#define GENICONV_H
#include <iconv.h>
#ifdef iconv_open
#undef iconv_open
#endif
#define iconv_open libiconv_open
#ifdef iconv
#undef iconv
#endif
#define iconv libiconv
#ifdef iconv_close
#undef iconv_close
#endif
#define iconv_close libiconv_close
#define iconv_clean libiconv_clean
/* Non-standard function for iconv to unload the used dynamic library */
void libiconv_clean(void);
iconv_t libiconv_open (const char *tocode, const char *fromcode);
int libiconv_close(iconv_t cd);
size_t libiconv (iconv_t cd, char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);
/* System codepage <-> UTF-8
*
* StrUTF8()
* Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
* the system cp (fToUTF8 is 0). Converted ASCIIZ string will be placed at the
* buffer pcDst, up to cbDst - 1 (for sys->utf8) or 2 (for utf8->sys) bytes.
* Returns the number of bytes written into pcDst, not counting the terminating
* 0 byte(s) or -1 on error.
*/
int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc);
/* StrUTF8New()
* Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
* the system cp (fToUTF8 is 0). Memory for the new string is obtained by
* using libc malloc().
* Returns converted string, terminating two bytes 0 is appended to the result.
* Returns null on error.
*/
char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr);
/* StrUTF8Free()
* Deallocates the memory block located by StrUTF8New() (just libc free()).
*/
void StrUTF8Free(char *pszStr);
#endif /* GENICONV_H */
/* vi: set ts=4 sw=4 expandtab: */

21
externals/SDL/src/core/os2/geniconv/iconv.h vendored Executable file
View File

@@ -0,0 +1,21 @@
#ifndef ICONV_H_ /* minimal iconv.h header based on public knowledge */
#define ICONV_H_
#include <stddef.h> /* size_t */
#include <errno.h>
typedef void *iconv_t;
#ifdef __cplusplus
extern "C" {
#endif
extern iconv_t iconv_open(const char *, const char *);
extern size_t iconv(iconv_t, char **, size_t *, char **, size_t *);
extern int iconv_close(iconv_t);
#ifdef __cplusplus
}
#endif
#endif /* ICONV_H_ */

37
externals/SDL/src/core/os2/geniconv/makefile vendored Executable file
View File

@@ -0,0 +1,37 @@
#
# Universal iconv implementation for OS/2.
#
# OpenWatcom makefile to build a library that uses kiconv.dll / iconv2.dll /
# iconv.dll or OS/2 Uni*() API.
#
# Andrey Vasilkin, 2016.
#
LIBFILE = geniconv.lib
all: $(LIBFILE) test.exe .symbolic
CFLAGS = -I$(%WATCOM)/h/os2 -I$(%WATCOM)/h -I. -bt=os2 -q -d0 -w2
SRCS = geniconv.c os2cp.c os2iconv.c
SRCS+= sys2utf8.c
OBJS = $(SRCS:.c=.obj)
LIBS = libuls.lib libconv.lib $(LIBFILE)
test.exe: $(LIBFILE) test.obj
wlink op quiet system os2v2 file test.obj lib {$(LIBS)} name $*
$(LIBFILE): $(OBJS)
@if exist $@ rm $@
@for %f in ($(OBJS)) do wlib -q -b $* +%f
.c.obj:
wcc386 $(CFLAGS) -fo=$^@ $<
clean: .SYMBOLIC
@if exist *.obj rm *.obj
@if exist *.err rm *.err
@if exist $(LIBFILE) rm $(LIBFILE)
@if exist test.exe rm test.exe

401
externals/SDL/src/core/os2/geniconv/os2cp.c vendored Executable file
View File

@@ -0,0 +1,401 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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.
*/
#define INCL_DOSNLS
#define INCL_DOSERRORS
#include <os2.h>
#include <string.h>
#include <ctype.h>
#include "os2cp.h"
typedef struct _CP2NAME {
ULONG ulCode;
PSZ pszName;
} CP2NAME;
typedef struct _NAME2CP {
PSZ pszName;
ULONG ulCode;
} NAME2CP;
static CP2NAME aCP2Name[] = {
{367, "ANSI_X3.4-1968"},
{813, "ECMA-118"},
{819, "CP819"},
{850, "850"},
{862, "862"},
{866, "866"},
{874, "ISO-IR-166"},
{878, "KOI8-R"},
{896, "JISX0201-1976"},
{901, "ISO-8859-13"},
{912, "ISO-8859-2"},
{913, "ISO-8859-3"},
{914, "ISO-8859-4"},
{915, "CYRILLIC"},
{920, "ISO-8859-9"},
{923, "ISO-8859-15"},
{943, "MS_KANJI"},
{954, "EUC-JP"},
{964, "EUC-TW"},
{970, "EUC-KR"},
{1051, "HP-ROMAN8"},
{1089, "ARABIC"},
{1129, "VISCII"},
{1168, "KOI8-U"},
{1200, "ISO-10646-UCS-2"},
{1202, "UTF-16LE"},
{1204, "UCS-2BE"},
{1208, "UTF-8"},
{1232, "UTF-32BE"},
{1234, "UTF-32LE"},
{1236, "ISO-10646-UCS-4"},
{1250, "CP1250"},
{1251, "CP1251"},
{1252, "CP1252"},
{1253, "CP1253"},
{1254, "CP1254"},
{1255, "CP1255"},
{1256, "CP1256"},
{1257, "CP1257"},
{1275, "MAC"},
{1383, "CN-GB"},
{1386, "GBK"},
{1392, "GB18030"},
{62210, "HEBREW"}
};
static NAME2CP aName2CP[] = {
{"850", 850},
{"862", 862},
{"866", 866},
{"ANSI_X3.4-1968", 367},
{"ANSI_X3.4-1986", 367},
{"ARABIC", 1089},
{"ASCII", 367},
{"ASMO-708", 1089},
{"CN-GB", 1383},
{"CP1250", 1250},
{"CP1251", 1251},
{"CP1252", 1252},
{"CP1253", 1253},
{"CP1254", 1254},
{"CP1255", 1255},
{"CP1256", 1256},
{"CP1257", 1257},
{"CP367", 367},
{"CP819", 819},
{"CP850", 850},
{"CP862", 862},
{"CP866", 866},
{"CP936", 1386},
{"CSASCII", 367},
{"CSEUCKR", 970},
{"CSEUCPKDFMTJAPANESE", 954},
{"CSEUCTW", 964},
{"CSGB2312", 1383},
{"CSHALFWIDTHKATAKANA", 896},
{"CSHPROMAN8", 1051},
{"CSIBM866", 866},
{"CSISOLATIN1", 819},
{"CSISOLATIN2", 912},
{"CSISOLATIN3", 913},
{"CSISOLATIN4", 914},
{"CSISOLATIN5", 920},
{"CSISOLATINARABIC", 1089},
{"CSISOLATINCYRILLIC", 915},
{"CSISOLATINGREEK", 813},
{"CSISOLATINHEBREW", 62210},
{"CSKOI8R", 878},
{"CSKSC56011987", 970},
{"CSMACINTOSH", 1275},
{"CSPC850MULTILINGUAL", 850},
{"CSPC862LATINHEBREW", 862},
{"CSSHIFTJIS", 943},
{"CSUCS4", 1236},
{"CSUNICODE", 1200},
{"CSUNICODE11", 1204},
{"CSVISCII", 1129},
{"CYRILLIC", 915},
{"ECMA-114", 1089},
{"ECMA-118", 813},
{"ELOT_928", 813},
{"EUC-CN", 1383},
{"EUC-JP", 954},
{"EUC-KR", 970},
{"EUC-TW", 964},
{"EUCCN", 1383},
{"EUCJP", 954},
{"EUCKR", 970},
{"EUCTW", 964},
{"EXTENDED_UNIX_CODE_PACKED_FORMAT_FOR_JAPANESE", 954},
{"GB18030", 1392},
{"GB2312", 1383},
{"GBK", 1386},
{"GREEK", 813},
{"GREEK8", 813},
{"HEBREW", 62210},
{"HP-ROMAN8", 1051},
{"IBM367", 367},
{"IBM819", 819},
{"IBM850", 850},
{"IBM862", 862},
{"IBM866", 866},
{"ISO-10646-UCS-2", 1200},
{"ISO-10646-UCS-4", 1236},
{"ISO-8859-1", 819},
{"ISO-8859-13", 901},
{"ISO-8859-15", 923},
{"ISO-8859-2", 912},
{"ISO-8859-3", 913},
{"ISO-8859-4", 914},
{"ISO-8859-5", 915},
{"ISO-8859-6", 1089},
{"ISO-8859-7", 813},
{"ISO-8859-8", 62210},
{"ISO-8859-9", 920},
{"ISO-IR-100", 819},
{"ISO-IR-101", 912},
{"ISO-IR-109", 913},
{"ISO-IR-110", 914},
{"ISO-IR-126", 813},
{"ISO-IR-127", 1089},
{"ISO-IR-138", 62210},
{"ISO-IR-144", 915},
{"ISO-IR-148", 920},
{"ISO-IR-149", 970},
{"ISO-IR-166", 874},
{"ISO-IR-179", 901},
{"ISO-IR-203", 923},
{"ISO-IR-6", 367},
{"ISO646-US", 367},
{"ISO8859-1", 819},
{"ISO8859-13", 901},
{"ISO8859-15", 923},
{"ISO8859-2", 912},
{"ISO8859-3", 913},
{"ISO8859-4", 914},
{"ISO8859-5", 915},
{"ISO8859-6", 1089},
{"ISO8859-7", 813},
{"ISO8859-8", 62210},
{"ISO8859-9", 920},
{"ISO_646.IRV:1991", 367},
{"ISO_8859-1", 819},
{"ISO_8859-13", 901},
{"ISO_8859-15", 923},
{"ISO_8859-15:1998", 923},
{"ISO_8859-1:1987", 819},
{"ISO_8859-2", 912},
{"ISO_8859-2:1987", 912},
{"ISO_8859-3", 913},
{"ISO_8859-3:1988", 913},
{"ISO_8859-4", 914},
{"ISO_8859-4:1988", 914},
{"ISO_8859-5", 915},
{"ISO_8859-5:1988", 915},
{"ISO_8859-6", 1089},
{"ISO_8859-6:1987", 1089},
{"ISO_8859-7", 813},
{"ISO_8859-7:1987", 813},
{"ISO_8859-7:2003", 813},
{"ISO_8859-8", 62210},
{"ISO_8859-8:1988", 62210},
{"ISO_8859-9", 920},
{"ISO_8859-9:1989", 920},
{"JISX0201-1976", 896},
{"JIS_X0201", 896},
{"KOI8-R", 878},
{"KOI8-U", 1168},
{"KOREAN", 970},
{"KSC_5601", 970},
{"KS_C_5601-1987", 970},
{"KS_C_5601-1989", 970},
{"L1", 819},
{"L2", 912},
{"L3", 913},
{"L4", 914},
{"L5", 920},
{"L7", 901},
{"LATIN-9", 923},
{"LATIN1", 819},
{"LATIN2", 912},
{"LATIN3", 913},
{"LATIN4", 914},
{"LATIN5", 920},
{"LATIN7", 901},
{"MAC", 1275},
{"MACINTOSH", 1275},
{"MACROMAN", 1275},
{"MS-ANSI", 1252},
{"MS-ARAB", 1256},
{"MS-CYRL", 1251},
{"MS-EE", 1250},
{"MS-GREEK", 1253},
{"MS-HEBR", 1255},
{"MS-TURK", 1254},
{"MS936", 1386},
{"MS_KANJI", 943},
{"R8", 1051},
{"ROMAN8", 1051},
{"SHIFT-JIS", 943},
{"SHIFT_JIS", 943},
{"SJIS", 943},
{"TIS-620", 874},
{"TIS620", 874},
{"TIS620-0", 874},
{"TIS620.2529-1", 874},
{"TIS620.2533-0", 874},
{"TIS620.2533-1", 874},
{"UCS-2", 1200},
{"UCS-2BE", 1204},
{"UCS-4", 1236},
{"UNICODE-1-1", 1204},
{"UNICODEBIG", 1204},
{"US", 367},
{"US-ASCII", 367},
{"UTF-16", 1204},
{"UTF-16BE", 1200},
{"UTF-16LE", 1202},
{"UTF-32", 1236},
{"UTF-32BE", 1232},
{"UTF-32LE", 1234},
{"UTF-8", 1208},
{"VISCII", 1129},
{"VISCII1.1-1", 1129},
{"WINBALTRIM", 1257},
{"WINDOWS-1250", 1250},
{"WINDOWS-1251", 1251},
{"WINDOWS-1252", 1252},
{"WINDOWS-1253", 1253},
{"WINDOWS-1254", 1254},
{"WINDOWS-1255", 1255},
{"WINDOWS-1256", 1256},
{"WINDOWS-1257", 1257},
{"WINDOWS-936", 1386},
{"X0201", 896}
};
char *os2cpToName(unsigned long cp)
{
ULONG ulLo = 0;
ULONG ulHi = (sizeof(aCP2Name) / sizeof(struct _CP2NAME)) - 1;
ULONG ulNext;
LONG lFound = -1;
if (cp == SYSTEM_CP) {
ULONG aulCP[3];
ULONG cCP;
if (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)
return NULL;
cp = aulCP[0];
}
if (aCP2Name[0].ulCode > cp || aCP2Name[ulHi].ulCode < cp)
return NULL;
if (aCP2Name[0].ulCode == cp)
return aCP2Name[0].pszName;
if (aCP2Name[ulHi].ulCode == cp)
return aCP2Name[ulHi].pszName;
while ((ulHi - ulLo) > 1) {
ulNext = (ulLo + ulHi) / 2;
if (aCP2Name[ulNext].ulCode < cp)
ulLo = ulNext;
else if (aCP2Name[ulNext].ulCode > cp)
ulHi = ulNext;
else {
lFound = ulNext;
break;
}
}
return (lFound == -1)? NULL : aCP2Name[lFound].pszName;
}
unsigned long os2cpFromName(char *cp)
{
ULONG ulLo = 0;
ULONG ulHi = (sizeof(aName2CP) / sizeof(struct _NAME2CP)) - 1;
ULONG ulNext;
LONG lFound = -1;
LONG lCmp;
PCHAR pcEnd;
CHAR acBuf[64];
if (cp == NULL) {
ULONG aulCP[3];
ULONG cCP;
return (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)? 0 : aulCP[0];
}
while (isspace(*cp))
cp++;
pcEnd = strchr(cp, ' ');
if (pcEnd == NULL)
pcEnd = strchr(cp, '\0');
ulNext = pcEnd - cp;
if (ulNext >= sizeof(acBuf))
return 0;
memcpy(acBuf, cp, ulNext);
acBuf[ulNext] = '\0';
strupr(acBuf);
lCmp = strcmp(aName2CP[0].pszName, acBuf);
if (lCmp > 0)
return 0;
else if (lCmp == 0)
return aName2CP[0].ulCode;
lCmp = strcmp(aName2CP[ulHi].pszName, acBuf);
if (lCmp < 0)
return 0;
else if (lCmp == 0)
return aName2CP[ulHi].ulCode;
while ((ulHi - ulLo) > 1) {
ulNext = (ulLo + ulHi) / 2;
lCmp = strcmp(aName2CP[ulNext].pszName, acBuf);
if (lCmp < 0)
ulLo = ulNext;
else if (lCmp > 0)
ulHi = ulNext;
else {
lFound = ulNext;
break;
}
}
return (lFound == -1)? 0 : aName2CP[lFound].ulCode;
}
/* vi: set ts=4 sw=4 expandtab: */

32
externals/SDL/src/core/os2/geniconv/os2cp.h vendored Executable file
View File

@@ -0,0 +1,32 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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.
*/
#ifndef OS2CP_H
#define OS2CP_H 1
#define SYSTEM_CP 0
char *os2cpToName(unsigned long cp);
unsigned long os2cpFromName(char *cp);
#endif /* OS2CP_H */
/* vi: set ts=4 sw=4 expandtab: */

270
externals/SDL/src/core/os2/geniconv/os2iconv.c vendored Executable file
View File

@@ -0,0 +1,270 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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.
*/
/*
Implementation iconv via OS/2 conversion objects API.
Andrey Vasilkin.
*/
#define ICONV_THREAD_SAFE 1
#include "geniconv.h"
#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"
#if !defined(min)
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
#define MAX_CP_NAME_LEN 64
typedef struct iuconv_obj {
UconvObject uo_tocode;
UconvObject uo_fromcode;
int buf_len;
UniChar *buf;
#ifdef ICONV_THREAD_SAFE
HMTX hMtx;
#endif
} iuconv_obj;
static int _createUconvObj(const char *code, UconvObject *uobj)
{
UniChar uc_code[MAX_CP_NAME_LEN];
int i;
const char *ch = code;
if (code == NULL)
uc_code[0] = 0;
else {
for (i = 0; i < MAX_CP_NAME_LEN; i++) {
uc_code[i] = (unsigned short)*ch;
if (! (*ch))
break;
ch++;
}
}
return UniCreateUconvObject(uc_code, uobj);
}
static int uconv_open(const char *code, UconvObject *uobj)
{
int rc;
if (!stricmp(code, "UTF-16")) {
*uobj = NULL;
return ULS_SUCCESS;
}
rc = _createUconvObj(code, uobj);
if (rc != ULS_SUCCESS) {
unsigned long cp = os2cpFromName((char *)code);
char cp_name[16];
if (cp != 0 && _snprintf(cp_name, sizeof(cp_name), "IBM-%u", cp) > 0)
rc = _createUconvObj(cp_name, uobj);
}
return rc;
}
extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
{
UconvObject uo_tocode;
UconvObject uo_fromcode;
int rc;
iuconv_obj *iuobj;
if (tocode == NULL)
tocode = "";
if (fromcode == NULL)
fromcode = "";
if (stricmp(tocode, fromcode) != 0) {
rc = uconv_open(fromcode, &uo_fromcode);
if (rc != ULS_SUCCESS) {
errno = EINVAL;
return (iconv_t)(-1);
}
rc = uconv_open(tocode, &uo_tocode);
if (rc != ULS_SUCCESS) {
UniFreeUconvObject(uo_fromcode);
errno = EINVAL;
return (iconv_t)(-1);
}
} else {
uo_tocode = NULL;
uo_fromcode = NULL;
}
iuobj = (iuconv_obj *) malloc(sizeof(iuconv_obj));
iuobj->uo_tocode = uo_tocode;
iuobj->uo_fromcode = uo_fromcode;
iuobj->buf_len = 0;
iuobj->buf = NULL;
#ifdef ICONV_THREAD_SAFE
DosCreateMutexSem(NULL, &iuobj->hMtx, 0, FALSE);
#endif
return iuobj;
}
extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
size_t *inbytesleft,
char* * outbuf, size_t *outbytesleft)
{
UconvObject uo_tocode = ((iuconv_obj *)(cd))->uo_tocode;
UconvObject uo_fromcode = ((iuconv_obj *)(cd))->uo_fromcode;
size_t nonIdenticalConv = 0;
UniChar *uc_buf;
size_t uc_buf_len;
UniChar **uc_str;
size_t *uc_str_len;
int rc;
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);
*inbytesleft -= uc_buf_len;
*outbytesleft -= uc_buf_len;
outbuf += uc_buf_len;
inbuf += uc_buf_len;
return uc_buf_len;
}
#ifdef ICONV_THREAD_SAFE
DosRequestMutexSem(((iuconv_obj *)(cd))->hMtx, SEM_INDEFINITE_WAIT);
#endif
if (uo_tocode && uo_fromcode &&
(((iuconv_obj *)cd)->buf_len >> 1) < *inbytesleft) {
if (((iuconv_obj *)cd)->buf != NULL)
free(((iuconv_obj *)cd)->buf);
((iuconv_obj *)cd)->buf_len = *inbytesleft << 1;
((iuconv_obj *)cd)->buf = (UniChar *)malloc(((iuconv_obj *)cd)->buf_len);
}
if (uo_fromcode) {
if (uo_tocode) {
uc_buf = ((iuconv_obj *)cd)->buf;
uc_buf_len = ((iuconv_obj *)cd)->buf_len;
uc_str = &uc_buf;
} else {
uc_str = (UniChar **)outbuf;
uc_buf_len = *outbytesleft;
}
uc_buf_len = uc_buf_len >> 1;
uc_str_len = &uc_buf_len;
rc = UniUconvToUcs(uo_fromcode, (void **)inbuf, inbytesleft,
uc_str, uc_str_len, &nonIdenticalConv);
uc_buf_len = uc_buf_len << 1;
if (!uo_tocode)
*outbytesleft = uc_buf_len;
if (rc != ULS_SUCCESS) {
errno = EILSEQ;
goto done;
} else if (*inbytesleft && !*uc_str_len) {
errno = E2BIG;
goto done;
}
if (!uo_tocode)
return nonIdenticalConv;
uc_buf = ((iuconv_obj *)cd)->buf;
uc_buf_len = ((iuconv_obj *)cd)->buf_len - uc_buf_len;
uc_str = &uc_buf;
uc_str_len = &uc_buf_len;
} else {
uc_str = (UniChar **)inbuf;
uc_str_len = inbytesleft;
}
*uc_str_len = *uc_str_len>>1;
rc = UniUconvFromUcs(uo_tocode, uc_str, uc_str_len, (void **)outbuf,
outbytesleft, &nonIdenticalConv);
if (rc != ULS_SUCCESS) {
switch (rc) {
case ULS_BUFFERFULL:
errno = E2BIG;
break;
case ULS_ILLEGALSEQUENCE:
errno = EILSEQ;
break;
case ULS_INVALID:
errno = EINVAL;
break;
}
goto done;
} else if (*uc_str_len && !*outbytesleft) {
errno = E2BIG;
goto done;
}
ret = nonIdenticalConv;
done:
#ifdef ICONV_THREAD_SAFE
DosReleaseMutexSem(((iuconv_obj *)cd)->hMtx);
#endif
return ret;
}
int _System os2_iconv_close(iconv_t cd)
{
if (!cd) return 0;
#ifdef ICONV_THREAD_SAFE
DosCloseMutexSem(((iuconv_obj *)cd)->hMtx);
#endif
if (((iuconv_obj *)cd)->uo_tocode != NULL)
UniFreeUconvObject(((iuconv_obj *)cd)->uo_tocode);
if (((iuconv_obj *)cd)->uo_fromcode != NULL)
UniFreeUconvObject(((iuconv_obj *)cd)->uo_fromcode);
if (((iuconv_obj *)cd)->buf != NULL)
free(((iuconv_obj *)cd)->buf);
free(cd);
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */

107
externals/SDL/src/core/os2/geniconv/sys2utf8.c vendored Executable file
View File

@@ -0,0 +1,107 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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 "geniconv.h"
#include <stdlib.h>
int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
{
size_t rc;
char *pcDstStart = pcDst;
iconv_t cd;
char *pszToCP, *pszFromCP;
int fError = 0;
if (cbDst < 4)
return -1;
if (fToUTF8) {
pszToCP = "UTF-8";
pszFromCP = "";
} else {
pszToCP = "";
pszFromCP = "UTF-8";
}
cd = iconv_open(pszToCP, pszFromCP);
if (cd == (iconv_t)-1)
return -1;
while (cbSrc > 0) {
rc = iconv(cd, &pcSrc, (size_t *)&cbSrc, &pcDst, (size_t *)&cbDst);
if (rc == (size_t)-1) {
if (errno == EILSEQ) {
/* Try to skip invalid character */
pcSrc++;
cbSrc--;
continue;
}
fError = 1;
break;
}
}
iconv_close(cd);
/* Write trailing ZERO (1 byte for UTF-8, 2 bytes for the system cp) */
if (fToUTF8) {
if (cbDst < 1) {
pcDst--;
fError = 1; /* The destination buffer overflow */
}
*pcDst = '\0';
} else {
if (cbDst < 2) {
pcDst -= (cbDst == 0)? 2 : 1;
fError = 1; /* The destination buffer overflow */
}
*((short *)pcDst) = '\0';
}
return (fError) ? -1 : (pcDst - pcDstStart);
}
char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr)
{
int cbNewStr = (((cbStr > 4)? cbStr : 4) + 1) * 2;
char *pszNewStr = (char *) 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)));
if (pcStr)
return pcStr;
}
free(pszNewStr);
return NULL;
}
void StrUTF8Free(char *pszStr)
{
free(pszStr);
}
/* vi: set ts=4 sw=4 expandtab: */

69
externals/SDL/src/core/os2/geniconv/test.c vendored Executable file
View File

@@ -0,0 +1,69 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "geniconv.h"
int main(void)
{
char acBuf[128];
char *inbuf = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"; /* KOI8-R string */
size_t inbytesleft = strlen(inbuf);
char *outbuf = acBuf;
size_t outbytesleft = sizeof(acBuf);
iconv_t ic;
/* KOI8 -> system cp */
ic = iconv_open("", "KOI8-R");
if (ic == (iconv_t)(-1)) {
puts("iconv_open() fail");
return 1;
}
iconv(ic, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
printf("KOI8-R to system cp: %s\n", acBuf);
iconv_close(ic);
/* System cp -> UTF-8 -> system cp: */
/* System cp -> UTF-8 by StrUTF8New() */
inbuf = StrUTF8New(1, acBuf, strlen(acBuf));
/* UTF-8 -> system cp. by StrUTF8() */
if (StrUTF8(0, acBuf, sizeof(acBuf), inbuf, strlen(inbuf)) == -1) {
puts("StrUTF8() failed");
} else {
printf("system cp. -> UTF-8 -> system cp.: %s\n", acBuf);
}
free(inbuf);
/* Unload used DLL */
iconv_clean();
puts("Done.");
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -21,7 +21,6 @@
#include "../../SDL_internal.h"
#include "SDL_assert.h"
#include "SDL_poll.h"
#ifdef HAVE_POLL

94
externals/SDL/src/core/windows/SDL_hid.c vendored Executable file
View File

@@ -0,0 +1,94 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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"
#ifndef __WINRT__
#include "SDL_hid.h"
HidD_GetString_t SDL_HidD_GetManufacturerString;
HidD_GetString_t SDL_HidD_GetProductString;
HidD_GetPreparsedData_t SDL_HidD_GetPreparsedData;
HidD_FreePreparsedData_t SDL_HidD_FreePreparsedData;
HidP_GetCaps_t SDL_HidP_GetCaps;
HidP_GetButtonCaps_t SDL_HidP_GetButtonCaps;
HidP_GetValueCaps_t SDL_HidP_GetValueCaps;
HidP_MaxDataListLength_t SDL_HidP_MaxDataListLength;
HidP_GetData_t SDL_HidP_GetData;
static HMODULE s_pHIDDLL = 0;
static int s_HIDDLLRefCount = 0;
int
WIN_LoadHIDDLL(void)
{
if (s_pHIDDLL) {
SDL_assert(s_HIDDLLRefCount > 0);
s_HIDDLLRefCount++;
return 0; /* already loaded */
}
s_pHIDDLL = LoadLibrary(L"hid.dll");
if (!s_pHIDDLL) {
return -1;
}
SDL_assert(s_HIDDLLRefCount == 0);
s_HIDDLLRefCount = 1;
SDL_HidD_GetManufacturerString = (HidD_GetString_t)GetProcAddress(s_pHIDDLL, "HidD_GetManufacturerString");
SDL_HidD_GetProductString = (HidD_GetString_t)GetProcAddress(s_pHIDDLL, "HidD_GetProductString");
SDL_HidD_GetPreparsedData = (HidD_GetPreparsedData_t)GetProcAddress(s_pHIDDLL, "HidD_GetPreparsedData");
SDL_HidD_FreePreparsedData = (HidD_FreePreparsedData_t)GetProcAddress(s_pHIDDLL, "HidD_FreePreparsedData");
SDL_HidP_GetCaps = (HidP_GetCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetCaps");
SDL_HidP_GetButtonCaps = (HidP_GetButtonCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetButtonCaps");
SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps");
SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength");
SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData");
if (!SDL_HidD_GetManufacturerString || !SDL_HidD_GetProductString || !SDL_HidD_GetPreparsedData ||
!SDL_HidD_FreePreparsedData || !SDL_HidP_GetCaps || !SDL_HidP_GetButtonCaps ||
!SDL_HidP_GetValueCaps || !SDL_HidP_MaxDataListLength || !SDL_HidP_GetData) {
WIN_UnloadHIDDLL();
return -1;
}
return 0;
}
void
WIN_UnloadHIDDLL(void)
{
if (s_pHIDDLL) {
SDL_assert(s_HIDDLLRefCount > 0);
if (--s_HIDDLLRefCount == 0) {
FreeLibrary(s_pHIDDLL);
s_pHIDDLL = NULL;
}
} else {
SDL_assert(s_HIDDLLRefCount == 0);
}
}
#endif /* !__WINRT__ */
/* vi: set ts=4 sw=4 expandtab: */

208
externals/SDL/src/core/windows/SDL_hid.h vendored Executable file
View File

@@ -0,0 +1,208 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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"
#ifndef SDL_hid_h_
#define SDL_hid_h_
#include "SDL_windows.h"
#ifndef __WINRT__
typedef LONG NTSTATUS;
typedef USHORT USAGE;
typedef struct _HIDP_PREPARSED_DATA *PHIDP_PREPARSED_DATA;
typedef struct _HIDD_ATTRIBUTES
{
ULONG Size;
USHORT VendorID;
USHORT ProductID;
USHORT VersionNumber;
} HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
typedef enum {
HidP_Input = 0,
HidP_Output = 1,
HidP_Feature = 2
} HIDP_REPORT_TYPE;
typedef struct {
USAGE UsagePage;
UCHAR ReportID;
BOOLEAN IsAlias;
USHORT BitField;
USHORT LinkCollection;
USAGE LinkUsage;
USAGE LinkUsagePage;
BOOLEAN IsRange;
BOOLEAN IsStringRange;
BOOLEAN IsDesignatorRange;
BOOLEAN IsAbsolute;
ULONG Reserved[ 10 ];
union {
struct {
USAGE UsageMin;
USAGE UsageMax;
USHORT StringMin;
USHORT StringMax;
USHORT DesignatorMin;
USHORT DesignatorMax;
USHORT DataIndexMin;
USHORT DataIndexMax;
} Range;
struct {
USAGE Usage;
USAGE Reserved1;
USHORT StringIndex;
USHORT Reserved2;
USHORT DesignatorIndex;
USHORT Reserved3;
USHORT DataIndex;
USHORT Reserved4;
} NotRange;
};
} HIDP_BUTTON_CAPS, *PHIDP_BUTTON_CAPS;
typedef struct {
USAGE UsagePage;
UCHAR ReportID;
BOOLEAN IsAlias;
USHORT BitField;
USHORT LinkCollection;
USAGE LinkUsage;
USAGE LinkUsagePage;
BOOLEAN IsRange;
BOOLEAN IsStringRange;
BOOLEAN IsDesignatorRange;
BOOLEAN IsAbsolute;
BOOLEAN HasNull;
UCHAR Reserved;
USHORT BitSize;
USHORT ReportCount;
USHORT Reserved2[ 5 ];
ULONG UnitsExp;
ULONG Units;
LONG LogicalMin;
LONG LogicalMax;
LONG PhysicalMin;
LONG PhysicalMax;
union {
struct {
USAGE UsageMin;
USAGE UsageMax;
USHORT StringMin;
USHORT StringMax;
USHORT DesignatorMin;
USHORT DesignatorMax;
USHORT DataIndexMin;
USHORT DataIndexMax;
} Range;
struct {
USAGE Usage;
USAGE Reserved1;
USHORT StringIndex;
USHORT Reserved2;
USHORT DesignatorIndex;
USHORT Reserved3;
USHORT DataIndex;
USHORT Reserved4;
} NotRange;
};
} HIDP_VALUE_CAPS, *PHIDP_VALUE_CAPS;
typedef struct {
USAGE Usage;
USAGE UsagePage;
USHORT InputReportByteLength;
USHORT OutputReportByteLength;
USHORT FeatureReportByteLength;
USHORT Reserved[ 17 ];
USHORT NumberLinkCollectionNodes;
USHORT NumberInputButtonCaps;
USHORT NumberInputValueCaps;
USHORT NumberInputDataIndices;
USHORT NumberOutputButtonCaps;
USHORT NumberOutputValueCaps;
USHORT NumberOutputDataIndices;
USHORT NumberFeatureButtonCaps;
USHORT NumberFeatureValueCaps;
USHORT NumberFeatureDataIndices;
} HIDP_CAPS, *PHIDP_CAPS;
typedef struct {
USHORT DataIndex;
USHORT Reserved;
union {
ULONG RawValue;
BOOLEAN On;
};
} HIDP_DATA, *PHIDP_DATA;
#define HIDP_ERROR_CODES( p1, p2 ) ((NTSTATUS)(((p1) << 28) | (0x11 << 16) | (p2)))
#define HIDP_STATUS_SUCCESS HIDP_ERROR_CODES( 0x0, 0x0000 )
#define HIDP_STATUS_NULL HIDP_ERROR_CODES( 0x8, 0x0001 )
#define HIDP_STATUS_INVALID_PREPARSED_DATA HIDP_ERROR_CODES( 0xC, 0x0001 )
#define HIDP_STATUS_INVALID_REPORT_TYPE HIDP_ERROR_CODES( 0xC, 0x0002 )
#define HIDP_STATUS_INVALID_REPORT_LENGTH HIDP_ERROR_CODES( 0xC, 0x0003 )
#define HIDP_STATUS_USAGE_NOT_FOUND HIDP_ERROR_CODES( 0xC, 0x0004 )
#define HIDP_STATUS_VALUE_OUT_OF_RANGE HIDP_ERROR_CODES( 0xC, 0x0005 )
#define HIDP_STATUS_BAD_LOG_PHY_VALUES HIDP_ERROR_CODES( 0xC, 0x0006 )
#define HIDP_STATUS_BUFFER_TOO_SMALL HIDP_ERROR_CODES( 0xC, 0x0007 )
#define HIDP_STATUS_INTERNAL_ERROR HIDP_ERROR_CODES( 0xC, 0x0008 )
#define HIDP_STATUS_I8042_TRANS_UNKNOWN HIDP_ERROR_CODES( 0xC, 0x0009 )
#define HIDP_STATUS_INCOMPATIBLE_REPORT_ID HIDP_ERROR_CODES( 0xC, 0x000A )
#define HIDP_STATUS_NOT_VALUE_ARRAY HIDP_ERROR_CODES( 0xC, 0x000B )
#define HIDP_STATUS_IS_VALUE_ARRAY HIDP_ERROR_CODES( 0xC, 0x000C )
#define HIDP_STATUS_DATA_INDEX_NOT_FOUND HIDP_ERROR_CODES( 0xC, 0x000D )
#define HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE HIDP_ERROR_CODES( 0xC, 0x000E )
#define HIDP_STATUS_BUTTON_NOT_PRESSED HIDP_ERROR_CODES( 0xC, 0x000F )
#define HIDP_STATUS_REPORT_DOES_NOT_EXIST HIDP_ERROR_CODES( 0xC, 0x0010 )
#define HIDP_STATUS_NOT_IMPLEMENTED HIDP_ERROR_CODES( 0xC, 0x0020 )
extern int WIN_LoadHIDDLL(void);
extern void WIN_UnloadHIDDLL(void);
typedef BOOLEAN (WINAPI *HidD_GetString_t)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
typedef BOOLEAN (WINAPI *HidD_GetPreparsedData_t)(HANDLE HidDeviceObject, PHIDP_PREPARSED_DATA *PreparsedData);
typedef BOOLEAN (WINAPI *HidD_FreePreparsedData_t)(PHIDP_PREPARSED_DATA PreparsedData);
typedef NTSTATUS (WINAPI *HidP_GetCaps_t)(PHIDP_PREPARSED_DATA PreparsedData, PHIDP_CAPS Capabilities);
typedef NTSTATUS (WINAPI *HidP_GetButtonCaps_t)(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAPS ButtonCaps, PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
typedef NTSTATUS (WINAPI *HidP_GetValueCaps_t)(HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps, PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
typedef ULONG (WINAPI *HidP_MaxDataListLength_t)(HIDP_REPORT_TYPE ReportType, PHIDP_PREPARSED_DATA PreparsedData);
typedef NTSTATUS (WINAPI *HidP_GetData_t)(HIDP_REPORT_TYPE ReportType, PHIDP_DATA DataList, PULONG DataLength, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
extern HidD_GetString_t SDL_HidD_GetManufacturerString;
extern HidD_GetString_t SDL_HidD_GetProductString;
extern HidD_GetPreparsedData_t SDL_HidD_GetPreparsedData;
extern HidD_FreePreparsedData_t SDL_HidD_FreePreparsedData;
extern HidP_GetCaps_t SDL_HidP_GetCaps;
extern HidP_GetButtonCaps_t SDL_HidP_GetButtonCaps;
extern HidP_GetValueCaps_t SDL_HidP_GetValueCaps;
extern HidP_MaxDataListLength_t SDL_HidP_MaxDataListLength;
extern HidP_GetData_t SDL_HidP_GetData;
#endif /* !__WINRT__ */
#endif /* SDL_hid_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -24,7 +24,6 @@
#include "SDL_windows.h"
#include "SDL_error.h"
#include "SDL_assert.h"
#include <objbase.h> /* for CoInitialize/CoUninitialize (Win32 only) */

View File

@@ -20,7 +20,6 @@
*/
#include "../../SDL_internal.h"
#include "SDL_assert.h"
#include "SDL_xinput.h"
@@ -82,6 +81,10 @@ WIN_LoadXInputDLL(void)
return 0; /* already loaded */
}
/* NOTE: Don't load XinputUap.dll
* This is XInput emulation over Windows.Gaming.Input, and has all the
* limitations of that API (no devices at startup, no background input, etc.)
*/
version = (1 << 16) | 4;
s_pXInputDLL = LoadLibrary(L"XInput1_4.dll"); /* 1.4 Ships with Windows 8. */
if (!s_pXInputDLL) {

View File

@@ -47,10 +47,8 @@ using namespace Windows::Phone::UI::Input;
/* SDL includes */
extern "C" {
#include "SDL_assert.h"
#include "SDL_events.h"
#include "SDL_hints.h"
#include "SDL_log.h"
#include "SDL_main.h"
#include "SDL_stdinc.h"
#include "SDL_render.h"