summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/SDL2/src/core
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/SDL2/src/core')
-rw-r--r--3rdparty/SDL2/src/core/android/SDL_android.c1776
-rw-r--r--3rdparty/SDL2/src/core/android/SDL_android.h92
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_dbus.c239
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_dbus.h82
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_evdev.c873
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_evdev.h39
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_fcitx.c553
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_fcitx.h40
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_ibus.c682
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_ibus.h58
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_ime.c138
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_ime.h38
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_udev.c539
-rw-r--r--3rdparty/SDL2/src/core/linux/SDL_udev.h119
-rw-r--r--3rdparty/SDL2/src/core/windows/SDL_directx.h111
-rw-r--r--3rdparty/SDL2/src/core/windows/SDL_windows.c207
-rw-r--r--3rdparty/SDL2/src/core/windows/SDL_windows.h67
-rw-r--r--3rdparty/SDL2/src/core/windows/SDL_xinput.c139
-rw-r--r--3rdparty/SDL2/src/core/windows/SDL_xinput.h172
-rw-r--r--3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.cpp37
-rw-r--r--3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.h31
-rw-r--r--3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.cpp855
-rw-r--r--3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.h92
-rw-r--r--3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.cpp160
-rw-r--r--3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.h33
25 files changed, 0 insertions, 7172 deletions
diff --git a/3rdparty/SDL2/src/core/android/SDL_android.c b/3rdparty/SDL2/src/core/android/SDL_android.c
deleted file mode 100644
index b93b1625516..00000000000
--- a/3rdparty/SDL2/src/core/android/SDL_android.c
+++ /dev/null
@@ -1,1776 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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 "SDL_stdinc.h"
-#include "SDL_assert.h"
-#include "SDL_hints.h"
-#include "SDL_log.h"
-
-#ifdef __ANDROID__
-
-#include "SDL_system.h"
-#include "SDL_android.h"
-#include <EGL/egl.h>
-
-#include "../../events/SDL_events_c.h"
-#include "../../video/android/SDL_androidkeyboard.h"
-#include "../../video/android/SDL_androidmouse.h"
-#include "../../video/android/SDL_androidtouch.h"
-#include "../../video/android/SDL_androidvideo.h"
-#include "../../video/android/SDL_androidwindow.h"
-#include "../../joystick/android/SDL_sysjoystick_c.h"
-
-#include <android/log.h>
-#include <pthread.h>
-#include <sys/types.h>
-#include <unistd.h>
-#define LOG_TAG "SDL_android"
-/* #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) */
-/* #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) */
-#define LOGI(...) do {} while (0)
-#define LOGE(...) do {} while (0)
-
-/* Uncomment this to log messages entering and exiting methods in this file */
-/* #define DEBUG_JNI */
-
-static void Android_JNI_ThreadDestroyed(void*);
-
-/*******************************************************************************
- This file links the Java side of Android with libsdl
-*******************************************************************************/
-#include <jni.h>
-#include <android/log.h>
-
-
-/*******************************************************************************
- Globals
-*******************************************************************************/
-static pthread_key_t mThreadKey;
-static JavaVM* mJavaVM;
-
-/* Main activity */
-static jclass mActivityClass;
-
-/* method signatures */
-static jmethodID midGetNativeSurface;
-static jmethodID midAudioOpen;
-static jmethodID midAudioWriteShortBuffer;
-static jmethodID midAudioWriteByteBuffer;
-static jmethodID midAudioClose;
-static jmethodID midCaptureOpen;
-static jmethodID midCaptureReadShortBuffer;
-static jmethodID midCaptureReadByteBuffer;
-static jmethodID midCaptureClose;
-static jmethodID midPollInputDevices;
-
-/* Accelerometer data storage */
-static float fLastAccelerometer[3];
-static SDL_bool bHasNewData;
-
-/*******************************************************************************
- Functions called by JNI
-*******************************************************************************/
-
-/* Library init */
-JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
-{
- JNIEnv *env;
- mJavaVM = vm;
- LOGI("JNI_OnLoad called");
- if ((*mJavaVM)->GetEnv(mJavaVM, (void**) &env, JNI_VERSION_1_4) != JNI_OK) {
- LOGE("Failed to get the environment using GetEnv()");
- return -1;
- }
- /*
- * Create mThreadKey so we can keep track of the JNIEnv assigned to each thread
- * Refer to http://developer.android.com/guide/practices/design/jni.html for the rationale behind this
- */
- if (pthread_key_create(&mThreadKey, Android_JNI_ThreadDestroyed) != 0) {
- __android_log_print(ANDROID_LOG_ERROR, "SDL", "Error initializing pthread key");
- }
- Android_JNI_SetupThread();
-
- return JNI_VERSION_1_4;
-}
-
-/* Called before SDL_main() to initialize JNI bindings */
-JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
-{
- __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init()");
-
- Android_JNI_SetupThread();
-
- mActivityClass = (jclass)((*mEnv)->NewGlobalRef(mEnv, cls));
-
- midGetNativeSurface = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "getNativeSurface","()Landroid/view/Surface;");
- midAudioOpen = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "audioOpen", "(IZZI)I");
- midAudioWriteShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "audioWriteShortBuffer", "([S)V");
- midAudioWriteByteBuffer = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "audioWriteByteBuffer", "([B)V");
- midAudioClose = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "audioClose", "()V");
- midCaptureOpen = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "captureOpen", "(IZZI)I");
- midCaptureReadShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "captureReadShortBuffer", "([SZ)I");
- midCaptureReadByteBuffer = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "captureReadByteBuffer", "([BZ)I");
- midCaptureClose = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "captureClose", "()V");
- midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "pollInputDevices", "()V");
-
- bHasNewData = SDL_FALSE;
-
- if (!midGetNativeSurface ||
- !midAudioOpen || !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioClose ||
- !midCaptureOpen || !midCaptureReadShortBuffer || !midCaptureReadByteBuffer || !midCaptureClose ||
- !midPollInputDevices) {
- __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
- }
- __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init() finished!");
-}
-
-/* Drop file */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeDropFile(
- JNIEnv* env, jclass jcls,
- jstring filename)
-{
- const char *path = (*env)->GetStringUTFChars(env, filename, NULL);
- SDL_SendDropFile(NULL, path);
- (*env)->ReleaseStringUTFChars(env, filename, path);
- SDL_SendDropComplete(NULL);
-}
-
-/* Resize */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeResize(
- JNIEnv* env, jclass jcls,
- jint width, jint height, jint format, jfloat rate)
-{
- Android_SetScreenResolution(width, height, format, rate);
-}
-
-/* Paddown */
-JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_onNativePadDown(
- JNIEnv* env, jclass jcls,
- jint device_id, jint keycode)
-{
- return Android_OnPadDown(device_id, keycode);
-}
-
-/* Padup */
-JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_onNativePadUp(
- JNIEnv* env, jclass jcls,
- jint device_id, jint keycode)
-{
- return Android_OnPadUp(device_id, keycode);
-}
-
-/* Joy */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeJoy(
- JNIEnv* env, jclass jcls,
- jint device_id, jint axis, jfloat value)
-{
- Android_OnJoy(device_id, axis, value);
-}
-
-/* POV Hat */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeHat(
- JNIEnv* env, jclass jcls,
- jint device_id, jint hat_id, jint x, jint y)
-{
- Android_OnHat(device_id, hat_id, x, y);
-}
-
-
-JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_nativeAddJoystick(
- JNIEnv* env, jclass jcls,
- jint device_id, jstring device_name, jint is_accelerometer,
- jint nbuttons, jint naxes, jint nhats, jint nballs)
-{
- int retval;
- const char *name = (*env)->GetStringUTFChars(env, device_name, NULL);
-
- retval = Android_AddJoystick(device_id, name, (SDL_bool) is_accelerometer, nbuttons, naxes, nhats, nballs);
-
- (*env)->ReleaseStringUTFChars(env, device_name, name);
-
- return retval;
-}
-
-JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_nativeRemoveJoystick(
- JNIEnv* env, jclass jcls, jint device_id)
-{
- return Android_RemoveJoystick(device_id);
-}
-
-
-/* Surface Created */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeSurfaceChanged(JNIEnv* env, jclass jcls)
-{
- SDL_WindowData *data;
- SDL_VideoDevice *_this;
-
- if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
- return;
- }
-
- _this = SDL_GetVideoDevice();
- data = (SDL_WindowData *) Android_Window->driverdata;
-
- /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
- if (data->egl_surface == EGL_NO_SURFACE) {
- if(data->native_window) {
- ANativeWindow_release(data->native_window);
- }
- data->native_window = Android_JNI_GetNativeWindow();
- data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
- }
-
- /* GL Context handling is done in the event loop because this function is run from the Java thread */
-
-}
-
-/* Surface Destroyed */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeSurfaceDestroyed(JNIEnv* env, jclass jcls)
-{
- /* We have to clear the current context and destroy the egl surface here
- * Otherwise there's BAD_NATIVE_WINDOW errors coming from eglCreateWindowSurface on resume
- * Ref: http://stackoverflow.com/questions/8762589/eglcreatewindowsurface-on-ics-and-switching-from-2d-to-3d
- */
- SDL_WindowData *data;
- SDL_VideoDevice *_this;
-
- if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
- return;
- }
-
- _this = SDL_GetVideoDevice();
- data = (SDL_WindowData *) Android_Window->driverdata;
-
- if (data->egl_surface != EGL_NO_SURFACE) {
- SDL_EGL_MakeCurrent(_this, NULL, NULL);
- SDL_EGL_DestroySurface(_this, data->egl_surface);
- data->egl_surface = EGL_NO_SURFACE;
- }
-
- /* GL Context handling is done in the event loop because this function is run from the Java thread */
-
-}
-
-/* Keydown */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyDown(
- JNIEnv* env, jclass jcls, jint keycode)
-{
- Android_OnKeyDown(keycode);
-}
-
-/* Keyup */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyUp(
- JNIEnv* env, jclass jcls, jint keycode)
-{
- Android_OnKeyUp(keycode);
-}
-
-/* Keyboard Focus Lost */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyboardFocusLost(
- JNIEnv* env, jclass jcls)
-{
- /* Calling SDL_StopTextInput will take care of hiding the keyboard and cleaning up the DummyText widget */
- SDL_StopTextInput();
-}
-
-
-/* Touch */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeTouch(
- JNIEnv* env, jclass jcls,
- jint touch_device_id_in, jint pointer_finger_id_in,
- jint action, jfloat x, jfloat y, jfloat p)
-{
- Android_OnTouch(touch_device_id_in, pointer_finger_id_in, action, x, y, p);
-}
-
-/* Mouse */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeMouse(
- JNIEnv* env, jclass jcls,
- jint button, jint action, jfloat x, jfloat y)
-{
- Android_OnMouse(button, action, x, y);
-}
-
-/* Accelerometer */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeAccel(
- JNIEnv* env, jclass jcls,
- jfloat x, jfloat y, jfloat z)
-{
- fLastAccelerometer[0] = x;
- fLastAccelerometer[1] = y;
- fLastAccelerometer[2] = z;
- bHasNewData = SDL_TRUE;
-}
-
-/* Low memory */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeLowMemory(
- JNIEnv* env, jclass cls)
-{
- SDL_SendAppEvent(SDL_APP_LOWMEMORY);
-}
-
-/* Quit */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeQuit(
- JNIEnv* env, jclass cls)
-{
- /* Discard previous events. The user should have handled state storage
- * in SDL_APP_WILLENTERBACKGROUND. After nativeQuit() is called, no
- * events other than SDL_QUIT and SDL_APP_TERMINATING should fire */
- SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
- /* Inject a SDL_QUIT event */
- SDL_SendQuit();
- SDL_SendAppEvent(SDL_APP_TERMINATING);
- /* Resume the event loop so that the app can catch SDL_QUIT which
- * should now be the top event in the event queue. */
- if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
-}
-
-/* Pause */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativePause(
- JNIEnv* env, jclass cls)
-{
- __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
- if (Android_Window) {
- SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
- SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
- SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
- SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
-
- /* *After* sending the relevant events, signal the pause semaphore
- * so the event loop knows to pause and (optionally) block itself */
- if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem);
- }
-}
-
-/* Resume */
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeResume(
- JNIEnv* env, jclass cls)
-{
- __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeResume()");
-
- if (Android_Window) {
- SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
- SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
- SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
- SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0);
- /* Signal the resume semaphore so the event loop knows to resume and restore the GL Context
- * We can't restore the GL Context here because it needs to be done on the SDL main thread
- * and this function will be called from the Java thread instead.
- */
- if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
- }
-}
-
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeCommitText(
- JNIEnv* env, jclass cls,
- jstring text, jint newCursorPosition)
-{
- const char *utftext = (*env)->GetStringUTFChars(env, text, NULL);
-
- SDL_SendKeyboardText(utftext);
-
- (*env)->ReleaseStringUTFChars(env, text, utftext);
-}
-
-JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeSetComposingText(
- JNIEnv* env, jclass cls,
- jstring text, jint newCursorPosition)
-{
- const char *utftext = (*env)->GetStringUTFChars(env, text, NULL);
-
- SDL_SendEditingText(utftext, 0, 0);
-
- (*env)->ReleaseStringUTFChars(env, text, utftext);
-}
-
-JNIEXPORT jstring JNICALL Java_org_libsdl_app_SDLActivity_nativeGetHint(JNIEnv* env, jclass cls, jstring name) {
- const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
- const char *hint = SDL_GetHint(utfname);
-
- jstring result = (*env)->NewStringUTF(env, hint);
- (*env)->ReleaseStringUTFChars(env, name, utfname);
-
- return result;
-}
-
-/*******************************************************************************
- Functions called by SDL into Java
-*******************************************************************************/
-
-static int s_active = 0;
-struct LocalReferenceHolder
-{
- JNIEnv *m_env;
- const char *m_func;
-};
-
-static struct LocalReferenceHolder LocalReferenceHolder_Setup(const char *func)
-{
- struct LocalReferenceHolder refholder;
- refholder.m_env = NULL;
- refholder.m_func = func;
-#ifdef DEBUG_JNI
- SDL_Log("Entering function %s", func);
-#endif
- return refholder;
-}
-
-static SDL_bool LocalReferenceHolder_Init(struct LocalReferenceHolder *refholder, JNIEnv *env)
-{
- const int capacity = 16;
- if ((*env)->PushLocalFrame(env, capacity) < 0) {
- SDL_SetError("Failed to allocate enough JVM local references");
- return SDL_FALSE;
- }
- ++s_active;
- refholder->m_env = env;
- return SDL_TRUE;
-}
-
-static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder)
-{
-#ifdef DEBUG_JNI
- SDL_Log("Leaving function %s", refholder->m_func);
-#endif
- if (refholder->m_env) {
- JNIEnv* env = refholder->m_env;
- (*env)->PopLocalFrame(env, NULL);
- --s_active;
- }
-}
-
-static SDL_bool LocalReferenceHolder_IsActive(void)
-{
- return s_active > 0;
-}
-
-ANativeWindow* Android_JNI_GetNativeWindow(void)
-{
- ANativeWindow* anw;
- jobject s;
- JNIEnv *env = Android_JNI_GetEnv();
-
- s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface);
- anw = ANativeWindow_fromSurface(env, s);
- (*env)->DeleteLocalRef(env, s);
-
- return anw;
-}
-
-void Android_JNI_SetActivityTitle(const char *title)
-{
- jmethodID mid;
- JNIEnv *mEnv = Android_JNI_GetEnv();
- mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"setActivityTitle","(Ljava/lang/String;)Z");
- if (mid) {
- jstring jtitle = (jstring)((*mEnv)->NewStringUTF(mEnv, title));
- (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, mid, jtitle);
- (*mEnv)->DeleteLocalRef(mEnv, jtitle);
- }
-}
-
-SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
-{
- int i;
- SDL_bool retval = SDL_FALSE;
-
- if (bHasNewData) {
- for (i = 0; i < 3; ++i) {
- values[i] = fLastAccelerometer[i];
- }
- bHasNewData = SDL_FALSE;
- retval = SDL_TRUE;
- }
-
- return retval;
-}
-
-static void Android_JNI_ThreadDestroyed(void* value)
-{
- /* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */
- JNIEnv *env = (JNIEnv*) value;
- if (env != NULL) {
- (*mJavaVM)->DetachCurrentThread(mJavaVM);
- pthread_setspecific(mThreadKey, NULL);
- }
-}
-
-JNIEnv* Android_JNI_GetEnv(void)
-{
- /* From http://developer.android.com/guide/practices/jni.html
- * All threads are Linux threads, scheduled by the kernel.
- * They're usually started from managed code (using Thread.start), but they can also be created elsewhere and then
- * attached to the JavaVM. For example, a thread started with pthread_create can be attached with the
- * JNI AttachCurrentThread or AttachCurrentThreadAsDaemon functions. Until a thread is attached, it has no JNIEnv,
- * and cannot make JNI calls.
- * Attaching a natively-created thread causes a java.lang.Thread object to be constructed and added to the "main"
- * ThreadGroup, making it visible to the debugger. Calling AttachCurrentThread on an already-attached thread
- * is a no-op.
- * Note: You can call this function any number of times for the same thread, there's no harm in it
- */
-
- JNIEnv *env;
- int status = (*mJavaVM)->AttachCurrentThread(mJavaVM, &env, NULL);
- if(status < 0) {
- LOGE("failed to attach current thread");
- return 0;
- }
-
- /* From http://developer.android.com/guide/practices/jni.html
- * Threads attached through JNI must call DetachCurrentThread before they exit. If coding this directly is awkward,
- * in Android 2.0 (Eclair) and higher you can use pthread_key_create to define a destructor function that will be
- * called before the thread exits, and call DetachCurrentThread from there. (Use that key with pthread_setspecific
- * to store the JNIEnv in thread-local-storage; that way it'll be passed into your destructor as the argument.)
- * Note: The destructor is not called unless the stored value is != NULL
- * Note: You can call this function any number of times for the same thread, there's no harm in it
- * (except for some lost CPU cycles)
- */
- pthread_setspecific(mThreadKey, (void*) env);
-
- return env;
-}
-
-int Android_JNI_SetupThread(void)
-{
- Android_JNI_GetEnv();
- return 1;
-}
-
-/*
- * Audio support
- */
-static jboolean audioBuffer16Bit = JNI_FALSE;
-static jobject audioBuffer = NULL;
-static void* audioBufferPinned = NULL;
-static jboolean captureBuffer16Bit = JNI_FALSE;
-static jobject captureBuffer = NULL;
-
-int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames)
-{
- jboolean audioBufferStereo;
- int audioBufferFrames;
- jobject jbufobj = NULL;
- jboolean isCopy;
-
- JNIEnv *env = Android_JNI_GetEnv();
-
- if (!env) {
- LOGE("callback_handler: failed to attach current thread");
- }
- Android_JNI_SetupThread();
-
- audioBufferStereo = channelCount > 1;
-
- if (iscapture) {
- __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for capture");
- captureBuffer16Bit = is16Bit;
- if ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames) != 0) {
- /* Error during audio initialization */
- __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioRecord initialization!");
- return 0;
- }
- } else {
- __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for output");
- audioBuffer16Bit = is16Bit;
- if ((*env)->CallStaticIntMethod(env, mActivityClass, midAudioOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames) != 0) {
- /* Error during audio initialization */
- __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioTrack initialization!");
- return 0;
- }
- }
-
- /* Allocating the audio buffer from the Java side and passing it as the return value for audioInit no longer works on
- * Android >= 4.2 due to a "stale global reference" error. So now we allocate this buffer directly from this side. */
-
- if (is16Bit) {
- jshortArray audioBufferLocal = (*env)->NewShortArray(env, desiredBufferFrames * (audioBufferStereo ? 2 : 1));
- if (audioBufferLocal) {
- jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal);
- (*env)->DeleteLocalRef(env, audioBufferLocal);
- }
- }
- else {
- jbyteArray audioBufferLocal = (*env)->NewByteArray(env, desiredBufferFrames * (audioBufferStereo ? 2 : 1));
- if (audioBufferLocal) {
- jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal);
- (*env)->DeleteLocalRef(env, audioBufferLocal);
- }
- }
-
- if (jbufobj == NULL) {
- __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: could not allocate an audio buffer!");
- return 0;
- }
-
- if (iscapture) {
- captureBuffer = jbufobj;
- } else {
- audioBuffer = jbufobj;
- }
-
- isCopy = JNI_FALSE;
-
- if (is16Bit) {
- if (!iscapture) {
- audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy);
- }
- audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer);
- } else {
- if (!iscapture) {
- audioBufferPinned = (*env)->GetByteArrayElements(env, (jbyteArray)audioBuffer, &isCopy);
- }
- audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer);
- }
-
- if (audioBufferStereo) {
- audioBufferFrames /= 2;
- }
-
- return audioBufferFrames;
-}
-
-void * Android_JNI_GetAudioBuffer(void)
-{
- return audioBufferPinned;
-}
-
-void Android_JNI_WriteAudioBuffer(void)
-{
- JNIEnv *mAudioEnv = Android_JNI_GetEnv();
-
- if (audioBuffer16Bit) {
- (*mAudioEnv)->ReleaseShortArrayElements(mAudioEnv, (jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT);
- (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mActivityClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer);
- } else {
- (*mAudioEnv)->ReleaseByteArrayElements(mAudioEnv, (jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT);
- (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mActivityClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer);
- }
-
- /* JNI_COMMIT means the changes are committed to the VM but the buffer remains pinned */
-}
-
-int Android_JNI_CaptureAudioBuffer(void *buffer, int buflen)
-{
- JNIEnv *env = Android_JNI_GetEnv();
- jboolean isCopy = JNI_FALSE;
- jint br;
-
- if (captureBuffer16Bit) {
- SDL_assert((*env)->GetArrayLength(env, (jshortArray)captureBuffer) == (buflen / 2));
- br = (*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_TRUE);
- if (br > 0) {
- jshort *ptr = (*env)->GetShortArrayElements(env, (jshortArray)captureBuffer, &isCopy);
- br *= 2;
- SDL_memcpy(buffer, ptr, br);
- (*env)->ReleaseShortArrayElements(env, (jshortArray)captureBuffer, (jshort *)ptr, JNI_ABORT);
- }
- } else {
- SDL_assert((*env)->GetArrayLength(env, (jshortArray)captureBuffer) == buflen);
- br = (*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_TRUE);
- if (br > 0) {
- jbyte *ptr = (*env)->GetByteArrayElements(env, (jbyteArray)captureBuffer, &isCopy);
- SDL_memcpy(buffer, ptr, br);
- (*env)->ReleaseByteArrayElements(env, (jbyteArray)captureBuffer, (jbyte *)ptr, JNI_ABORT);
- }
- }
-
- return (int) br;
-}
-
-void Android_JNI_FlushCapturedAudio(void)
-{
- JNIEnv *env = Android_JNI_GetEnv();
- #if 0 /* !!! FIXME: this needs API 23, or it'll do blocking reads and never end. */
- if (captureBuffer16Bit) {
- const jint len = (*env)->GetArrayLength(env, (jshortArray)captureBuffer);
- while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
- } else {
- const jint len = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer);
- while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
- }
- #else
- if (captureBuffer16Bit) {
- (*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE);
- } else {
- (*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE);
- }
- #endif
-}
-
-void Android_JNI_CloseAudioDevice(const int iscapture)
-{
- JNIEnv *env = Android_JNI_GetEnv();
-
- if (iscapture) {
- (*env)->CallStaticVoidMethod(env, mActivityClass, midCaptureClose);
- if (captureBuffer) {
- (*env)->DeleteGlobalRef(env, captureBuffer);
- captureBuffer = NULL;
- }
- } else {
- (*env)->CallStaticVoidMethod(env, mActivityClass, midAudioClose);
- if (audioBuffer) {
- (*env)->DeleteGlobalRef(env, audioBuffer);
- audioBuffer = NULL;
- audioBufferPinned = NULL;
- }
- }
-}
-
-/* Test for an exception and call SDL_SetError with its detail if one occurs */
-/* If the parameter silent is truthy then SDL_SetError() will not be called. */
-static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
-{
- JNIEnv *mEnv = Android_JNI_GetEnv();
- jthrowable exception;
-
- SDL_assert(LocalReferenceHolder_IsActive());
-
- exception = (*mEnv)->ExceptionOccurred(mEnv);
- if (exception != NULL) {
- jmethodID mid;
-
- /* Until this happens most JNI operations have undefined behaviour */
- (*mEnv)->ExceptionClear(mEnv);
-
- if (!silent) {
- jclass exceptionClass = (*mEnv)->GetObjectClass(mEnv, exception);
- jclass classClass = (*mEnv)->FindClass(mEnv, "java/lang/Class");
- jstring exceptionName;
- const char* exceptionNameUTF8;
- jstring exceptionMessage;
-
- mid = (*mEnv)->GetMethodID(mEnv, classClass, "getName", "()Ljava/lang/String;");
- exceptionName = (jstring)(*mEnv)->CallObjectMethod(mEnv, exceptionClass, mid);
- exceptionNameUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionName, 0);
-
- mid = (*mEnv)->GetMethodID(mEnv, exceptionClass, "getMessage", "()Ljava/lang/String;");
- exceptionMessage = (jstring)(*mEnv)->CallObjectMethod(mEnv, exception, mid);
-
- if (exceptionMessage != NULL) {
- const char* exceptionMessageUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionMessage, 0);
- SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8);
- (*mEnv)->ReleaseStringUTFChars(mEnv, exceptionMessage, exceptionMessageUTF8);
- } else {
- SDL_SetError("%s", exceptionNameUTF8);
- }
-
- (*mEnv)->ReleaseStringUTFChars(mEnv, exceptionName, exceptionNameUTF8);
- }
-
- return SDL_TRUE;
- }
-
- return SDL_FALSE;
-}
-
-static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
-{
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
-
- int result = 0;
-
- jmethodID mid;
- jobject context;
- jobject assetManager;
- jobject inputStream;
- jclass channels;
- jobject readableByteChannel;
- jstring fileNameJString;
- jobject fd;
- jclass fdCls;
- jfieldID descriptor;
-
- JNIEnv *mEnv = Android_JNI_GetEnv();
- if (!LocalReferenceHolder_Init(&refs, mEnv)) {
- goto failure;
- }
-
- fileNameJString = (jstring)ctx->hidden.androidio.fileNameRef;
- ctx->hidden.androidio.position = 0;
-
- /* context = SDLActivity.getContext(); */
- mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "getContext","()Landroid/content/Context;");
- context = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, mid);
-
-
- /* assetManager = context.getAssets(); */
- mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
- "getAssets", "()Landroid/content/res/AssetManager;");
- assetManager = (*mEnv)->CallObjectMethod(mEnv, 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 = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;");
- inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString);
- if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
- goto fallback;
- }
-
- mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getStartOffset", "()J");
- ctx->hidden.androidio.offset = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
- if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
- goto fallback;
- }
-
- mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getDeclaredLength", "()J");
- ctx->hidden.androidio.size = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
- if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
- goto fallback;
- }
-
- mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getFileDescriptor", "()Ljava/io/FileDescriptor;");
- fd = (*mEnv)->CallObjectMethod(mEnv, inputStream, mid);
- fdCls = (*mEnv)->GetObjectClass(mEnv, fd);
- descriptor = (*mEnv)->GetFieldID(mEnv, fdCls, "descriptor", "I");
- ctx->hidden.androidio.fd = (*mEnv)->GetIntField(mEnv, fd, descriptor);
- ctx->hidden.androidio.assetFileDescriptorRef = (*mEnv)->NewGlobalRef(mEnv, 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 = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager),
- "open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
- inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
- if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
- /* Try fallback to APK expansion files */
- mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
- "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
- if (!mid) {
- SDL_SetError("No openAPKExpansionInputStream() in Java class");
- goto failure; /* Java class is missing the required method */
- }
- inputStream = (*mEnv)->CallObjectMethod(mEnv, context, mid, 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 = (*mEnv)->NewGlobalRef(mEnv, 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 = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
- "available", "()I");
- ctx->hidden.androidio.size = (long)(*mEnv)->CallIntMethod(mEnv, inputStream, mid);
- if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
- goto failure;
- }
-
- /* readableByteChannel = Channels.newChannel(inputStream); */
- channels = (*mEnv)->FindClass(mEnv, "java/nio/channels/Channels");
- mid = (*mEnv)->GetStaticMethodID(mEnv, channels,
- "newChannel",
- "(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
- readableByteChannel = (*mEnv)->CallStaticObjectMethod(
- mEnv, channels, mid, inputStream);
- if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
- goto failure;
- }
-
- ctx->hidden.androidio.readableByteChannelRef =
- (*mEnv)->NewGlobalRef(mEnv, readableByteChannel);
-
- /* Store .read id for reading purposes */
- mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, readableByteChannel),
- "read", "(Ljava/nio/ByteBuffer;)I");
- ctx->hidden.androidio.readMethod = mid;
- }
-
- if (0) {
-failure:
- result = -1;
-
- (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.fileNameRef);
-
- if(ctx->hidden.androidio.inputStreamRef != NULL) {
- (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef);
- }
-
- if(ctx->hidden.androidio.readableByteChannelRef != NULL) {
- (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef);
- }
-
- if(ctx->hidden.androidio.assetFileDescriptorRef != NULL) {
- (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
- }
-
- }
-
- LocalReferenceHolder_Cleanup(&refs);
- return result;
-}
-
-int Android_JNI_FileOpen(SDL_RWops* ctx,
- const char* fileName, const char* mode)
-{
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
- JNIEnv *mEnv = Android_JNI_GetEnv();
- int retval;
- jstring fileNameJString;
-
- if (!LocalReferenceHolder_Init(&refs, mEnv)) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
-
- if (!ctx) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
-
- fileNameJString = (*mEnv)->NewStringUTF(mEnv, fileName);
- ctx->hidden.androidio.fileNameRef = (*mEnv)->NewGlobalRef(mEnv, 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;
-}
-
-size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
- size_t size, size_t maxnum)
-{
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
-
- 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;
- } else {
- jlong bytesRemaining = (jlong) (size * maxnum);
- jlong bytesMax = (jlong) (ctx->hidden.androidio.size - ctx->hidden.androidio.position);
- int bytesRead = 0;
- JNIEnv *mEnv;
- 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;
-
- mEnv = Android_JNI_GetEnv();
- if (!LocalReferenceHolder_Init(&refs, mEnv)) {
- LocalReferenceHolder_Cleanup(&refs);
- return 0;
- }
-
- readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannelRef;
- readMethod = (jmethodID)ctx->hidden.androidio.readMethod;
- byteBuffer = (*mEnv)->NewDirectByteBuffer(mEnv, buffer, bytesRemaining);
-
- while (bytesRemaining > 0) {
- /* result = readableByteChannel.read(...); */
- int result = (*mEnv)->CallIntMethod(mEnv, 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;
- }
-}
-
-size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer,
- size_t size, size_t num)
-{
- SDL_SetError("Cannot write to Android package filesystem");
- return 0;
-}
-
-static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, SDL_bool release)
-{
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
-
- int result = 0;
- JNIEnv *mEnv = Android_JNI_GetEnv();
-
- if (!LocalReferenceHolder_Init(&refs, mEnv)) {
- LocalReferenceHolder_Cleanup(&refs);
- return SDL_SetError("Failed to allocate enough JVM local references");
- }
-
- if (ctx) {
- if (release) {
- (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.fileNameRef);
- }
-
- if (ctx->hidden.androidio.assetFileDescriptorRef) {
- jobject inputStream = (jobject)ctx->hidden.androidio.assetFileDescriptorRef;
- jmethodID mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
- "close", "()V");
- (*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
- (*mEnv)->DeleteGlobalRef(mEnv, (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 = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
- "close", "()V");
- (*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
- (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef);
- (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef);
- if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
- result = -1;
- }
- }
-
- if (release) {
- SDL_FreeRW(ctx);
- }
- }
-
- LocalReferenceHolder_Cleanup(&refs);
- return result;
-}
-
-
-Sint64 Android_JNI_FileSize(SDL_RWops* ctx)
-{
- 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'");
- }
- whence = SEEK_SET;
-
- 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, 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;
-
-}
-
-int Android_JNI_FileClose(SDL_RWops* ctx)
-{
- return Internal_Android_JNI_FileClose(ctx, SDL_TRUE);
-}
-
-/* returns a new global reference which needs to be released later */
-static jobject Android_JNI_GetSystemServiceObject(const char* name)
-{
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
- JNIEnv* env = Android_JNI_GetEnv();
- jobject retval = NULL;
- jstring service;
- jmethodID mid;
- jobject context;
- jobject manager;
-
- if (!LocalReferenceHolder_Init(&refs, env)) {
- LocalReferenceHolder_Cleanup(&refs);
- return NULL;
- }
-
- service = (*env)->NewStringUTF(env, name);
-
- mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
- context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
-
- mid = (*env)->GetMethodID(env, mActivityClass, "getSystemServiceFromUiThread", "(Ljava/lang/String;)Ljava/lang/Object;");
- manager = (*env)->CallObjectMethod(env, context, mid, service);
-
- (*env)->DeleteLocalRef(env, service);
-
- retval = manager ? (*env)->NewGlobalRef(env, manager) : NULL;
- LocalReferenceHolder_Cleanup(&refs);
- return retval;
-}
-
-#define SETUP_CLIPBOARD(error) \
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); \
- JNIEnv* env = Android_JNI_GetEnv(); \
- jobject clipboard; \
- if (!LocalReferenceHolder_Init(&refs, env)) { \
- LocalReferenceHolder_Cleanup(&refs); \
- return error; \
- } \
- clipboard = Android_JNI_GetSystemServiceObject("clipboard"); \
- if (!clipboard) { \
- LocalReferenceHolder_Cleanup(&refs); \
- return error; \
- }
-
-#define CLEANUP_CLIPBOARD() \
- LocalReferenceHolder_Cleanup(&refs);
-
-int Android_JNI_SetClipboardText(const char* text)
-{
- /* Watch out for C89 scoping rules because of the macro */
- SETUP_CLIPBOARD(-1)
-
- /* Nest the following in a scope to avoid C89 declaration rules triggered by the macro */
- {
- jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, clipboard), "setText", "(Ljava/lang/CharSequence;)V");
- jstring string = (*env)->NewStringUTF(env, text);
- (*env)->CallVoidMethod(env, clipboard, mid, string);
- (*env)->DeleteGlobalRef(env, clipboard);
- (*env)->DeleteLocalRef(env, string);
- }
- CLEANUP_CLIPBOARD();
-
- return 0;
-}
-
-char* Android_JNI_GetClipboardText(void)
-{
- /* Watch out for C89 scoping rules because of the macro */
- SETUP_CLIPBOARD(SDL_strdup(""))
-
- /* Nest the following in a scope to avoid C89 declaration rules triggered by the macro */
- {
- jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, clipboard), "getText", "()Ljava/lang/CharSequence;");
- jobject sequence = (*env)->CallObjectMethod(env, clipboard, mid);
- (*env)->DeleteGlobalRef(env, clipboard);
- if (sequence) {
- jstring string;
- const char* utf;
- mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, sequence), "toString", "()Ljava/lang/String;");
- string = (jstring)((*env)->CallObjectMethod(env, sequence, mid));
- utf = (*env)->GetStringUTFChars(env, string, 0);
- if (utf) {
- char* text = SDL_strdup(utf);
- (*env)->ReleaseStringUTFChars(env, string, utf);
-
- CLEANUP_CLIPBOARD();
-
- return text;
- }
- }
- }
- CLEANUP_CLIPBOARD();
-
- return SDL_strdup("");
-}
-
-SDL_bool Android_JNI_HasClipboardText(void)
-{
- jmethodID mid;
- jboolean has;
- /* Watch out for C89 scoping rules because of the macro */
- SETUP_CLIPBOARD(SDL_FALSE)
-
- mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, clipboard), "hasText", "()Z");
- has = (*env)->CallBooleanMethod(env, clipboard, mid);
- (*env)->DeleteGlobalRef(env, clipboard);
-
- CLEANUP_CLIPBOARD();
-
- return has ? SDL_TRUE : SDL_FALSE;
-}
-
-
-/* returns 0 on success or -1 on error (others undefined then)
- * returns truthy or falsy value in plugged, charged and battery
- * returns the value in seconds and percent or -1 if not available
- */
-int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent)
-{
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
- JNIEnv* env = Android_JNI_GetEnv();
- jmethodID mid;
- jobject context;
- jstring action;
- jclass cls;
- jobject filter;
- jobject intent;
- jstring iname;
- jmethodID imid;
- jstring bname;
- jmethodID bmid;
- if (!LocalReferenceHolder_Init(&refs, env)) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
-
-
- mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
- context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
-
- action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED");
-
- cls = (*env)->FindClass(env, "android/content/IntentFilter");
-
- mid = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/lang/String;)V");
- filter = (*env)->NewObject(env, cls, mid, action);
-
- (*env)->DeleteLocalRef(env, action);
-
- mid = (*env)->GetMethodID(env, mActivityClass, "registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;");
- intent = (*env)->CallObjectMethod(env, context, mid, NULL, filter);
-
- (*env)->DeleteLocalRef(env, filter);
-
- cls = (*env)->GetObjectClass(env, intent);
-
- imid = (*env)->GetMethodID(env, cls, "getIntExtra", "(Ljava/lang/String;I)I");
-
- /* Watch out for C89 scoping rules because of the macro */
-#define GET_INT_EXTRA(var, key) \
- int var; \
- iname = (*env)->NewStringUTF(env, key); \
- var = (*env)->CallIntMethod(env, intent, imid, iname, -1); \
- (*env)->DeleteLocalRef(env, iname);
-
- bmid = (*env)->GetMethodID(env, cls, "getBooleanExtra", "(Ljava/lang/String;Z)Z");
-
- /* Watch out for C89 scoping rules because of the macro */
-#define GET_BOOL_EXTRA(var, key) \
- int var; \
- bname = (*env)->NewStringUTF(env, key); \
- var = (*env)->CallBooleanMethod(env, intent, bmid, bname, JNI_FALSE); \
- (*env)->DeleteLocalRef(env, bname);
-
- if (plugged) {
- /* Watch out for C89 scoping rules because of the macro */
- GET_INT_EXTRA(plug, "plugged") /* == BatteryManager.EXTRA_PLUGGED (API 5) */
- if (plug == -1) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
- /* 1 == BatteryManager.BATTERY_PLUGGED_AC */
- /* 2 == BatteryManager.BATTERY_PLUGGED_USB */
- *plugged = (0 < plug) ? 1 : 0;
- }
-
- if (charged) {
- /* Watch out for C89 scoping rules because of the macro */
- GET_INT_EXTRA(status, "status") /* == BatteryManager.EXTRA_STATUS (API 5) */
- if (status == -1) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
- /* 5 == BatteryManager.BATTERY_STATUS_FULL */
- *charged = (status == 5) ? 1 : 0;
- }
-
- if (battery) {
- GET_BOOL_EXTRA(present, "present") /* == BatteryManager.EXTRA_PRESENT (API 5) */
- *battery = present ? 1 : 0;
- }
-
- if (seconds) {
- *seconds = -1; /* not possible */
- }
-
- if (percent) {
- int level;
- int scale;
-
- /* Watch out for C89 scoping rules because of the macro */
- {
- GET_INT_EXTRA(level_temp, "level") /* == BatteryManager.EXTRA_LEVEL (API 5) */
- level = level_temp;
- }
- /* Watch out for C89 scoping rules because of the macro */
- {
- GET_INT_EXTRA(scale_temp, "scale") /* == BatteryManager.EXTRA_SCALE (API 5) */
- scale = scale_temp;
- }
-
- if ((level == -1) || (scale == -1)) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
- *percent = level * 100 / scale;
- }
-
- (*env)->DeleteLocalRef(env, intent);
-
- LocalReferenceHolder_Cleanup(&refs);
- return 0;
-}
-
-/* returns number of found touch devices as return value and ids in parameter ids */
-int Android_JNI_GetTouchDeviceIds(int **ids) {
- JNIEnv *env = Android_JNI_GetEnv();
- jint sources = 4098; /* == InputDevice.SOURCE_TOUCHSCREEN */
- jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "inputGetInputDeviceIds", "(I)[I");
- jintArray array = (jintArray) (*env)->CallStaticObjectMethod(env, mActivityClass, mid, sources);
- int number = 0;
- *ids = NULL;
- if (array) {
- number = (int) (*env)->GetArrayLength(env, array);
- if (0 < number) {
- jint* elements = (*env)->GetIntArrayElements(env, array, NULL);
- if (elements) {
- int i;
- *ids = SDL_malloc(number * sizeof (**ids));
- for (i = 0; i < number; ++i) { /* not assuming sizeof (jint) == sizeof (int) */
- (*ids)[i] = elements[i];
- }
- (*env)->ReleaseIntArrayElements(env, array, elements, JNI_ABORT);
- }
- }
- (*env)->DeleteLocalRef(env, array);
- }
- return number;
-}
-
-void Android_JNI_PollInputDevices(void)
-{
- JNIEnv *env = Android_JNI_GetEnv();
- (*env)->CallStaticVoidMethod(env, mActivityClass, midPollInputDevices);
-}
-
-/* See SDLActivity.java for constants. */
-#define COMMAND_SET_KEEP_SCREEN_ON 5
-
-/* sends message to be handled on the UI event dispatch thread */
-int Android_JNI_SendMessage(int command, int param)
-{
- JNIEnv *env = Android_JNI_GetEnv();
- jmethodID mid;
- jboolean success;
- if (!env) {
- return -1;
- }
- mid = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z");
- if (!mid) {
- return -1;
- }
- success = (*env)->CallStaticBooleanMethod(env, mActivityClass, mid, command, param);
- return success ? 0 : -1;
-}
-
-void Android_JNI_SuspendScreenSaver(SDL_bool suspend)
-{
- Android_JNI_SendMessage(COMMAND_SET_KEEP_SCREEN_ON, (suspend == SDL_FALSE) ? 0 : 1);
-}
-
-void Android_JNI_ShowTextInput(SDL_Rect *inputRect)
-{
- JNIEnv *env = Android_JNI_GetEnv();
- jmethodID mid;
- if (!env) {
- return;
- }
-
- mid = (*env)->GetStaticMethodID(env, mActivityClass, "showTextInput", "(IIII)Z");
- if (!mid) {
- return;
- }
- (*env)->CallStaticBooleanMethod(env, mActivityClass, mid,
- inputRect->x,
- inputRect->y,
- inputRect->w,
- inputRect->h );
-}
-
-void Android_JNI_HideTextInput(void)
-{
- /* has to match Activity constant */
- const int COMMAND_TEXTEDIT_HIDE = 3;
- Android_JNI_SendMessage(COMMAND_TEXTEDIT_HIDE, 0);
-}
-
-int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
-{
- JNIEnv *env;
- jclass clazz;
- jmethodID mid;
- jobject context;
- jstring title;
- jstring message;
- jintArray button_flags;
- jintArray button_ids;
- jobjectArray button_texts;
- jintArray colors;
- jobject text;
- jint temp;
- int i;
-
- env = Android_JNI_GetEnv();
-
- /* convert parameters */
-
- clazz = (*env)->FindClass(env, "java/lang/String");
-
- title = (*env)->NewStringUTF(env, messageboxdata->title);
- message = (*env)->NewStringUTF(env, messageboxdata->message);
-
- button_flags = (*env)->NewIntArray(env, messageboxdata->numbuttons);
- button_ids = (*env)->NewIntArray(env, messageboxdata->numbuttons);
- button_texts = (*env)->NewObjectArray(env, messageboxdata->numbuttons,
- clazz, NULL);
- for (i = 0; i < messageboxdata->numbuttons; ++i) {
- temp = messageboxdata->buttons[i].flags;
- (*env)->SetIntArrayRegion(env, button_flags, i, 1, &temp);
- temp = messageboxdata->buttons[i].buttonid;
- (*env)->SetIntArrayRegion(env, button_ids, i, 1, &temp);
- text = (*env)->NewStringUTF(env, messageboxdata->buttons[i].text);
- (*env)->SetObjectArrayElement(env, button_texts, i, text);
- (*env)->DeleteLocalRef(env, text);
- }
-
- if (messageboxdata->colorScheme) {
- colors = (*env)->NewIntArray(env, SDL_MESSAGEBOX_COLOR_MAX);
- for (i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; ++i) {
- temp = (0xFF << 24) |
- (messageboxdata->colorScheme->colors[i].r << 16) |
- (messageboxdata->colorScheme->colors[i].g << 8) |
- (messageboxdata->colorScheme->colors[i].b << 0);
- (*env)->SetIntArrayRegion(env, colors, i, 1, &temp);
- }
- } else {
- colors = NULL;
- }
-
- (*env)->DeleteLocalRef(env, clazz);
-
- /* call function */
-
- mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
-
- context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
-
- clazz = (*env)->GetObjectClass(env, context);
-
- mid = (*env)->GetMethodID(env, clazz,
- "messageboxShowMessageBox", "(ILjava/lang/String;Ljava/lang/String;[I[I[Ljava/lang/String;[I)I");
- *buttonid = (*env)->CallIntMethod(env, context, mid,
- messageboxdata->flags,
- title,
- message,
- button_flags,
- button_ids,
- button_texts,
- colors);
-
- (*env)->DeleteLocalRef(env, context);
- (*env)->DeleteLocalRef(env, clazz);
-
- /* delete parameters */
-
- (*env)->DeleteLocalRef(env, title);
- (*env)->DeleteLocalRef(env, message);
- (*env)->DeleteLocalRef(env, button_flags);
- (*env)->DeleteLocalRef(env, button_ids);
- (*env)->DeleteLocalRef(env, button_texts);
- (*env)->DeleteLocalRef(env, colors);
-
- return 0;
-}
-
-/*
-//////////////////////////////////////////////////////////////////////////////
-//
-// Functions exposed to SDL applications in SDL_system.h
-//////////////////////////////////////////////////////////////////////////////
-*/
-
-void *SDL_AndroidGetJNIEnv()
-{
- return Android_JNI_GetEnv();
-}
-
-
-
-void *SDL_AndroidGetActivity()
-{
- /* See SDL_system.h for caveats on using this function. */
-
- jmethodID mid;
-
- JNIEnv *env = Android_JNI_GetEnv();
- if (!env) {
- return NULL;
- }
-
- /* return SDLActivity.getContext(); */
- mid = (*env)->GetStaticMethodID(env, mActivityClass,
- "getContext","()Landroid/content/Context;");
- return (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
-}
-
-const char * SDL_AndroidGetInternalStoragePath()
-{
- static char *s_AndroidInternalFilesPath = NULL;
-
- if (!s_AndroidInternalFilesPath) {
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
- jmethodID mid;
- jobject context;
- jobject fileObject;
- jstring pathString;
- const char *path;
-
- JNIEnv *env = Android_JNI_GetEnv();
- if (!LocalReferenceHolder_Init(&refs, env)) {
- LocalReferenceHolder_Cleanup(&refs);
- return NULL;
- }
-
- /* context = SDLActivity.getContext(); */
- mid = (*env)->GetStaticMethodID(env, mActivityClass,
- "getContext","()Landroid/content/Context;");
- context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
-
- /* fileObj = context.getFilesDir(); */
- mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
- "getFilesDir", "()Ljava/io/File;");
- fileObject = (*env)->CallObjectMethod(env, context, mid);
- if (!fileObject) {
- SDL_SetError("Couldn't get internal directory");
- LocalReferenceHolder_Cleanup(&refs);
- return NULL;
- }
-
- /* path = fileObject.getAbsolutePath(); */
- mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, fileObject),
- "getAbsolutePath", "()Ljava/lang/String;");
- pathString = (jstring)(*env)->CallObjectMethod(env, fileObject, mid);
-
- path = (*env)->GetStringUTFChars(env, pathString, NULL);
- s_AndroidInternalFilesPath = SDL_strdup(path);
- (*env)->ReleaseStringUTFChars(env, pathString, path);
-
- LocalReferenceHolder_Cleanup(&refs);
- }
- return s_AndroidInternalFilesPath;
-}
-
-int SDL_AndroidGetExternalStorageState()
-{
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
- jmethodID mid;
- jclass cls;
- jstring stateString;
- const char *state;
- int stateFlags;
-
- JNIEnv *env = Android_JNI_GetEnv();
- if (!LocalReferenceHolder_Init(&refs, env)) {
- LocalReferenceHolder_Cleanup(&refs);
- return 0;
- }
-
- cls = (*env)->FindClass(env, "android/os/Environment");
- mid = (*env)->GetStaticMethodID(env, cls,
- "getExternalStorageState", "()Ljava/lang/String;");
- stateString = (jstring)(*env)->CallStaticObjectMethod(env, cls, mid);
-
- state = (*env)->GetStringUTFChars(env, stateString, NULL);
-
- /* Print an info message so people debugging know the storage state */
- __android_log_print(ANDROID_LOG_INFO, "SDL", "external storage state: %s", state);
-
- if (SDL_strcmp(state, "mounted") == 0) {
- stateFlags = SDL_ANDROID_EXTERNAL_STORAGE_READ |
- SDL_ANDROID_EXTERNAL_STORAGE_WRITE;
- } else if (SDL_strcmp(state, "mounted_ro") == 0) {
- stateFlags = SDL_ANDROID_EXTERNAL_STORAGE_READ;
- } else {
- stateFlags = 0;
- }
- (*env)->ReleaseStringUTFChars(env, stateString, state);
-
- LocalReferenceHolder_Cleanup(&refs);
- return stateFlags;
-}
-
-const char * SDL_AndroidGetExternalStoragePath()
-{
- static char *s_AndroidExternalFilesPath = NULL;
-
- if (!s_AndroidExternalFilesPath) {
- struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
- jmethodID mid;
- jobject context;
- jobject fileObject;
- jstring pathString;
- const char *path;
-
- JNIEnv *env = Android_JNI_GetEnv();
- if (!LocalReferenceHolder_Init(&refs, env)) {
- LocalReferenceHolder_Cleanup(&refs);
- return NULL;
- }
-
- /* context = SDLActivity.getContext(); */
- mid = (*env)->GetStaticMethodID(env, mActivityClass,
- "getContext","()Landroid/content/Context;");
- context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
-
- /* fileObj = context.getExternalFilesDir(); */
- mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
- "getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;");
- fileObject = (*env)->CallObjectMethod(env, context, mid, NULL);
- if (!fileObject) {
- SDL_SetError("Couldn't get external directory");
- LocalReferenceHolder_Cleanup(&refs);
- return NULL;
- }
-
- /* path = fileObject.getAbsolutePath(); */
- mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, fileObject),
- "getAbsolutePath", "()Ljava/lang/String;");
- pathString = (jstring)(*env)->CallObjectMethod(env, fileObject, mid);
-
- path = (*env)->GetStringUTFChars(env, pathString, NULL);
- s_AndroidExternalFilesPath = SDL_strdup(path);
- (*env)->ReleaseStringUTFChars(env, pathString, path);
-
- LocalReferenceHolder_Cleanup(&refs);
- }
- return s_AndroidExternalFilesPath;
-}
-
-jclass Android_JNI_GetActivityClass(void)
-{
- return mActivityClass;
-}
-
-#endif /* __ANDROID__ */
-
-/* vi: set ts=4 sw=4 expandtab: */
-
diff --git a/3rdparty/SDL2/src/core/android/SDL_android.h b/3rdparty/SDL2/src/core/android/SDL_android.h
deleted file mode 100644
index cb7ff07364d..00000000000
--- a/3rdparty/SDL2/src/core/android/SDL_android.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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"
-
-/* Set up for C function definitions, even when using C++ */
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-extern "C" {
-/* *INDENT-ON* */
-#endif
-
-#include <EGL/eglplatform.h>
-#include <android/native_window_jni.h>
-
-#include "SDL_rect.h"
-
-/* Interface from the SDL library into the Android Java activity */
-extern void Android_JNI_SetActivityTitle(const char *title);
-extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);
-extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect);
-extern void Android_JNI_HideTextInput(void);
-extern ANativeWindow* Android_JNI_GetNativeWindow(void);
-
-/* Audio support */
-extern int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames);
-extern void* Android_JNI_GetAudioBuffer(void);
-extern void Android_JNI_WriteAudioBuffer(void);
-extern int Android_JNI_CaptureAudioBuffer(void *buffer, int buflen);
-extern void Android_JNI_FlushCapturedAudio(void);
-extern void Android_JNI_CloseAudioDevice(const int iscapture);
-
-#include "SDL_rwops.h"
-
-int Android_JNI_FileOpen(SDL_RWops* ctx, const char* fileName, const char* mode);
-Sint64 Android_JNI_FileSize(SDL_RWops* ctx);
-Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence);
-size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer, size_t size, size_t maxnum);
-size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer, size_t size, size_t num);
-int Android_JNI_FileClose(SDL_RWops* ctx);
-
-/* Clipboard support */
-int Android_JNI_SetClipboardText(const char* text);
-char* Android_JNI_GetClipboardText(void);
-SDL_bool Android_JNI_HasClipboardText(void);
-
-/* Power support */
-int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent);
-
-/* Joystick support */
-void Android_JNI_PollInputDevices(void);
-
-/* Video */
-void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
-
-/* Touch support */
-int Android_JNI_GetTouchDeviceIds(int **ids);
-
-/* Threads */
-#include <jni.h>
-JNIEnv *Android_JNI_GetEnv(void);
-int Android_JNI_SetupThread(void);
-jclass Android_JNI_GetActivityClass(void);
-
-/* Generic messages */
-int Android_JNI_SendMessage(int command, int param);
-
-/* Ends C function definitions when using C++ */
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-}
-/* *INDENT-ON* */
-#endif
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/linux/SDL_dbus.c b/3rdparty/SDL2/src/core/linux/SDL_dbus.c
deleted file mode 100644
index ab73ca17c93..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_dbus.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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 "SDL_dbus.h"
-
-#if SDL_USE_LIBDBUS
-/* we never link directly to libdbus. */
-#include "SDL_loadso.h"
-static const char *dbus_library = "libdbus-1.so.3";
-static void *dbus_handle = NULL;
-static unsigned int screensaver_cookie = 0;
-static SDL_DBusContext dbus;
-
-static int
-LoadDBUSSyms(void)
-{
- #define SDL_DBUS_SYM2(x, y) \
- if (!(dbus.x = SDL_LoadFunction(dbus_handle, #y))) return -1
-
- #define SDL_DBUS_SYM(x) \
- SDL_DBUS_SYM2(x, dbus_##x)
-
- SDL_DBUS_SYM(bus_get_private);
- SDL_DBUS_SYM(bus_register);
- SDL_DBUS_SYM(bus_add_match);
- SDL_DBUS_SYM(connection_open_private);
- SDL_DBUS_SYM(connection_set_exit_on_disconnect);
- SDL_DBUS_SYM(connection_get_is_connected);
- SDL_DBUS_SYM(connection_add_filter);
- SDL_DBUS_SYM(connection_try_register_object_path);
- SDL_DBUS_SYM(connection_send);
- SDL_DBUS_SYM(connection_send_with_reply_and_block);
- SDL_DBUS_SYM(connection_close);
- SDL_DBUS_SYM(connection_unref);
- SDL_DBUS_SYM(connection_flush);
- SDL_DBUS_SYM(connection_read_write);
- SDL_DBUS_SYM(connection_dispatch);
- SDL_DBUS_SYM(message_is_signal);
- SDL_DBUS_SYM(message_new_method_call);
- SDL_DBUS_SYM(message_append_args);
- SDL_DBUS_SYM(message_get_args);
- SDL_DBUS_SYM(message_iter_init);
- SDL_DBUS_SYM(message_iter_next);
- SDL_DBUS_SYM(message_iter_get_basic);
- SDL_DBUS_SYM(message_iter_get_arg_type);
- SDL_DBUS_SYM(message_iter_recurse);
- SDL_DBUS_SYM(message_unref);
- SDL_DBUS_SYM(error_init);
- SDL_DBUS_SYM(error_is_set);
- SDL_DBUS_SYM(error_free);
- SDL_DBUS_SYM(get_local_machine_id);
- SDL_DBUS_SYM(free);
- SDL_DBUS_SYM(shutdown);
-
- #undef SDL_DBUS_SYM
- #undef SDL_DBUS_SYM2
-
- return 0;
-}
-
-static void
-UnloadDBUSLibrary(void)
-{
- if (dbus_handle != NULL) {
- SDL_UnloadObject(dbus_handle);
- dbus_handle = NULL;
- }
-}
-
-static int
-LoadDBUSLibrary(void)
-{
- int retval = 0;
- if (dbus_handle == NULL) {
- dbus_handle = SDL_LoadObject(dbus_library);
- if (dbus_handle == NULL) {
- retval = -1;
- /* Don't call SDL_SetError(): SDL_LoadObject already did. */
- } else {
- retval = LoadDBUSSyms();
- if (retval < 0) {
- UnloadDBUSLibrary();
- }
- }
- }
-
- return retval;
-}
-
-void
-SDL_DBus_Init(void)
-{
- if (!dbus.session_conn && LoadDBUSLibrary() != -1) {
- DBusError err;
- dbus.error_init(&err);
- dbus.session_conn = dbus.bus_get_private(DBUS_BUS_SESSION, &err);
- if (dbus.error_is_set(&err)) {
- dbus.error_free(&err);
- if (dbus.session_conn) {
- dbus.connection_unref(dbus.session_conn);
- dbus.session_conn = NULL;
- }
- return; /* oh well */
- }
- dbus.connection_set_exit_on_disconnect(dbus.session_conn, 0);
- }
-}
-
-void
-SDL_DBus_Quit(void)
-{
- if (dbus.session_conn) {
- dbus.connection_close(dbus.session_conn);
- dbus.connection_unref(dbus.session_conn);
- dbus.shutdown();
- SDL_memset(&dbus, 0, sizeof(dbus));
- }
- UnloadDBUSLibrary();
-}
-
-SDL_DBusContext *
-SDL_DBus_GetContext(void)
-{
- if(!dbus_handle || !dbus.session_conn){
- SDL_DBus_Init();
- }
-
- if(dbus_handle && dbus.session_conn){
- return &dbus;
- } else {
- return NULL;
- }
-}
-
-void
-SDL_DBus_ScreensaverTickle(void)
-{
- DBusConnection *conn = dbus.session_conn;
- if (conn != NULL) {
- DBusMessage *msg = dbus.message_new_method_call("org.gnome.ScreenSaver",
- "/org/gnome/ScreenSaver",
- "org.gnome.ScreenSaver",
- "SimulateUserActivity");
- if (msg != NULL) {
- if (dbus.connection_send(conn, msg, NULL)) {
- dbus.connection_flush(conn);
- }
- dbus.message_unref(msg);
- }
- }
-}
-
-SDL_bool
-SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
-{
- DBusConnection *conn = dbus.session_conn;
-
- if (conn == NULL)
- return SDL_FALSE;
-
- if (inhibit &&
- screensaver_cookie != 0)
- return SDL_TRUE;
- if (!inhibit &&
- screensaver_cookie == 0)
- return SDL_TRUE;
-
- if (inhibit) {
- const char *app = "My SDL application";
- const char *reason = "Playing a game";
-
- DBusMessage *msg = dbus.message_new_method_call("org.freedesktop.ScreenSaver",
- "/org/freedesktop/ScreenSaver",
- "org.freedesktop.ScreenSaver",
- "Inhibit");
- if (msg != NULL) {
- dbus.message_append_args (msg,
- DBUS_TYPE_STRING, &app,
- DBUS_TYPE_STRING, &reason,
- DBUS_TYPE_INVALID);
- }
-
- if (msg != NULL) {
- DBusMessage *reply;
-
- reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
- if (reply) {
- if (!dbus.message_get_args(reply, NULL,
- DBUS_TYPE_UINT32, &screensaver_cookie,
- DBUS_TYPE_INVALID))
- screensaver_cookie = 0;
- dbus.message_unref(reply);
- }
-
- dbus.message_unref(msg);
- }
-
- if (screensaver_cookie == 0) {
- return SDL_FALSE;
- }
- return SDL_TRUE;
- } else {
- DBusMessage *msg = dbus.message_new_method_call("org.freedesktop.ScreenSaver",
- "/org/freedesktop/ScreenSaver",
- "org.freedesktop.ScreenSaver",
- "UnInhibit");
- dbus.message_append_args (msg,
- DBUS_TYPE_UINT32, &screensaver_cookie,
- DBUS_TYPE_INVALID);
- if (msg != NULL) {
- if (dbus.connection_send(conn, msg, NULL)) {
- dbus.connection_flush(conn);
- }
- dbus.message_unref(msg);
- }
-
- screensaver_cookie = 0;
- return SDL_TRUE;
- }
-}
-#endif
diff --git a/3rdparty/SDL2/src/core/linux/SDL_dbus.h b/3rdparty/SDL2/src/core/linux/SDL_dbus.h
deleted file mode 100644
index c064381a0c0..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_dbus.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_dbus_h
-#define _SDL_dbus_h
-
-#ifdef HAVE_DBUS_DBUS_H
-#define SDL_USE_LIBDBUS 1
-#include "SDL_stdinc.h"
-#include <dbus/dbus.h>
-
-
-typedef struct SDL_DBusContext {
- DBusConnection *session_conn;
-
- DBusConnection *(*bus_get_private)(DBusBusType, DBusError *);
- dbus_bool_t (*bus_register)(DBusConnection *, DBusError *);
- void (*bus_add_match)(DBusConnection *, const char *, DBusError *);
- DBusConnection * (*connection_open_private)(const char *, DBusError *);
- void (*connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t);
- dbus_bool_t (*connection_get_is_connected)(DBusConnection *);
- dbus_bool_t (*connection_add_filter)(DBusConnection *, DBusHandleMessageFunction,
- void *, DBusFreeFunction);
- dbus_bool_t (*connection_try_register_object_path)(DBusConnection *, const char *,
- const DBusObjectPathVTable *, void *, DBusError *);
- dbus_bool_t (*connection_send)(DBusConnection *, DBusMessage *, dbus_uint32_t *);
- DBusMessage *(*connection_send_with_reply_and_block)(DBusConnection *, DBusMessage *, int, DBusError *);
- void (*connection_close)(DBusConnection *);
- void (*connection_unref)(DBusConnection *);
- void (*connection_flush)(DBusConnection *);
- dbus_bool_t (*connection_read_write)(DBusConnection *, int);
- DBusDispatchStatus (*connection_dispatch)(DBusConnection *);
- dbus_bool_t (*message_is_signal)(DBusMessage *, const char *, const char *);
- 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_get_args)(DBusMessage *, DBusError *, int, ...);
- dbus_bool_t (*message_iter_init)(DBusMessage *, DBusMessageIter *);
- dbus_bool_t (*message_iter_next)(DBusMessageIter *);
- void (*message_iter_get_basic)(DBusMessageIter *, void *);
- int (*message_iter_get_arg_type)(DBusMessageIter *);
- void (*message_iter_recurse)(DBusMessageIter *, DBusMessageIter *);
- void (*message_unref)(DBusMessage *);
- void (*error_init)(DBusError *);
- dbus_bool_t (*error_is_set)(const DBusError *);
- void (*error_free)(DBusError *);
- char *(*get_local_machine_id)(void);
- void (*free)(void *);
- void (*shutdown)(void);
-
-} SDL_DBusContext;
-
-extern void SDL_DBus_Init(void);
-extern void SDL_DBus_Quit(void);
-extern SDL_DBusContext * SDL_DBus_GetContext(void);
-extern void SDL_DBus_ScreensaverTickle(void);
-extern SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit);
-
-#endif /* HAVE_DBUS_DBUS_H */
-
-#endif /* _SDL_dbus_h */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/linux/SDL_evdev.c b/3rdparty/SDL2/src/core/linux/SDL_evdev.c
deleted file mode 100644
index 4761f3e464c..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_evdev.c
+++ /dev/null
@@ -1,873 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifdef SDL_INPUT_LINUXEV
-
-/* This is based on the linux joystick driver */
-/* References: https://www.kernel.org/doc/Documentation/input/input.txt
- * https://www.kernel.org/doc/Documentation/input/event-codes.txt
- * /usr/include/linux/input.h
- * The evtest application is also useful to debug the protocol
- */
-
-#include "SDL_evdev.h"
-
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <limits.h> /* For the definition of PATH_MAX */
-#include <linux/input.h>
-#ifdef SDL_INPUT_LINUXKD
-#include <linux/kd.h>
-#include <linux/keyboard.h>
-#include <linux/vt.h>
-#include <linux/tiocl.h> /* for TIOCL_GETSHIFTSTATE */
-#endif
-
-#include "SDL.h"
-#include "SDL_assert.h"
-#include "SDL_endian.h"
-#include "../../core/linux/SDL_udev.h"
-#include "SDL_scancode.h"
-#include "../../events/SDL_events_c.h"
-#include "../../events/scancodes_linux.h" /* adds linux_scancode_table */
-
-/* This isn't defined in older Linux kernel headers */
-#ifndef SYN_DROPPED
-#define SYN_DROPPED 3
-#endif
-
-typedef struct SDL_evdevlist_item
-{
- char *path;
- int fd;
-
- /* TODO: use this for every device, not just touchscreen */
- int out_of_sync;
-
- /* TODO: expand on this to have data for every possible class (mouse,
- keyboard, touchpad, etc.). Also there's probably some things in here we
- can pull out to the SDL_evdevlist_item i.e. name */
- int is_touchscreen;
- struct {
- char* name;
-
- int min_x, max_x, range_x;
- int min_y, max_y, range_y;
-
- int max_slots;
- int current_slot;
- struct {
- enum {
- EVDEV_TOUCH_SLOTDELTA_NONE = 0,
- EVDEV_TOUCH_SLOTDELTA_DOWN,
- EVDEV_TOUCH_SLOTDELTA_UP,
- EVDEV_TOUCH_SLOTDELTA_MOVE
- } delta;
- int tracking_id;
- int x, y;
- } * slots;
- } * touchscreen_data;
-
- struct SDL_evdevlist_item *next;
-} SDL_evdevlist_item;
-
-typedef struct SDL_EVDEV_PrivateData
-{
- SDL_evdevlist_item *first;
- SDL_evdevlist_item *last;
- int num_devices;
- int ref_count;
- int console_fd;
- int kb_mode;
-} SDL_EVDEV_PrivateData;
-
-#define _THIS SDL_EVDEV_PrivateData *_this
-static _THIS = NULL;
-
-static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode);
-static void SDL_EVDEV_sync_device(SDL_evdevlist_item *item);
-static int SDL_EVDEV_device_removed(const char *dev_path);
-
-#if SDL_USE_LIBUDEV
-static int SDL_EVDEV_device_added(const char *dev_path, int udev_class);
-void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class,
- const char *dev_path);
-#endif /* SDL_USE_LIBUDEV */
-
-static Uint8 EVDEV_MouseButtons[] = {
- SDL_BUTTON_LEFT, /* BTN_LEFT 0x110 */
- SDL_BUTTON_RIGHT, /* BTN_RIGHT 0x111 */
- SDL_BUTTON_MIDDLE, /* BTN_MIDDLE 0x112 */
- SDL_BUTTON_X1, /* BTN_SIDE 0x113 */
- SDL_BUTTON_X2, /* BTN_EXTRA 0x114 */
- SDL_BUTTON_X2 + 1, /* BTN_FORWARD 0x115 */
- SDL_BUTTON_X2 + 2, /* BTN_BACK 0x116 */
- SDL_BUTTON_X2 + 3 /* BTN_TASK 0x117 */
-};
-
-static const char* EVDEV_consoles[] = {
- /* "/proc/self/fd/0",
- "/dev/tty",
- "/dev/tty0", */ /* the tty ioctl's prohibit these */
- "/dev/tty1",
- "/dev/tty2",
- "/dev/tty3",
- "/dev/tty4",
- "/dev/tty5",
- "/dev/tty6",
- "/dev/tty7", /* usually X is spawned in tty7 */
- "/dev/vc/0",
- "/dev/console"
-};
-
-static int SDL_EVDEV_is_console(int fd) {
- int type;
-
- return isatty(fd) && ioctl(fd, KDGKBTYPE, &type) == 0 &&
- (type == KB_101 || type == KB_84);
-}
-
-/* Prevent keystrokes from reaching the tty */
-static int SDL_EVDEV_mute_keyboard(int tty_fd, int* old_kb_mode)
-{
- if (!SDL_EVDEV_is_console(tty_fd)) {
- return SDL_SetError("Tried to mute an invalid tty");
- }
-
- if (ioctl(tty_fd, KDGKBMODE, old_kb_mode) < 0) {
- return SDL_SetError("Failed to get keyboard mode during muting");
- }
-
- /* FIXME: atm this absolutely ruins the vt, and KDSKBMUTE isn't implemented
- in the kernel */
- /*
- if (ioctl(tty_fd, KDSKBMODE, K_OFF) < 0) {
- return SDL_SetError("Failed to set keyboard mode during muting");
- }
- */
-
- return 0;
-}
-
-/* Restore the keyboard mode for given tty */
-static void SDL_EVDEV_unmute_keyboard(int tty_fd, int kb_mode)
-{
- /* read above */
- /*
- if (ioctl(tty_fd, KDSKBMODE, kb_mode) < 0) {
- SDL_Log("Failed to unmute keyboard");
- }
- */
-}
-
-static int SDL_EVDEV_get_active_tty()
-{
- int i, fd, ret, tty = 0;
- char tiocl;
- struct vt_stat vt_state;
- char path[PATH_MAX + 1];
-
- for(i = 0; i < SDL_arraysize(EVDEV_consoles); i++) {
- fd = open(EVDEV_consoles[i], O_RDONLY);
-
- if (fd < 0 && !SDL_EVDEV_is_console(fd))
- break;
-
- tiocl = TIOCL_GETFGCONSOLE;
- if ((ret = ioctl(fd, TIOCLINUX, &tiocl)) >= 0)
- tty = ret + 1;
- else if (ioctl(fd, VT_GETSTATE, &vt_state) == 0)
- tty = vt_state.v_active;
-
- close(fd);
-
- if (tty) {
- sprintf(path, "/dev/tty%u", tty);
- fd = open(path, O_RDONLY);
- if (fd >= 0 && SDL_EVDEV_is_console(fd))
- return fd;
- }
- }
-
- return SDL_SetError("Failed to determine active tty");
-}
-
-int
-SDL_EVDEV_Init(void)
-{
- if (_this == NULL) {
- _this = (SDL_EVDEV_PrivateData*)SDL_calloc(1, sizeof(*_this));
- if (_this == NULL) {
- return SDL_OutOfMemory();
- }
-
-#if SDL_USE_LIBUDEV
- if (SDL_UDEV_Init() < 0) {
- SDL_free(_this);
- _this = NULL;
- return -1;
- }
-
- /* Set up the udev callback */
- if (SDL_UDEV_AddCallback(SDL_EVDEV_udev_callback) < 0) {
- SDL_UDEV_Quit();
- SDL_free(_this);
- _this = NULL;
- return -1;
- }
-
- /* Force a scan to build the initial device list */
- SDL_UDEV_Scan();
-#else
- /* TODO: Scan the devices manually, like a caveman */
-#endif /* SDL_USE_LIBUDEV */
-
- /* We need a physical terminal (not PTS) to be able to translate key
- code to symbols via the kernel tables */
- _this->console_fd = SDL_EVDEV_get_active_tty();
-
- /* Mute the keyboard so keystrokes only generate evdev events and do not
- leak through to the console */
- SDL_EVDEV_mute_keyboard(_this->console_fd, &_this->kb_mode);
- }
-
- _this->ref_count += 1;
-
- return 0;
-}
-
-void
-SDL_EVDEV_Quit(void)
-{
- if (_this == NULL) {
- return;
- }
-
- _this->ref_count -= 1;
-
- if (_this->ref_count < 1) {
-#if SDL_USE_LIBUDEV
- SDL_UDEV_DelCallback(SDL_EVDEV_udev_callback);
- SDL_UDEV_Quit();
-#endif /* SDL_USE_LIBUDEV */
-
- if (_this->console_fd >= 0) {
- SDL_EVDEV_unmute_keyboard(_this->console_fd, _this->kb_mode);
- close(_this->console_fd);
- }
-
- /* Remove existing devices */
- while(_this->first != NULL) {
- SDL_EVDEV_device_removed(_this->first->path);
- }
-
- SDL_assert(_this->first == NULL);
- SDL_assert(_this->last == NULL);
- SDL_assert(_this->num_devices == 0);
-
- SDL_free(_this);
- _this = NULL;
- }
-}
-
-#if SDL_USE_LIBUDEV
-void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_class,
- const char* dev_path)
-{
- if (dev_path == NULL) {
- return;
- }
-
- switch(udev_event) {
- case SDL_UDEV_DEVICEADDED:
- if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD |
- SDL_UDEV_DEVICE_TOUCHSCREEN)))
- return;
-
- SDL_EVDEV_device_added(dev_path, udev_class);
- break;
- case SDL_UDEV_DEVICEREMOVED:
- SDL_EVDEV_device_removed(dev_path);
- break;
- default:
- break;
- }
-}
-#endif /* SDL_USE_LIBUDEV */
-
-#ifdef SDL_INPUT_LINUXKD
-/* this logic is pulled from kbd_keycode() in drivers/tty/vt/keyboard.c in the
- Linux kernel source */
-static void SDL_EVDEV_do_text_input(unsigned short keycode) {
- char shift_state;
- int locks_state;
- struct kbentry kbe;
- unsigned char type;
- char text[2] = { 0 };
-
- if (_this->console_fd < 0)
- return;
-
- shift_state = TIOCL_GETSHIFTSTATE;
- if (ioctl(_this->console_fd, TIOCLINUX, &shift_state) < 0) {
- /* TODO: error */
- return;
- }
-
- kbe.kb_table = shift_state;
- kbe.kb_index = keycode;
-
- if (ioctl(_this->console_fd, KDGKBENT, &kbe) < 0) {
- /* TODO: error */
- return;
- }
-
- type = KTYP(kbe.kb_value);
-
- if (type < 0xf0) {
- /*
- * FIXME: keysyms with a type below 0xf0 represent a unicode character
- * which requires special handling due to dead characters, diacritics,
- * etc. For perfect input a proper way to deal with such characters
- * should be implemented.
- *
- * For reference, the only place I was able to find out about this
- * special 0xf0 value was in an unused? couple of patches listed below.
- *
- * http://ftp.tc.edu.tw/pub/docs/Unicode/utf8/linux-2.3.12-keyboard.diff
- * http://ftp.tc.edu.tw/pub/docs/Unicode/utf8/linux-2.3.12-console.diff
- */
-
- return;
- }
-
- type -= 0xf0;
-
- /* if type is KT_LETTER then it can be affected by Caps Lock */
- if (type == KT_LETTER) {
- type = KT_LATIN;
-
- if (ioctl(_this->console_fd, KDGKBLED, &locks_state) < 0) {
- /* TODO: error */
- return;
- }
-
- if (locks_state & K_CAPSLOCK) {
- kbe.kb_table = shift_state ^ (1 << KG_SHIFT);
-
- if (ioctl(_this->console_fd, KDGKBENT, &kbe) < 0) {
- /* TODO: error */
- return;
- }
- }
- }
-
- /* TODO: convert values >= 0x80 from ISO-8859-1? to UTF-8 */
- if (type != KT_LATIN || KVAL(kbe.kb_value) >= 0x80)
- return;
-
- *text = KVAL(kbe.kb_value);
- SDL_SendKeyboardText(text);
-}
-#endif /* SDL_INPUT_LINUXKD */
-
-void
-SDL_EVDEV_Poll(void)
-{
- struct input_event events[32];
- int i, j, len;
- SDL_evdevlist_item *item;
- SDL_Scancode scan_code;
- int mouse_button;
- SDL_Mouse *mouse;
- float norm_x, norm_y;
-
- if (!_this) {
- return;
- }
-
-#if SDL_USE_LIBUDEV
- SDL_UDEV_Poll();
-#endif
-
- mouse = SDL_GetMouse();
-
- for (item = _this->first; item != NULL; item = item->next) {
- while ((len = read(item->fd, events, (sizeof events))) > 0) {
- len /= sizeof(events[0]);
- for (i = 0; i < len; ++i) {
- /* special handling for touchscreen, that should eventually be
- used for all devices */
- if (item->out_of_sync && item->is_touchscreen &&
- events[i].type == EV_SYN && events[i].code != SYN_REPORT) {
- break;
- }
-
- switch (events[i].type) {
- case EV_KEY:
- if (events[i].code >= BTN_MOUSE && events[i].code < BTN_MOUSE + SDL_arraysize(EVDEV_MouseButtons)) {
- mouse_button = events[i].code - BTN_MOUSE;
- if (events[i].value == 0) {
- SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, EVDEV_MouseButtons[mouse_button]);
- } else if (events[i].value == 1) {
- SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, EVDEV_MouseButtons[mouse_button]);
- }
- break;
- }
-
- /* Probably keyboard */
- scan_code = SDL_EVDEV_translate_keycode(events[i].code);
- if (scan_code != SDL_SCANCODE_UNKNOWN) {
- if (events[i].value == 0) {
- SDL_SendKeyboardKey(SDL_RELEASED, scan_code);
- } else if (events[i].value == 1 || events[i].value == 2 /* key repeated */) {
- SDL_SendKeyboardKey(SDL_PRESSED, scan_code);
-#ifdef SDL_INPUT_LINUXKD
- SDL_EVDEV_do_text_input(events[i].code);
-#endif /* SDL_INPUT_LINUXKD */
- }
- }
- break;
- case EV_ABS:
- switch(events[i].code) {
- case ABS_MT_SLOT:
- if (!item->is_touchscreen) /* FIXME: temp hack */
- break;
- item->touchscreen_data->current_slot = events[i].value;
- break;
- case ABS_MT_TRACKING_ID:
- if (!item->is_touchscreen) /* FIXME: temp hack */
- break;
- if (events[i].value >= 0) {
- item->touchscreen_data->slots[item->touchscreen_data->current_slot].tracking_id = events[i].value;
- item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
- } else {
- item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_UP;
- }
- break;
- case ABS_MT_POSITION_X:
- if (!item->is_touchscreen) /* FIXME: temp hack */
- break;
- item->touchscreen_data->slots[item->touchscreen_data->current_slot].x = events[i].value;
- if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
- item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
- }
- break;
- case ABS_MT_POSITION_Y:
- if (!item->is_touchscreen) /* FIXME: temp hack */
- break;
- item->touchscreen_data->slots[item->touchscreen_data->current_slot].y = events[i].value;
- if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
- item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
- }
- break;
- case ABS_X:
- if (item->is_touchscreen) /* FIXME: temp hack */
- break;
- SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, events[i].value, mouse->y);
- break;
- case ABS_Y:
- if (item->is_touchscreen) /* FIXME: temp hack */
- break;
- SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, mouse->x, events[i].value);
- break;
- default:
- break;
- }
- break;
- case EV_REL:
- switch(events[i].code) {
- case REL_X:
- SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, events[i].value, 0);
- break;
- case REL_Y:
- SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, 0, events[i].value);
- break;
- case REL_WHEEL:
- SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value, SDL_MOUSEWHEEL_NORMAL);
- break;
- case REL_HWHEEL:
- SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL);
- break;
- default:
- break;
- }
- break;
- case EV_SYN:
- switch (events[i].code) {
- case SYN_REPORT:
- if (!item->is_touchscreen) /* FIXME: temp hack */
- break;
-
- for(j = 0; j < item->touchscreen_data->max_slots; j++) {
- norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) /
- (float)item->touchscreen_data->range_x;
- norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) /
- (float)item->touchscreen_data->range_y;
-
- switch(item->touchscreen_data->slots[j].delta) {
- case EVDEV_TOUCH_SLOTDELTA_DOWN:
- SDL_SendTouch(item->fd, item->touchscreen_data->slots[j].tracking_id, SDL_TRUE, norm_x, norm_y, 1.0f);
- item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
- break;
- case EVDEV_TOUCH_SLOTDELTA_UP:
- SDL_SendTouch(item->fd, item->touchscreen_data->slots[j].tracking_id, SDL_FALSE, norm_x, norm_y, 1.0f);
- item->touchscreen_data->slots[j].tracking_id = -1;
- item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
- break;
- case EVDEV_TOUCH_SLOTDELTA_MOVE:
- SDL_SendTouchMotion(item->fd, item->touchscreen_data->slots[j].tracking_id, norm_x, norm_y, 1.0f);
- item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
- break;
- default:
- break;
- }
- }
-
- if (item->out_of_sync)
- item->out_of_sync = 0;
- break;
- case SYN_DROPPED:
- if (item->is_touchscreen)
- item->out_of_sync = 1;
- SDL_EVDEV_sync_device(item);
- break;
- default:
- break;
- }
- break;
- }
- }
- }
- }
-}
-
-static SDL_Scancode
-SDL_EVDEV_translate_keycode(int keycode)
-{
- SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
-
- if (keycode < SDL_arraysize(linux_scancode_table))
- scancode = linux_scancode_table[keycode];
-
- if (scancode == SDL_SCANCODE_UNKNOWN) {
- SDL_Log("The key you just pressed is not recognized by SDL. To help "
- "get this fixed, please report this to the SDL mailing list "
- "<sdl@libsdl.org> EVDEV KeyCode %d\n", keycode);
- }
-
- return scancode;
-}
-
-#ifdef SDL_USE_LIBUDEV
-static int
-SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item)
-{
- int ret, i;
- char name[64];
- struct input_absinfo abs_info;
-
- if (!item->is_touchscreen)
- return 0;
-
- item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data));
- if (item->touchscreen_data == NULL)
- return SDL_OutOfMemory();
-
- ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
- if (ret < 0) {
- SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen name");
- }
-
- item->touchscreen_data->name = SDL_strdup(name);
- if (item->touchscreen_data->name == NULL) {
- SDL_free(item->touchscreen_data);
- return SDL_OutOfMemory();
- }
-
- ret = ioctl(item->fd, EVIOCGABS(ABS_MT_POSITION_X), &abs_info);
- if (ret < 0) {
- SDL_free(item->touchscreen_data->name);
- SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
- }
- item->touchscreen_data->min_x = abs_info.minimum;
- item->touchscreen_data->max_x = abs_info.maximum;
- item->touchscreen_data->range_x = abs_info.maximum - abs_info.minimum;
-
- ret = ioctl(item->fd, EVIOCGABS(ABS_MT_POSITION_Y), &abs_info);
- if (ret < 0) {
- SDL_free(item->touchscreen_data->name);
- SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
- }
- item->touchscreen_data->min_y = abs_info.minimum;
- item->touchscreen_data->max_y = abs_info.maximum;
- item->touchscreen_data->range_y = abs_info.maximum - abs_info.minimum;
-
- ret = ioctl(item->fd, EVIOCGABS(ABS_MT_SLOT), &abs_info);
- if (ret < 0) {
- SDL_free(item->touchscreen_data->name);
- SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
- }
- item->touchscreen_data->max_slots = abs_info.maximum + 1;
-
- item->touchscreen_data->slots = SDL_calloc(
- item->touchscreen_data->max_slots,
- sizeof(*item->touchscreen_data->slots));
- if (item->touchscreen_data->slots == NULL) {
- SDL_free(item->touchscreen_data->name);
- SDL_free(item->touchscreen_data);
- return SDL_OutOfMemory();
- }
-
- for(i = 0; i < item->touchscreen_data->max_slots; i++) {
- item->touchscreen_data->slots[i].tracking_id = -1;
- }
-
- ret = SDL_AddTouch(item->fd, /* I guess our fd is unique enough */
- item->touchscreen_data->name);
- if (ret < 0) {
- SDL_free(item->touchscreen_data->slots);
- SDL_free(item->touchscreen_data->name);
- SDL_free(item->touchscreen_data);
- return ret;
- }
-
- return 0;
-}
-#endif /* SDL_USE_LIBUDEV */
-
-static void
-SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) {
- if (!item->is_touchscreen)
- return;
-
- SDL_DelTouch(item->fd);
- SDL_free(item->touchscreen_data->slots);
- SDL_free(item->touchscreen_data->name);
- SDL_free(item->touchscreen_data);
-}
-
-static void
-SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
-{
-#ifdef EVIOCGMTSLOTS
- int i, ret;
- struct input_absinfo abs_info;
- /*
- * struct input_mt_request_layout {
- * __u32 code;
- * __s32 values[num_slots];
- * };
- *
- * this is the structure we're trying to emulate
- */
- __u32* mt_req_code;
- __s32* mt_req_values;
- size_t mt_req_size;
-
- /* TODO: sync devices other than touchscreen */
- if (!item->is_touchscreen)
- return;
-
- mt_req_size = sizeof(*mt_req_code) +
- sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
-
- mt_req_code = SDL_calloc(1, mt_req_size);
- if (mt_req_code == NULL) {
- return;
- }
-
- mt_req_values = (__s32*)mt_req_code + 1;
-
- *mt_req_code = ABS_MT_TRACKING_ID;
- ret = ioctl(item->fd, EVIOCGMTSLOTS(mt_req_size), mt_req_code);
- if (ret < 0) {
- SDL_free(mt_req_code);
- return;
- }
- for(i = 0; i < item->touchscreen_data->max_slots; i++) {
- /*
- * This doesn't account for the very edge case of the user removing their
- * finger and replacing it on the screen during the time we're out of sync,
- * which'll mean that we're not going from down -> up or up -> down, we're
- * going from down -> down but with a different tracking id, meaning we'd
- * have to tell SDL of the two events, but since we wait till SYN_REPORT in
- * SDL_EVDEV_Poll to tell SDL, the current structure of this code doesn't
- * allow it. Lets just pray to God it doesn't happen.
- */
- if (item->touchscreen_data->slots[i].tracking_id < 0 &&
- mt_req_values[i] >= 0) {
- item->touchscreen_data->slots[i].tracking_id = mt_req_values[i];
- item->touchscreen_data->slots[i].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
- } else if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
- mt_req_values[i] < 0) {
- item->touchscreen_data->slots[i].tracking_id = -1;
- item->touchscreen_data->slots[i].delta = EVDEV_TOUCH_SLOTDELTA_UP;
- }
- }
-
- *mt_req_code = ABS_MT_POSITION_X;
- ret = ioctl(item->fd, EVIOCGMTSLOTS(mt_req_size), mt_req_code);
- if (ret < 0) {
- SDL_free(mt_req_code);
- return;
- }
- for(i = 0; i < item->touchscreen_data->max_slots; i++) {
- if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
- item->touchscreen_data->slots[i].x != mt_req_values[i]) {
- item->touchscreen_data->slots[i].x = mt_req_values[i];
- if (item->touchscreen_data->slots[i].delta ==
- EVDEV_TOUCH_SLOTDELTA_NONE) {
- item->touchscreen_data->slots[i].delta =
- EVDEV_TOUCH_SLOTDELTA_MOVE;
- }
- }
- }
-
- *mt_req_code = ABS_MT_POSITION_Y;
- ret = ioctl(item->fd, EVIOCGMTSLOTS(mt_req_size), mt_req_code);
- if (ret < 0) {
- SDL_free(mt_req_code);
- return;
- }
- for(i = 0; i < item->touchscreen_data->max_slots; i++) {
- if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
- item->touchscreen_data->slots[i].y != mt_req_values[i]) {
- item->touchscreen_data->slots[i].y = mt_req_values[i];
- if (item->touchscreen_data->slots[i].delta ==
- EVDEV_TOUCH_SLOTDELTA_NONE) {
- item->touchscreen_data->slots[i].delta =
- EVDEV_TOUCH_SLOTDELTA_MOVE;
- }
- }
- }
-
- ret = ioctl(item->fd, EVIOCGABS(ABS_MT_SLOT), &abs_info);
- if (ret < 0) {
- SDL_free(mt_req_code);
- return;
- }
- item->touchscreen_data->current_slot = abs_info.value;
-
- SDL_free(mt_req_code);
-
-#endif /* EVIOCGMTSLOTS */
-}
-
-#if SDL_USE_LIBUDEV
-static int
-SDL_EVDEV_device_added(const char *dev_path, int udev_class)
-{
- int ret;
- SDL_evdevlist_item *item;
-
- /* Check to make sure it's not already in list. */
- for (item = _this->first; item != NULL; item = item->next) {
- if (SDL_strcmp(dev_path, item->path) == 0) {
- return -1; /* already have this one */
- }
- }
-
- item = (SDL_evdevlist_item *) SDL_calloc(1, sizeof (SDL_evdevlist_item));
- if (item == NULL) {
- return SDL_OutOfMemory();
- }
-
- item->fd = open(dev_path, O_RDONLY | O_NONBLOCK);
- if (item->fd < 0) {
- SDL_free(item);
- return SDL_SetError("Unable to open %s", dev_path);
- }
-
- item->path = SDL_strdup(dev_path);
- if (item->path == NULL) {
- close(item->fd);
- SDL_free(item);
- return SDL_OutOfMemory();
- }
-
- if (udev_class & SDL_UDEV_DEVICE_TOUCHSCREEN) {
- item->is_touchscreen = 1;
-
- if ((ret = SDL_EVDEV_init_touchscreen(item)) < 0) {
- close(item->fd);
- SDL_free(item);
- return ret;
- }
- }
-
- if (_this->last == NULL) {
- _this->first = _this->last = item;
- } else {
- _this->last->next = item;
- _this->last = item;
- }
-
- SDL_EVDEV_sync_device(item);
-
- return _this->num_devices++;
-}
-#endif /* SDL_USE_LIBUDEV */
-
-static int
-SDL_EVDEV_device_removed(const char *dev_path)
-{
- SDL_evdevlist_item *item;
- SDL_evdevlist_item *prev = NULL;
-
- for (item = _this->first; item != NULL; item = item->next) {
- /* found it, remove it. */
- if (SDL_strcmp(dev_path, item->path) == 0) {
- if (prev != NULL) {
- prev->next = item->next;
- } else {
- SDL_assert(_this->first == item);
- _this->first = item->next;
- }
- if (item == _this->last) {
- _this->last = prev;
- }
- if (item->is_touchscreen) {
- SDL_EVDEV_destroy_touchscreen(item);
- }
- close(item->fd);
- SDL_free(item->path);
- SDL_free(item);
- _this->num_devices--;
- return 0;
- }
- prev = item;
- }
-
- return -1;
-}
-
-
-#endif /* SDL_INPUT_LINUXEV */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/linux/SDL_evdev.h b/3rdparty/SDL2/src/core/linux/SDL_evdev.h
deleted file mode 100644
index 85b193864ce..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_evdev.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_evdev_h
-#define _SDL_evdev_h
-
-#ifdef SDL_INPUT_LINUXEV
-
-#include "SDL_events.h"
-
-extern int SDL_EVDEV_Init(void);
-extern void SDL_EVDEV_Quit(void);
-extern void SDL_EVDEV_Poll(void);
-
-#endif /* SDL_INPUT_LINUXEV */
-
-#endif /* _SDL_evdev_h */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/linux/SDL_fcitx.c b/3rdparty/SDL2/src/core/linux/SDL_fcitx.c
deleted file mode 100644
index 83d19e690c5..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_fcitx.c
+++ /dev/null
@@ -1,553 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifdef HAVE_FCITX_FRONTEND_H
-
-#include <fcitx/frontend.h>
-#include <unistd.h>
-
-#include "SDL_fcitx.h"
-#include "SDL_keycode.h"
-#include "SDL_keyboard.h"
-#include "../../events/SDL_keyboard_c.h"
-#include "SDL_dbus.h"
-#include "SDL_syswm.h"
-#if SDL_VIDEO_DRIVER_X11
-# include "../../video/x11/SDL_x11video.h"
-#endif
-#include "SDL_hints.h"
-
-#define FCITX_DBUS_SERVICE "org.fcitx.Fcitx"
-
-#define FCITX_IM_DBUS_PATH "/inputmethod"
-#define FCITX_IC_DBUS_PATH "/inputcontext_%d"
-
-#define FCITX_IM_DBUS_INTERFACE "org.fcitx.Fcitx.InputMethod"
-#define FCITX_IC_DBUS_INTERFACE "org.fcitx.Fcitx.InputContext"
-
-#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];
-
- int id;
-
- SDL_Rect cursor_rect;
-} 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()
-{
-#if defined(__LINUX__) || defined(__FREEBSD__)
- char *spot;
- char procfile[1024];
- char linkfile[1024];
- int linksize;
-
-#if defined(__LINUX__)
- SDL_snprintf(procfile, sizeof(procfile), "/proc/%d/exe", getpid());
-#elif defined(__FREEBSD__)
- SDL_snprintf(procfile, sizeof(procfile), "/proc/%d/file", getpid());
-#endif
- linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1);
- if (linksize > 0) {
- linkfile[linksize] = '\0';
- spot = SDL_strrchr(linkfile, '/');
- if (spot) {
- return SDL_strdup(spot + 1);
- } else {
- return SDL_strdup(linkfile);
- }
- }
-#endif /* __LINUX__ || __FREEBSD__ */
-
- return SDL_strdup("SDL_App");
-}
-
-/*
- * Copied from fcitx source
- */
-#define CONT(i) ISUTF8_CB(in[i])
-#define VAL(i, s) ((in[i]&0x3f) << s)
-
-static char *
-_fcitx_utf8_get_char(const char *i, uint32_t *chr)
-{
- const unsigned char* in = (const unsigned char *)i;
- if (!(in[0] & 0x80)) {
- *(chr) = *(in);
- return (char *)in + 1;
- }
-
- /* 2-byte, 0x80-0x7ff */
- if ((in[0] & 0xe0) == 0xc0 && CONT(1)) {
- *chr = ((in[0] & 0x1f) << 6) | VAL(1, 0);
- return (char *)in + 2;
- }
-
- /* 3-byte, 0x800-0xffff */
- if ((in[0] & 0xf0) == 0xe0 && CONT(1) && CONT(2)) {
- *chr = ((in[0] & 0xf) << 12) | VAL(1, 6) | VAL(2, 0);
- return (char *)in + 3;
- }
-
- /* 4-byte, 0x10000-0x1FFFFF */
- if ((in[0] & 0xf8) == 0xf0 && CONT(1) && CONT(2) && CONT(3)) {
- *chr = ((in[0] & 0x7) << 18) | VAL(1, 12) | VAL(2, 6) | VAL(3, 0);
- return (char *)in + 4;
- }
-
- /* 5-byte, 0x200000-0x3FFFFFF */
- if ((in[0] & 0xfc) == 0xf8 && CONT(1) && CONT(2) && CONT(3) && CONT(4)) {
- *chr = ((in[0] & 0x3) << 24) | VAL(1, 18) | VAL(2, 12) | VAL(3, 6) | VAL(4, 0);
- return (char *)in + 5;
- }
-
- /* 6-byte, 0x400000-0x7FFFFFF */
- if ((in[0] & 0xfe) == 0xfc && CONT(1) && CONT(2) && CONT(3) && CONT(4) && CONT(5)) {
- *chr = ((in[0] & 0x1) << 30) | VAL(1, 24) | VAL(2, 18) | VAL(3, 12) | VAL(4, 6) | VAL(5, 0);
- return (char *)in + 6;
- }
-
- *chr = *in;
-
- return (char *)in + 1;
-}
-
-static size_t
-_fcitx_utf8_strlen(const char *s)
-{
- unsigned int l = 0;
-
- while (*s) {
- uint32_t chr;
-
- s = _fcitx_utf8_get_char(s, &chr);
- l++;
- }
-
- return l;
-}
-
-static DBusHandlerResult
-DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
-{
- SDL_DBusContext *dbus = (SDL_DBusContext *)data;
-
- if (dbus->message_is_signal(msg, FCITX_IC_DBUS_INTERFACE, "CommitString")) {
- DBusMessageIter iter;
- const char *text = NULL;
-
- dbus->message_iter_init(msg, &iter);
- dbus->message_iter_get_basic(&iter, &text);
-
- if (text)
- SDL_SendKeyboardText(text);
-
- 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) {
- char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
- size_t text_bytes = SDL_strlen(text), i = 0;
- size_t cursor = 0;
-
- while (i < text_bytes) {
- size_t sz = SDL_utf8strlcpy(buf, text + i, sizeof(buf));
- size_t chars = _fcitx_utf8_strlen(buf);
-
- SDL_SendEditingText(buf, cursor, chars);
-
- i += sz;
- cursor += chars;
- }
- }
-
- SDL_Fcitx_UpdateTextRect(NULL);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static DBusMessage*
-FcitxClientICNewMethod(FcitxClient *client,
- const char *method)
-{
- SDL_DBusContext *dbus = client->dbus;
- return dbus->message_new_method_call(
- client->servicename,
- client->icname,
- FCITX_IC_DBUS_INTERFACE,
- method);
-}
-
-static void
-FcitxClientICCallMethod(FcitxClient *client,
- const char *method)
-{
- SDL_DBusContext *dbus = client->dbus;
- DBusMessage *msg = FcitxClientICNewMethod(client, method);
-
- if (msg == NULL)
- return ;
-
- if (dbus->connection_send(dbus->session_conn, msg, NULL)) {
- dbus->connection_flush(dbus->session_conn);
- }
-
- dbus->message_unref(msg);
-}
-
-static void
-Fcitx_SetCapabilities(void *data,
- const char *name,
- const char *old_val,
- const char *internal_editing)
-{
- FcitxClient *client = (FcitxClient *)data;
- SDL_DBusContext *dbus = client->dbus;
- Uint32 caps = CAPACITY_NONE;
-
- DBusMessage *msg = FcitxClientICNewMethod(client, "SetCapacity");
- if (msg == NULL)
- return ;
-
- if (!(internal_editing && *internal_editing == '1')) {
- caps |= CAPACITY_PREEDIT;
- }
-
- dbus->message_append_args(msg,
- DBUS_TYPE_UINT32, &caps,
- DBUS_TYPE_INVALID);
- if (dbus->connection_send(dbus->session_conn, msg, NULL)) {
- dbus->connection_flush(dbus->session_conn);
- }
-
- dbus->message_unref(msg);
-}
-
-static void
-FcitxClientCreateIC(FcitxClient *client)
-{
- char *appname = NULL;
- pid_t pid = 0;
- int id = 0;
- SDL_bool enable;
- Uint32 arg1, arg2, arg3, arg4;
-
- SDL_DBusContext *dbus = client->dbus;
- DBusMessage *reply = NULL;
- DBusMessage *msg = dbus->message_new_method_call(
- client->servicename,
- FCITX_IM_DBUS_PATH,
- FCITX_IM_DBUS_INTERFACE,
- "CreateICv3"
- );
-
- if (msg == NULL)
- return ;
-
- appname = GetAppName();
- pid = getpid();
- dbus->message_append_args(msg,
- DBUS_TYPE_STRING, &appname,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INVALID);
-
- do {
- reply = dbus->connection_send_with_reply_and_block(
- dbus->session_conn,
- msg,
- DBUS_TIMEOUT,
- NULL);
-
- if (!reply)
- break;
- if (!dbus->message_get_args(reply, NULL,
- 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))
- break;
-
- if (id < 0)
- break;
- client->id = id;
-
- SDL_snprintf(client->icname, IC_NAME_MAX,
- FCITX_IC_DBUS_PATH, client->id);
-
- dbus->bus_add_match(dbus->session_conn,
- "type='signal', interface='org.fcitx.Fcitx.InputContext'",
- NULL);
- dbus->connection_add_filter(dbus->session_conn,
- &DBus_MessageFilter, dbus,
- NULL);
- dbus->connection_flush(dbus->session_conn);
-
- SDL_AddHintCallback(SDL_HINT_IME_INTERNAL_EDITING, &Fcitx_SetCapabilities, client);
- }
- while (0);
-
- if (reply)
- dbus->message_unref(reply);
- dbus->message_unref(msg);
- SDL_free(appname);
-}
-
-static Uint32
-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;
-
- return fcitx_mods;
-}
-
-SDL_bool
-SDL_Fcitx_Init()
-{
- fcitx_client.dbus = SDL_DBus_GetContext();
-
- fcitx_client.cursor_rect.x = -1;
- fcitx_client.cursor_rect.y = -1;
- 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());
-
- FcitxClientCreateIC(&fcitx_client);
-
- return SDL_TRUE;
-}
-
-void
-SDL_Fcitx_Quit()
-{
- FcitxClientICCallMethod(&fcitx_client, "DestroyIC");
-}
-
-void
-SDL_Fcitx_SetFocus(SDL_bool focused)
-{
- if (focused) {
- FcitxClientICCallMethod(&fcitx_client, "FocusIn");
- } else {
- FcitxClientICCallMethod(&fcitx_client, "FocusOut");
- }
-}
-
-void
-SDL_Fcitx_Reset(void)
-{
- FcitxClientICCallMethod(&fcitx_client, "Reset");
- FcitxClientICCallMethod(&fcitx_client, "CloseIC");
-}
-
-SDL_bool
-SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
-{
- DBusMessage *msg = NULL;
- DBusMessage *reply = NULL;
- SDL_DBusContext *dbus = fcitx_client.dbus;
-
- Uint32 state = 0;
- SDL_bool handled = SDL_FALSE;
- int type = FCITX_PRESS_KEY;
- Uint32 event_time = 0;
-
- msg = FcitxClientICNewMethod(&fcitx_client, "ProcessKeyEvent");
- if (msg == NULL)
- return SDL_FALSE;
-
- state = Fcitx_ModState();
- dbus->message_append_args(msg,
- DBUS_TYPE_UINT32, &keysym,
- DBUS_TYPE_UINT32, &keycode,
- DBUS_TYPE_UINT32, &state,
- DBUS_TYPE_INT32, &type,
- DBUS_TYPE_UINT32, &event_time,
- DBUS_TYPE_INVALID);
-
- reply = dbus->connection_send_with_reply_and_block(dbus->session_conn,
- msg,
- -1,
- NULL);
-
- if (reply) {
- dbus->message_get_args(reply,
- NULL,
- DBUS_TYPE_INT32, &handled,
- DBUS_TYPE_INVALID);
-
- dbus->message_unref(reply);
- }
-
- if (handled) {
- SDL_Fcitx_UpdateTextRect(NULL);
- }
-
- return handled;
-}
-
-void
-SDL_Fcitx_UpdateTextRect(SDL_Rect *rect)
-{
- SDL_Window *focused_win = NULL;
- SDL_SysWMinfo info;
- int x = 0, y = 0;
- SDL_Rect *cursor = &fcitx_client.cursor_rect;
-
- SDL_DBusContext *dbus = fcitx_client.dbus;
- DBusMessage *msg = NULL;
- DBusConnection *conn;
-
- if (rect) {
- SDL_memcpy(cursor, rect, sizeof(SDL_Rect));
- }
-
- focused_win = SDL_GetKeyboardFocus();
- if (!focused_win) {
- return ;
- }
-
- SDL_VERSION(&info.version);
- if (!SDL_GetWindowWMInfo(focused_win, &info)) {
- return;
- }
-
- SDL_GetWindowPosition(focused_win, &x, &y);
-
-#if SDL_VIDEO_DRIVER_X11
- if (info.subsystem == SDL_SYSWM_X11) {
- SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(focused_win)->driverdata;
-
- Display *x_disp = info.info.x11.display;
- Window x_win = info.info.x11.window;
- int x_screen = displaydata->screen;
- Window unused;
- X11_XTranslateCoordinates(x_disp, x_win, RootWindow(x_disp, x_screen), 0, 0, &x, &y, &unused);
- }
-#endif
-
- if (cursor->x == -1 && cursor->y == -1 && cursor->w == 0 && cursor->h == 0) {
- // move to bottom left
- int w = 0, h = 0;
- SDL_GetWindowSize(focused_win, &w, &h);
- cursor->x = 0;
- cursor->y = h;
- }
-
- x += cursor->x;
- y += cursor->y;
-
- msg = FcitxClientICNewMethod(&fcitx_client, "SetCursorRect");
- if (msg == NULL)
- return ;
-
- dbus->message_append_args(msg,
- DBUS_TYPE_INT32, &x,
- DBUS_TYPE_INT32, &y,
- DBUS_TYPE_INT32, &cursor->w,
- DBUS_TYPE_INT32, &cursor->h,
- DBUS_TYPE_INVALID);
-
- conn = dbus->session_conn;
- if (dbus->connection_send(conn, msg, NULL))
- dbus->connection_flush(conn);
-
- dbus->message_unref(msg);
-}
-
-void
-SDL_Fcitx_PumpEvents()
-{
- SDL_DBusContext *dbus = fcitx_client.dbus;
- DBusConnection *conn = dbus->session_conn;
-
- dbus->connection_read_write(conn, 0);
-
- while (dbus->connection_dispatch(conn) == DBUS_DISPATCH_DATA_REMAINS) {
- /* Do nothing, actual work happens in DBus_MessageFilter */
- usleep(10);
- }
-}
-
-#endif /* HAVE_FCITX_FRONTEND_H */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/linux/SDL_fcitx.h b/3rdparty/SDL2/src/core/linux/SDL_fcitx.h
deleted file mode 100644
index 64020475c0a..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_fcitx.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_fcitx_h
-#define _SDL_fcitx_h
-
-#include "../../SDL_internal.h"
-
-#include "SDL_stdinc.h"
-#include "SDL_rect.h"
-
-extern SDL_bool SDL_Fcitx_Init(void);
-extern void SDL_Fcitx_Quit(void);
-extern void SDL_Fcitx_SetFocus(SDL_bool focused);
-extern void SDL_Fcitx_Reset(void);
-extern SDL_bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode);
-extern void SDL_Fcitx_UpdateTextRect(SDL_Rect *rect);
-extern void SDL_Fcitx_PumpEvents();
-
-#endif /* _SDL_fcitx_h */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/linux/SDL_ibus.c b/3rdparty/SDL2/src/core/linux/SDL_ibus.c
deleted file mode 100644
index 3d63b8b30c3..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_ibus.c
+++ /dev/null
@@ -1,682 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifdef HAVE_IBUS_IBUS_H
-#include "SDL.h"
-#include "SDL_syswm.h"
-#include "SDL_ibus.h"
-#include "SDL_dbus.h"
-#include "../../video/SDL_sysvideo.h"
-#include "../../events/SDL_keyboard_c.h"
-
-#if SDL_VIDEO_DRIVER_X11
- #include "../../video/x11/SDL_x11video.h"
-#endif
-
-#include <sys/inotify.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-static const char IBUS_SERVICE[] = "org.freedesktop.IBus";
-static const char IBUS_PATH[] = "/org/freedesktop/IBus";
-static const char IBUS_INTERFACE[] = "org.freedesktop.IBus";
-static const char IBUS_INPUT_INTERFACE[] = "org.freedesktop.IBus.InputContext";
-
-static char *input_ctx_path = NULL;
-static SDL_Rect ibus_cursor_rect = { 0, 0, 0, 0 };
-static DBusConnection *ibus_conn = NULL;
-static char *ibus_addr_file = NULL;
-int inotify_fd = -1, inotify_wd = -1;
-
-static Uint32
-IBus_ModState(void)
-{
- Uint32 ibus_mods = 0;
- SDL_Keymod sdl_mods = SDL_GetModState();
-
- /* Not sure about MOD3, MOD4 and HYPER mappings */
- if (sdl_mods & KMOD_LSHIFT) ibus_mods |= IBUS_SHIFT_MASK;
- if (sdl_mods & KMOD_CAPS) ibus_mods |= IBUS_LOCK_MASK;
- if (sdl_mods & KMOD_LCTRL) ibus_mods |= IBUS_CONTROL_MASK;
- if (sdl_mods & KMOD_LALT) ibus_mods |= IBUS_MOD1_MASK;
- if (sdl_mods & KMOD_NUM) ibus_mods |= IBUS_MOD2_MASK;
- if (sdl_mods & KMOD_MODE) ibus_mods |= IBUS_MOD5_MASK;
- if (sdl_mods & KMOD_LGUI) ibus_mods |= IBUS_SUPER_MASK;
- if (sdl_mods & KMOD_RGUI) ibus_mods |= IBUS_META_MASK;
-
- return ibus_mods;
-}
-
-static const char *
-IBus_GetVariantText(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus)
-{
- /* The text we need is nested weirdly, use dbus-monitor to see the structure better */
- const char *text = NULL;
- const char *struct_id = NULL;
- DBusMessageIter sub1, sub2;
-
- if (dbus->message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
- return NULL;
- }
-
- dbus->message_iter_recurse(iter, &sub1);
-
- if (dbus->message_iter_get_arg_type(&sub1) != DBUS_TYPE_STRUCT) {
- return NULL;
- }
-
- dbus->message_iter_recurse(&sub1, &sub2);
-
- if (dbus->message_iter_get_arg_type(&sub2) != DBUS_TYPE_STRING) {
- return NULL;
- }
-
- dbus->message_iter_get_basic(&sub2, &struct_id);
- if (!struct_id || SDL_strncmp(struct_id, "IBusText", sizeof("IBusText")) != 0) {
- return NULL;
- }
-
- dbus->message_iter_next(&sub2);
- dbus->message_iter_next(&sub2);
-
- if (dbus->message_iter_get_arg_type(&sub2) != DBUS_TYPE_STRING) {
- return NULL;
- }
-
- dbus->message_iter_get_basic(&sub2, &text);
-
- return text;
-}
-
-static size_t
-IBus_utf8_strlen(const char *str)
-{
- size_t utf8_len = 0;
- const char *p;
-
- for (p = str; *p; ++p) {
- if (!((*p & 0x80) && !(*p & 0x40))) {
- ++utf8_len;
- }
- }
-
- return utf8_len;
-}
-
-static DBusHandlerResult
-IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
-{
- SDL_DBusContext *dbus = (SDL_DBusContext *)user_data;
-
- if (dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "CommitText")) {
- DBusMessageIter iter;
- const char *text;
-
- dbus->message_iter_init(msg, &iter);
-
- text = IBus_GetVariantText(conn, &iter, dbus);
- if (text && *text) {
- char buf[SDL_TEXTEDITINGEVENT_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, IBUS_INPUT_INTERFACE, "UpdatePreeditText")) {
- DBusMessageIter iter;
- const char *text;
-
- dbus->message_iter_init(msg, &iter);
- text = IBus_GetVariantText(conn, &iter, dbus);
-
- if (text) {
- char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
- size_t text_bytes = SDL_strlen(text), i = 0;
- size_t cursor = 0;
-
- do {
- size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
- size_t chars = IBus_utf8_strlen(buf);
-
- SDL_SendEditingText(buf, cursor, chars);
-
- i += sz;
- cursor += chars;
- } while (i < text_bytes);
- }
-
- SDL_IBus_UpdateTextRect(NULL);
-
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
- if (dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "HidePreeditText")) {
- SDL_SendEditingText("", 0, 0);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static char *
-IBus_ReadAddressFromFile(const char *file_path)
-{
- char addr_buf[1024];
- SDL_bool success = SDL_FALSE;
- FILE *addr_file;
-
- addr_file = fopen(file_path, "r");
- if (!addr_file) {
- return NULL;
- }
-
- while (fgets(addr_buf, sizeof(addr_buf), addr_file)) {
- if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) {
- size_t sz = SDL_strlen(addr_buf);
- if (addr_buf[sz-1] == '\n') addr_buf[sz-1] = 0;
- if (addr_buf[sz-2] == '\r') addr_buf[sz-2] = 0;
- success = SDL_TRUE;
- break;
- }
- }
-
- fclose(addr_file);
-
- if (success) {
- return SDL_strdup(addr_buf + (sizeof("IBUS_ADDRESS=") - 1));
- } else {
- return NULL;
- }
-}
-
-static char *
-IBus_GetDBusAddressFilename(void)
-{
- SDL_DBusContext *dbus;
- const char *disp_env;
- char config_dir[PATH_MAX];
- char *display = NULL;
- const char *addr;
- const char *conf_env;
- char *key;
- char file_path[PATH_MAX];
- const char *host;
- char *disp_num, *screen_num;
-
- if (ibus_addr_file) {
- return SDL_strdup(ibus_addr_file);
- }
-
- dbus = SDL_DBus_GetContext();
- if (!dbus) {
- return NULL;
- }
-
- /* Use this environment variable if it exists. */
- addr = SDL_getenv("IBUS_ADDRESS");
- if (addr && *addr) {
- return SDL_strdup(addr);
- }
-
- /* Otherwise, we have to get the hostname, display, machine id, config dir
- and look up the address from a filepath using all those bits, eek. */
- disp_env = SDL_getenv("DISPLAY");
-
- if (!disp_env || !*disp_env) {
- display = SDL_strdup(":0.0");
- } else {
- display = SDL_strdup(disp_env);
- }
-
- host = display;
- disp_num = SDL_strrchr(display, ':');
- screen_num = SDL_strrchr(display, '.');
-
- if (!disp_num) {
- SDL_free(display);
- return NULL;
- }
-
- *disp_num = 0;
- disp_num++;
-
- if (screen_num) {
- *screen_num = 0;
- }
-
- if (!*host) {
- host = "unix";
- }
-
- SDL_memset(config_dir, 0, sizeof(config_dir));
-
- conf_env = SDL_getenv("XDG_CONFIG_HOME");
- if (conf_env && *conf_env) {
- SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
- } else {
- const char *home_env = SDL_getenv("HOME");
- if (!home_env || !*home_env) {
- SDL_free(display);
- return NULL;
- }
- SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
- }
-
- key = dbus->get_local_machine_id();
-
- SDL_memset(file_path, 0, sizeof(file_path));
- SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",
- config_dir, key, host, disp_num);
- dbus->free(key);
- SDL_free(display);
-
- return SDL_strdup(file_path);
-}
-
-static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus);
-
-static void
-IBus_SetCapabilities(void *data, const char *name, const char *old_val,
- const char *internal_editing)
-{
- SDL_DBusContext *dbus = SDL_DBus_GetContext();
-
- if (IBus_CheckConnection(dbus)) {
-
- DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
- input_ctx_path,
- IBUS_INPUT_INTERFACE,
- "SetCapabilities");
- if (msg) {
- Uint32 caps = IBUS_CAP_FOCUS;
- if (!(internal_editing && *internal_editing == '1')) {
- caps |= IBUS_CAP_PREEDIT_TEXT;
- }
-
- dbus->message_append_args(msg,
- DBUS_TYPE_UINT32, &caps,
- DBUS_TYPE_INVALID);
- }
-
- if (msg) {
- if (dbus->connection_send(ibus_conn, msg, NULL)) {
- dbus->connection_flush(ibus_conn);
- }
- dbus->message_unref(msg);
- }
- }
-}
-
-
-static SDL_bool
-IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
-{
- const char *path = NULL;
- SDL_bool result = SDL_FALSE;
- DBusMessage *msg;
- DBusObjectPathVTable ibus_vtable;
-
- SDL_zero(ibus_vtable);
- ibus_vtable.message_function = &IBus_MessageHandler;
-
- ibus_conn = dbus->connection_open_private(addr, NULL);
-
- if (!ibus_conn) {
- return SDL_FALSE;
- }
-
- dbus->connection_flush(ibus_conn);
-
- if (!dbus->bus_register(ibus_conn, NULL)) {
- ibus_conn = NULL;
- return SDL_FALSE;
- }
-
- dbus->connection_flush(ibus_conn);
-
- msg = dbus->message_new_method_call(IBUS_SERVICE, IBUS_PATH, IBUS_INTERFACE, "CreateInputContext");
- if (msg) {
- const char *client_name = "SDL2_Application";
- dbus->message_append_args(msg,
- DBUS_TYPE_STRING, &client_name,
- DBUS_TYPE_INVALID);
- }
-
- if (msg) {
- DBusMessage *reply;
-
- reply = dbus->connection_send_with_reply_and_block(ibus_conn, msg, 1000, NULL);
- if (reply) {
- if (dbus->message_get_args(reply, NULL,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID)) {
- if (input_ctx_path) {
- SDL_free(input_ctx_path);
- }
- input_ctx_path = SDL_strdup(path);
- result = SDL_TRUE;
- }
- dbus->message_unref(reply);
- }
- dbus->message_unref(msg);
- }
-
- if (result) {
- SDL_AddHintCallback(SDL_HINT_IME_INTERNAL_EDITING, &IBus_SetCapabilities, NULL);
-
- dbus->bus_add_match(ibus_conn, "type='signal',interface='org.freedesktop.IBus.InputContext'", NULL);
- dbus->connection_try_register_object_path(ibus_conn, input_ctx_path, &ibus_vtable, dbus, NULL);
- dbus->connection_flush(ibus_conn);
- }
-
- SDL_IBus_SetFocus(SDL_GetKeyboardFocus() != NULL);
- SDL_IBus_UpdateTextRect(NULL);
-
- return result;
-}
-
-static SDL_bool
-IBus_CheckConnection(SDL_DBusContext *dbus)
-{
- if (!dbus) return SDL_FALSE;
-
- if (ibus_conn && dbus->connection_get_is_connected(ibus_conn)) {
- return SDL_TRUE;
- }
-
- if (inotify_fd > 0 && inotify_wd > 0) {
- char buf[1024];
- ssize_t readsize = read(inotify_fd, buf, sizeof(buf));
- if (readsize > 0) {
-
- char *p;
- SDL_bool file_updated = SDL_FALSE;
-
- for (p = buf; p < buf + readsize; /**/) {
- struct inotify_event *event = (struct inotify_event*) p;
- if (event->len > 0) {
- char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
- if (!addr_file_no_path) return SDL_FALSE;
-
- if (SDL_strcmp(addr_file_no_path + 1, event->name) == 0) {
- file_updated = SDL_TRUE;
- break;
- }
- }
-
- p += sizeof(struct inotify_event) + event->len;
- }
-
- if (file_updated) {
- char *addr = IBus_ReadAddressFromFile(ibus_addr_file);
- if (addr) {
- SDL_bool result = IBus_SetupConnection(dbus, addr);
- SDL_free(addr);
- return result;
- }
- }
- }
- }
-
- return SDL_FALSE;
-}
-
-SDL_bool
-SDL_IBus_Init(void)
-{
- SDL_bool result = SDL_FALSE;
- SDL_DBusContext *dbus = SDL_DBus_GetContext();
-
- if (dbus) {
- char *addr_file = IBus_GetDBusAddressFilename();
- char *addr;
- char *addr_file_dir;
-
- if (!addr_file) {
- return SDL_FALSE;
- }
-
- /* !!! FIXME: if ibus_addr_file != NULL, this will overwrite it and leak (twice!) */
- ibus_addr_file = SDL_strdup(addr_file);
-
- addr = IBus_ReadAddressFromFile(addr_file);
- if (!addr) {
- SDL_free(addr_file);
- return SDL_FALSE;
- }
-
- if (inotify_fd < 0) {
- inotify_fd = inotify_init();
- fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
- }
-
- addr_file_dir = SDL_strrchr(addr_file, '/');
- if (addr_file_dir) {
- *addr_file_dir = 0;
- }
-
- inotify_wd = inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
- SDL_free(addr_file);
-
- if (addr) {
- result = IBus_SetupConnection(dbus, addr);
- SDL_free(addr);
- }
- }
-
- return result;
-}
-
-void
-SDL_IBus_Quit(void)
-{
- SDL_DBusContext *dbus;
-
- if (input_ctx_path) {
- SDL_free(input_ctx_path);
- input_ctx_path = NULL;
- }
-
- if (ibus_addr_file) {
- SDL_free(ibus_addr_file);
- ibus_addr_file = NULL;
- }
-
- dbus = SDL_DBus_GetContext();
-
- if (dbus && ibus_conn) {
- dbus->connection_close(ibus_conn);
- dbus->connection_unref(ibus_conn);
- }
-
- if (inotify_fd > 0 && inotify_wd > 0) {
- inotify_rm_watch(inotify_fd, inotify_wd);
- inotify_wd = -1;
- }
-
- SDL_DelHintCallback(SDL_HINT_IME_INTERNAL_EDITING, &IBus_SetCapabilities, NULL);
-
- SDL_memset(&ibus_cursor_rect, 0, sizeof(ibus_cursor_rect));
-}
-
-static void
-IBus_SimpleMessage(const char *method)
-{
- SDL_DBusContext *dbus = SDL_DBus_GetContext();
-
- if (IBus_CheckConnection(dbus)) {
- DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
- input_ctx_path,
- IBUS_INPUT_INTERFACE,
- method);
- if (msg) {
- if (dbus->connection_send(ibus_conn, msg, NULL)) {
- dbus->connection_flush(ibus_conn);
- }
- dbus->message_unref(msg);
- }
- }
-}
-
-void
-SDL_IBus_SetFocus(SDL_bool focused)
-{
- const char *method = focused ? "FocusIn" : "FocusOut";
- IBus_SimpleMessage(method);
-}
-
-void
-SDL_IBus_Reset(void)
-{
- IBus_SimpleMessage("Reset");
-}
-
-SDL_bool
-SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
-{
- SDL_bool result = SDL_FALSE;
- SDL_DBusContext *dbus = SDL_DBus_GetContext();
-
- if (IBus_CheckConnection(dbus)) {
- DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
- input_ctx_path,
- IBUS_INPUT_INTERFACE,
- "ProcessKeyEvent");
- if (msg) {
- Uint32 mods = IBus_ModState();
- dbus->message_append_args(msg,
- DBUS_TYPE_UINT32, &keysym,
- DBUS_TYPE_UINT32, &keycode,
- DBUS_TYPE_UINT32, &mods,
- DBUS_TYPE_INVALID);
- }
-
- if (msg) {
- DBusMessage *reply;
-
- reply = dbus->connection_send_with_reply_and_block(ibus_conn, msg, 300, NULL);
- if (reply) {
- if (!dbus->message_get_args(reply, NULL,
- DBUS_TYPE_BOOLEAN, &result,
- DBUS_TYPE_INVALID)) {
- result = SDL_FALSE;
- }
- dbus->message_unref(reply);
- }
- dbus->message_unref(msg);
- }
-
- }
-
- SDL_IBus_UpdateTextRect(NULL);
-
- return result;
-}
-
-void
-SDL_IBus_UpdateTextRect(SDL_Rect *rect)
-{
- SDL_Window *focused_win;
- SDL_SysWMinfo info;
- int x = 0, y = 0;
- SDL_DBusContext *dbus;
-
- if (rect) {
- SDL_memcpy(&ibus_cursor_rect, rect, sizeof(ibus_cursor_rect));
- }
-
- focused_win = SDL_GetKeyboardFocus();
- if (!focused_win) {
- return;
- }
-
- SDL_VERSION(&info.version);
- if (!SDL_GetWindowWMInfo(focused_win, &info)) {
- return;
- }
-
- SDL_GetWindowPosition(focused_win, &x, &y);
-
-#if SDL_VIDEO_DRIVER_X11
- if (info.subsystem == SDL_SYSWM_X11) {
- SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(focused_win)->driverdata;
-
- Display *x_disp = info.info.x11.display;
- Window x_win = info.info.x11.window;
- int x_screen = displaydata->screen;
- Window unused;
-
- X11_XTranslateCoordinates(x_disp, x_win, RootWindow(x_disp, x_screen), 0, 0, &x, &y, &unused);
- }
-#endif
-
- x += ibus_cursor_rect.x;
- y += ibus_cursor_rect.y;
-
- dbus = SDL_DBus_GetContext();
-
- if (IBus_CheckConnection(dbus)) {
- DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
- input_ctx_path,
- IBUS_INPUT_INTERFACE,
- "SetCursorLocation");
- if (msg) {
- dbus->message_append_args(msg,
- DBUS_TYPE_INT32, &x,
- DBUS_TYPE_INT32, &y,
- DBUS_TYPE_INT32, &ibus_cursor_rect.w,
- DBUS_TYPE_INT32, &ibus_cursor_rect.h,
- DBUS_TYPE_INVALID);
- }
-
- if (msg) {
- if (dbus->connection_send(ibus_conn, msg, NULL)) {
- dbus->connection_flush(ibus_conn);
- }
- dbus->message_unref(msg);
- }
- }
-}
-
-void
-SDL_IBus_PumpEvents(void)
-{
- SDL_DBusContext *dbus = SDL_DBus_GetContext();
-
- if (IBus_CheckConnection(dbus)) {
- dbus->connection_read_write(ibus_conn, 0);
-
- while (dbus->connection_dispatch(ibus_conn) == DBUS_DISPATCH_DATA_REMAINS) {
- /* Do nothing, actual work happens in IBus_MessageHandler */
- }
- }
-}
-
-#endif
diff --git a/3rdparty/SDL2/src/core/linux/SDL_ibus.h b/3rdparty/SDL2/src/core/linux/SDL_ibus.h
deleted file mode 100644
index 5ee7a8e407c..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_ibus.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_ibus_h
-#define _SDL_ibus_h
-
-#ifdef HAVE_IBUS_IBUS_H
-#define SDL_USE_IBUS 1
-#include "SDL_stdinc.h"
-#include <ibus-1.0/ibus.h>
-
-extern SDL_bool SDL_IBus_Init(void);
-extern void SDL_IBus_Quit(void);
-
-/* Lets the IBus server know about changes in window focus */
-extern void SDL_IBus_SetFocus(SDL_bool focused);
-
-/* Closes the candidate list and resets any text currently being edited */
-extern void SDL_IBus_Reset(void);
-
-/* Sends a keypress event to IBus, returns SDL_TRUE if IBus used this event to
- update its candidate list or change input methods. PumpEvents should be
- called some time after this, to recieve the TextInput / TextEditing event back. */
-extern SDL_bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode);
-
-/* Update the position of IBus' candidate list. If rect is NULL then this will
- just reposition it relative to the focused window's new position. */
-extern void SDL_IBus_UpdateTextRect(SDL_Rect *window_relative_rect);
-
-/* Checks DBus for new IBus events, and calls SDL_SendKeyboardText /
- SDL_SendEditingText for each event it finds */
-extern void SDL_IBus_PumpEvents();
-
-#endif /* HAVE_IBUS_IBUS_H */
-
-#endif /* _SDL_ibus_h */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/linux/SDL_ime.c b/3rdparty/SDL2/src/core/linux/SDL_ime.c
deleted file mode 100644
index 049bd6e02e9..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_ime.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_ime.h"
-#include "SDL_ibus.h"
-#include "SDL_fcitx.h"
-
-typedef SDL_bool (*_SDL_IME_Init)();
-typedef void (*_SDL_IME_Quit)();
-typedef void (*_SDL_IME_SetFocus)(SDL_bool);
-typedef void (*_SDL_IME_Reset)();
-typedef SDL_bool (*_SDL_IME_ProcessKeyEvent)(Uint32, Uint32);
-typedef void (*_SDL_IME_UpdateTextRect)(SDL_Rect *);
-typedef void (*_SDL_IME_PumpEvents)();
-
-static _SDL_IME_Init SDL_IME_Init_Real = NULL;
-static _SDL_IME_Quit SDL_IME_Quit_Real = NULL;
-static _SDL_IME_SetFocus SDL_IME_SetFocus_Real = NULL;
-static _SDL_IME_Reset SDL_IME_Reset_Real = NULL;
-static _SDL_IME_ProcessKeyEvent SDL_IME_ProcessKeyEvent_Real = NULL;
-static _SDL_IME_UpdateTextRect SDL_IME_UpdateTextRect_Real = NULL;
-static _SDL_IME_PumpEvents SDL_IME_PumpEvents_Real = NULL;
-
-static void
-InitIME()
-{
- static SDL_bool inited = SDL_FALSE;
-#ifdef HAVE_FCITX_FRONTEND_H
- const char *im_module = SDL_getenv("SDL_IM_MODULE");
- const char *xmodifiers = SDL_getenv("XMODIFIERS");
-#endif
-
- if (inited == SDL_TRUE)
- return;
-
- inited = SDL_TRUE;
-
- /* See if fcitx IME support is being requested */
-#ifdef HAVE_FCITX_FRONTEND_H
- if (!SDL_IME_Init_Real &&
- ((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
- (!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
- SDL_IME_Init_Real = SDL_Fcitx_Init;
- SDL_IME_Quit_Real = SDL_Fcitx_Quit;
- SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
- SDL_IME_Reset_Real = SDL_Fcitx_Reset;
- SDL_IME_ProcessKeyEvent_Real = SDL_Fcitx_ProcessKeyEvent;
- SDL_IME_UpdateTextRect_Real = SDL_Fcitx_UpdateTextRect;
- SDL_IME_PumpEvents_Real = SDL_Fcitx_PumpEvents;
- }
-#endif /* HAVE_FCITX_FRONTEND_H */
-
- /* default to IBus */
-#ifdef HAVE_IBUS_IBUS_H
- if (!SDL_IME_Init_Real) {
- SDL_IME_Init_Real = SDL_IBus_Init;
- SDL_IME_Quit_Real = SDL_IBus_Quit;
- SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
- SDL_IME_Reset_Real = SDL_IBus_Reset;
- SDL_IME_ProcessKeyEvent_Real = SDL_IBus_ProcessKeyEvent;
- SDL_IME_UpdateTextRect_Real = SDL_IBus_UpdateTextRect;
- SDL_IME_PumpEvents_Real = SDL_IBus_PumpEvents;
- }
-#endif /* HAVE_IBUS_IBUS_H */
-}
-
-SDL_bool
-SDL_IME_Init(void)
-{
- InitIME();
-
- if (SDL_IME_Init_Real)
- return SDL_IME_Init_Real();
-
- return SDL_FALSE;
-}
-
-void
-SDL_IME_Quit(void)
-{
- if (SDL_IME_Quit_Real)
- SDL_IME_Quit_Real();
-}
-
-void
-SDL_IME_SetFocus(SDL_bool focused)
-{
- if (SDL_IME_SetFocus_Real)
- SDL_IME_SetFocus_Real(focused);
-}
-
-void
-SDL_IME_Reset(void)
-{
- if (SDL_IME_Reset_Real)
- SDL_IME_Reset_Real();
-}
-
-SDL_bool
-SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
-{
- if (SDL_IME_ProcessKeyEvent_Real)
- return SDL_IME_ProcessKeyEvent_Real(keysym, keycode);
-
- return SDL_FALSE;
-}
-
-void
-SDL_IME_UpdateTextRect(SDL_Rect *rect)
-{
- if (SDL_IME_UpdateTextRect_Real)
- SDL_IME_UpdateTextRect_Real(rect);
-}
-
-void
-SDL_IME_PumpEvents()
-{
- if (SDL_IME_PumpEvents_Real)
- SDL_IME_PumpEvents_Real();
-}
diff --git a/3rdparty/SDL2/src/core/linux/SDL_ime.h b/3rdparty/SDL2/src/core/linux/SDL_ime.h
deleted file mode 100644
index 22b31de398b..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_ime.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_ime_h
-#define _SDL_ime_h
-
-#include "../../SDL_internal.h"
-
-#include "SDL_stdinc.h"
-#include "SDL_rect.h"
-
-extern SDL_bool SDL_IME_Init();
-extern void SDL_IME_Quit();
-extern void SDL_IME_SetFocus(SDL_bool focused);
-extern void SDL_IME_Reset();
-extern SDL_bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode);
-extern void SDL_IME_UpdateTextRect(SDL_Rect *rect);
-extern void SDL_IME_PumpEvents();
-
-#endif /* _SDL_ime_h */
diff --git a/3rdparty/SDL2/src/core/linux/SDL_udev.c b/3rdparty/SDL2/src/core/linux/SDL_udev.c
deleted file mode 100644
index ae78ddd6849..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_udev.c
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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.
-*/
-
-/*
- * To list the properties of a device, try something like:
- * udevadm info -a -n snd/hwC0D0 (for a sound card)
- * udevadm info --query=all -n input/event3 (for a keyboard, mouse, etc)
- * udevadm info --query=property -n input/event2
- */
-#include "SDL_udev.h"
-
-#ifdef SDL_USE_LIBUDEV
-
-#include <linux/input.h>
-
-#include "SDL.h"
-
-static const char* SDL_UDEV_LIBS[] = { "libudev.so.1", "libudev.so.0" };
-
-#define _THIS SDL_UDEV_PrivateData *_this
-static _THIS = NULL;
-
-static SDL_bool SDL_UDEV_load_sym(const char *fn, void **addr);
-static int SDL_UDEV_load_syms(void);
-static SDL_bool SDL_UDEV_hotplug_update_available(void);
-static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev);
-
-static SDL_bool
-SDL_UDEV_load_sym(const char *fn, void **addr)
-{
- *addr = SDL_LoadFunction(_this->udev_handle, fn);
- if (*addr == NULL) {
- /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
- return SDL_FALSE;
- }
-
- return SDL_TRUE;
-}
-
-static int
-SDL_UDEV_load_syms(void)
-{
- /* cast funcs to char* first, to please GCC's strict aliasing rules. */
- #define SDL_UDEV_SYM(x) \
- if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->x)) return -1
-
- SDL_UDEV_SYM(udev_device_get_action);
- SDL_UDEV_SYM(udev_device_get_devnode);
- SDL_UDEV_SYM(udev_device_get_subsystem);
- SDL_UDEV_SYM(udev_device_get_parent_with_subsystem_devtype);
- SDL_UDEV_SYM(udev_device_get_property_value);
- SDL_UDEV_SYM(udev_device_get_sysattr_value);
- SDL_UDEV_SYM(udev_device_new_from_syspath);
- SDL_UDEV_SYM(udev_device_unref);
- SDL_UDEV_SYM(udev_enumerate_add_match_property);
- SDL_UDEV_SYM(udev_enumerate_add_match_subsystem);
- SDL_UDEV_SYM(udev_enumerate_get_list_entry);
- SDL_UDEV_SYM(udev_enumerate_new);
- SDL_UDEV_SYM(udev_enumerate_scan_devices);
- SDL_UDEV_SYM(udev_enumerate_unref);
- SDL_UDEV_SYM(udev_list_entry_get_name);
- SDL_UDEV_SYM(udev_list_entry_get_next);
- SDL_UDEV_SYM(udev_monitor_enable_receiving);
- SDL_UDEV_SYM(udev_monitor_filter_add_match_subsystem_devtype);
- SDL_UDEV_SYM(udev_monitor_get_fd);
- SDL_UDEV_SYM(udev_monitor_new_from_netlink);
- SDL_UDEV_SYM(udev_monitor_receive_device);
- SDL_UDEV_SYM(udev_monitor_unref);
- SDL_UDEV_SYM(udev_new);
- SDL_UDEV_SYM(udev_unref);
- SDL_UDEV_SYM(udev_device_new_from_devnum);
- SDL_UDEV_SYM(udev_device_get_devnum);
- #undef SDL_UDEV_SYM
-
- return 0;
-}
-
-static SDL_bool
-SDL_UDEV_hotplug_update_available(void)
-{
- if (_this->udev_mon != NULL) {
- const int fd = _this->udev_monitor_get_fd(_this->udev_mon);
- fd_set fds;
- struct timeval tv;
-
- FD_ZERO(&fds);
- FD_SET(fd, &fds);
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- if ((select(fd+1, &fds, NULL, NULL, &tv) > 0) && (FD_ISSET(fd, &fds))) {
- return SDL_TRUE;
- }
- }
- return SDL_FALSE;
-}
-
-
-int
-SDL_UDEV_Init(void)
-{
- int retval = 0;
-
- if (_this == NULL) {
- _this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
- if(_this == NULL) {
- return SDL_OutOfMemory();
- }
-
- retval = SDL_UDEV_LoadLibrary();
- if (retval < 0) {
- SDL_UDEV_Quit();
- return retval;
- }
-
- /* Set up udev monitoring
- * Listen for input devices (mouse, keyboard, joystick, etc) and sound devices
- */
-
- _this->udev = _this->udev_new();
- if (_this->udev == NULL) {
- SDL_UDEV_Quit();
- return SDL_SetError("udev_new() failed");
- }
-
- _this->udev_mon = _this->udev_monitor_new_from_netlink(_this->udev, "udev");
- if (_this->udev_mon == NULL) {
- SDL_UDEV_Quit();
- return SDL_SetError("udev_monitor_new_from_netlink() failed");
- }
-
- _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "input", NULL);
- _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "sound", NULL);
- _this->udev_monitor_enable_receiving(_this->udev_mon);
-
- /* Do an initial scan of existing devices */
- SDL_UDEV_Scan();
-
- }
-
- _this->ref_count += 1;
-
- return retval;
-}
-
-void
-SDL_UDEV_Quit(void)
-{
- SDL_UDEV_CallbackList *item;
-
- if (_this == NULL) {
- return;
- }
-
- _this->ref_count -= 1;
-
- if (_this->ref_count < 1) {
-
- if (_this->udev_mon != NULL) {
- _this->udev_monitor_unref(_this->udev_mon);
- _this->udev_mon = NULL;
- }
- if (_this->udev != NULL) {
- _this->udev_unref(_this->udev);
- _this->udev = NULL;
- }
-
- /* Remove existing devices */
- while (_this->first != NULL) {
- item = _this->first;
- _this->first = _this->first->next;
- SDL_free(item);
- }
-
- SDL_UDEV_UnloadLibrary();
- SDL_free(_this);
- _this = NULL;
- }
-}
-
-void
-SDL_UDEV_Scan(void)
-{
- struct udev_enumerate *enumerate = NULL;
- struct udev_list_entry *devs = NULL;
- struct udev_list_entry *item = NULL;
-
- if (_this == NULL) {
- return;
- }
-
- enumerate = _this->udev_enumerate_new(_this->udev);
- if (enumerate == NULL) {
- SDL_UDEV_Quit();
- SDL_SetError("udev_monitor_new_from_netlink() failed");
- return;
- }
-
- _this->udev_enumerate_add_match_subsystem(enumerate, "input");
- _this->udev_enumerate_add_match_subsystem(enumerate, "sound");
-
- _this->udev_enumerate_scan_devices(enumerate);
- devs = _this->udev_enumerate_get_list_entry(enumerate);
- for (item = devs; item; item = _this->udev_list_entry_get_next(item)) {
- const char *path = _this->udev_list_entry_get_name(item);
- struct udev_device *dev = _this->udev_device_new_from_syspath(_this->udev, path);
- if (dev != NULL) {
- device_event(SDL_UDEV_DEVICEADDED, dev);
- _this->udev_device_unref(dev);
- }
- }
-
- _this->udev_enumerate_unref(enumerate);
-}
-
-
-void
-SDL_UDEV_UnloadLibrary(void)
-{
- if (_this == NULL) {
- return;
- }
-
- if (_this->udev_handle != NULL) {
- SDL_UnloadObject(_this->udev_handle);
- _this->udev_handle = NULL;
- }
-}
-
-int
-SDL_UDEV_LoadLibrary(void)
-{
- int retval = 0, i;
-
- if (_this == NULL) {
- return SDL_SetError("UDEV not initialized");
- }
-
-
- if (_this->udev_handle == NULL) {
- for( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
- _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
- if (_this->udev_handle != NULL) {
- retval = SDL_UDEV_load_syms();
- if (retval < 0) {
- SDL_UDEV_UnloadLibrary();
- }
- else {
- break;
- }
- }
- }
-
- if (_this->udev_handle == NULL) {
- retval = -1;
- /* Don't call SDL_SetError(): SDL_LoadObject already did. */
- }
- }
-
- 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 BIT(x) (1UL<<OFF(x))
-#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;
- char text[4096];
- char *word;
- int i;
- unsigned long v;
-
- SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
- value = _this->udev_device_get_sysattr_value(pdev, attr);
- if (!value) {
- return;
- }
-
- SDL_strlcpy(text, value, sizeof(text));
- i = 0;
- while ((word = SDL_strrchr(text, ' ')) != NULL) {
- v = SDL_strtoul(word+1, NULL, 16);
- if (i < bitmask_len) {
- bitmask[i] = v;
- }
- ++i;
- *word = '\0';
- }
- v = SDL_strtoul(text, NULL, 16);
- if (i < bitmask_len) {
- bitmask[i] = v;
- }
-}
-
-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 */
- pdev = dev;
- while (pdev && !_this->udev_device_get_sysattr_value(pdev, "capabilities/ev")) {
- pdev = _this->udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
- }
- if (!pdev) {
- return 0;
- }
-
- get_caps(dev, pdev, "capabilities/ev", bitmask_ev, SDL_arraysize(bitmask_ev));
- get_caps(dev, pdev, "capabilities/abs", bitmask_abs, SDL_arraysize(bitmask_abs));
- 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;
-}
-
-static void
-device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
-{
- const char *subsystem;
- const char *val = NULL;
- int devclass = 0;
- const char *path;
- SDL_UDEV_CallbackList *item;
-
- path = _this->udev_device_get_devnode(dev);
- if (path == NULL) {
- return;
- }
-
- subsystem = _this->udev_device_get_subsystem(dev);
- if (SDL_strcmp(subsystem, "sound") == 0) {
- devclass = SDL_UDEV_DEVICE_SOUND;
- } else if (SDL_strcmp(subsystem, "input") == 0) {
- /* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */
-
- val = _this->udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
- if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
- devclass |= SDL_UDEV_DEVICE_JOYSTICK;
- }
-
- val = _this->udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
- if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
- devclass |= SDL_UDEV_DEVICE_MOUSE;
- }
-
- val = _this->udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
- if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
- devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
- }
-
- /* The undocumented rule is:
- - All devices with keys get ID_INPUT_KEY
- - From this subset, if they have ESC, numbers, and Q to D, it also gets ID_INPUT_KEYBOARD
-
- Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183
- */
- val = _this->udev_device_get_property_value(dev, "ID_INPUT_KEY");
- if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
- devclass |= SDL_UDEV_DEVICE_KEYBOARD;
- }
-
- if (devclass == 0) {
- /* Fall back to old style input classes */
- val = _this->udev_device_get_property_value(dev, "ID_CLASS");
- if (val != NULL) {
- if (SDL_strcmp(val, "joystick") == 0) {
- devclass = SDL_UDEV_DEVICE_JOYSTICK;
- } else if (SDL_strcmp(val, "mouse") == 0) {
- devclass = SDL_UDEV_DEVICE_MOUSE;
- } else if (SDL_strcmp(val, "kbd") == 0) {
- devclass = SDL_UDEV_DEVICE_KEYBOARD;
- } else {
- return;
- }
- } else {
- /* We could be linked with libudev on a system that doesn't have udev running */
- devclass = guess_device_class(dev);
- }
- }
- } else {
- return;
- }
-
- /* Process callbacks */
- for (item = _this->first; item != NULL; item = item->next) {
- item->callback(type, devclass, path);
- }
-}
-
-void
-SDL_UDEV_Poll(void)
-{
- struct udev_device *dev = NULL;
- const char *action = NULL;
-
- if (_this == NULL) {
- return;
- }
-
- while (SDL_UDEV_hotplug_update_available()) {
- dev = _this->udev_monitor_receive_device(_this->udev_mon);
- if (dev == NULL) {
- break;
- }
- action = _this->udev_device_get_action(dev);
-
- if (SDL_strcmp(action, "add") == 0) {
- /* Wait for the device to finish initialization */
- SDL_Delay(100);
-
- device_event(SDL_UDEV_DEVICEADDED, dev);
- } else if (SDL_strcmp(action, "remove") == 0) {
- device_event(SDL_UDEV_DEVICEREMOVED, dev);
- }
-
- _this->udev_device_unref(dev);
- }
-}
-
-int
-SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
-{
- SDL_UDEV_CallbackList *item;
- item = (SDL_UDEV_CallbackList *) SDL_calloc(1, sizeof (SDL_UDEV_CallbackList));
- if (item == NULL) {
- return SDL_OutOfMemory();
- }
-
- item->callback = cb;
-
- if (_this->last == NULL) {
- _this->first = _this->last = item;
- } else {
- _this->last->next = item;
- _this->last = item;
- }
-
- return 1;
-}
-
-void
-SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
-{
- SDL_UDEV_CallbackList *item;
- SDL_UDEV_CallbackList *prev = NULL;
-
- for (item = _this->first; item != NULL; item = item->next) {
- /* found it, remove it. */
- if (item->callback == cb) {
- if (prev != NULL) {
- prev->next = item->next;
- } else {
- SDL_assert(_this->first == item);
- _this->first = item->next;
- }
- if (item == _this->last) {
- _this->last = prev;
- }
- SDL_free(item);
- return;
- }
- prev = item;
- }
-
-}
-
-
-#endif /* SDL_USE_LIBUDEV */
diff --git a/3rdparty/SDL2/src/core/linux/SDL_udev.h b/3rdparty/SDL2/src/core/linux/SDL_udev.h
deleted file mode 100644
index 9ffbb3252b2..00000000000
--- a/3rdparty/SDL2/src/core/linux/SDL_udev.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_udev_h
-#define _SDL_udev_h
-
-#if HAVE_LIBUDEV_H
-
-#ifndef SDL_USE_LIBUDEV
-#define SDL_USE_LIBUDEV 1
-#endif
-
-#include "SDL_loadso.h"
-#include "SDL_events.h"
-#include <libudev.h>
-#include <sys/time.h>
-#include <sys/types.h>
-
-/**
- * \brief Device type
- */
-
-typedef enum
-{
- SDL_UDEV_DEVICEADDED = 1,
- 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 {
- SDL_UDEV_Callback callback;
- struct SDL_UDEV_CallbackList *next;
-} SDL_UDEV_CallbackList;
-
-typedef struct SDL_UDEV_PrivateData
-{
- const char *udev_library;
- void *udev_handle;
- struct udev *udev;
- struct udev_monitor *udev_mon;
- int ref_count;
- SDL_UDEV_CallbackList *first, *last;
-
- /* Function pointers */
- const char *(*udev_device_get_action)(struct udev_device *);
- const char *(*udev_device_get_devnode)(struct udev_device *);
- const char *(*udev_device_get_subsystem)(struct udev_device *);
- struct udev_device *(*udev_device_get_parent_with_subsystem_devtype)(struct udev_device *udev_device, const char *subsystem, const char *devtype);
- const char *(*udev_device_get_property_value)(struct udev_device *, const char *);
- const char *(*udev_device_get_sysattr_value)(struct udev_device *udev_device, const char *sysattr);
- struct udev_device *(*udev_device_new_from_syspath)(struct udev *, const char *);
- void (*udev_device_unref)(struct udev_device *);
- int (*udev_enumerate_add_match_property)(struct udev_enumerate *, const char *, const char *);
- int (*udev_enumerate_add_match_subsystem)(struct udev_enumerate *, const char *);
- struct udev_list_entry *(*udev_enumerate_get_list_entry)(struct udev_enumerate *);
- struct udev_enumerate *(*udev_enumerate_new)(struct udev *);
- int (*udev_enumerate_scan_devices)(struct udev_enumerate *);
- void (*udev_enumerate_unref)(struct udev_enumerate *);
- const char *(*udev_list_entry_get_name)(struct udev_list_entry *);
- struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *);
- int (*udev_monitor_enable_receiving)(struct udev_monitor *);
- int (*udev_monitor_filter_add_match_subsystem_devtype)(struct udev_monitor *, const char *, const char *);
- int (*udev_monitor_get_fd)(struct udev_monitor *);
- struct udev_monitor *(*udev_monitor_new_from_netlink)(struct udev *, const char *);
- struct udev_device *(*udev_monitor_receive_device)(struct udev_monitor *);
- void (*udev_monitor_unref)(struct udev_monitor *);
- struct udev *(*udev_new)(void);
- void (*udev_unref)(struct udev *);
- struct udev_device * (*udev_device_new_from_devnum)(struct udev *udev, char type, dev_t devnum);
- dev_t (*udev_device_get_devnum) (struct udev_device *udev_device);
-} SDL_UDEV_PrivateData;
-
-extern int SDL_UDEV_Init(void);
-extern void SDL_UDEV_Quit(void);
-extern void SDL_UDEV_UnloadLibrary(void);
-extern int SDL_UDEV_LoadLibrary(void);
-extern void SDL_UDEV_Poll(void);
-extern void SDL_UDEV_Scan(void);
-extern int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
-extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
-
-
-
-
-#endif /* HAVE_LIBUDEV_H */
-
-#endif /* _SDL_udev_h */
diff --git a/3rdparty/SDL2/src/core/windows/SDL_directx.h b/3rdparty/SDL2/src/core/windows/SDL_directx.h
deleted file mode 100644
index 0533f61edab..00000000000
--- a/3rdparty/SDL2/src/core/windows/SDL_directx.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_directx_h
-#define _SDL_directx_h
-
-/* Include all of the DirectX 8.0 headers and adds any necessary tweaks */
-
-#include "SDL_windows.h"
-#include <mmsystem.h>
-#ifndef WIN32
-#define WIN32
-#endif
-#undef WINNT
-
-/* Far pointers don't exist in 32-bit code */
-#ifndef FAR
-#define FAR
-#endif
-
-/* Error codes not yet included in Win32 API header files */
-#ifndef MAKE_HRESULT
-#define MAKE_HRESULT(sev,fac,code) \
- ((HRESULT)(((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))))
-#endif
-
-#ifndef S_OK
-#define S_OK (HRESULT)0x00000000L
-#endif
-
-#ifndef SUCCEEDED
-#define SUCCEEDED(x) ((HRESULT)(x) >= 0)
-#endif
-#ifndef FAILED
-#define FAILED(x) ((HRESULT)(x)<0)
-#endif
-
-#ifndef E_FAIL
-#define E_FAIL (HRESULT)0x80000008L
-#endif
-#ifndef E_NOINTERFACE
-#define E_NOINTERFACE (HRESULT)0x80004002L
-#endif
-#ifndef E_OUTOFMEMORY
-#define E_OUTOFMEMORY (HRESULT)0x8007000EL
-#endif
-#ifndef E_INVALIDARG
-#define E_INVALIDARG (HRESULT)0x80070057L
-#endif
-#ifndef E_NOTIMPL
-#define E_NOTIMPL (HRESULT)0x80004001L
-#endif
-#ifndef REGDB_E_CLASSNOTREG
-#define REGDB_E_CLASSNOTREG (HRESULT)0x80040154L
-#endif
-
-/* Severity codes */
-#ifndef SEVERITY_ERROR
-#define SEVERITY_ERROR 1
-#endif
-
-/* Error facility codes */
-#ifndef FACILITY_WIN32
-#define FACILITY_WIN32 7
-#endif
-
-#ifndef FIELD_OFFSET
-#define FIELD_OFFSET(type, field) ((LONG)&(((type *)0)->field))
-#endif
-
-/* DirectX headers (if it isn't included, I haven't tested it yet)
- */
-/* We need these defines to mark what version of DirectX API we use */
-#define DIRECTDRAW_VERSION 0x0700
-#define DIRECTSOUND_VERSION 0x0800
-#define DIRECTINPUT_VERSION 0x0800 /* Need version 7 for force feedback. Need version 8 so IDirectInput8_EnumDevices doesn't leak like a sieve... */
-
-#ifdef HAVE_DDRAW_H
-#include <ddraw.h>
-#endif
-#ifdef HAVE_DSOUND_H
-#include <dsound.h>
-#endif
-#ifdef HAVE_DINPUT_H
-#include <dinput.h>
-#else
-typedef struct { int unused; } DIDEVICEINSTANCE;
-#endif
-
-#endif /* _SDL_directx_h */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/windows/SDL_windows.c b/3rdparty/SDL2/src/core/windows/SDL_windows.c
deleted file mode 100644
index 6433fe26f3c..00000000000
--- a/3rdparty/SDL2/src/core/windows/SDL_windows.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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(__WIN32__) || defined(__WINRT__)
-
-#include "SDL_windows.h"
-#include "SDL_error.h"
-#include "SDL_assert.h"
-
-#include <objbase.h> /* for CoInitialize/CoUninitialize (Win32 only) */
-
-#ifndef _WIN32_WINNT_VISTA
-#define _WIN32_WINNT_VISTA 0x0600
-#endif
-
-
-/* Sets an error message based on GetLastError() */
-int
-WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr)
-{
- TCHAR buffer[1024];
- char *message;
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0,
- buffer, SDL_arraysize(buffer), NULL);
- message = WIN_StringToUTF8(buffer);
- SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message);
- SDL_free(message);
- return -1;
-}
-
-/* Sets an error message based on GetLastError() */
-int
-WIN_SetError(const char *prefix)
-{
- return WIN_SetErrorFromHRESULT(prefix, GetLastError());
-}
-
-HRESULT
-WIN_CoInitialize(void)
-{
- /* SDL handles any threading model, so initialize with the default, which
- is compatible with OLE and if that doesn't work, try multi-threaded mode.
-
- If you need multi-threaded mode, call CoInitializeEx() before SDL_Init()
- */
-#ifdef __WINRT__
- /* DLudwig: On WinRT, it is assumed that COM was initialized in main().
- CoInitializeEx is available (not CoInitialize though), however
- on WinRT, main() is typically declared with the [MTAThread]
- attribute, which, AFAIK, should initialize COM.
- */
- return S_OK;
-#else
- HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
- if (hr == RPC_E_CHANGED_MODE) {
- hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
- }
-
- /* S_FALSE means success, but someone else already initialized. */
- /* You still need to call CoUninitialize in this case! */
- if (hr == S_FALSE) {
- return S_OK;
- }
-
- return hr;
-#endif
-}
-
-void
-WIN_CoUninitialize(void)
-{
-#ifndef __WINRT__
- CoUninitialize();
-#endif
-}
-
-#ifndef __WINRT__
-static BOOL
-IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
-{
- OSVERSIONINFOEXW osvi;
- DWORDLONG const dwlConditionMask = VerSetConditionMask(
- VerSetConditionMask(
- VerSetConditionMask(
- 0, VER_MAJORVERSION, VER_GREATER_EQUAL ),
- VER_MINORVERSION, VER_GREATER_EQUAL ),
- VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL );
-
- SDL_zero(osvi);
- osvi.dwOSVersionInfoSize = sizeof(osvi);
- osvi.dwMajorVersion = wMajorVersion;
- osvi.dwMinorVersion = wMinorVersion;
- osvi.wServicePackMajor = wServicePackMajor;
-
- return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
-}
-#endif
-
-BOOL WIN_IsWindowsVistaOrGreater()
-{
-#ifdef __WINRT__
- return TRUE;
-#else
- return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 0);
-#endif
-}
-
-/*
-WAVExxxCAPS gives you 31 bytes for the device name, and just truncates if it's
-longer. However, since WinXP, you can use the WAVExxxCAPS2 structure, which
-will give you a name GUID. The full name is in the Windows Registry under
-that GUID, located here: HKLM\System\CurrentControlSet\Control\MediaCategories
-
-Note that drivers can report GUID_NULL for the name GUID, in which case,
-Windows makes a best effort to fill in those 31 bytes in the usual place.
-This info summarized from MSDN:
-
-http://web.archive.org/web/20131027093034/http://msdn.microsoft.com/en-us/library/windows/hardware/ff536382(v=vs.85).aspx
-
-Always look this up in the registry if possible, because the strings are
-different! At least on Win10, I see "Yeti Stereo Microphone" in the
-Registry, and a unhelpful "Microphone(Yeti Stereo Microph" in winmm. Sigh.
-
-(Also, DirectSound shouldn't be limited to 32 chars, but its device enum
-has the same problem.)
-*/
-char *
-WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
-{
-#if __WINRT__
- return WIN_StringToUTF8(name); /* No registry access on WinRT/UWP, go with what we've got. */
-#else
- static const GUID nullguid = { 0 };
- const unsigned char *ptr;
- char keystr[128];
- WCHAR *strw = NULL;
- SDL_bool rc;
- HKEY hkey;
- DWORD len = 0;
- char *retval = NULL;
-
- if (SDL_memcmp(guid, &nullguid, sizeof (*guid)) == 0) {
- return WIN_StringToUTF8(name); /* No GUID, go with what we've got. */
- }
-
- ptr = (const unsigned char *) guid;
- SDL_snprintf(keystr, sizeof (keystr),
- "System\\CurrentControlSet\\Control\\MediaCategories\\{%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
- ptr[3], ptr[2], ptr[1], ptr[0], ptr[5], ptr[4], ptr[7], ptr[6],
- ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15]);
-
- strw = WIN_UTF8ToString(keystr);
- rc = (RegOpenKeyExW(HKEY_LOCAL_MACHINE, strw, 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS);
- SDL_free(strw);
- if (!rc) {
- return WIN_StringToUTF8(name); /* oh well. */
- }
-
- rc = (RegQueryValueExW(hkey, L"Name", NULL, NULL, NULL, &len) == ERROR_SUCCESS);
- if (!rc) {
- RegCloseKey(hkey);
- return WIN_StringToUTF8(name); /* oh well. */
- }
-
- strw = (WCHAR *) SDL_malloc(len + sizeof (WCHAR));
- if (!strw) {
- RegCloseKey(hkey);
- return WIN_StringToUTF8(name); /* oh well. */
- }
-
- rc = (RegQueryValueExW(hkey, L"Name", NULL, NULL, (LPBYTE) strw, &len) == ERROR_SUCCESS);
- RegCloseKey(hkey);
- if (!rc) {
- SDL_free(strw);
- return WIN_StringToUTF8(name); /* oh well. */
- }
-
- strw[len / 2] = 0; /* make sure it's null-terminated. */
-
- retval = WIN_StringToUTF8(strw);
- SDL_free(strw);
- return retval ? retval : WIN_StringToUTF8(name);
-#endif /* if __WINRT__ / else */
-}
-
-#endif /* __WIN32__ || __WINRT__ */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/windows/SDL_windows.h b/3rdparty/SDL2/src/core/windows/SDL_windows.h
deleted file mode 100644
index 0f67e4be5e7..00000000000
--- a/3rdparty/SDL2/src/core/windows/SDL_windows.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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.
-*/
-
-/* This is an include file for windows.h with the SDL build settings */
-
-#ifndef _INCLUDED_WINDOWS_H
-#define _INCLUDED_WINDOWS_H
-
-#if defined(__WIN32__)
-#define WIN32_LEAN_AND_MEAN
-#define STRICT
-#ifndef UNICODE
-#define UNICODE 1
-#endif
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x501 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */
-#endif
-
-#include <windows.h>
-
-/* Routines to convert from UTF8 to native Windows text */
-#if UNICODE
-#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR))
-#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1)
-#else
-/* !!! FIXME: UTF8ToString() can just be a SDL_strdup() here. */
-#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)(S), (SDL_strlen(S)+1))
-#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)(S), SDL_strlen(S)+1)
-#endif
-
-/* Sets an error message based on a given HRESULT */
-extern int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr);
-
-/* Sets an error message based on GetLastError(). Always return -1. */
-extern int WIN_SetError(const char *prefix);
-
-/* Wrap up the oddities of CoInitialize() into a common function. */
-extern HRESULT WIN_CoInitialize(void);
-extern void WIN_CoUninitialize(void);
-
-/* Returns SDL_TRUE if we're running on Windows Vista and newer */
-extern BOOL WIN_IsWindowsVistaOrGreater();
-
-/* You need to SDL_free() the result of this call. */
-extern char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid);
-
-#endif /* _INCLUDED_WINDOWS_H */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/windows/SDL_xinput.c b/3rdparty/SDL2/src/core/windows/SDL_xinput.c
deleted file mode 100644
index 355cd83436d..00000000000
--- a/3rdparty/SDL2/src/core/windows/SDL_xinput.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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 "SDL_assert.h"
-#include "SDL_xinput.h"
-
-
-#ifdef HAVE_XINPUT_H
-
-XInputGetState_t SDL_XInputGetState = NULL;
-XInputSetState_t SDL_XInputSetState = NULL;
-XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL;
-XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation = NULL;
-DWORD SDL_XInputVersion = 0;
-
-static HANDLE s_pXInputDLL = 0;
-static int s_XInputDLLRefCount = 0;
-
-
-#ifdef __WINRT__
-
-int
-WIN_LoadXInputDLL(void)
-{
- /* Getting handles to system dlls (via LoadLibrary and its variants) is not
- * supported on WinRT, thus, pointers to XInput's functions can't be
- * retrieved via GetProcAddress.
- *
- * When on WinRT, assume that XInput is already loaded, and directly map
- * its XInput.h-declared functions to the SDL_XInput* set of function
- * pointers.
- *
- * Side-note: XInputGetStateEx is not available for use in WinRT.
- * This seems to mean that support for the guide button is not available
- * in WinRT, unfortunately.
- */
- SDL_XInputGetState = (XInputGetState_t)XInputGetState;
- SDL_XInputSetState = (XInputSetState_t)XInputSetState;
- SDL_XInputGetCapabilities = (XInputGetCapabilities_t)XInputGetCapabilities;
- SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)XInputGetBatteryInformation;
-
- /* XInput 1.4 ships with Windows 8 and 8.1: */
- SDL_XInputVersion = (1 << 16) | 4;
-
- return 0;
-}
-
-void
-WIN_UnloadXInputDLL(void)
-{
-}
-
-#else /* !__WINRT__ */
-
-int
-WIN_LoadXInputDLL(void)
-{
- DWORD version = 0;
-
- if (s_pXInputDLL) {
- SDL_assert(s_XInputDLLRefCount > 0);
- s_XInputDLLRefCount++;
- return 0; /* already loaded */
- }
-
- version = (1 << 16) | 4;
- s_pXInputDLL = LoadLibrary(L"XInput1_4.dll"); /* 1.4 Ships with Windows 8. */
- if (!s_pXInputDLL) {
- version = (1 << 16) | 3;
- s_pXInputDLL = LoadLibrary(L"XInput1_3.dll"); /* 1.3 can be installed as a redistributable component. */
- }
- if (!s_pXInputDLL) {
- s_pXInputDLL = LoadLibrary(L"bin\\XInput1_3.dll");
- }
- if (!s_pXInputDLL) {
- /* "9.1.0" Ships with Vista and Win7, and is more limited than 1.3+ (e.g. XInputGetStateEx is not available.) */
- s_pXInputDLL = LoadLibrary(L"XInput9_1_0.dll");
- }
- if (!s_pXInputDLL) {
- return -1;
- }
-
- SDL_assert(s_XInputDLLRefCount == 0);
- SDL_XInputVersion = version;
- s_XInputDLLRefCount = 1;
-
- /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */
- SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, (LPCSTR)100);
- if (!SDL_XInputGetState) {
- SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetState");
- }
- SDL_XInputSetState = (XInputSetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputSetState");
- SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetCapabilities");
- SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetBatteryInformation" );
- if (!SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities) {
- WIN_UnloadXInputDLL();
- return -1;
- }
-
- return 0;
-}
-
-void
-WIN_UnloadXInputDLL(void)
-{
- if (s_pXInputDLL) {
- SDL_assert(s_XInputDLLRefCount > 0);
- if (--s_XInputDLLRefCount == 0) {
- FreeLibrary(s_pXInputDLL);
- s_pXInputDLL = NULL;
- }
- } else {
- SDL_assert(s_XInputDLLRefCount == 0);
- }
-}
-
-#endif /* __WINRT__ */
-#endif /* HAVE_XINPUT_H */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/windows/SDL_xinput.h b/3rdparty/SDL2/src/core/windows/SDL_xinput.h
deleted file mode 100644
index 67f8fdc1f8f..00000000000
--- a/3rdparty/SDL2/src/core/windows/SDL_xinput.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_xinput_h
-#define _SDL_xinput_h
-
-#ifdef HAVE_XINPUT_H
-
-#include "SDL_windows.h"
-#include <xinput.h>
-
-#ifndef XUSER_MAX_COUNT
-#define XUSER_MAX_COUNT 4
-#endif
-#ifndef XUSER_INDEX_ANY
-#define XUSER_INDEX_ANY 0x000000FF
-#endif
-#ifndef XINPUT_CAPS_FFB_SUPPORTED
-#define XINPUT_CAPS_FFB_SUPPORTED 0x0001
-#endif
-
-#ifndef XINPUT_DEVSUBTYPE_UNKNOWN
-#define XINPUT_DEVSUBTYPE_UNKNOWN 0x00
-#endif
-#ifndef XINPUT_DEVSUBTYPE_GAMEPAD
-#define XINPUT_DEVSUBTYPE_GAMEPAD 0x01
-#endif
-#ifndef XINPUT_DEVSUBTYPE_WHEEL
-#define XINPUT_DEVSUBTYPE_WHEEL 0x02
-#endif
-#ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK
-#define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03
-#endif
-#ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
-#define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x04
-#endif
-#ifndef XINPUT_DEVSUBTYPE_DANCE_PAD
-#define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05
-#endif
-#ifndef XINPUT_DEVSUBTYPE_GUITAR
-#define XINPUT_DEVSUBTYPE_GUITAR 0x06
-#endif
-#ifndef XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE
-#define XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE 0x07
-#endif
-#ifndef XINPUT_DEVSUBTYPE_DRUM_KIT
-#define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08
-#endif
-#ifndef XINPUT_DEVSUBTYPE_GUITAR_BASS
-#define XINPUT_DEVSUBTYPE_GUITAR_BASS 0x0B
-#endif
-#ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD
-#define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13
-#endif
-
-#ifndef XINPUT_GAMEPAD_GUIDE
-#define XINPUT_GAMEPAD_GUIDE 0x0400
-#endif
-
-#ifndef BATTERY_DEVTYPE_GAMEPAD
-#define BATTERY_DEVTYPE_GAMEPAD 0x00
-#endif
-#ifndef BATTERY_TYPE_WIRED
-#define BATTERY_TYPE_WIRED 0x01
-#endif
-
-#ifndef BATTERY_TYPE_UNKNOWN
-#define BATTERY_TYPE_UNKNOWN 0xFF
-#endif
-#ifndef BATTERY_LEVEL_EMPTY
-#define BATTERY_LEVEL_EMPTY 0x00
-#endif
-#ifndef BATTERY_LEVEL_LOW
-#define BATTERY_LEVEL_LOW 0x01
-#endif
-#ifndef BATTERY_LEVEL_MEDIUM
-#define BATTERY_LEVEL_MEDIUM 0x02
-#endif
-#ifndef BATTERY_LEVEL_FULL
-#define BATTERY_LEVEL_FULL 0x03
-#endif
-
-/* typedef's for XInput structs we use */
-typedef struct
-{
- WORD wButtons;
- BYTE bLeftTrigger;
- BYTE bRightTrigger;
- SHORT sThumbLX;
- SHORT sThumbLY;
- SHORT sThumbRX;
- SHORT sThumbRY;
- DWORD dwPaddingReserved;
-} XINPUT_GAMEPAD_EX;
-
-typedef struct
-{
- DWORD dwPacketNumber;
- XINPUT_GAMEPAD_EX Gamepad;
-} XINPUT_STATE_EX;
-
-typedef struct
-{
- BYTE BatteryType;
- BYTE BatteryLevel;
-} XINPUT_BATTERY_INFORMATION_EX;
-
-/* Forward decl's for XInput API's we load dynamically and use if available */
-typedef DWORD (WINAPI *XInputGetState_t)
- (
- DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
- XINPUT_STATE_EX* pState /* [out] Receives the current state */
- );
-
-typedef DWORD (WINAPI *XInputSetState_t)
- (
- DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
- XINPUT_VIBRATION* pVibration /* [in, out] The vibration information to send to the controller */
- );
-
-typedef DWORD (WINAPI *XInputGetCapabilities_t)
- (
- DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
- DWORD dwFlags, /* [in] Input flags that identify the device type */
- XINPUT_CAPABILITIES* pCapabilities /* [out] Receives the capabilities */
- );
-
-typedef DWORD (WINAPI *XInputGetBatteryInformation_t)
- (
- DWORD dwUserIndex,
- BYTE devType,
- XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation
- );
-
-extern int WIN_LoadXInputDLL(void);
-extern void WIN_UnloadXInputDLL(void);
-
-extern XInputGetState_t SDL_XInputGetState;
-extern XInputSetState_t SDL_XInputSetState;
-extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
-extern XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation;
-extern DWORD SDL_XInputVersion; /* ((major << 16) & 0xFF00) | (minor & 0xFF) */
-
-#define XINPUTGETSTATE SDL_XInputGetState
-#define XINPUTSETSTATE SDL_XInputSetState
-#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities
-#define XINPUTGETBATTERYINFORMATION SDL_XInputGetBatteryInformation
-
-#endif /* HAVE_XINPUT_H */
-
-#endif /* _SDL_xinput_h */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.cpp b/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.cpp
deleted file mode 100644
index 265aa942e04..00000000000
--- a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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 "SDL_system.h"
-#include "SDL_winrtapp_direct3d.h"
-#include "SDL_winrtapp_xaml.h"
-
-int (*WINRT_SDLAppEntryPoint)(int, char **) = NULL;
-
-extern "C" DECLSPEC int
-SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel)
-{
- if (xamlBackgroundPanel) {
- return SDL_WinRTInitXAMLApp(mainFunction, xamlBackgroundPanel);
- } else {
- return SDL_WinRTInitNonXAMLApp(mainFunction);
- }
-}
diff --git a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.h b/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.h
deleted file mode 100644
index e87a0b6b638..00000000000
--- a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_config.h"
-
-#ifndef _SDL_winrtapp_common_h
-#define _SDL_winrtapp_common_h
-
-/* A pointer to the app's C-style main() function (which is a different
- function than the WinRT app's actual entry point).
- */
-extern int (*WINRT_SDLAppEntryPoint)(int, char **);
-
-#endif // ifndef _SDL_winrtapp_common_h
diff --git a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.cpp b/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.cpp
deleted file mode 100644
index e4ffadaad09..00000000000
--- a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.cpp
+++ /dev/null
@@ -1,855 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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"
-
-/* Standard C++11 includes */
-#include <functional>
-#include <string>
-#include <sstream>
-using namespace std;
-
-
-/* Windows includes */
-#include "ppltasks.h"
-using namespace concurrency;
-using namespace Windows::ApplicationModel;
-using namespace Windows::ApplicationModel::Core;
-using namespace Windows::ApplicationModel::Activation;
-using namespace Windows::Devices::Input;
-using namespace Windows::Graphics::Display;
-using namespace Windows::Foundation;
-using namespace Windows::System;
-using namespace Windows::UI::Core;
-using namespace Windows::UI::Input;
-
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
-using namespace Windows::Phone::UI::Input;
-#endif
-
-
-/* SDL includes */
-extern "C" {
-#include "../../SDL_internal.h"
-#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"
-#include "../../video/SDL_sysvideo.h"
-//#include "../../SDL_hints_c.h"
-#include "../../events/SDL_events_c.h"
-#include "../../events/SDL_keyboard_c.h"
-#include "../../events/SDL_mouse_c.h"
-#include "../../events/SDL_windowevents_c.h"
-#include "../../render/SDL_sysrender.h"
-#include "../windows/SDL_windows.h"
-}
-
-#include "../../video/winrt/SDL_winrtevents_c.h"
-#include "../../video/winrt/SDL_winrtvideo_cpp.h"
-#include "SDL_winrtapp_common.h"
-#include "SDL_winrtapp_direct3d.h"
-
-#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
-/* Calling IDXGIDevice3::Trim on the active Direct3D 11.x device is necessary
- * when Windows 8.1 apps are about to get suspended.
- */
-extern "C" void D3D11_Trim(SDL_Renderer *);
-#endif
-
-
-// Compile-time debugging options:
-// To enable, uncomment; to disable, comment them out.
-//#define LOG_POINTER_EVENTS 1
-//#define LOG_WINDOW_EVENTS 1
-//#define LOG_ORIENTATION_EVENTS 1
-
-
-// HACK, DLudwig: record a reference to the global, WinRT 'app'/view.
-// SDL/WinRT will use this throughout its code.
-//
-// TODO, WinRT: consider replacing SDL_WinRTGlobalApp with something
-// non-global, such as something created inside
-// SDL_InitSubSystem(SDL_INIT_VIDEO), or something inside
-// SDL_CreateWindow().
-SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;
-
-ref class SDLApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
-{
-public:
- virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
-};
-
-IFrameworkView^ SDLApplicationSource::CreateView()
-{
- // TODO, WinRT: see if this function (CreateView) can ever get called
- // more than once. For now, just prevent it from ever assigning
- // SDL_WinRTGlobalApp more than once.
- SDL_assert(!SDL_WinRTGlobalApp);
- SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
- if (!SDL_WinRTGlobalApp)
- {
- SDL_WinRTGlobalApp = app;
- }
- return app;
-}
-
-int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **))
-{
- WINRT_SDLAppEntryPoint = mainFunction;
- auto direct3DApplicationSource = ref new SDLApplicationSource();
- CoreApplication::Run(direct3DApplicationSource);
- return 0;
-}
-
-static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
-{
- SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
-
- /* HACK: prevent SDL from altering an app's .appxmanifest-set orientation
- * from being changed on startup, by detecting when SDL_HINT_ORIENTATIONS
- * is getting registered.
- *
- * TODO, WinRT: consider reading in an app's .appxmanifest file, and apply its orientation when 'newValue == NULL'.
- */
- if ((oldValue == NULL) && (newValue == NULL)) {
- return;
- }
-
- // Start with no orientation flags, then add each in as they're parsed
- // from newValue.
- unsigned int orientationFlags = 0;
- if (newValue) {
- std::istringstream tokenizer(newValue);
- while (!tokenizer.eof()) {
- std::string orientationName;
- std::getline(tokenizer, orientationName, ' ');
- if (orientationName == "LandscapeLeft") {
- orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
- } else if (orientationName == "LandscapeRight") {
- orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
- } else if (orientationName == "Portrait") {
- orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
- } else if (orientationName == "PortraitUpsideDown") {
- orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
- }
- }
- }
-
- // If no valid orientation flags were specified, use a reasonable set of defaults:
- if (!orientationFlags) {
- // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
- orientationFlags = (unsigned int) ( \
- DisplayOrientations::Landscape |
- DisplayOrientations::LandscapeFlipped |
- DisplayOrientations::Portrait |
- DisplayOrientations::PortraitFlipped);
- }
-
- // Set the orientation/rotation preferences. Please note that this does
- // not constitute a 100%-certain lock of a given set of possible
- // orientations. According to Microsoft's documentation on WinRT [1]
- // when a device is not capable of being rotated, Windows may ignore
- // the orientation preferences, and stick to what the device is capable of
- // displaying.
- //
- // [1] Documentation on the 'InitialRotationPreference' setting for a
- // Windows app's manifest file describes how some orientation/rotation
- // preferences may be ignored. See
- // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
- // for details. Microsoft's "Display orientation sample" also gives an
- // outline of how Windows treats device rotation
- // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
- WINRT_DISPLAY_PROPERTY(AutoRotationPreferences) = (DisplayOrientations) orientationFlags;
-}
-
-static void
-WINRT_ProcessWindowSizeChange() // TODO: Pass an SDL_Window-identifying thing into WINRT_ProcessWindowSizeChange()
-{
- CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread();
- if (coreWindow) {
- if (WINRT_GlobalSDLWindow) {
- SDL_Window * window = WINRT_GlobalSDLWindow;
- SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
-
- int x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
- int y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
- int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
- int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
-
-#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8)
- /* WinPhone 8.0 always keeps its native window size in portrait,
- regardless of orientation. This changes in WinPhone 8.1,
- in which the native window's size changes along with
- orientation.
-
- Attempt to emulate WinPhone 8.1's behavior on WinPhone 8.0, with
- regards to window size. This fixes a rendering bug that occurs
- when a WinPhone 8.0 app is rotated to either 90 or 270 degrees.
- */
- const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
- switch (currentOrientation) {
- case DisplayOrientations::Landscape:
- case DisplayOrientations::LandscapeFlipped: {
- int tmp = w;
- w = h;
- h = tmp;
- } break;
- }
-#endif
-
- const Uint32 latestFlags = WINRT_DetectWindowFlags(window);
- if (latestFlags & SDL_WINDOW_MAXIMIZED) {
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
- } else {
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
- }
-
- WINRT_UpdateWindowFlags(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
-
- /* The window can move during a resize event, such as when maximizing
- or resizing from a corner */
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
- }
- }
-}
-
-SDL_WinRTApp::SDL_WinRTApp() :
- m_windowClosed(false),
- m_windowVisible(true)
-{
-}
-
-void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
-{
- applicationView->Activated +=
- ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnAppActivated);
-
- CoreApplication::Suspending +=
- ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
-
- CoreApplication::Resuming +=
- ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
-
- CoreApplication::Exiting +=
- ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnExiting);
-
-#if NTDDI_VERSION >= NTDDI_WIN10
- /* HACK ALERT! Xbox One doesn't seem to detect gamepads unless something
- gets registered to receive Win10's Windows.Gaming.Input.Gamepad.GamepadAdded
- events. We'll register an event handler for these events here, to make
- sure that gamepad detection works later on, if requested.
- */
- Windows::Gaming::Input::Gamepad::GamepadAdded +=
- ref new Windows::Foundation::EventHandler<Windows::Gaming::Input::Gamepad^>(
- this, &SDL_WinRTApp::OnGamepadAdded
- );
-#endif
-}
-
-#if NTDDI_VERSION > NTDDI_WIN8
-void SDL_WinRTApp::OnOrientationChanged(DisplayInformation^ sender, Object^ args)
-#else
-void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
-#endif
-{
-#if LOG_ORIENTATION_EVENTS==1
- {
- CoreWindow^ window = CoreWindow::GetForCurrentThread();
- if (window) {
- SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, CoreWindow Bounds={%f,%f,%f,%f}\n",
- __FUNCTION__,
- WINRT_DISPLAY_PROPERTY(CurrentOrientation),
- WINRT_DISPLAY_PROPERTY(NativeOrientation),
- WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
- window->Bounds.X,
- window->Bounds.Y,
- window->Bounds.Width,
- window->Bounds.Height);
- } else {
- SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d\n",
- __FUNCTION__,
- WINRT_DISPLAY_PROPERTY(CurrentOrientation),
- WINRT_DISPLAY_PROPERTY(NativeOrientation),
- WINRT_DISPLAY_PROPERTY(AutoRotationPreferences));
- }
- }
-#endif
-
- WINRT_ProcessWindowSizeChange();
-
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
- // HACK: Make sure that orientation changes
- // lead to the Direct3D renderer's viewport getting updated:
- //
- // For some reason, this doesn't seem to need to be done on Windows 8.x,
- // even when going from Landscape to LandscapeFlipped. It only seems to
- // be needed on Windows Phone, at least when I tested on my devices.
- // I'm not currently sure why this is, but it seems to work fine. -- David L.
- //
- // TODO, WinRT: do more extensive research into why orientation changes on Win 8.x don't need D3D changes, or if they might, in some cases
- SDL_Window * window = WINRT_GlobalSDLWindow;
- if (window) {
- SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
- int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
- int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
- SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_SIZE_CHANGED, w, h);
- }
-#endif
-
-}
-
-void SDL_WinRTApp::SetWindow(CoreWindow^ window)
-{
-#if LOG_WINDOW_EVENTS==1
- SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, window bounds={%f, %f, %f,%f}\n",
- __FUNCTION__,
- WINRT_DISPLAY_PROPERTY(CurrentOrientation),
- WINRT_DISPLAY_PROPERTY(NativeOrientation),
- WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
- window->Bounds.X,
- window->Bounds.Y,
- window->Bounds.Width,
- window->Bounds.Height);
-#endif
-
- window->SizeChanged +=
- ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
-
- window->VisibilityChanged +=
- ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
-
- window->Activated +=
- ref new TypedEventHandler<CoreWindow^, WindowActivatedEventArgs^>(this, &SDL_WinRTApp::OnWindowActivated);
-
- window->Closed +=
- ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
-
-#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
- window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
-#endif
-
- window->PointerPressed +=
- ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
-
- window->PointerMoved +=
- ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
-
- window->PointerReleased +=
- ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
-
- window->PointerEntered +=
- ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerEntered);
-
- window->PointerExited +=
- ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerExited);
-
- window->PointerWheelChanged +=
- ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerWheelChanged);
-
-#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
- // Retrieves relative-only mouse movements:
- Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
- ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
-#endif
-
- window->KeyDown +=
- ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
-
- window->KeyUp +=
- ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
-
- window->CharacterReceived +=
- ref new TypedEventHandler<CoreWindow^, CharacterReceivedEventArgs^>(this, &SDL_WinRTApp::OnCharacterReceived);
-
-#if NTDDI_VERSION >= NTDDI_WIN10
- Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->BackRequested +=
- ref new EventHandler<BackRequestedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
-#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
- HardwareButtons::BackPressed +=
- ref new EventHandler<BackPressedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
-#endif
-
-#if NTDDI_VERSION > NTDDI_WIN8
- DisplayInformation::GetForCurrentView()->OrientationChanged +=
- ref new TypedEventHandler<Windows::Graphics::Display::DisplayInformation^, Object^>(this, &SDL_WinRTApp::OnOrientationChanged);
-#else
- DisplayProperties::OrientationChanged +=
- ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
-#endif
-
- // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.
- // TODO, WinRT: see if an app's default orientation can be found out via WinRT API(s), then set the initial value of SDL_HINT_ORIENTATIONS accordingly.
- SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
-
-#if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10) // for Windows 8/8.1/RT apps... (and not Phone apps)
- // Make sure we know when a user has opened the app's settings pane.
- // This is needed in order to display a privacy policy, which needs
- // to be done for network-enabled apps, as per Windows Store requirements.
- using namespace Windows::UI::ApplicationSettings;
- SettingsPane::GetForCurrentView()->CommandsRequested +=
- ref new TypedEventHandler<SettingsPane^, SettingsPaneCommandsRequestedEventArgs^>
- (this, &SDL_WinRTApp::OnSettingsPaneCommandsRequested);
-#endif
-}
-
-void SDL_WinRTApp::Load(Platform::String^ entryPoint)
-{
-}
-
-void SDL_WinRTApp::Run()
-{
- SDL_SetMainReady();
- if (WINRT_SDLAppEntryPoint)
- {
- // TODO, WinRT: pass the C-style main() a reasonably realistic
- // representation of command line arguments.
- int argc = 0;
- char **argv = NULL;
- WINRT_SDLAppEntryPoint(argc, argv);
- }
-}
-
-static bool IsSDLWindowEventPending(SDL_WindowEventID windowEventID)
-{
- SDL_Event events[128];
- const int count = SDL_PeepEvents(events, sizeof(events)/sizeof(SDL_Event), SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT);
- for (int i = 0; i < count; ++i) {
- if (events[i].window.event == windowEventID) {
- return true;
- }
- }
- return false;
-}
-
-bool SDL_WinRTApp::ShouldWaitForAppResumeEvents()
-{
- /* Don't wait if the app is visible: */
- if (m_windowVisible) {
- return false;
- }
-
- /* Don't wait until the window-hide events finish processing.
- * Do note that if an app-suspend event is sent (as indicated
- * by SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND
- * events), then this code may be a moot point, as WinRT's
- * own event pump (aka ProcessEvents()) will pause regardless
- * of what we do here. This happens on Windows Phone 8, to note.
- * Windows 8.x apps, on the other hand, may get a chance to run
- * these.
- */
- if (IsSDLWindowEventPending(SDL_WINDOWEVENT_HIDDEN)) {
- return false;
- } else if (IsSDLWindowEventPending(SDL_WINDOWEVENT_FOCUS_LOST)) {
- return false;
- } else if (IsSDLWindowEventPending(SDL_WINDOWEVENT_MINIMIZED)) {
- return false;
- }
-
- return true;
-}
-
-void SDL_WinRTApp::PumpEvents()
-{
- if (!m_windowClosed) {
- if (!ShouldWaitForAppResumeEvents()) {
- /* This is the normal way in which events should be pumped.
- * 'ProcessAllIfPresent' will make ProcessEvents() process anywhere
- * from zero to N events, and will then return.
- */
- CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
- } else {
- /* This style of event-pumping, with 'ProcessOneAndAllPending',
- * will cause anywhere from one to N events to be processed. If
- * at least one event is processed, the call will return. If
- * no events are pending, then the call will wait until one is
- * available, and will not return (to the caller) until this
- * happens! This should only occur when the app is hidden.
- */
- CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
- }
- }
-}
-
-void SDL_WinRTApp::Uninitialize()
-{
-}
-
-#if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10)
-void SDL_WinRTApp::OnSettingsPaneCommandsRequested(
- Windows::UI::ApplicationSettings::SettingsPane ^p,
- Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args)
-{
- using namespace Platform;
- using namespace Windows::UI::ApplicationSettings;
- using namespace Windows::UI::Popups;
-
- String ^privacyPolicyURL = nullptr; // a URL to an app's Privacy Policy
- String ^privacyPolicyLabel = nullptr; // label/link text
- const char *tmpHintValue = NULL; // SDL_GetHint-retrieved value, used immediately
- wchar_t *tmpStr = NULL; // used for UTF8 to UCS2 conversion
-
- // Setup a 'Privacy Policy' link, if one is available (via SDL_GetHint):
- tmpHintValue = SDL_GetHint(SDL_HINT_WINRT_PRIVACY_POLICY_URL);
- if (tmpHintValue && tmpHintValue[0] != '\0') {
- // Convert the privacy policy's URL to UCS2:
- tmpStr = WIN_UTF8ToString(tmpHintValue);
- privacyPolicyURL = ref new String(tmpStr);
- SDL_free(tmpStr);
-
- // Optionally retrieve custom label-text for the link. If this isn't
- // available, a default value will be used instead.
- tmpHintValue = SDL_GetHint(SDL_HINT_WINRT_PRIVACY_POLICY_LABEL);
- if (tmpHintValue && tmpHintValue[0] != '\0') {
- tmpStr = WIN_UTF8ToString(tmpHintValue);
- privacyPolicyLabel = ref new String(tmpStr);
- SDL_free(tmpStr);
- } else {
- privacyPolicyLabel = ref new String(L"Privacy Policy");
- }
-
- // Register the link, along with a handler to be called if and when it is
- // clicked:
- auto cmd = ref new SettingsCommand(L"privacyPolicy", privacyPolicyLabel,
- ref new UICommandInvokedHandler([=](IUICommand ^) {
- Windows::System::Launcher::LaunchUriAsync(ref new Uri(privacyPolicyURL));
- }));
- args->Request->ApplicationCommands->Append(cmd);
- }
-}
-#endif // if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10)
-
-void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
-{
-#if LOG_WINDOW_EVENTS==1
- SDL_Log("%s, size={%f,%f}, bounds={%f,%f,%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, WINRT_GlobalSDLWindow?=%s\n",
- __FUNCTION__,
- args->Size.Width, args->Size.Height,
- sender->Bounds.X, sender->Bounds.Y, sender->Bounds.Width, sender->Bounds.Height,
- WINRT_DISPLAY_PROPERTY(CurrentOrientation),
- WINRT_DISPLAY_PROPERTY(NativeOrientation),
- WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
- (WINRT_GlobalSDLWindow ? "yes" : "no"));
-#endif
-
- WINRT_ProcessWindowSizeChange();
-}
-
-void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
-{
-#if LOG_WINDOW_EVENTS==1
- SDL_Log("%s, visible?=%s, bounds={%f,%f,%f,%f}, WINRT_GlobalSDLWindow?=%s\n",
- __FUNCTION__,
- (args->Visible ? "yes" : "no"),
- sender->Bounds.X, sender->Bounds.Y,
- sender->Bounds.Width, sender->Bounds.Height,
- (WINRT_GlobalSDLWindow ? "yes" : "no"));
-#endif
-
- m_windowVisible = args->Visible;
- if (WINRT_GlobalSDLWindow) {
- SDL_bool wasSDLWindowSurfaceValid = WINRT_GlobalSDLWindow->surface_valid;
- Uint32 latestWindowFlags = WINRT_DetectWindowFlags(WINRT_GlobalSDLWindow);
- if (args->Visible) {
- SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_SHOWN, 0, 0);
- SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
- if (latestWindowFlags & SDL_WINDOW_MAXIMIZED) {
- SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
- } else {
- SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_RESTORED, 0, 0);
- }
- } else {
- SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_HIDDEN, 0, 0);
- SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
- SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
- }
-
- // HACK: Prevent SDL's window-hide handling code, which currently
- // triggers a fake window resize (possibly erronously), from
- // marking the SDL window's surface as invalid.
- //
- // A better solution to this probably involves figuring out if the
- // fake window resize can be prevented.
- WINRT_GlobalSDLWindow->surface_valid = wasSDLWindowSurfaceValid;
- }
-}
-
-void SDL_WinRTApp::OnWindowActivated(CoreWindow^ sender, WindowActivatedEventArgs^ args)
-{
-#if LOG_WINDOW_EVENTS==1
- SDL_Log("%s, WINRT_GlobalSDLWindow?=%s\n\n",
- __FUNCTION__,
- (WINRT_GlobalSDLWindow ? "yes" : "no"));
-#endif
-
- /* There's no property in Win 8.x to tell whether a window is active or
- not. [De]activation events are, however, sent to the app. We'll just
- record those, in case the CoreWindow gets wrapped by an SDL_Window at
- some future time.
- */
- sender->CustomProperties->Insert("SDLHelperWindowActivationState", args->WindowActivationState);
-
- SDL_Window * window = WINRT_GlobalSDLWindow;
- if (window) {
- if (args->WindowActivationState != CoreWindowActivationState::Deactivated) {
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
- if (SDL_GetKeyboardFocus() != window) {
- SDL_SetKeyboardFocus(window);
- }
-
- /* Send a mouse-motion event as appropriate.
- This doesn't work when called from OnPointerEntered, at least
- not in WinRT CoreWindow apps (as OnPointerEntered doesn't
- appear to be called after window-reactivation, at least not
- in Windows 10, Build 10586.3 (November 2015 update, non-beta).
-
- Don't do it on WinPhone 8.0 though, as CoreWindow's 'PointerPosition'
- property isn't available.
- */
-#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION >= NTDDI_WINBLUE)
- Point cursorPos = WINRT_TransformCursorPosition(window, sender->PointerPosition, TransformToSDLWindowSize);
- SDL_SendMouseMotion(window, 0, 0, (int)cursorPos.X, (int)cursorPos.Y);
-#endif
-
- /* TODO, WinRT: see if the Win32 bugfix from https://hg.libsdl.org/SDL/rev/d278747da408 needs to be applied (on window activation) */
- //WIN_CheckAsyncMouseRelease(data);
-
- /* TODO, WinRT: implement clipboard support, if possible */
- ///*
- // * FIXME: Update keyboard state
- // */
- //WIN_CheckClipboardUpdate(data->videodata);
-
- // HACK: Resetting the mouse-cursor here seems to fix
- // https://bugzilla.libsdl.org/show_bug.cgi?id=3217, whereby a
- // WinRT app's mouse cursor may switch to Windows' 'wait' cursor,
- // after a user alt-tabs back into a full-screened SDL app.
- // This bug does not appear to reproduce 100% of the time.
- // It may be a bug in Windows itself (v.10.0.586.36, as tested,
- // and the most-recent as of this writing).
- SDL_SetCursor(NULL);
- } else {
- if (SDL_GetKeyboardFocus() == window) {
- SDL_SetKeyboardFocus(NULL);
- }
- }
- }
-}
-
-void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
-{
-#if LOG_WINDOW_EVENTS==1
- SDL_Log("%s\n", __FUNCTION__);
-#endif
- m_windowClosed = true;
-}
-
-void SDL_WinRTApp::OnAppActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
-{
- CoreWindow::GetForCurrentThread()->Activate();
-}
-
-void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
-{
- // Save app state asynchronously after requesting a deferral. Holding a deferral
- // indicates that the application is busy performing suspending operations. Be
- // aware that a deferral may not be held indefinitely. After about five seconds,
- // the app will be forced to exit.
-
- // ... but first, let the app know it's about to go to the background.
- // The separation of events may be important, given that the deferral
- // runs in a separate thread. This'll make SDL_APP_WILLENTERBACKGROUND
- // the only event among the two that runs in the main thread. Given
- // that a few WinRT operations can only be done from the main thread
- // (things that access the WinRT CoreWindow are one example of this),
- // this could be important.
- SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
-
- SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
- create_task([this, deferral]()
- {
- // Send an app did-enter-background event immediately to observers.
- // CoreDispatcher::ProcessEvents, which is the backbone on which
- // SDL_WinRTApp::PumpEvents is built, will not return to its caller
- // once it sends out a suspend event. Any events posted to SDL's
- // event queue won't get received until the WinRT app is resumed.
- // SDL_AddEventWatch() may be used to receive app-suspend events on
- // WinRT.
- SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
-
- // Let the Direct3D 11 renderer prepare for the app to be backgrounded.
- // This is necessary for Windows 8.1, possibly elsewhere in the future.
- // More details at: http://msdn.microsoft.com/en-us/library/windows/apps/Hh994929.aspx
-#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
- if (WINRT_GlobalSDLWindow) {
- SDL_Renderer * renderer = SDL_GetRenderer(WINRT_GlobalSDLWindow);
- if (renderer && (SDL_strcmp(renderer->info.name, "direct3d11") == 0)) {
- D3D11_Trim(renderer);
- }
- }
-#endif
-
- deferral->Complete();
- });
-}
-
-void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
-{
- // Restore any data or state that was unloaded on suspend. By default, data
- // and state are persisted when resuming from suspend. Note that these events
- // do not occur if the app was previously terminated.
- SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
- SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
-}
-
-void SDL_WinRTApp::OnExiting(Platform::Object^ sender, Platform::Object^ args)
-{
- SDL_SendAppEvent(SDL_APP_TERMINATING);
-}
-
-static void
-WINRT_LogPointerEvent(const char * header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
-{
- Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
- SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
- header,
- pt->Position.X, pt->Position.Y,
- transformedPoint.X, transformedPoint.Y,
- pt->Properties->MouseWheelDelta,
- pt->FrameId,
- pt->PointerId,
- WINRT_GetSDLButtonForPointerPoint(pt));
-}
-
-void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
-{
-#if LOG_POINTER_EVENTS
- WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
-#endif
-
- WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
-}
-
-void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
-{
-#if LOG_POINTER_EVENTS
- WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
-#endif
-
- WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
-}
-
-void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
-{
-#if LOG_POINTER_EVENTS
- WINRT_LogPointerEvent("pointer released", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
-#endif
-
- WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
-}
-
-void SDL_WinRTApp::OnPointerEntered(CoreWindow^ sender, PointerEventArgs^ args)
-{
-#if LOG_POINTER_EVENTS
- WINRT_LogPointerEvent("pointer entered", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
-#endif
-
- WINRT_ProcessPointerEnteredEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
-}
-
-void SDL_WinRTApp::OnPointerExited(CoreWindow^ sender, PointerEventArgs^ args)
-{
-#if LOG_POINTER_EVENTS
- WINRT_LogPointerEvent("pointer exited", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
-#endif
-
- WINRT_ProcessPointerExitedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
-}
-
-void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
-{
-#if LOG_POINTER_EVENTS
- WINRT_LogPointerEvent("pointer wheel changed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
-#endif
-
- WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
-}
-
-void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
-{
- WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
-}
-
-void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
-{
- WINRT_ProcessKeyDownEvent(args);
-}
-
-void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
-{
- WINRT_ProcessKeyUpEvent(args);
-}
-
-void SDL_WinRTApp::OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args)
-{
- WINRT_ProcessCharacterReceivedEvent(args);
-}
-
-template <typename BackButtonEventArgs>
-static void WINRT_OnBackButtonPressed(BackButtonEventArgs ^ args)
-{
- SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_AC_BACK);
- SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_AC_BACK);
-
- if (SDL_GetHintBoolean(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_FALSE)) {
- args->Handled = true;
- }
-}
-
-#if NTDDI_VERSION == NTDDI_WIN10
-void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args)
-
-{
- WINRT_OnBackButtonPressed(args);
-}
-#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
-void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args)
-
-{
- WINRT_OnBackButtonPressed(args);
-}
-#endif
-
-#if NTDDI_VERSION >= NTDDI_WIN10
-void SDL_WinRTApp::OnGamepadAdded(Platform::Object ^sender, Windows::Gaming::Input::Gamepad ^gamepad)
-{
- /* HACK ALERT: Nothing needs to be done here, as this method currently
- only exists to allow something to be registered with Win10's
- GamepadAdded event, an operation that seems to be necessary to get
- Xinput-based detection to work on Xbox One.
- */
-}
-#endif
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.h b/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.h
deleted file mode 100644
index 4b48115f058..00000000000
--- a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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 <Windows.h>
-
-extern int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **));
-
-ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
-{
-public:
- SDL_WinRTApp();
-
- // IFrameworkView Methods.
- virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
- virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
- virtual void Load(Platform::String^ entryPoint);
- virtual void Run();
- virtual void Uninitialize();
-
-internal:
- // SDL-specific methods
- void PumpEvents();
-
-protected:
- bool ShouldWaitForAppResumeEvents();
-
- // Event Handlers.
-
-#if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10) // for Windows 8/8.1/RT apps... (and not Phone apps)
- void OnSettingsPaneCommandsRequested(
- Windows::UI::ApplicationSettings::SettingsPane ^p,
- Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args);
-#endif // if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10)
-
-#if NTDDI_VERSION > NTDDI_WIN8
- void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
-#else
- void OnOrientationChanged(Platform::Object^ sender);
-#endif
- void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
- void OnLogicalDpiChanged(Platform::Object^ sender);
- void OnAppActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
- void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
- void OnResuming(Platform::Object^ sender, Platform::Object^ args);
- void OnExiting(Platform::Object^ sender, Platform::Object^ args);
- void OnWindowActivated(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowActivatedEventArgs^ args);
- void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
- void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
- void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
- void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
- void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
- void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
- void OnPointerEntered(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
- void OnPointerExited(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
- void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args);
- void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
- void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
- void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args);
-
-#if NTDDI_VERSION >= NTDDI_WIN10
- void OnBackButtonPressed(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args);
-#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
- void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args);
-#endif
-
-#if NTDDI_VERSION >= NTDDI_WIN10
- void OnGamepadAdded(Platform::Object ^sender, Windows::Gaming::Input::Gamepad ^gamepad);
-#endif
-
-private:
- bool m_windowClosed;
- bool m_windowVisible;
-};
-
-extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
diff --git a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.cpp b/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.cpp
deleted file mode 100644
index 201e3b6c2a4..00000000000
--- a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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.
-*/
-
-/* Windows includes */
-#include <agile.h>
-#include <Windows.h>
-
-#if WINAPI_FAMILY == WINAPI_FAMILY_APP
-#include <windows.ui.xaml.media.dxinterop.h>
-#endif
-
-
-/* SDL includes */
-#include "../../SDL_internal.h"
-#include "SDL.h"
-#include "../../video/winrt/SDL_winrtevents_c.h"
-#include "../../video/winrt/SDL_winrtvideo_cpp.h"
-#include "SDL_winrtapp_common.h"
-#include "SDL_winrtapp_xaml.h"
-
-
-
-/* SDL-internal globals: */
-SDL_bool WINRT_XAMLWasEnabled = SDL_FALSE;
-
-#if WINAPI_FAMILY == WINAPI_FAMILY_APP
-extern "C"
-ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative = NULL;
-static Windows::Foundation::EventRegistrationToken WINRT_XAMLAppEventToken;
-#endif
-
-
-/*
- * Input event handlers (XAML)
- */
-#if WINAPI_FAMILY == WINAPI_FAMILY_APP
-
-static void
-WINRT_OnPointerPressedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
-{
- WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
-}
-
-static void
-WINRT_OnPointerMovedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
-{
- WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
-}
-
-static void
-WINRT_OnPointerReleasedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
-{
- WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
-}
-
-static void
-WINRT_OnPointerWheelChangedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
-{
- WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
-}
-
-#endif // WINAPI_FAMILY == WINAPI_FAMILY_APP
-
-
-/*
- * XAML-to-SDL Rendering Callback
- */
-#if WINAPI_FAMILY == WINAPI_FAMILY_APP
-
-static void
-WINRT_OnRenderViaXAML(_In_ Platform::Object^ sender, _In_ Platform::Object^ args)
-{
- WINRT_CycleXAMLThread();
-}
-
-#endif // WINAPI_FAMILY == WINAPI_FAMILY_APP
-
-
-/*
- * SDL + XAML Initialization
- */
-
-int
-SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void * backgroundPanelAsIInspectable)
-{
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
- return SDL_SetError("XAML support is not yet available in Windows Phone.");
-#else
- // Declare C++/CX namespaces:
- using namespace Platform;
- using namespace Windows::Foundation;
- using namespace Windows::UI::Core;
- using namespace Windows::UI::Xaml;
- using namespace Windows::UI::Xaml::Controls;
- using namespace Windows::UI::Xaml::Input;
- using namespace Windows::UI::Xaml::Media;
-
- // Make sure we have a valid XAML element (to draw onto):
- if ( ! backgroundPanelAsIInspectable) {
- return SDL_SetError("'backgroundPanelAsIInspectable' can't be NULL");
- }
-
- Platform::Object ^ backgroundPanel = reinterpret_cast<Object ^>((IInspectable *) backgroundPanelAsIInspectable);
- SwapChainBackgroundPanel ^swapChainBackgroundPanel = dynamic_cast<SwapChainBackgroundPanel ^>(backgroundPanel);
- if ( ! swapChainBackgroundPanel) {
- return SDL_SetError("An unknown or unsupported type of XAML control was specified.");
- }
-
- // Setup event handlers:
- swapChainBackgroundPanel->PointerPressed += ref new PointerEventHandler(WINRT_OnPointerPressedViaXAML);
- swapChainBackgroundPanel->PointerReleased += ref new PointerEventHandler(WINRT_OnPointerReleasedViaXAML);
- swapChainBackgroundPanel->PointerWheelChanged += ref new PointerEventHandler(WINRT_OnPointerWheelChangedViaXAML);
- swapChainBackgroundPanel->PointerMoved += ref new PointerEventHandler(WINRT_OnPointerMovedViaXAML);
-
- // Setup for rendering:
- IInspectable *panelInspectable = (IInspectable*) reinterpret_cast<IInspectable*>(swapChainBackgroundPanel);
- panelInspectable->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void **)&WINRT_GlobalSwapChainBackgroundPanelNative);
-
- WINRT_XAMLAppEventToken = CompositionTarget::Rendering::add(ref new EventHandler<Object^>(WINRT_OnRenderViaXAML));
-
- // Make sure the app is ready to call the SDL-centric main() function:
- WINRT_SDLAppEntryPoint = mainFunction;
- SDL_SetMainReady();
-
- // Make sure video-init knows that we're initializing XAML:
- SDL_bool oldXAMLWasEnabledValue = WINRT_XAMLWasEnabled;
- WINRT_XAMLWasEnabled = SDL_TRUE;
-
- // Make sure video modes are detected now, while we still have access to the WinRT
- // CoreWindow. WinRT will not allow the app's CoreWindow to be accessed via the
- // SDL/WinRT thread.
- if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
- // SDL_InitSubSystem will, on error, set the SDL error. Let that propogate to
- // the caller to here:
- WINRT_XAMLWasEnabled = oldXAMLWasEnabledValue;
- return -1;
- }
-
- // All done, for now.
- return 0;
-#endif // WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP / else
-}
diff --git a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.h b/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.h
deleted file mode 100644
index a08b67c40b9..00000000000
--- a/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 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_config.h"
-
-#ifndef _SDL_winrtapp_xaml_h
-#define _SDL_winrtapp_xaml_h
-
-#include "SDL_stdinc.h"
-
-#ifdef __cplusplus
-extern SDL_bool WINRT_XAMLWasEnabled;
-extern int SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void * backgroundPanelAsIInspectable);
-#endif // ifdef __cplusplus
-
-#endif // ifndef _SDL_winrtapp_xaml_h