early-access version 1667

This commit is contained in:
pineappleEA
2021-05-09 11:30:38 +02:00
parent 5e268d25d7
commit 5dbb928ff2
1069 changed files with 38272 additions and 14437 deletions

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -79,7 +79,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetScreenResolution)(
JNIEnv *env, jclass jcls,
jint surfaceWidth, jint surfaceHeight,
jint deviceWidth, jint deviceHeight, jint format, jfloat rate);
jint deviceWidth, jint deviceHeight, jfloat rate);
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
JNIEnv *env, jclass cls);
@@ -168,7 +168,7 @@ static JNINativeMethod SDLActivity_tab[] = {
{ "nativeSetupJNI", "()I", SDL_JAVA_INTERFACE(nativeSetupJNI) },
{ "nativeRunMain", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)I", SDL_JAVA_INTERFACE(nativeRunMain) },
{ "onNativeDropFile", "(Ljava/lang/String;)V", SDL_JAVA_INTERFACE(onNativeDropFile) },
{ "nativeSetScreenResolution", "(IIIIIF)V", SDL_JAVA_INTERFACE(nativeSetScreenResolution) },
{ "nativeSetScreenResolution", "(IIIIF)V", SDL_JAVA_INTERFACE(nativeSetScreenResolution) },
{ "onNativeResize", "()V", SDL_JAVA_INTERFACE(onNativeResize) },
{ "onNativeSurfaceCreated", "()V", SDL_JAVA_INTERFACE(onNativeSurfaceCreated) },
{ "onNativeSurfaceChanged", "()V", SDL_JAVA_INTERFACE(onNativeSurfaceChanged) },
@@ -312,12 +312,12 @@ static jmethodID midManualBackButton;
static jmethodID midMinimizeWindow;
static jmethodID midOpenURL;
static jmethodID midRequestPermission;
static jmethodID midShowToast;
static jmethodID midSendMessage;
static jmethodID midSetActivityTitle;
static jmethodID midSetCustomCursor;
static jmethodID midSetOrientation;
static jmethodID midSetRelativeMouseEnabled;
static jmethodID midSetSurfaceViewFormat;
static jmethodID midSetSystemCursor;
static jmethodID midSetWindowStyle;
static jmethodID midShouldMinimizeOnFocusLoss;
@@ -591,12 +591,12 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
midMinimizeWindow = (*env)->GetStaticMethodID(env, mActivityClass, "minimizeWindow","()V");
midOpenURL = (*env)->GetStaticMethodID(env, mActivityClass, "openURL", "(Ljava/lang/String;)I");
midRequestPermission = (*env)->GetStaticMethodID(env, mActivityClass, "requestPermission", "(Ljava/lang/String;I)V");
midShowToast = (*env)->GetStaticMethodID(env, mActivityClass, "showToast", "(Ljava/lang/String;IIII)I");
midSendMessage = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z");
midSetActivityTitle = (*env)->GetStaticMethodID(env, mActivityClass, "setActivityTitle","(Ljava/lang/String;)Z");
midSetCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "setCustomCursor", "(I)Z");
midSetOrientation = (*env)->GetStaticMethodID(env, mActivityClass, "setOrientation","(IIZLjava/lang/String;)V");
midSetRelativeMouseEnabled = (*env)->GetStaticMethodID(env, mActivityClass, "setRelativeMouseEnabled", "(Z)Z");
midSetSurfaceViewFormat = (*env)->GetStaticMethodID(env, mActivityClass, "setSurfaceViewFormat","(I)V");
midSetSystemCursor = (*env)->GetStaticMethodID(env, mActivityClass, "setSystemCursor", "(I)Z");
midSetWindowStyle = (*env)->GetStaticMethodID(env, mActivityClass, "setWindowStyle","(Z)V");
midShouldMinimizeOnFocusLoss = (*env)->GetStaticMethodID(env, mActivityClass, "shouldMinimizeOnFocusLoss","()Z");
@@ -621,12 +621,12 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
!midMinimizeWindow ||
!midOpenURL ||
!midRequestPermission ||
!midShowToast ||
!midSendMessage ||
!midSetActivityTitle ||
!midSetCustomCursor ||
!midSetOrientation ||
!midSetRelativeMouseEnabled ||
!midSetSurfaceViewFormat ||
!midSetSystemCursor ||
!midSetWindowStyle ||
!midShouldMinimizeOnFocusLoss ||
@@ -842,11 +842,11 @@ retry:
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetScreenResolution)(
JNIEnv *env, jclass jcls,
jint surfaceWidth, jint surfaceHeight,
jint deviceWidth, jint deviceHeight, jint format, jfloat rate)
jint deviceWidth, jint deviceHeight, jfloat rate)
{
SDL_LockMutex(Android_ActivityMutex);
Android_SetScreenResolution(surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, format, rate);
Android_SetScreenResolution(surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, rate);
SDL_UnlockMutex(Android_ActivityMutex);
}
@@ -1381,26 +1381,6 @@ ANativeWindow* Android_JNI_GetNativeWindow(void)
return anw;
}
void Android_JNI_SetSurfaceViewFormat(int format)
{
JNIEnv *env = Android_JNI_GetEnv();
int new_format = 0;
/* Format from android/native_window.h,
* convert to temporary arbitrary values,
* then to java PixelFormat */
if (format == WINDOW_FORMAT_RGBA_8888) {
new_format = 1;
} else if (format == WINDOW_FORMAT_RGBX_8888) {
new_format = 2;
} else if (format == WINDOW_FORMAT_RGB_565) {
/* Default */
new_format = 0;
}
(*env)->CallStaticVoidMethod(env, mActivityClass, midSetSurfaceViewFormat, new_format);
}
void Android_JNI_SetActivityTitle(const char *title)
{
JNIEnv *env = Android_JNI_GetEnv();
@@ -2468,6 +2448,11 @@ SDL_bool SDL_AndroidRequestPermission(const char *permission)
return Android_JNI_RequestPermission(permission);
}
int SDL_AndroidShowToast(const char* message, int duration, int gravity, int xOffset, int yOffset)
{
return Android_JNI_ShowToast(message, duration, gravity, xOffset, yOffset);
}
void Android_JNI_GetManifestEnvironmentVariables(void)
{
if (!mActivityClass || !midGetManifestEnvironmentVariables) {
@@ -2547,6 +2532,17 @@ SDL_bool Android_JNI_RequestPermission(const char *permission)
return bPermissionRequestResult;
}
/* Show toast notification */
int Android_JNI_ShowToast(const char* message, int duration, int gravity, int xOffset, int yOffset)
{
int result = 0;
JNIEnv *env = Android_JNI_GetEnv();
jstring jmessage = (*env)->NewStringUTF(env, message);
result = (*env)->CallStaticIntMethod(env, mActivityClass, midShowToast, jmessage, duration, gravity, xOffset, yOffset);
(*env)->DeleteLocalRef(env, jmessage);
return result;
}
int Android_JNI_GetLocale(char *buf, size_t buflen)
{
AConfiguration *cfg;

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -47,7 +47,6 @@ extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect);
extern void Android_JNI_HideTextInput(void);
extern SDL_bool Android_JNI_IsScreenKeyboardShown(void);
extern ANativeWindow* Android_JNI_GetNativeWindow(void);
extern void Android_JNI_SetSurfaceViewFormat(int format);
extern SDL_DisplayOrientation Android_JNI_GetDisplayOrientation(void);
extern int Android_JNI_GetDisplayDPI(float *ddpi, float *xdpi, float *ydpi);
@@ -129,6 +128,9 @@ SDL_bool Android_JNI_SetRelativeMouseEnabled(SDL_bool enabled);
/* Request permission */
SDL_bool Android_JNI_RequestPermission(const char *permission);
/* Show toast notification */
int Android_JNI_ShowToast(const char* message, int duration, int gravity, int xOffset, int yOffset);
int Android_JNI_OpenURL(const char *url);
int SDL_GetAndroidSDKVersion(void);

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -87,15 +87,18 @@ static int fatal_signals[] =
static void kbd_cleanup(void)
{
struct mouse_info mData;
SDL_EVDEV_keyboard_state* kbd = kbd_cleanup_state;
if (kbd == NULL) {
return;
}
kbd_cleanup_state = NULL;
SDL_zero(mData);
mData.operation = MOUSE_SHOW;
ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
if (kbd->keyboard_fd != kbd->console_fd) close(kbd->keyboard_fd);
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
ioctl(kbd->console_fd, CONS_MOUSECTL, &mData);
}
void
@@ -221,9 +224,12 @@ SDL_EVDEV_keyboard_state *
SDL_EVDEV_kbd_init(void)
{
SDL_EVDEV_keyboard_state *kbd;
struct mouse_info mData;
char flag_state;
char* devicePath;
SDL_zero(mData);
mData.operation = MOUSE_HIDE;
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
if (!kbd) {
return NULL;
@@ -241,7 +247,8 @@ SDL_EVDEV_kbd_init(void)
kbd->kbInfo = SDL_calloc(sizeof(keyboard_info_t), 1);
ioctl(kbd->console_fd, KDGKBINFO, kbd->kbInfo);
ioctl(kbd->console_fd, CONS_MOUSECTL, &mData);
if (ioctl(kbd->console_fd, KDGKBSTATE, &flag_state) == 0) {
kbd->ledflagstate = flag_state;
}
@@ -292,9 +299,14 @@ SDL_EVDEV_kbd_init(void)
void
SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
{
struct mouse_info mData;
if (!kbd) {
return;
}
SDL_zero(mData);
mData.operation = MOUSE_SHOW;
ioctl(kbd->console_fd, CONS_MOUSECTL, &mData);
kbd_unregister_emerg_cleanup();

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -222,6 +222,9 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
SDL_UDEV_DEVICE_TOUCHSCREEN)))
return;
if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK))
return;
SDL_EVDEV_device_added(dev_path, udev_class);
break;
case SDL_UDEV_DEVICEREMOVED:

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 2020 Collabora Ltd.
This software is provided 'as-is', without any express or implied
@@ -24,12 +24,34 @@
#if HAVE_LIBUDEV_H || defined(SDL_JOYSTICK_LINUX)
/* missing defines in older Linux kernel headers */
#ifndef BTN_TRIGGER_HAPPY
#define BTN_TRIGGER_HAPPY 0x2c0
#endif
#ifndef BTN_DPAD_UP
#define BTN_DPAD_UP 0x220
#endif
#ifndef KEY_ALS_TOGGLE
#define KEY_ALS_TOGGLE 0x230
#endif
extern int
SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
unsigned long bitmask_abs[NBITS(ABS_MAX)],
unsigned long bitmask_key[NBITS(KEY_MAX)],
unsigned long bitmask_rel[NBITS(REL_MAX)])
{
struct range {
unsigned start;
unsigned end;
};
/* key code ranges above BTN_MISC (start is inclusive, stop is exclusive)*/
static const struct range high_key_blocks[] = {
{ KEY_OK, BTN_DPAD_UP },
{ KEY_ALS_TOGGLE, BTN_TRIGGER_HAPPY }
};
int devclass = 0;
unsigned long keyboard_mask;
@@ -86,6 +108,31 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
}
if (test_bit(EV_KEY, bitmask_ev)) {
unsigned i;
unsigned long found = 0;
for (i = 0; i < BTN_MISC/BITS_PER_LONG; ++i) {
found |= bitmask_key[i];
}
/* If there are no keys in the lower block, check the higher blocks */
if (!found) {
unsigned block;
for (block = 0; block < (sizeof(high_key_blocks) / sizeof(struct range)); ++block) {
for (i = high_key_blocks[block].start; i < high_key_blocks[block].end; ++i) {
if (test_bit(i, bitmask_key)) {
found = 1;
break;
}
}
}
}
if (found > 0) {
devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEY */
}
}
/* 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;

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 2020 Collabora Ltd.
This software is provided 'as-is', without any express or implied

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -257,7 +257,12 @@ IBus_GetDBusAddressFilename(void)
}
if (!*host) {
host = "unix";
const char *session = SDL_getenv("XDG_SESSION_TYPE");
if (session != NULL && SDL_strcmp(session, "wayland") == 0) {
host = "unix-wayland";
} else {
host = "unix";
}
}
SDL_memset(config_dir, 0, sizeof(config_dir));
@@ -479,7 +484,7 @@ IBus_SimpleMessage(const char *method)
{
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if (IBus_CheckConnection(dbus)) {
if ((input_ctx_path != NULL) && (IBus_CheckConnection(dbus))) {
SDL_DBus_CallVoidMethodOnConnection(ibus_conn, IBUS_SERVICE, input_ctx_path, IBUS_INPUT_INTERFACE, method, DBUS_TYPE_INVALID);
}
}

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -449,13 +449,15 @@ SDL_UDEV_Poll(void)
}
action = _this->syms.udev_device_get_action(dev);
if (SDL_strcmp(action, "add") == 0) {
/* Wait for the device to finish initialization */
SDL_Delay(100);
if (action) {
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);
device_event(SDL_UDEV_DEVICEADDED, dev);
} else if (SDL_strcmp(action, "remove") == 0) {
device_event(SDL_UDEV_DEVICEREMOVED, dev);
}
}
_this->syms.udev_device_unref(dev);

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

27
externals/SDL/src/core/openbsd/SDL_wscons.h vendored Executable file
View File

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

View File

@@ -0,0 +1,833 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include <dev/wscons/wsksymvar.h>
#include <dev/wscons/wsksymdef.h>
#include "SDL_scancode.h"
#include "SDL_events.h"
#include "SDL_keyboard.h"
#include "SDL_wscons.h"
#include "SDL_log.h"
#include <sys/time.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsdisplay_usl_io.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <unistd.h>
#include "../../events/SDL_events_c.h"
#ifdef __NetBSD__
#define KS_GROUP_Ascii KS_GROUP_Plain
#define KS_Cmd_ScrollBack KS_Cmd_ScrollFastUp
#define KS_Cmd_ScrollFwd KS_Cmd_ScrollFastDown
#endif
#define RETIFIOCTLERR(x) if (x == -1) { free(input); input = NULL; return NULL;}
typedef struct SDL_WSCONS_mouse_input_data SDL_WSCONS_mouse_input_data;
extern SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse();
extern void updateMouse(SDL_WSCONS_mouse_input_data* input);
extern void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data* input);
/* Conversion table courtesy of /usr/src/sys/dev/wscons/wskbdutil.c */
static const unsigned char latin1_to_upper[256] = {
/* 0 8 1 9 2 a 3 b 4 c 5 d 6 e 7 f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 5 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 5 */
0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', /* 6 */
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', /* 6 */
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', /* 7 */
'X', 'Y', 'Z', 0x00, 0x00, 0x00, 0x00, 0x00, /* 7 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d */
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* e */
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, /* e */
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0x00, /* f */
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0x00, /* f */
};
/* Compose table courtesy of /usr/src/sys/dev/wscons/wskbdutil.c */
static struct SDL_wscons_compose_tab_s {
keysym_t elem[2];
keysym_t result;
} compose_tab[] = {
{ { KS_plus, KS_plus }, KS_numbersign },
{ { KS_a, KS_a }, KS_at },
{ { KS_parenleft, KS_parenleft }, KS_bracketleft },
{ { KS_slash, KS_slash }, KS_backslash },
{ { KS_parenright, KS_parenright }, KS_bracketright },
{ { KS_parenleft, KS_minus }, KS_braceleft },
{ { KS_slash, KS_minus }, KS_bar },
{ { KS_parenright, KS_minus }, KS_braceright },
{ { KS_exclam, KS_exclam }, KS_exclamdown },
{ { KS_c, KS_slash }, KS_cent },
{ { KS_l, KS_minus }, KS_sterling },
{ { KS_y, KS_minus }, KS_yen },
{ { KS_s, KS_o }, KS_section },
{ { KS_x, KS_o }, KS_currency },
{ { KS_c, KS_o }, KS_copyright },
{ { KS_less, KS_less }, KS_guillemotleft },
{ { KS_greater, KS_greater }, KS_guillemotright },
{ { KS_question, KS_question }, KS_questiondown },
{ { KS_dead_acute, KS_space }, KS_apostrophe },
{ { KS_dead_grave, KS_space }, KS_grave },
{ { KS_dead_tilde, KS_space }, KS_asciitilde },
{ { KS_dead_circumflex, KS_space }, KS_asciicircum },
{ { KS_dead_diaeresis, KS_space }, KS_quotedbl },
{ { KS_dead_cedilla, KS_space }, KS_comma },
{ { KS_dead_circumflex, KS_A }, KS_Acircumflex },
{ { KS_dead_diaeresis, KS_A }, KS_Adiaeresis },
{ { KS_dead_grave, KS_A }, KS_Agrave },
{ { KS_dead_abovering, KS_A }, KS_Aring },
{ { KS_dead_tilde, KS_A }, KS_Atilde },
{ { KS_dead_cedilla, KS_C }, KS_Ccedilla },
{ { KS_dead_acute, KS_E }, KS_Eacute },
{ { KS_dead_circumflex, KS_E }, KS_Ecircumflex },
{ { KS_dead_diaeresis, KS_E }, KS_Ediaeresis },
{ { KS_dead_grave, KS_E }, KS_Egrave },
{ { KS_dead_acute, KS_I }, KS_Iacute },
{ { KS_dead_circumflex, KS_I }, KS_Icircumflex },
{ { KS_dead_diaeresis, KS_I }, KS_Idiaeresis },
{ { KS_dead_grave, KS_I }, KS_Igrave },
{ { KS_dead_tilde, KS_N }, KS_Ntilde },
{ { KS_dead_acute, KS_O }, KS_Oacute },
{ { KS_dead_circumflex, KS_O }, KS_Ocircumflex },
{ { KS_dead_diaeresis, KS_O }, KS_Odiaeresis },
{ { KS_dead_grave, KS_O }, KS_Ograve },
{ { KS_dead_tilde, KS_O }, KS_Otilde },
{ { KS_dead_acute, KS_U }, KS_Uacute },
{ { KS_dead_circumflex, KS_U }, KS_Ucircumflex },
{ { KS_dead_diaeresis, KS_U }, KS_Udiaeresis },
{ { KS_dead_grave, KS_U }, KS_Ugrave },
{ { KS_dead_acute, KS_Y }, KS_Yacute },
{ { KS_dead_acute, KS_a }, KS_aacute },
{ { KS_dead_circumflex, KS_a }, KS_acircumflex },
{ { KS_dead_diaeresis, KS_a }, KS_adiaeresis },
{ { KS_dead_grave, KS_a }, KS_agrave },
{ { KS_dead_abovering, KS_a }, KS_aring },
{ { KS_dead_tilde, KS_a }, KS_atilde },
{ { KS_dead_cedilla, KS_c }, KS_ccedilla },
{ { KS_dead_acute, KS_e }, KS_eacute },
{ { KS_dead_circumflex, KS_e }, KS_ecircumflex },
{ { KS_dead_diaeresis, KS_e }, KS_ediaeresis },
{ { KS_dead_grave, KS_e }, KS_egrave },
{ { KS_dead_acute, KS_i }, KS_iacute },
{ { KS_dead_circumflex, KS_i }, KS_icircumflex },
{ { KS_dead_diaeresis, KS_i }, KS_idiaeresis },
{ { KS_dead_grave, KS_i }, KS_igrave },
{ { KS_dead_tilde, KS_n }, KS_ntilde },
{ { KS_dead_acute, KS_o }, KS_oacute },
{ { KS_dead_circumflex, KS_o }, KS_ocircumflex },
{ { KS_dead_diaeresis, KS_o }, KS_odiaeresis },
{ { KS_dead_grave, KS_o }, KS_ograve },
{ { KS_dead_tilde, KS_o }, KS_otilde },
{ { KS_dead_acute, KS_u }, KS_uacute },
{ { KS_dead_circumflex, KS_u }, KS_ucircumflex },
{ { KS_dead_diaeresis, KS_u }, KS_udiaeresis },
{ { KS_dead_grave, KS_u }, KS_ugrave },
{ { KS_dead_acute, KS_y }, KS_yacute },
{ { KS_dead_diaeresis, KS_y }, KS_ydiaeresis },
{ { KS_quotedbl, KS_A }, KS_Adiaeresis },
{ { KS_quotedbl, KS_E }, KS_Ediaeresis },
{ { KS_quotedbl, KS_I }, KS_Idiaeresis },
{ { KS_quotedbl, KS_O }, KS_Odiaeresis },
{ { KS_quotedbl, KS_U }, KS_Udiaeresis },
{ { KS_quotedbl, KS_a }, KS_adiaeresis },
{ { KS_quotedbl, KS_e }, KS_ediaeresis },
{ { KS_quotedbl, KS_i }, KS_idiaeresis },
{ { KS_quotedbl, KS_o }, KS_odiaeresis },
{ { KS_quotedbl, KS_u }, KS_udiaeresis },
{ { KS_quotedbl, KS_y }, KS_ydiaeresis },
{ { KS_acute, KS_A }, KS_Aacute },
{ { KS_asciicircum, KS_A }, KS_Acircumflex },
{ { KS_grave, KS_A }, KS_Agrave },
{ { KS_asterisk, KS_A }, KS_Aring },
{ { KS_asciitilde, KS_A }, KS_Atilde },
{ { KS_cedilla, KS_C }, KS_Ccedilla },
{ { KS_acute, KS_E }, KS_Eacute },
{ { KS_asciicircum, KS_E }, KS_Ecircumflex },
{ { KS_grave, KS_E }, KS_Egrave },
{ { KS_acute, KS_I }, KS_Iacute },
{ { KS_asciicircum, KS_I }, KS_Icircumflex },
{ { KS_grave, KS_I }, KS_Igrave },
{ { KS_asciitilde, KS_N }, KS_Ntilde },
{ { KS_acute, KS_O }, KS_Oacute },
{ { KS_asciicircum, KS_O }, KS_Ocircumflex },
{ { KS_grave, KS_O }, KS_Ograve },
{ { KS_asciitilde, KS_O }, KS_Otilde },
{ { KS_acute, KS_U }, KS_Uacute },
{ { KS_asciicircum, KS_U }, KS_Ucircumflex },
{ { KS_grave, KS_U }, KS_Ugrave },
{ { KS_acute, KS_Y }, KS_Yacute },
{ { KS_acute, KS_a }, KS_aacute },
{ { KS_asciicircum, KS_a }, KS_acircumflex },
{ { KS_grave, KS_a }, KS_agrave },
{ { KS_asterisk, KS_a }, KS_aring },
{ { KS_asciitilde, KS_a }, KS_atilde },
{ { KS_cedilla, KS_c }, KS_ccedilla },
{ { KS_acute, KS_e }, KS_eacute },
{ { KS_asciicircum, KS_e }, KS_ecircumflex },
{ { KS_grave, KS_e }, KS_egrave },
{ { KS_acute, KS_i }, KS_iacute },
{ { KS_asciicircum, KS_i }, KS_icircumflex },
{ { KS_grave, KS_i }, KS_igrave },
{ { KS_asciitilde, KS_n }, KS_ntilde },
{ { KS_acute, KS_o }, KS_oacute },
{ { KS_asciicircum, KS_o }, KS_ocircumflex },
{ { KS_grave, KS_o }, KS_ograve },
{ { KS_asciitilde, KS_o }, KS_otilde },
{ { KS_acute, KS_u }, KS_uacute },
{ { KS_asciicircum, KS_u }, KS_ucircumflex },
{ { KS_grave, KS_u }, KS_ugrave },
{ { KS_acute, KS_y }, KS_yacute },
#ifndef __NetBSD__
{ { KS_dead_caron, KS_space }, KS_L2_caron },
{ { KS_dead_caron, KS_S }, KS_L2_Scaron },
{ { KS_dead_caron, KS_Z }, KS_L2_Zcaron },
{ { KS_dead_caron, KS_s }, KS_L2_scaron },
{ { KS_dead_caron, KS_z }, KS_L2_zcaron }
#endif
};
static keysym_t ksym_upcase(keysym_t ksym)
{
if (ksym >= KS_f1 && ksym <= KS_f20)
return(KS_F1 - KS_f1 + ksym);
if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff &&
latin1_to_upper[ksym] != 0x00)
return(latin1_to_upper[ksym]);
return(ksym);
}
static struct wscons_keycode_to_SDL {
keysym_t sourcekey;
SDL_Scancode targetKey;
} conversion_table[] = {
{KS_Menu, SDL_SCANCODE_APPLICATION},
{KS_Up, SDL_SCANCODE_UP},
{KS_Down, SDL_SCANCODE_DOWN},
{KS_Left, SDL_SCANCODE_LEFT},
{KS_Right, SDL_SCANCODE_RIGHT},
{KS_Hold_Screen, SDL_SCANCODE_SCROLLLOCK},
{KS_Num_Lock, SDL_SCANCODE_NUMLOCKCLEAR},
{KS_Caps_Lock, SDL_SCANCODE_CAPSLOCK},
{KS_BackSpace, SDL_SCANCODE_BACKSPACE},
{KS_Delete, SDL_SCANCODE_BACKSPACE},
{KS_Home, SDL_SCANCODE_HOME},
{KS_End, SDL_SCANCODE_END},
{KS_Pause, SDL_SCANCODE_PAUSE},
{KS_Print_Screen, SDL_SCANCODE_PRINTSCREEN},
{KS_Insert, SDL_SCANCODE_INSERT},
{KS_Escape, SDL_SCANCODE_ESCAPE},
{KS_Return, SDL_SCANCODE_RETURN},
{KS_Linefeed, SDL_SCANCODE_RETURN},
{KS_KP_Delete, SDL_SCANCODE_DELETE},
{KS_KP_Insert, SDL_SCANCODE_INSERT},
{KS_Control_L, SDL_SCANCODE_LCTRL},
{KS_Control_R, SDL_SCANCODE_RCTRL},
{KS_Shift_L, SDL_SCANCODE_LSHIFT},
{KS_Shift_R, SDL_SCANCODE_RSHIFT},
{KS_Alt_L, SDL_SCANCODE_LALT},
{KS_Alt_R, SDL_SCANCODE_RALT},
{KS_grave, SDL_SCANCODE_GRAVE},
{KS_KP_0, SDL_SCANCODE_KP_0},
{KS_KP_1, SDL_SCANCODE_KP_1},
{KS_KP_2, SDL_SCANCODE_KP_2},
{KS_KP_3, SDL_SCANCODE_KP_3},
{KS_KP_4, SDL_SCANCODE_KP_4},
{KS_KP_5, SDL_SCANCODE_KP_5},
{KS_KP_6, SDL_SCANCODE_KP_6},
{KS_KP_7, SDL_SCANCODE_KP_7},
{KS_KP_8, SDL_SCANCODE_KP_8},
{KS_KP_9, SDL_SCANCODE_KP_9},
{KS_KP_Enter, SDL_SCANCODE_KP_ENTER},
{KS_KP_Multiply, SDL_SCANCODE_KP_MULTIPLY},
{KS_KP_Add, SDL_SCANCODE_KP_PLUS},
{KS_KP_Subtract, SDL_SCANCODE_KP_MINUS},
{KS_KP_Divide, SDL_SCANCODE_KP_DIVIDE},
{KS_KP_Up, SDL_SCANCODE_UP},
{KS_KP_Down, SDL_SCANCODE_DOWN},
{KS_KP_Left, SDL_SCANCODE_LEFT},
{KS_KP_Right, SDL_SCANCODE_RIGHT},
{KS_KP_Equal, SDL_SCANCODE_KP_EQUALS},
{KS_f1, SDL_SCANCODE_F1},
{KS_f2, SDL_SCANCODE_F2},
{KS_f3, SDL_SCANCODE_F3},
{KS_f4, SDL_SCANCODE_F4},
{KS_f5, SDL_SCANCODE_F5},
{KS_f6, SDL_SCANCODE_F6},
{KS_f7, SDL_SCANCODE_F7},
{KS_f8, SDL_SCANCODE_F8},
{KS_f9, SDL_SCANCODE_F9},
{KS_f10, SDL_SCANCODE_F10},
{KS_f11, SDL_SCANCODE_F11},
{KS_f12, SDL_SCANCODE_F12},
{KS_f13, SDL_SCANCODE_F13},
{KS_f14, SDL_SCANCODE_F14},
{KS_f15, SDL_SCANCODE_F15},
{KS_f16, SDL_SCANCODE_F16},
{KS_f17, SDL_SCANCODE_F17},
{KS_f18, SDL_SCANCODE_F18},
{KS_f19, SDL_SCANCODE_F19},
{KS_f20, SDL_SCANCODE_F20},
#if !defined(__NetBSD__)
{KS_f21, SDL_SCANCODE_F21},
{KS_f22, SDL_SCANCODE_F22},
{KS_f23, SDL_SCANCODE_F23},
{KS_f24, SDL_SCANCODE_F24},
#endif
{KS_Meta_L, SDL_SCANCODE_LGUI},
{KS_Meta_R, SDL_SCANCODE_RGUI},
{KS_Zenkaku_Hankaku, SDL_SCANCODE_LANG5},
{KS_Hiragana_Katakana, SDL_SCANCODE_INTERNATIONAL2},
{KS_yen, SDL_SCANCODE_INTERNATIONAL3},
{KS_Henkan, SDL_SCANCODE_INTERNATIONAL4},
{KS_Muhenkan, SDL_SCANCODE_INTERNATIONAL5},
{KS_KP_Prior, SDL_SCANCODE_PRIOR},
{KS_a, SDL_SCANCODE_A},
{KS_b, SDL_SCANCODE_B},
{KS_c, SDL_SCANCODE_C},
{KS_d, SDL_SCANCODE_D},
{KS_e, SDL_SCANCODE_E},
{KS_f, SDL_SCANCODE_F},
{KS_g, SDL_SCANCODE_G},
{KS_h, SDL_SCANCODE_H},
{KS_i, SDL_SCANCODE_I},
{KS_j, SDL_SCANCODE_J},
{KS_k, SDL_SCANCODE_K},
{KS_l, SDL_SCANCODE_L},
{KS_m, SDL_SCANCODE_M},
{KS_n, SDL_SCANCODE_N},
{KS_o, SDL_SCANCODE_O},
{KS_p, SDL_SCANCODE_P},
{KS_q, SDL_SCANCODE_Q},
{KS_r, SDL_SCANCODE_R},
{KS_s, SDL_SCANCODE_S},
{KS_t, SDL_SCANCODE_T},
{KS_u, SDL_SCANCODE_U},
{KS_v, SDL_SCANCODE_V},
{KS_w, SDL_SCANCODE_W},
{KS_x, SDL_SCANCODE_X},
{KS_y, SDL_SCANCODE_Y},
{KS_z, SDL_SCANCODE_Z},
{KS_0, SDL_SCANCODE_0},
{KS_1, SDL_SCANCODE_1},
{KS_2, SDL_SCANCODE_2},
{KS_3, SDL_SCANCODE_3},
{KS_4, SDL_SCANCODE_4},
{KS_5, SDL_SCANCODE_5},
{KS_6, SDL_SCANCODE_6},
{KS_7, SDL_SCANCODE_7},
{KS_8, SDL_SCANCODE_8},
{KS_9, SDL_SCANCODE_9},
{KS_minus, SDL_SCANCODE_MINUS},
{KS_equal, SDL_SCANCODE_EQUALS},
{KS_Tab, SDL_SCANCODE_TAB},
{KS_KP_Tab, SDL_SCANCODE_KP_TAB},
{KS_apostrophe, SDL_SCANCODE_APOSTROPHE},
{KS_bracketleft, SDL_SCANCODE_LEFTBRACKET},
{KS_bracketright, SDL_SCANCODE_RIGHTBRACKET},
{KS_semicolon, SDL_SCANCODE_SEMICOLON},
{KS_comma, SDL_SCANCODE_COMMA},
{KS_period, SDL_SCANCODE_PERIOD},
{KS_slash, SDL_SCANCODE_SLASH},
{KS_backslash, SDL_SCANCODE_BACKSLASH}
};
typedef struct {
int fd;
struct wskbd_map_data keymap;
int ledstate;
int origledstate;
int shiftstate[4];
int shiftheldstate[8];
int lockheldstate[5];
kbd_t encoding;
char text[128];
unsigned int text_len;
keysym_t composebuffer[2];
unsigned char composelen;
} SDL_WSCONS_input_data;
static SDL_WSCONS_input_data* inputs[4] = {NULL, NULL, NULL, NULL};
static SDL_WSCONS_mouse_input_data* mouseInputData = NULL;
#define IS_CONTROL_HELD (input->shiftstate[2] > 0)
#define IS_ALT_HELD (input->shiftstate[1] > 0)
#define IS_SHIFT_HELD ((input->shiftstate[0] > 0) || (input->ledstate & (1 << 5)))
#define IS_ALTGR_MODE ((input->ledstate & (1 << 4)) || (input->shiftstate[3] > 0))
#define IS_NUMLOCK_ON (input->ledstate & LED_NUM)
#define IS_SCROLLLOCK_ON (input->ledstate & LED_SCR)
#define IS_CAPSLOCK_ON (input->ledstate & LED_CAP)
static SDL_WSCONS_input_data* SDL_WSCONS_Init_Keyboard(const char* dev)
{
#ifdef WSKBDIO_SETVERSION
int version = WSKBDIO_EVENT_VERSION;
#endif
SDL_WSCONS_input_data* input = (SDL_WSCONS_input_data*)SDL_calloc(1, sizeof(SDL_WSCONS_input_data));
if (!input) {
return input;
}
input->fd = open(dev,O_RDWR | O_NONBLOCK);
if (input->fd == -1) {
free(input);
input = NULL;
return NULL;
}
input->keymap.map = SDL_calloc(sizeof(struct wscons_keymap), KS_NUMKEYCODES);
if (input->keymap.map == NULL) {
free(input);
return NULL;
}
input->keymap.maplen = KS_NUMKEYCODES;
RETIFIOCTLERR(ioctl(input->fd, WSKBDIO_GETMAP, &input->keymap));
RETIFIOCTLERR(ioctl(input->fd, WSKBDIO_GETLEDS, &input->ledstate));
input->origledstate = input->ledstate;
RETIFIOCTLERR(ioctl(input->fd, WSKBDIO_GETENCODING, &input->encoding));
#ifdef WSKBDIO_SETVERSION
RETIFIOCTLERR(ioctl(input->fd, WSKBDIO_SETVERSION, &version));
#endif
return input;
}
void SDL_WSCONS_Init()
{
inputs[0] = SDL_WSCONS_Init_Keyboard("/dev/wskbd0");
inputs[1] = SDL_WSCONS_Init_Keyboard("/dev/wskbd1");
inputs[2] = SDL_WSCONS_Init_Keyboard("/dev/wskbd2");
inputs[3] = SDL_WSCONS_Init_Keyboard("/dev/wskbd3");
mouseInputData = SDL_WSCONS_Init_Mouse();
return;
}
void SDL_WSCONS_Quit()
{
int i = 0;
SDL_WSCONS_input_data* input = NULL;
SDL_WSCONS_Quit_Mouse(mouseInputData);
mouseInputData = NULL;
for (i = 0; i < 4; i++) {
input = inputs[i];
if (input) {
if (input->fd != -1 && input->fd != 0) {
ioctl(input->fd,WSKBDIO_SETLEDS, &input->origledstate);
close(input->fd);
input->fd = -1;
}
free(input);
input = NULL;
}
inputs[i] = NULL;
}
}
static void put_queue(SDL_WSCONS_input_data *kbd, uint c)
{
/* c is already part of a UTF-8 sequence and safe to add as a character */
if (kbd->text_len < (sizeof(kbd->text)-1)) {
kbd->text[kbd->text_len++] = (char)(c);
}
}
static void put_utf8(SDL_WSCONS_input_data* input, uint c)
{
if (c < 0x80)
/* 0******* */
put_queue(input, c);
else if (c < 0x800) {
/* 110***** 10****** */
put_queue(input, 0xc0 | (c >> 6));
put_queue(input, 0x80 | (c & 0x3f));
} else if (c < 0x10000) {
if (c >= 0xD800 && c <= 0xF500)
return;
if (c == 0xFFFF)
return;
/* 1110**** 10****** 10****** */
put_queue(input, 0xe0 | (c >> 12));
put_queue(input, 0x80 | ((c >> 6) & 0x3f));
put_queue(input, 0x80 | (c & 0x3f));
} else if (c < 0x110000) {
/* 11110*** 10****** 10****** 10****** */
put_queue(input, 0xf0 | (c >> 18));
put_queue(input, 0x80 | ((c >> 12) & 0x3f));
put_queue(input, 0x80 | ((c >> 6) & 0x3f));
put_queue(input, 0x80 | (c & 0x3f));
}
}
static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym)
{
if (KS_GROUP(ksym) == KS_GROUP_Keypad) {
if (isprint(ksym & 0xFF)) ksym &= 0xFF;
}
switch(ksym) {
case KS_Escape:
case KS_Delete:
case KS_BackSpace:
case KS_Return:
case KS_Linefeed:
/* All of these are unprintable characters. Ignore them */
break;
default:
put_utf8(input, ksym);
break;
}
if (input->text_len > 0) {
input->text[input->text_len] = '\0';
SDL_SendKeyboardText(input->text);
/*memset(input->text, 0, sizeof(input->text));*/
input->text_len = 0;
input->text[0] = 0;
}
}
static void Translate_to_keycode(SDL_WSCONS_input_data* input, int type, keysym_t ksym)
{
struct wscons_keymap keyDesc = input->keymap.map[ksym];
keysym_t* group = &keyDesc.group1[KS_GROUP(keyDesc.group1[0]) == KS_GROUP_Keypad && IS_NUMLOCK_ON ? !IS_SHIFT_HELD : 0];
int i = 0;
/* Check command first, then group[0]*/
switch (keyDesc.command) {
case KS_Cmd_ScrollBack: {
SDL_SendKeyboardKey(type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_PAGEUP);
return;
}
case KS_Cmd_ScrollFwd: {
SDL_SendKeyboardKey(type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_PAGEDOWN);
return;
}
}
for (i = 0; i < sizeof(conversion_table) / sizeof(struct wscons_keycode_to_SDL); i++) {
if (conversion_table[i].sourcekey == group[0]) {
SDL_SendKeyboardKey(type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, conversion_table[i].targetKey);
return;
}
}
SDL_SendKeyboardKey(type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_UNKNOWN);
}
static void updateKeyboard(SDL_WSCONS_input_data* input)
{
struct wscons_event events[64];
int type;
int n,i,gindex,acc_i;
keysym_t *group;
keysym_t ksym, result;
if (!input) return;
if ((n = read(input->fd, events, sizeof(events))) > 0) {
n /= sizeof(struct wscons_event);
for (i = 0; i < n; i++) {
type = events[i].type;
switch(type) {
case WSCONS_EVENT_KEY_DOWN: {
switch (input->keymap.map[events[i].value].group1[0]) {
case KS_Hold_Screen: {
if (input->lockheldstate[0] >= 1) break;
input->ledstate ^= LED_SCR;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[0] = 1;
break;
}
case KS_Num_Lock: {
if (input->lockheldstate[1] >= 1) break;
input->ledstate ^= LED_NUM;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[1] = 1;
break;
}
case KS_Caps_Lock: {
if (input->lockheldstate[2] >= 1) break;
input->ledstate ^= LED_CAP;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[2] = 1;
break;
}
#ifndef __NetBSD__
case KS_Mode_Lock: {
if (input->lockheldstate[3] >= 1) break;
input->ledstate ^= 1 << 4;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[3] = 1;
break;
}
#endif
case KS_Shift_Lock: {
if (input->lockheldstate[4] >= 1) break;
input->ledstate ^= 1 << 5;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[4] = 1;
break;
}
case KS_Shift_L: {
if (input->shiftheldstate[0]) break;
input->shiftstate[0]++;
input->shiftheldstate[0] = 1;
break;
}
case KS_Shift_R: {
if (input->shiftheldstate[1]) break;
input->shiftstate[0]++;
input->shiftheldstate[1] = 1;
break;
}
case KS_Alt_L: {
if (input->shiftheldstate[2]) break;
input->shiftstate[1]++;
input->shiftheldstate[2] = 1;
break;
}
case KS_Alt_R: {
if (input->shiftheldstate[3]) break;
input->shiftstate[1]++;
input->shiftheldstate[3] = 1;
break;
}
case KS_Control_L: {
if (input->shiftheldstate[4]) break;
input->shiftstate[2]++;
input->shiftheldstate[4] = 1;
break;
}
case KS_Control_R: {
if (input->shiftheldstate[5]) break;
input->shiftstate[2]++;
input->shiftheldstate[5] = 1;
break;
}
case KS_Mode_switch: {
if (input->shiftheldstate[6]) break;
input->shiftstate[3]++;
input->shiftheldstate[6] = 1;
break;
}
}
}
break;
case WSCONS_EVENT_KEY_UP: {
switch(input->keymap.map[events[i].value].group1[0]) {
case KS_Hold_Screen: {
if (input->lockheldstate[0]) input->lockheldstate[0] = 0;
}
break;
case KS_Num_Lock: {
if (input->lockheldstate[1]) input->lockheldstate[1] = 0;
}
break;
case KS_Caps_Lock: {
if (input->lockheldstate[2]) input->lockheldstate[2] = 0;
}
break;
#ifndef __NetBSD__
case KS_Mode_Lock: {
if (input->lockheldstate[3]) input->lockheldstate[3] = 0;
}
break;
#endif
case KS_Shift_Lock: {
if (input->lockheldstate[4]) input->lockheldstate[4] = 0;
}
break;
case KS_Shift_L: {
input->shiftheldstate[0] = 0;
if (input->shiftstate[0]) input->shiftstate[0]--;
break;
}
case KS_Shift_R: {
input->shiftheldstate[1] = 0;
if (input->shiftstate[0]) input->shiftstate[0]--;
break;
}
case KS_Alt_L: {
input->shiftheldstate[2] = 0;
if (input->shiftstate[1]) input->shiftstate[1]--;
break;
}
case KS_Alt_R: {
input->shiftheldstate[3] = 0;
if (input->shiftstate[1]) input->shiftstate[1]--;
break;
}
case KS_Control_L: {
input->shiftheldstate[4] = 0;
if (input->shiftstate[2]) input->shiftstate[2]--;
break;
}
case KS_Control_R: {
input->shiftheldstate[5] = 0;
if (input->shiftstate[2]) input->shiftstate[2]--;
break;
}
case KS_Mode_switch: {
input->shiftheldstate[6] = 0;
if (input->shiftstate[3]) input->shiftstate[3]--;
break;
}
}
}
break;
case WSCONS_EVENT_ALL_KEYS_UP:
for (i = 0; i < SDL_NUM_SCANCODES; i++) {
SDL_SendKeyboardKey(SDL_RELEASED, i);
}
break;
}
Translate_to_keycode(input, type, events[i].value);
if (type == WSCONS_EVENT_KEY_UP) continue;
if (IS_ALTGR_MODE && !IS_CONTROL_HELD)
group = &input->keymap.map[events[i].value].group2[0];
else
group = &input->keymap.map[events[i].value].group1[0];
if (IS_NUMLOCK_ON && KS_GROUP(group[1]) == KS_GROUP_Keypad) {
gindex = !IS_SHIFT_HELD;
ksym = group[gindex];
} else {
if (IS_CAPSLOCK_ON && !IS_SHIFT_HELD) {
gindex = 0;
ksym = ksym_upcase(group[0]);
} else {
gindex = IS_SHIFT_HELD;
ksym = group[gindex];
}
}
result = KS_voidSymbol;
switch (KS_GROUP(ksym)) {
case KS_GROUP_Ascii:
case KS_GROUP_Keypad:
case KS_GROUP_Function:
result = ksym;
break;
case KS_GROUP_Mod:
if (ksym == KS_Multi_key) {
input->ledstate |= WSKBD_LED_COMPOSE;
ioctl(input->fd,WSKBDIO_SETLEDS, &input->ledstate);
input->composelen = 2;
input->composebuffer[0] = input->composebuffer[1] = 0;
}
break;
case KS_GROUP_Dead:
if (input->composelen == 0) {
input->ledstate |= WSKBD_LED_COMPOSE;
ioctl(input->fd,WSKBDIO_SETLEDS, &input->ledstate);
input->composelen = 1;
input->composebuffer[0] = ksym;
input->composebuffer[1] = 0;
} else result = ksym;
break;
}
if (result == KS_voidSymbol) continue;
if (input->composelen > 0) {
if (input->composelen == 2 && group == &input->keymap.map[events[i].value].group2[0]) {
if (input->keymap.map[events[i].value].group2[gindex] == input->keymap.map[events[i].value].group1[gindex]) {
input->composelen = 0;
input->composebuffer[0] = input->composebuffer[1] = 0;
}
}
if (input->composelen != 0) {
input->composebuffer[2 - input->composelen] = result;
if (--input->composelen == 0) {
result = KS_voidSymbol;
input->ledstate &= ~WSKBD_LED_COMPOSE;
ioctl(input->fd,WSKBDIO_SETLEDS, &input->ledstate);
for (acc_i = 0; acc_i < SDL_arraysize(compose_tab); acc_i++) {
if ((compose_tab[acc_i].elem[0] == input->composebuffer[0]
&& compose_tab[acc_i].elem[1] == input->composebuffer[1])
|| (compose_tab[acc_i].elem[0] == input->composebuffer[1]
&& compose_tab[acc_i].elem[1] == input->composebuffer[0])) {
result = compose_tab[acc_i].result;
break;
}
}
} else continue;
}
}
if (KS_GROUP(result) == KS_GROUP_Ascii) {
if (IS_CONTROL_HELD) {
if ((result >= KS_at && result <= KS_z) || result == KS_space)
result = result & 0x1f;
else if (result == KS_2)
result = 0x00;
else if (result >= KS_3 && result <= KS_7)
result = KS_Escape + (result - KS_3);
else if (result == KS_8)
result = KS_Delete;
}
if (IS_ALT_HELD) {
if (input->encoding & KB_METAESC) {
Translate_to_keycode(input, WSCONS_EVENT_KEY_DOWN, KS_Escape);
Translate_to_text(input, result);
continue;
} else result |= 0x80;
}
}
Translate_to_text(input,result);
continue;
}
}
}
void SDL_WSCONS_PumpEvents()
{
int i = 0;
for (i = 0; i < 4; i++)
updateKeyboard(inputs[i]);
if (mouseInputData != NULL) updateMouse(mouseInputData);
}

View File

@@ -0,0 +1,134 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_events.h"
#include <sys/time.h>
#include <dev/wscons/wsconsio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <fcntl.h>
#include "../../events/SDL_mouse_c.h"
typedef struct SDL_WSCONS_mouse_input_data
{
int fd;
} SDL_WSCONS_mouse_input_data;
SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse()
{
#ifdef WSMOUSEIO_SETVERSION
int version = WSMOUSE_EVENT_VERSION;
#endif
SDL_WSCONS_mouse_input_data* mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data));
if (!mouseInputData) return NULL;
mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK);
if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; }
#ifdef WSMOUSEIO_SETMODE
ioctl(mouseInputData->fd, WSMOUSEIO_SETMODE, WSMOUSE_COMPAT);
#endif
#ifdef WSMOUSEIO_SETVERSION
ioctl(mouseInputData->fd, WSMOUSEIO_SETVERSION, &version);
#endif
return mouseInputData;
}
void updateMouse(SDL_WSCONS_mouse_input_data* inputData)
{
struct wscons_event events[64];
int type;
int n,i;
SDL_Mouse* mouse = SDL_GetMouse();
if ((n = read(inputData->fd, events, sizeof(events))) > 0)
{
n /= sizeof(struct wscons_event);
for (i = 0; i < n; i++)
{
type = events[i].type;
switch(type)
{
case WSCONS_EVENT_MOUSE_DOWN:
{
switch (events[i].value)
{
case 0: /* Left Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_LEFT);
break;
case 1: /* Middle Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_MIDDLE);
break;
case 2: /* Right Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_RIGHT);
break;
}
}
break;
case WSCONS_EVENT_MOUSE_UP:
{
switch (events[i].value)
{
case 0: /* Left Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_LEFT);
break;
case 1: /* Middle Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_MIDDLE);
break;
case 2: /* Right Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_RIGHT);
break;
}
}
break;
case WSCONS_EVENT_MOUSE_DELTA_X:
{
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, events[i].value * 2, 0);
break;
}
case WSCONS_EVENT_MOUSE_DELTA_Y:
{
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, 0, -events[i].value * 2);
break;
}
case WSCONS_EVENT_MOUSE_DELTA_W:
{
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL);
break;
}
case WSCONS_EVENT_MOUSE_DELTA_Z:
{
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, -events[i].value, SDL_MOUSEWHEEL_NORMAL);
break;
}
}
}
}
}
void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data* inputData)
{
if (!inputData) return;
close(inputData->fd);
free(inputData);
}

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -48,7 +48,7 @@ WIN_LoadHIDDLL(void)
return 0; /* already loaded */
}
s_pHIDDLL = LoadLibrary(L"hid.dll");
s_pHIDDLL = LoadLibrary(TEXT("hid.dll"));
if (!s_pHIDDLL) {
return -1;
}

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -33,6 +33,9 @@
#ifndef _WIN32_WINNT_WIN7
#define _WIN32_WINNT_WIN7 0x0601
#endif
#ifndef _WIN32_WINNT_WIN8
#define _WIN32_WINNT_WIN8 0x0602
#endif
/* Sets an error message based on an HRESULT */
@@ -135,6 +138,15 @@ BOOL WIN_IsWindows7OrGreater(void)
#endif
}
BOOL WIN_IsWindows8OrGreater(void)
{
#ifdef __WINRT__
return TRUE;
#else
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN8), LOBYTE(_WIN32_WINNT_WIN8), 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

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -38,13 +38,21 @@
#include <basetyps.h> /* for REFIID with broken mingw.org headers */
/* 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
#define WIN_StringToUTF8W(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR))
#define WIN_UTF8ToStringW(S) (WCHAR *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1)
/* !!! 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)
#define WIN_StringToUTF8A(S) SDL_iconv_string("UTF-8", "ASCII", (char *)(S), (SDL_strlen(S)+1))
#define WIN_UTF8ToStringA(S) SDL_iconv_string("ASCII", "UTF-8", (char *)(S), SDL_strlen(S)+1)
#if UNICODE
#define WIN_StringToUTF8 WIN_StringToUTF8W
#define WIN_UTF8ToString WIN_UTF8ToStringW
#define SDL_tcslen SDL_wcslen
#define SDL_tcsstr SDL_wcsstr
#else
#define WIN_StringToUTF8 WIN_StringToUTF8A
#define WIN_UTF8ToString WIN_UTF8ToStringA
#define SDL_tcslen SDL_strlen
#define SDL_tcsstr SDL_strstr
#endif
/* Sets an error message based on a given HRESULT */
@@ -63,6 +71,9 @@ extern BOOL WIN_IsWindowsVistaOrGreater(void);
/* Returns SDL_TRUE if we're running on Windows 7 and newer */
extern BOOL WIN_IsWindows7OrGreater(void);
/* Returns SDL_TRUE if we're running on Windows 8 and newer */
extern BOOL WIN_IsWindows8OrGreater(void);
/* You need to SDL_free() the result of this call. */
extern char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid);

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -86,17 +86,17 @@ WIN_LoadXInputDLL(void)
* limitations of that API (no devices at startup, no background input, etc.)
*/
version = (1 << 16) | 4;
s_pXInputDLL = LoadLibrary(L"XInput1_4.dll"); /* 1.4 Ships with Windows 8. */
s_pXInputDLL = LoadLibrary(TEXT("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. */
s_pXInputDLL = LoadLibrary(TEXT("XInput1_3.dll")); /* 1.3 can be installed as a redistributable component. */
}
if (!s_pXInputDLL) {
s_pXInputDLL = LoadLibrary(L"bin\\XInput1_3.dll");
s_pXInputDLL = LoadLibrary(TEXT("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");
s_pXInputDLL = LoadLibrary(TEXT("XInput9_1_0.dll"));
}
if (!s_pXInputDLL) {
return -1;

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages