Pass the OS event timestamp for keyboard, mouse, and touch events where possible

Currently implemented for Windows and Apple platforms
This commit is contained in:
Sam Lantinga
2022-12-02 09:03:13 -08:00
parent 1f4cc733a1
commit 0a3262e819
62 changed files with 441 additions and 313 deletions
+1 -1
View File
@@ -35,4 +35,4 @@ General:
* SDL_GetTicks() now returns a 64-bit value and the tick values should be directly compared instead of using the SDL_TICKS_PASSED macro
* Added SDL_GetTicksNS() to return the number of nanoseconds since the SDL library initialized
* Added SDL_DelayNS() to specify a delay in nanoseconds, to the highest precision the system will support
* The timestamp member of the SDL_Event structure is now in nanoseconds, filled in with SDL_GetTicksNS()
* The timestamp member of the SDL_Event structure is now in nanoseconds, filled in with the time the event was generated, or the time it was queued if that's not available
+3
View File
@@ -35,6 +35,9 @@ The SDL3main and SDL3test libraries have been renamed SDL3_main and SDL3_test, r
The `timestamp` member of the SDL_Event structure now represents nanoseconds, and is populated with `SDL_GetTicksNS()`
You should set the `event.common.timestamp` field before passing an event to `SDL_PushEvent()`. If the timestamp is 0 it will be filled in with `SDL_GetTicksNS()`.
## SDL_platform.h
The preprocessor symbol __MACOSX__ has been renamed __MACOS__, and __IPHONEOS__ has been renamed __IOS__
+6 -6
View File
@@ -414,8 +414,8 @@ void SDL_AddAudioDevice(const SDL_bool iscapture, const char *name, SDL_AudioSpe
/* Post the event, if desired */
if (SDL_GetEventState(SDL_AUDIODEVICEADDED) == SDL_ENABLE) {
SDL_Event event;
SDL_zero(event);
event.adevice.type = SDL_AUDIODEVICEADDED;
event.type = SDL_AUDIODEVICEADDED;
event.common.timestamp = 0;
event.adevice.which = device_index;
event.adevice.iscapture = iscapture;
SDL_PushEvent(&event);
@@ -445,8 +445,8 @@ void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
/* Post the event, if desired */
if (SDL_GetEventState(SDL_AUDIODEVICEREMOVED) == SDL_ENABLE) {
SDL_Event event;
SDL_zero(event);
event.adevice.type = SDL_AUDIODEVICEREMOVED;
event.type = SDL_AUDIODEVICEREMOVED;
event.common.timestamp = 0;
event.adevice.which = device->id;
event.adevice.iscapture = device->iscapture ? 1 : 0;
SDL_PushEvent(&event);
@@ -497,8 +497,8 @@ void SDL_RemoveAudioDevice(const SDL_bool iscapture, void *handle)
if (!device_was_opened) {
if (SDL_GetEventState(SDL_AUDIODEVICEREMOVED) == SDL_ENABLE) {
SDL_Event event;
SDL_zero(event);
event.adevice.type = SDL_AUDIODEVICEREMOVED;
event.type = SDL_AUDIODEVICEREMOVED;
event.common.timestamp = 0;
event.adevice.which = 0;
event.adevice.iscapture = iscapture ? 1 : 0;
SDL_PushEvent(&event);
+1 -1
View File
@@ -1257,7 +1257,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeGenerateScancod
JNIEnv *env, jclass cls,
jchar chUnicode)
{
SDL_SendKeyboardUnicodeKey(chUnicode);
SDL_SendKeyboardUnicodeKey(0, chUnicode);
}
JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
+9 -9
View File
@@ -302,9 +302,9 @@ void SDL_EVDEV_Poll(void)
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, (SDL_MouseID)item->fd, SDL_RELEASED, EVDEV_MouseButtons[mouse_button]);
SDL_SendMouseButton(0, mouse->focus, (SDL_MouseID)item->fd, SDL_RELEASED, EVDEV_MouseButtons[mouse_button]);
} else if (events[i].value == 1) {
SDL_SendMouseButton(mouse->focus, (SDL_MouseID)item->fd, SDL_PRESSED, EVDEV_MouseButtons[mouse_button]);
SDL_SendMouseButton(0, mouse->focus, (SDL_MouseID)item->fd, SDL_PRESSED, EVDEV_MouseButtons[mouse_button]);
}
break;
}
@@ -328,9 +328,9 @@ void SDL_EVDEV_Poll(void)
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);
SDL_SendKeyboardKey(0, SDL_RELEASED, scan_code);
} else if (events[i].value == 1 || events[i].value == 2 /* key repeated */) {
SDL_SendKeyboardKey(SDL_PRESSED, scan_code);
SDL_SendKeyboardKey(0, SDL_PRESSED, scan_code);
}
}
SDL_EVDEV_kbd_keycode(_this->kbd, events[i].code, events[i].value);
@@ -446,11 +446,11 @@ void SDL_EVDEV_Poll(void)
case SYN_REPORT:
/* Send mouse axis changes together to ensure consistency and reduce event processing overhead */
if (item->mouse_x != 0 || item->mouse_y != 0) {
SDL_SendMouseMotion(mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse, item->mouse_x, item->mouse_y);
SDL_SendMouseMotion(0, mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse, item->mouse_x, item->mouse_y);
item->mouse_x = item->mouse_y = 0;
}
if (item->mouse_wheel != 0 || item->mouse_hwheel != 0) {
SDL_SendMouseWheel(mouse->focus, (SDL_MouseID)item->fd,
SDL_SendMouseWheel(0, mouse->focus, (SDL_MouseID)item->fd,
item->mouse_hwheel / (item->high_res_hwheel ? 120.0f : 1.0f),
item->mouse_wheel / (item->high_res_wheel ? 120.0f : 1.0f),
SDL_MOUSEWHEEL_NORMAL);
@@ -480,16 +480,16 @@ void SDL_EVDEV_Poll(void)
* be window-relative in that case. */
switch (item->touchscreen_data->slots[j].delta) {
case EVDEV_TOUCH_SLOTDELTA_DOWN:
SDL_SendTouch(item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_TRUE, norm_x, norm_y, norm_pressure);
SDL_SendTouch(0, item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_TRUE, norm_x, norm_y, norm_pressure);
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, NULL, SDL_FALSE, norm_x, norm_y, norm_pressure);
SDL_SendTouch(0, item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_FALSE, norm_x, norm_y, norm_pressure);
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, NULL, norm_x, norm_y, norm_pressure);
SDL_SendTouchMotion(0, item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, norm_x, norm_y, norm_pressure);
item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
break;
default:
+6 -6
View File
@@ -553,22 +553,22 @@ static void Translate_to_keycode(SDL_WSCONS_input_data *input, int type, keysym_
switch (keyDesc.command) {
case KS_Cmd_ScrollBack:
{
SDL_SendKeyboardKey(type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_PAGEUP);
SDL_SendKeyboardKey(0, 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);
SDL_SendKeyboardKey(0, 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);
SDL_SendKeyboardKey(0, 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);
SDL_SendKeyboardKey(0, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_UNKNOWN);
}
static void updateKeyboard(SDL_WSCONS_input_data *input)
@@ -802,13 +802,13 @@ static void updateKeyboard(SDL_WSCONS_input_data *input)
} break;
case WSCONS_EVENT_ALL_KEYS_UP:
for (i = 0; i < SDL_NUM_SCANCODES; i++) {
SDL_SendKeyboardKey(SDL_RELEASED, i);
SDL_SendKeyboardKey(0, SDL_RELEASED, i);
}
break;
}
if (input->type == WSKBD_TYPE_USB && events[i].value <= 0xE7)
SDL_SendKeyboardKey(type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)events[i].value);
SDL_SendKeyboardKey(0, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)events[i].value);
else
Translate_to_keycode(input, type, events[i].value);
+10 -10
View File
@@ -74,13 +74,13 @@ void updateMouse(SDL_WSCONS_mouse_input_data *inputData)
{
switch (events[i].value) {
case 0: /* Left Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(0, 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);
SDL_SendMouseButton(0, 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);
SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_RIGHT);
break;
}
} break;
@@ -88,34 +88,34 @@ void updateMouse(SDL_WSCONS_mouse_input_data *inputData)
{
switch (events[i].value) {
case 0: /* Left Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(0, 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);
SDL_SendMouseButton(0, 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);
SDL_SendMouseButton(0, 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, 0);
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 1, events[i].value, 0);
break;
}
case WSCONS_EVENT_MOUSE_DELTA_Y:
{
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, 0, -events[i].value);
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 1, 0, -events[i].value);
break;
}
case WSCONS_EVENT_MOUSE_DELTA_W:
{
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL);
SDL_SendMouseWheel(0, 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);
SDL_SendMouseWheel(0, mouse->focus, mouse->mouseID, 0, -events[i].value, SDL_MOUSEWHEEL_NORMAL);
break;
}
}
+3 -3
View File
@@ -552,7 +552,7 @@ void SDL_WinRTApp::OnWindowActivated(CoreWindow ^ sender, WindowActivatedEventAr
*/
#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);
SDL_SendMouseMotion(0, 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) */
@@ -743,8 +743,8 @@ void SDL_WinRTApp::OnCharacterReceived(Windows::UI::Core::CoreWindow ^ sender, W
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);
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_AC_BACK);
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_AC_BACK);
if (SDL_GetHintBoolean(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_FALSE)) {
args->Handled = true;
+1 -1
View File
@@ -34,7 +34,7 @@ int SDL_SendClipboardUpdate(void)
if (SDL_GetEventState(SDL_CLIPBOARDUPDATE) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_CLIPBOARDUPDATE;
event.common.timestamp = 0;
posted = (SDL_PushEvent(&event) > 0);
}
return posted;
+1
View File
@@ -45,6 +45,7 @@ int SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data
if (SDL_GetEventState(SDL_DISPLAYEVENT) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_DISPLAYEVENT;
event.common.timestamp = 0;
event.display.event = displayevent;
event.display.display = SDL_GetIndexOfDisplay(display);
event.display.data1 = data1;
+3 -5
View File
@@ -40,11 +40,8 @@ static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const ch
if (need_begin) {
SDL_zero(event);
event.type = SDL_DROPBEGIN;
if (window) {
event.drop.windowID = window->id;
}
event.common.timestamp = 0;
event.drop.windowID = window ? window->id : 0;
posted = (SDL_PushEvent(&event) > 0);
if (!posted) {
return 0;
@@ -58,6 +55,7 @@ static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const ch
SDL_zero(event);
event.type = evtype;
event.common.timestamp = 0;
event.drop.file = data ? SDL_strdup(data) : NULL;
event.drop.windowID = window ? window->id : 0;
posted = (SDL_PushEvent(&event) > 0);
+6 -2
View File
@@ -948,8 +948,8 @@ static void SDL_PumpEventsInternal(SDL_bool push_sentinel)
if (push_sentinel && SDL_GetEventState(SDL_POLLSENTINEL) == SDL_ENABLE) {
SDL_Event sentinel;
SDL_zero(sentinel);
sentinel.type = SDL_POLLSENTINEL;
sentinel.common.timestamp = 0;
SDL_PushEvent(&sentinel);
}
}
@@ -1192,7 +1192,9 @@ int SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS)
int SDL_PushEvent(SDL_Event *event)
{
event->common.timestamp = SDL_GetTicksNS();
if (!event->common.timestamp) {
event->common.timestamp = SDL_GetTicksNS();
}
if (SDL_EventOK.callback || SDL_event_watchers_count > 0) {
if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
@@ -1414,6 +1416,7 @@ int SDL_SendAppEvent(SDL_EventType eventType)
if (SDL_GetEventState(eventType) == SDL_ENABLE) {
SDL_Event event;
event.type = eventType;
event.common.timestamp = 0;
posted = (SDL_PushEvent(&event) > 0);
}
return posted;
@@ -1428,6 +1431,7 @@ int SDL_SendSysWMEvent(SDL_SysWMmsg *message)
SDL_Event event;
SDL_memset(&event, 0, sizeof(event));
event.type = SDL_SYSWMEVENT;
event.common.timestamp = 0;
event.syswm.msg = message;
posted = (SDL_PushEvent(&event) > 0);
}
+6 -3
View File
@@ -525,7 +525,8 @@ static void SDL_SendGestureMulti(SDL_GestureTouch *touch, float dTheta, float dD
{
if (SDL_GetEventState(SDL_MULTIGESTURE) == SDL_ENABLE) {
SDL_Event event;
event.mgesture.type = SDL_MULTIGESTURE;
event.type = SDL_MULTIGESTURE;
event.common.timestamp = 0;
event.mgesture.touchId = touch->id;
event.mgesture.x = touch->centroid.x;
event.mgesture.y = touch->centroid.y;
@@ -542,7 +543,8 @@ static void SDL_SendGestureDollar(SDL_GestureTouch *touch,
{
if (SDL_GetEventState(SDL_DOLLARGESTURE) == SDL_ENABLE) {
SDL_Event event;
event.dgesture.type = SDL_DOLLARGESTURE;
event.type = SDL_DOLLARGESTURE;
event.common.timestamp = 0;
event.dgesture.touchId = touch->id;
event.dgesture.x = touch->centroid.x;
event.dgesture.y = touch->centroid.y;
@@ -558,7 +560,8 @@ static void SDL_SendDollarRecord(SDL_GestureTouch *touch, SDL_GestureID gestureI
{
if (SDL_GetEventState(SDL_DOLLARRECORD) == SDL_ENABLE) {
SDL_Event event;
event.dgesture.type = SDL_DOLLARRECORD;
event.type = SDL_DOLLARRECORD;
event.common.timestamp = 0;
event.dgesture.touchId = touch->id;
event.dgesture.gestureId = gestureId;
SDL_PushEvent(&event);
+22 -18
View File
@@ -681,7 +681,7 @@ void SDL_ResetKeyboard(void)
#endif
for (scancode = (SDL_Scancode)0; scancode < SDL_NUM_SCANCODES; ++scancode) {
if (keyboard->keystate[scancode] == SDL_PRESSED) {
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
SDL_SendKeyboardKey(0, SDL_RELEASED, scancode);
}
}
}
@@ -789,7 +789,7 @@ void SDL_SetKeyboardFocus(SDL_Window *window)
}
}
static int SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint8 source, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
{
SDL_Keyboard *keyboard = &SDL_keyboard;
int posted;
@@ -903,7 +903,8 @@ static int SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode s
posted = 0;
if (SDL_GetEventState(type) == SDL_ENABLE) {
SDL_Event event;
event.key.type = type;
event.type = type;
event.common.timestamp = timestamp;
event.key.state = state;
event.key.repeat = repeat;
event.key.keysym.scancode = scancode;
@@ -931,7 +932,7 @@ static int SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode s
return posted;
}
int SDL_SendKeyboardUnicodeKey(Uint32 ch)
int SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch)
{
SDL_Scancode code = SDL_SCANCODE_UNKNOWN;
uint16_t mod = 0;
@@ -943,33 +944,33 @@ int SDL_SendKeyboardUnicodeKey(Uint32 ch)
if (mod & KMOD_SHIFT) {
/* If the character uses shift, press shift down */
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
SDL_SendKeyboardKey(timestamp, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
}
/* Send a keydown and keyup for the character */
SDL_SendKeyboardKey(SDL_PRESSED, code);
SDL_SendKeyboardKey(SDL_RELEASED, code);
SDL_SendKeyboardKey(timestamp, SDL_PRESSED, code);
SDL_SendKeyboardKey(timestamp, SDL_RELEASED, code);
if (mod & KMOD_SHIFT) {
/* If the character uses shift, release shift */
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
SDL_SendKeyboardKey(timestamp, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
}
return 0;
}
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_SendKeyboardKey(Uint64 timestamp, Uint8 state, SDL_Scancode scancode)
{
return SDL_SendKeyboardKeyInternal(KEYBOARD_HARDWARE, state, scancode, SDLK_UNKNOWN);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, state, scancode, SDLK_UNKNOWN);
}
int SDL_SendKeyboardKeyAndKeycode(Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
int SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
{
return SDL_SendKeyboardKeyInternal(KEYBOARD_HARDWARE, state, scancode, keycode);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, state, scancode, keycode);
}
int SDL_SendKeyboardKeyAutoRelease(SDL_Scancode scancode)
int SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode)
{
return SDL_SendKeyboardKeyInternal(KEYBOARD_AUTORELEASE, SDL_PRESSED, scancode, SDLK_UNKNOWN);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_AUTORELEASE, SDL_PRESSED, scancode, SDLK_UNKNOWN);
}
void SDL_ReleaseAutoReleaseKeys(void)
@@ -980,7 +981,7 @@ void SDL_ReleaseAutoReleaseKeys(void)
if (keyboard->autorelease_pending) {
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
if (keyboard->keysource[scancode] == KEYBOARD_AUTORELEASE) {
SDL_SendKeyboardKeyInternal(KEYBOARD_AUTORELEASE, SDL_RELEASED, scancode, SDLK_UNKNOWN);
SDL_SendKeyboardKeyInternal(0, KEYBOARD_AUTORELEASE, SDL_RELEASED, scancode, SDLK_UNKNOWN);
}
}
keyboard->autorelease_pending = SDL_FALSE;
@@ -1017,7 +1018,8 @@ int SDL_SendKeyboardText(const char *text)
SDL_Event event;
size_t pos = 0, advance, length = SDL_strlen(text);
event.text.type = SDL_TEXTINPUT;
event.type = SDL_TEXTINPUT;
event.common.timestamp = 0;
event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
while (pos < length) {
advance = SDL_utf8strlcpy(event.text.text, text + pos, SDL_arraysize(event.text.text));
@@ -1043,13 +1045,15 @@ int SDL_SendEditingText(const char *text, int start, int length)
if (SDL_GetHintBoolean(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, SDL_FALSE) &&
SDL_strlen(text) >= SDL_arraysize(event.text.text)) {
event.editExt.type = SDL_TEXTEDITING_EXT;
event.type = SDL_TEXTEDITING_EXT;
event.common.timestamp = 0;
event.editExt.windowID = keyboard->focus ? keyboard->focus->id : 0;
event.editExt.text = text ? SDL_strdup(text) : NULL;
event.editExt.start = start;
event.editExt.length = length;
} else {
event.edit.type = SDL_TEXTEDITING;
event.type = SDL_TEXTEDITING;
event.common.timestamp = 0;
event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
event.edit.start = start;
event.edit.length = length;
+4 -4
View File
@@ -47,15 +47,15 @@ extern void SDL_SetKeyboardFocus(SDL_Window *window);
/* Send a character from an on-screen keyboard as scancode and modifier key events,
currently assuming ASCII characters on a US keyboard layout
*/
extern int SDL_SendKeyboardUnicodeKey(Uint32 ch);
extern int SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch);
/* Send a keyboard key event */
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
extern int SDL_SendKeyboardKeyAutoRelease(SDL_Scancode scancode);
extern int SDL_SendKeyboardKey(Uint64 timestamp, Uint8 state, SDL_Scancode scancode);
extern int SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode);
/* This is for platforms that don't know the keymap but can report scancode and keycode directly.
Most platforms should prefer to optionally call SDL_SetKeymap and then use SDL_SendKeyboardKey. */
extern int SDL_SendKeyboardKeyAndKeycode(Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode);
extern int SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode);
/* Release all the autorelease keys */
extern void SDL_ReleaseAutoReleaseKeys(void);
+21 -18
View File
@@ -37,7 +37,7 @@ static SDL_Mouse SDL_mouse;
/* for mapping mouse events to touch */
static SDL_bool track_mouse_down = SDL_FALSE;
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y);
static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y);
static void SDLCALL SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
@@ -261,7 +261,7 @@ SDL_ResetMouse(void)
for (i = 1; i <= sizeof(buttonState)*8; ++i) {
if (buttonState & SDL_BUTTON(i)) {
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, i);
SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, SDL_RELEASED, i);
}
}
SDL_assert(GetButtonState(mouse, SDL_FALSE) == 0);
@@ -324,7 +324,7 @@ static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 bu
SDL_Log("Mouse left window, synthesizing move & focus lost event\n");
#endif
if (send_mouse_motion) {
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
SDL_PrivateSendMouseMotion(0, window, mouse->mouseID, 0, x, y);
}
SDL_SetMouseFocus(NULL);
}
@@ -337,13 +337,13 @@ static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 bu
#endif
SDL_SetMouseFocus(window);
if (send_mouse_motion) {
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
SDL_PrivateSendMouseMotion(0, window, mouse->mouseID, 0, x, y);
}
}
return SDL_TRUE;
}
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
{
if (window && !relative) {
SDL_Mouse *mouse = SDL_GetMouse();
@@ -352,7 +352,7 @@ int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, i
}
}
return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
return SDL_PrivateSendMouseMotion(timestamp, window, mouseID, relative, x, y);
}
static int GetScaledMouseDelta(float scale, int value, float *accum)
@@ -463,7 +463,7 @@ static void GetScaledMouseDeltas(SDL_Mouse *mouse, int *x, int *y)
}
}
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
@@ -476,7 +476,7 @@ static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, i
if (window) {
float fx = (float)x / (float)window->w;
float fy = (float)y / (float)window->h;
SDL_SendTouchMotion(SDL_MOUSE_TOUCHID, 0, window, fx, fy, 1.0f);
SDL_SendTouchMotion(timestamp, SDL_MOUSE_TOUCHID, 0, window, fx, fy, 1.0f);
}
}
}
@@ -504,7 +504,7 @@ static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, i
if (mouse->WarpMouse) {
mouse->WarpMouse(window, center_x, center_y);
} else {
SDL_PrivateSendMouseMotion(window, mouseID, 0, center_x, center_y);
SDL_PrivateSendMouseMotion(timestamp, window, mouseID, 0, center_x, center_y);
}
}
}
@@ -603,7 +603,8 @@ static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, i
posted = 0;
if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) {
SDL_Event event;
event.motion.type = SDL_MOUSEMOTION;
event.type = SDL_MOUSEMOTION;
event.common.timestamp = timestamp;
event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
event.motion.which = mouseID;
/* Set us pending (or clear during a normal mouse movement event) as having triggered */
@@ -668,7 +669,7 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
return &mouse->clickstate[button];
}
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
@@ -693,7 +694,7 @@ static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, U
if (window) {
float fx = (float)mouse->x / (float)window->w;
float fy = (float)mouse->y / (float)window->h;
SDL_SendTouch(SDL_MOUSE_TOUCHID, 0, window, track_mouse_down, fx, fy, 1.0f);
SDL_SendTouch(timestamp, SDL_MOUSE_TOUCHID, 0, window, track_mouse_down, fx, fy, 1.0f);
}
}
}
@@ -760,6 +761,7 @@ static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, U
if (SDL_GetEventState(type) == SDL_ENABLE) {
SDL_Event event;
event.type = type;
event.common.timestamp = timestamp;
event.button.windowID = mouse->focus ? mouse->focus->id : 0;
event.button.which = mouseID;
event.button.state = state;
@@ -783,18 +785,18 @@ static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, U
return posted;
}
int SDL_SendMouseButtonClicks(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
int SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
{
clicks = SDL_max(clicks, 0);
return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
return SDL_PrivateSendMouseButton(timestamp, window, mouseID, state, button, clicks);
}
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
int SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
{
return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
return SDL_PrivateSendMouseButton(timestamp, window, mouseID, state, button, -1);
}
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
int SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
@@ -851,6 +853,7 @@ int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y
if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_MOUSEWHEEL;
event.common.timestamp = timestamp;
event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
event.wheel.which = mouseID;
event.wheel.x = integral_x;
@@ -1026,7 +1029,7 @@ void SDL_PerformWarpMouseInWindow(SDL_Window *window, int x, int y, SDL_bool ign
(!mouse->relative_mode || mouse->relative_mode_warp)) {
mouse->WarpMouse(window, x, y);
} else {
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
SDL_PrivateSendMouseMotion(0, window, mouse->mouseID, 0, x, y);
}
}
+4 -4
View File
@@ -145,16 +145,16 @@ extern int SDL_UpdateMouseCapture(SDL_bool force_release);
extern int SDL_SetMouseSystemScale(int num_values, const float *values);
/* Send a mouse motion event */
extern int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y);
extern int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y);
/* Send a mouse button event */
extern int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
extern int SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
/* Send a mouse button event with a click count */
extern int SDL_SendMouseButtonClicks(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks);
extern int SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks);
/* Send a mouse wheel event */
extern int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction);
extern int SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction);
/* Warp the mouse within the window, potentially overriding relative mode */
extern void SDL_PerformWarpMouseInWindow(SDL_Window *window, int x, int y, SDL_bool ignore_relative_mode);
+14 -12
View File
@@ -237,8 +237,7 @@ static int SDL_DelFinger(SDL_Touch *touch, SDL_FingerID fingerid)
return 0;
}
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
SDL_bool down, float x, float y, float pressure)
int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, SDL_bool down, float x, float y, float pressure)
{
int posted;
SDL_Finger *finger;
@@ -279,12 +278,12 @@ int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
if (pos_y > window->h - 1) {
pos_y = window->h - 1;
}
SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
SDL_SendMouseMotion(timestamp, window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
SDL_SendMouseButton(timestamp, window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
}
} else {
if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(timestamp, window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
}
}
}
@@ -316,7 +315,7 @@ int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
if (finger) {
/* This finger is already down.
Assume the finger-up for the previous touch was lost, and send it. */
SDL_SendTouch(id, fingerid, window, SDL_FALSE, x, y, pressure);
SDL_SendTouch(timestamp, id, fingerid, window, SDL_FALSE, x, y, pressure);
}
if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
@@ -326,7 +325,8 @@ int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
posted = 0;
if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
SDL_Event event;
event.tfinger.type = SDL_FINGERDOWN;
event.type = SDL_FINGERDOWN;
event.common.timestamp = timestamp;
event.tfinger.touchId = id;
event.tfinger.fingerId = fingerid;
event.tfinger.x = x;
@@ -346,7 +346,8 @@ int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
posted = 0;
if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
SDL_Event event;
event.tfinger.type = SDL_FINGERUP;
event.type = SDL_FINGERUP;
event.common.timestamp = timestamp;
event.tfinger.touchId = id;
event.tfinger.fingerId = fingerid;
/* I don't trust the coordinates passed on fingerUp */
@@ -364,7 +365,7 @@ int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
return posted;
}
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
float x, float y, float pressure)
{
SDL_Touch *touch;
@@ -401,7 +402,7 @@ int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *windo
if (pos_y > window->h - 1) {
pos_y = window->h - 1;
}
SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
SDL_SendMouseMotion(timestamp, window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
}
}
}
@@ -418,7 +419,7 @@ int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *windo
finger = SDL_GetFinger(touch, fingerid);
if (finger == NULL) {
return SDL_SendTouch(id, fingerid, window, SDL_TRUE, x, y, pressure);
return SDL_SendTouch(timestamp, id, fingerid, window, SDL_TRUE, x, y, pressure);
}
xrel = x - finger->x;
@@ -442,7 +443,8 @@ int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *windo
posted = 0;
if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
SDL_Event event;
event.tfinger.type = SDL_FINGERMOTION;
event.type = SDL_FINGERMOTION;
event.common.timestamp = timestamp;
event.tfinger.touchId = id;
event.tfinger.fingerId = fingerid;
event.tfinger.x = x;
+2 -4
View File
@@ -43,12 +43,10 @@ extern int SDL_AddTouch(SDL_TouchID id, SDL_TouchDeviceType type, const char *na
extern SDL_Touch *SDL_GetTouch(SDL_TouchID id);
/* Send a touch down/up event for a touch */
extern int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
SDL_bool down, float x, float y, float pressure);
extern int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, SDL_bool down, float x, float y, float pressure);
/* Send a touch motion event for a touch */
extern int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window,
float x, float y, float pressure);
extern int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, float x, float y, float pressure);
/* Remove a touch */
extern void SDL_DelTouch(SDL_TouchID id);
+1
View File
@@ -187,6 +187,7 @@ int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1,
if (SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_WINDOWEVENT;
event.common.timestamp = 0;
event.window.event = windowevent;
event.window.data1 = data1;
event.window.data2 = data2;
+8
View File
@@ -405,7 +405,9 @@ static int SDLCALL SDL_GameControllerEventWatcher(void *userdata, SDL_Event *eve
{
if (SDL_IsGameController(event->jdevice.which)) {
SDL_Event deviceevent;
deviceevent.type = SDL_CONTROLLERDEVICEADDED;
deviceevent.common.timestamp = 0;
deviceevent.cdevice.which = event->jdevice.which;
SDL_PushEvent(&deviceevent);
}
@@ -426,6 +428,7 @@ static int SDLCALL SDL_GameControllerEventWatcher(void *userdata, SDL_Event *eve
SDL_Event deviceevent;
deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
deviceevent.common.timestamp = 0;
deviceevent.cdevice.which = event->jdevice.which;
SDL_PushEvent(&deviceevent);
}
@@ -1189,7 +1192,9 @@ static void SDL_PrivateGameControllerRefreshMapping(ControllerMapping_t *pContro
{
SDL_Event event;
event.type = SDL_CONTROLLERDEVICEREMAPPED;
event.common.timestamp = 0;
event.cdevice.which = gamecontrollerlist->joystick->instance_id;
SDL_PushEvent(&event);
}
@@ -1834,6 +1839,7 @@ int SDL_GameControllerInit(void)
if (SDL_IsGameController(i)) {
SDL_Event deviceevent;
deviceevent.type = SDL_CONTROLLERDEVICEADDED;
deviceevent.common.timestamp = 0;
deviceevent.cdevice.which = i;
SDL_PushEvent(&deviceevent);
}
@@ -2863,6 +2869,7 @@ static int SDL_PrivateGameControllerAxis(SDL_GameController *gamecontroller, SDL
if (SDL_GetEventState(SDL_CONTROLLERAXISMOTION) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_CONTROLLERAXISMOTION;
event.common.timestamp = 0;
event.caxis.which = gamecontroller->joystick->instance_id;
event.caxis.axis = axis;
event.caxis.value = value;
@@ -2898,6 +2905,7 @@ static int SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, S
/* Invalid state -- bail */
return 0;
}
event.common.timestamp = 0;
#endif /* !SDL_EVENTS_DISABLED */
if (button == SDL_CONTROLLER_BUTTON_GUIDE) {
+11 -3
View File
@@ -1307,6 +1307,7 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID device_instance)
SDL_Event event;
event.type = SDL_JOYDEVICEADDED;
event.common.timestamp = 0;
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jdevice.which = device_index;
@@ -1430,8 +1431,8 @@ void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
}
#if !SDL_EVENTS_DISABLED
SDL_zero(event);
event.type = SDL_JOYDEVICEREMOVED;
event.common.timestamp = 0;
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jdevice.which = device_instance;
@@ -1507,6 +1508,7 @@ int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_JOYAXISMOTION;
event.common.timestamp = 0;
event.jaxis.which = joystick->instance_id;
event.jaxis.axis = axis;
event.jaxis.value = value;
@@ -1549,7 +1551,8 @@ int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
#if !SDL_EVENTS_DISABLED
if (SDL_GetEventState(SDL_JOYHATMOTION) == SDL_ENABLE) {
SDL_Event event;
event.jhat.type = SDL_JOYHATMOTION;
event.type = SDL_JOYHATMOTION;
event.common.timestamp = 0;
event.jhat.which = joystick->instance_id;
event.jhat.hat = hat;
event.jhat.value = value;
@@ -1587,7 +1590,8 @@ int SDL_PrivateJoystickBall(SDL_Joystick *joystick, Uint8 ball,
#if !SDL_EVENTS_DISABLED
if (SDL_GetEventState(SDL_JOYBALLMOTION) == SDL_ENABLE) {
SDL_Event event;
event.jball.type = SDL_JOYBALLMOTION;
event.type = SDL_JOYBALLMOTION;
event.common.timestamp = 0;
event.jball.which = joystick->instance_id;
event.jball.ball = ball;
event.jball.xrel = xrel;
@@ -1617,6 +1621,7 @@ int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
/* Invalid state -- bail */
return 0;
}
event.common.timestamp = 0;
#endif /* !SDL_EVENTS_DISABLED */
SDL_AssertJoysticksLocked();
@@ -2843,6 +2848,7 @@ void SDL_PrivateJoystickBatteryLevel(SDL_Joystick *joystick, SDL_JoystickPowerLe
if (SDL_GetEventState(SDL_JOYBATTERYUPDATED) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_JOYBATTERYUPDATED;
event.common.timestamp = 0;
event.jbattery.which = joystick->instance_id;
event.jbattery.level = ePowerLevel;
SDL_PushEvent(&event);
@@ -2938,6 +2944,7 @@ int SDL_PrivateJoystickTouchpad(SDL_Joystick *joystick, int touchpad, int finger
if (SDL_GetEventState(event_type) == SDL_ENABLE) {
SDL_Event event;
event.type = event_type;
event.common.timestamp = 0;
event.ctouchpad.which = joystick->instance_id;
event.ctouchpad.touchpad = touchpad;
event.ctouchpad.finger = finger;
@@ -2978,6 +2985,7 @@ int SDL_PrivateJoystickSensor(SDL_Joystick *joystick, SDL_SensorType type, Uint6
if (SDL_GetEventState(SDL_CONTROLLERSENSORUPDATE) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_CONTROLLERSENSORUPDATE;
event.common.timestamp = 0;
event.csensor.which = joystick->instance_id;
event.csensor.sensor = type;
num_values = SDL_min(num_values, SDL_arraysize(event.csensor.data));
+2 -2
View File
@@ -204,7 +204,7 @@ int Android_OnPadDown(int device_id, int keycode)
if (item && item->joystick) {
SDL_PrivateJoystickButton(item->joystick, button, SDL_PRESSED);
} else {
SDL_SendKeyboardKey(SDL_PRESSED, button_to_scancode(button));
SDL_SendKeyboardKey(0, SDL_PRESSED, button_to_scancode(button));
}
SDL_UnlockJoysticks();
return 0;
@@ -223,7 +223,7 @@ int Android_OnPadUp(int device_id, int keycode)
if (item && item->joystick) {
SDL_PrivateJoystickButton(item->joystick, button, SDL_RELEASED);
} else {
SDL_SendKeyboardKey(SDL_RELEASED, button_to_scancode(button));
SDL_SendKeyboardKey(0, SDL_RELEASED, button_to_scancode(button));
}
SDL_UnlockJoysticks();
return 0;
+5 -5
View File
@@ -254,12 +254,12 @@ class SDL_BApp : public BApplication
SDL_GetWindowPosition(win, &winPosX, &winPosY);
int dx = x - (winWidth / 2);
int dy = y - (winHeight / 2);
SDL_SendMouseMotion(win, 0, SDL_GetMouse()->relative_mode, dx, dy);
SDL_SendMouseMotion(0, win, 0, SDL_GetMouse()->relative_mode, dx, dy);
set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2));
if (!be_app->IsCursorHidden())
be_app->HideCursor();
} else {
SDL_SendMouseMotion(win, 0, 0, x, y);
SDL_SendMouseMotion(0, win, 0, 0, x, y);
if (SDL_ShowCursor(-1) && be_app->IsCursorHidden())
be_app->ShowCursor();
}
@@ -277,7 +277,7 @@ class SDL_BApp : public BApplication
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseButton(win, 0, state, button);
SDL_SendMouseButton(0, win, 0, state, button);
}
void _HandleMouseWheel(BMessage *msg)
@@ -292,7 +292,7 @@ class SDL_BApp : public BApplication
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseWheel(win, 0, xTicks, -yTicks, SDL_MOUSEWHEEL_NORMAL);
SDL_SendMouseWheel(0, win, 0, xTicks, -yTicks, SDL_MOUSEWHEEL_NORMAL);
}
void _HandleKey(BMessage *msg)
@@ -309,7 +309,7 @@ class SDL_BApp : public BApplication
return;
}
HAIKU_SetKeyState(scancode, state);
SDL_SendKeyboardKey(state, HAIKU_GetScancodeFromBeKey(scancode));
SDL_SendKeyboardKey(0, state, HAIKU_GetScancodeFromBeKey(scancode));
if (state == SDL_PRESSED && SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
const int8 *keyUtf8;
+1
View File
@@ -1520,6 +1520,7 @@ static int D3D_Reset(SDL_Renderer *renderer)
{
SDL_Event event;
event.type = SDL_RENDER_TARGETS_RESET;
event.common.timestamp = 0;
SDL_PushEvent(&event);
}
+1
View File
@@ -875,6 +875,7 @@ D3D11_HandleDeviceLost(SDL_Renderer *renderer)
{
SDL_Event event;
event.type = SDL_RENDER_DEVICE_RESET;
event.common.timestamp = 0;
SDL_PushEvent(&event);
}
+1
View File
@@ -1233,6 +1233,7 @@ D3D12_HandleDeviceLost(SDL_Renderer *renderer)
{
SDL_Event event;
event.type = SDL_RENDER_DEVICE_RESET;
event.common.timestamp = 0;
SDL_PushEvent(&event);
}
+1
View File
@@ -492,6 +492,7 @@ int SDL_PrivateSensorUpdate(SDL_Sensor *sensor, Uint64 timestamp_us, float *data
if (SDL_GetEventState(SDL_SENSORUPDATE) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_SENSORUPDATE;
event.common.timestamp = 0;
event.sensor.which = sensor->instance_id;
num_values = SDL_min(num_values, SDL_arraysize(event.sensor.data));
SDL_memset(event.sensor.data, 0, sizeof(event.sensor.data));
+1
View File
@@ -78,6 +78,7 @@ static void android_egl_context_restore(SDL_Window *window)
data->egl_context = (EGLContext)SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context);
event.type = SDL_RENDER_DEVICE_RESET;
event.common.timestamp = 0;
SDL_PushEvent(&event);
}
data->backup_done = 0;
+2 -2
View File
@@ -328,12 +328,12 @@ static SDL_Scancode TranslateKeycode(int keycode)
int Android_OnKeyDown(int keycode)
{
return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
return SDL_SendKeyboardKey(0, SDL_PRESSED, TranslateKeycode(keycode));
}
int Android_OnKeyUp(int keycode)
{
return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
return SDL_SendKeyboardKey(0, SDL_RELEASED, TranslateKeycode(keycode));
}
SDL_bool
+6 -6
View File
@@ -224,25 +224,25 @@ void Android_OnMouse(SDL_Window *window, int state, int action, float x, float y
changes = state & ~last_state;
button = TranslateButton(changes);
last_state = state;
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
SDL_SendMouseMotion(0, window, 0, relative, (int)x, (int)y);
SDL_SendMouseButton(0, window, 0, SDL_PRESSED, button);
break;
case ACTION_UP:
changes = last_state & ~state;
button = TranslateButton(changes);
last_state = state;
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
SDL_SendMouseMotion(0, window, 0, relative, (int)x, (int)y);
SDL_SendMouseButton(0, window, 0, SDL_RELEASED, button);
break;
case ACTION_MOVE:
case ACTION_HOVER_MOVE:
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
SDL_SendMouseMotion(0, window, 0, relative, (int)x, (int)y);
break;
case ACTION_SCROLL:
SDL_SendMouseWheel(window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
SDL_SendMouseWheel(0, window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
break;
default:
+3 -3
View File
@@ -65,16 +65,16 @@ void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_fin
switch (action) {
case ACTION_DOWN:
case ACTION_POINTER_DOWN:
SDL_SendTouch(touchDeviceId, fingerId, window, SDL_TRUE, x, y, p);
SDL_SendTouch(0, touchDeviceId, fingerId, window, SDL_TRUE, x, y, p);
break;
case ACTION_MOVE:
SDL_SendTouchMotion(touchDeviceId, fingerId, window, x, y, p);
SDL_SendTouchMotion(0, touchDeviceId, fingerId, window, x, y, p);
break;
case ACTION_UP:
case ACTION_POINTER_UP:
SDL_SendTouch(touchDeviceId, fingerId, window, SDL_FALSE, x, y, p);
SDL_SendTouch(0, touchDeviceId, fingerId, window, SDL_FALSE, x, y, p);
break;
default:
+1
View File
@@ -24,6 +24,7 @@
#define SDL_cocoaevents_h_
extern void Cocoa_RegisterApp(void);
extern Uint64 Cocoa_GetEventTimestamp(NSTimeInterval nsTimestamp);
extern void Cocoa_PumpEvents(_THIS);
extern int Cocoa_WaitEventTimeout(_THIS, Sint64 timeoutNS);
extern void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window);
+18
View File
@@ -502,6 +502,24 @@ void Cocoa_RegisterApp(void)
}
}
Uint64 Cocoa_GetEventTimestamp(NSTimeInterval nsTimestamp)
{
static Uint64 timestamp_offset;
Uint64 timestamp = (Uint64)(nsTimestamp * SDL_NS_PER_SECOND);
Uint64 now = SDL_GetTicksNS();
if (!timestamp_offset) {
timestamp_offset = (now - timestamp);
}
timestamp += timestamp_offset;
if (timestamp > now) {
timestamp_offset -= (timestamp - now);
timestamp = now;
}
return timestamp;
}
int Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
{
for (;;) {
+4 -4
View File
@@ -220,9 +220,9 @@ static void HandleModifiers(_THIS, unsigned short scancode, unsigned int modifie
for (int i = 0; i < 12; i++) {
if (code == codes[i]) {
if (modifierFlags & modifiers[i]) {
SDL_SendKeyboardKey(SDL_PRESSED, code);
SDL_SendKeyboardKey(0, SDL_PRESSED, code);
} else {
SDL_SendKeyboardKey(SDL_RELEASED, code);
SDL_SendKeyboardKey(0, SDL_RELEASED, code);
}
}
}
@@ -399,7 +399,7 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
UpdateKeymap(data, SDL_TRUE);
}
SDL_SendKeyboardKey(SDL_PRESSED, code);
SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), SDL_PRESSED, code);
#ifdef DEBUG_SCANCODES
if (code == SDL_SCANCODE_UNKNOWN) {
SDL_Log("The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL forums/mailing list <https://discourse.libsdl.org/> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode);
@@ -418,7 +418,7 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
}
break;
case NSEventTypeKeyUp:
SDL_SendKeyboardKey(SDL_RELEASED, code);
SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), SDL_RELEASED, code);
break;
case NSEventTypeFlagsChanged:
HandleModifiers(_this, scancode, (unsigned int)[event modifierFlags]);
+3 -3
View File
@@ -278,7 +278,7 @@ static int Cocoa_WarpMouseGlobal(int x, int y)
SDL_SetMouseFocus(win);
if (win) {
SDL_assert(win == mouse->focus);
SDL_SendMouseMotion(win, mouse->mouseID, 0, x - win->x, y - win->y);
SDL_SendMouseMotion(0, win, mouse->mouseID, 0, x - win->x, y - win->y);
}
}
@@ -495,7 +495,7 @@ void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
}
SDL_SendMouseMotion(mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY);
SDL_SendMouseMotion(Cocoa_GetEventTimestamp([event timestamp]), mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY);
}
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
@@ -532,7 +532,7 @@ void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
}
}
SDL_SendMouseWheel(window, mouseID, x, y, direction);
SDL_SendMouseWheel(Cocoa_GetEventTimestamp([event timestamp]), window, mouseID, x, y, direction);
}
void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
+11 -11
View File
@@ -190,7 +190,7 @@
x = (int)point.x;
y = (int)(sdlwindow->h - point.y);
if (x >= 0 && x < sdlwindow->w && y >= 0 && y < sdlwindow->h) {
SDL_SendMouseMotion(sdlwindow, mouse->mouseID, 0, x, y);
SDL_SendMouseMotion(0, sdlwindow, mouse->mouseID, 0, x, y);
}
/* Code addon to update the mouse location */
@@ -855,7 +855,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
y = (int)(window->h - point.y);
if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
SDL_SendMouseMotion(0, window, mouse->mouseID, 0, x, y);
}
}
@@ -1133,8 +1133,8 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
const SDL_bool osenabled = ([theEvent modifierFlags] & NSEventModifierFlagCapsLock) ? SDL_TRUE : SDL_FALSE;
const SDL_bool sdlenabled = (SDL_GetModState() & KMOD_CAPS) ? SDL_TRUE : SDL_FALSE;
if (osenabled ^ sdlenabled) {
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
}
}
- (void)keyDown:(NSEvent *)theEvent
@@ -1193,14 +1193,14 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
// event for the background window, this just makes sure the button is reported at the
// correct position in its own event.
if (focus && ([theEvent window] == ((__bridge SDL_WindowData *)focus->driverdata).nswindow)) {
rc = SDL_SendMouseButtonClicks(window, mouseID, state, button, clicks);
rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
} else {
const int orig_x = mouse->x;
const int orig_y = mouse->y;
const NSPoint point = [theEvent locationInWindow];
mouse->x = (int)point.x;
mouse->y = (int)(window->h - point.y);
rc = SDL_SendMouseButtonClicks(window, mouseID, state, button, clicks);
rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
mouse->x = orig_x;
mouse->y = orig_y;
}
@@ -1352,7 +1352,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
}
}
SDL_SendMouseMotion(window, mouseID, 0, x, y);
SDL_SendMouseMotion(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, 0, x, y);
}
- (void)mouseDragged:(NSEvent *)theEvent
@@ -1428,7 +1428,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
* events from being generated from touch events.
*/
SDL_Window *window = NULL;
SDL_SendTouch(touchID, finger->id, window, SDL_FALSE, 0, 0, 0);
SDL_SendTouch(Cocoa_GetEventTimestamp([theEvent timestamp]), touchID, finger->id, window, SDL_FALSE, 0, 0, 0);
}
}
@@ -1496,14 +1496,14 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
switch (phase) {
case NSTouchPhaseBegan:
SDL_SendTouch(touchId, fingerId, window, SDL_TRUE, x, y, 1.0f);
SDL_SendTouch(Cocoa_GetEventTimestamp([theEvent timestamp]), touchId, fingerId, window, SDL_TRUE, x, y, 1.0f);
break;
case NSTouchPhaseEnded:
case NSTouchPhaseCancelled:
SDL_SendTouch(touchId, fingerId, window, SDL_FALSE, x, y, 1.0f);
SDL_SendTouch(Cocoa_GetEventTimestamp([theEvent timestamp]), touchId, fingerId, window, SDL_FALSE, x, y, 1.0f);
break;
case NSTouchPhaseMoved:
SDL_SendTouchMotion(touchId, fingerId, window, x, y, 1.0f);
SDL_SendTouchMotion(Cocoa_GetEventTimestamp([theEvent timestamp]), touchId, fingerId, window, x, y, 1.0f);
break;
default:
break;
+8 -8
View File
@@ -635,7 +635,7 @@ static EM_BOOL Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEv
my = mouseEvent->targetY * yscale;
}
SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
SDL_SendMouseMotion(0, window_data->window, 0, isPointerLocked, mx, my);
return 0;
}
@@ -671,7 +671,7 @@ static EM_BOOL Emscripten_HandleMouseButton(int eventType, const EmscriptenMouse
sdl_button_state = SDL_RELEASED;
sdl_event_type = SDL_MOUSEBUTTONUP;
}
SDL_SendMouseButton(window_data->window, 0, sdl_button_state, sdl_button);
SDL_SendMouseButton(0, window_data->window, 0, sdl_button_state, sdl_button);
/* Do not consume the event if the mouse is outside of the canvas. */
emscripten_get_element_css_size(window_data->canvas_id, &css_w, &css_h);
@@ -697,7 +697,7 @@ static EM_BOOL Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseE
mx = mx * (window_data->window->w / client_w);
my = my * (window_data->window->h / client_h);
SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
SDL_SendMouseMotion(0, window_data->window, 0, isPointerLocked, mx, my);
}
SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL);
@@ -722,7 +722,7 @@ static EM_BOOL Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent
break;
}
SDL_SendMouseWheel(window_data->window, 0, (float)wheelEvent->deltaX, -deltaY, SDL_MOUSEWHEEL_NORMAL);
SDL_SendMouseWheel(0, window_data->window, 0, (float)wheelEvent->deltaX, -deltaY, SDL_MOUSEWHEEL_NORMAL);
return SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE;
}
@@ -766,16 +766,16 @@ static EM_BOOL Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent
y = touchEvent->touches[i].targetY / client_h;
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
SDL_SendTouch(deviceId, id, window_data->window, SDL_TRUE, x, y, 1.0f);
SDL_SendTouch(0, deviceId, id, window_data->window, SDL_TRUE, x, y, 1.0f);
/* disable browser scrolling/pinch-to-zoom if app handles touch events */
if (!preventDefault && SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
preventDefault = 1;
}
} else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
SDL_SendTouchMotion(deviceId, id, window_data->window, x, y, 1.0f);
SDL_SendTouchMotion(0, deviceId, id, window_data->window, x, y, 1.0f);
} else {
SDL_SendTouch(deviceId, id, window_data->window, SDL_FALSE, x, y, 1.0f);
SDL_SendTouch(0, deviceId, id, window_data->window, SDL_FALSE, x, y, 1.0f);
/* block browser's simulated mousedown/mouseup on touchscreen devices */
preventDefault = 1;
@@ -802,7 +802,7 @@ static EM_BOOL Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent
}
if (scancode != SDL_SCANCODE_UNKNOWN) {
SDL_SendKeyboardKeyAndKeycode(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode, keycode);
SDL_SendKeyboardKeyAndKeycode(0, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode, keycode);
}
/* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
+5 -5
View File
@@ -254,12 +254,12 @@ class SDL_BApp : public BApplication
SDL_GetWindowPosition(win, &winPosX, &winPosY);
int dx = x - (winWidth / 2);
int dy = y - (winHeight / 2);
SDL_SendMouseMotion(win, 0, SDL_GetMouse()->relative_mode, dx, dy);
SDL_SendMouseMotion(0, win, 0, SDL_GetMouse()->relative_mode, dx, dy);
set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2));
if (!be_app->IsCursorHidden())
be_app->HideCursor();
} else {
SDL_SendMouseMotion(win, 0, 0, x, y);
SDL_SendMouseMotion(0, win, 0, 0, x, y);
if (SDL_ShowCursor(-1) && be_app->IsCursorHidden())
be_app->ShowCursor();
}
@@ -277,7 +277,7 @@ class SDL_BApp : public BApplication
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseButton(win, 0, state, button);
SDL_SendMouseButton(0, win, 0, state, button);
}
void _HandleMouseWheel(BMessage *msg)
@@ -292,7 +292,7 @@ class SDL_BApp : public BApplication
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseWheel(win, 0, xTicks, -yTicks, SDL_MOUSEWHEEL_NORMAL);
SDL_SendMouseWheel(0, win, 0, xTicks, -yTicks, SDL_MOUSEWHEEL_NORMAL);
}
void _HandleKey(BMessage *msg)
@@ -309,7 +309,7 @@ class SDL_BApp : public BApplication
return;
}
HAIKU_SetKeyState(scancode, state);
SDL_SendKeyboardKey(state, HAIKU_GetScancodeFromBeKey(scancode));
SDL_SendKeyboardKey(0, state, HAIKU_GetScancodeFromBeKey(scancode));
if (state == SDL_PRESSED && SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
const int8 *keyUtf8;
+1 -1
View File
@@ -372,7 +372,7 @@ static int KMSDRM_WarpMouseGlobal(int x, int y)
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata;
/* Update internal mouse position. */
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y);
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, x, y);
/* And now update the cursor graphic position on screen. */
if (dispdata->cursor_bo) {
+1
View File
@@ -36,6 +36,7 @@ void N3DS_PumpEvents(_THIS)
if (!aptMainLoop()) {
SDL_Event ev;
ev.type = SDL_QUIT;
ev.common.timestamp = 0;
SDL_PushEvent(&ev);
return;
}
+2 -2
View File
@@ -59,7 +59,7 @@ void N3DS_PollTouch(void)
if (pressed != was_pressed) {
was_pressed = pressed;
SDL_SendTouch(N3DS_TOUCH_ID,
SDL_SendTouch(0, N3DS_TOUCH_ID,
0,
NULL,
pressed,
@@ -67,7 +67,7 @@ void N3DS_PollTouch(void)
touch.py * TOUCHSCREEN_SCALE_Y,
pressed ? 1.0f : 0.0f);
} else if (pressed) {
SDL_SendTouchMotion(N3DS_TOUCH_ID,
SDL_SendTouchMotion(0, N3DS_TOUCH_ID,
0,
NULL,
touch.px * TOUCHSCREEN_SCALE_X,
+2 -2
View File
@@ -154,10 +154,10 @@ int HandleWsEvent(_THIS, const TWsEvent &aWsEvent)
switch (aWsEvent.Type()) {
case EEventKeyDown: /* Key events */
SDL_SendKeyboardKey(SDL_PRESSED, ConvertScancode(_this, aWsEvent.Key()->iScanCode));
SDL_SendKeyboardKey(0, SDL_PRESSED, ConvertScancode(_this, aWsEvent.Key()->iScanCode));
break;
case EEventKeyUp: /* Key events */
SDL_SendKeyboardKey(SDL_RELEASED, ConvertScancode(_this, aWsEvent.Key()->iScanCode));
SDL_SendKeyboardKey(0, SDL_RELEASED, ConvertScancode(_this, aWsEvent.Key()->iScanCode));
break;
case EEventFocusGained: /* SDL window got focus */
phdata->NGAGE_IsWindowFocused = ETrue;
+2 -2
View File
@@ -90,7 +90,7 @@ void PSP_PumpEvents(_THIS)
if (changed) {
for (i = 0; i < sizeof(keymap_psp) / sizeof(keymap_psp[0]); i++) {
if (changed & keymap_psp[i].id) {
SDL_SendKeyboardKey((keys & keymap_psp[i].id) ? SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
SDL_SendKeyboardKey(0, (keys & keymap_psp[i].id) ? SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
}
}
}
@@ -113,7 +113,7 @@ void PSP_PumpEvents(_THIS)
sym.sym = keymap[raw];
/* not tested */
/* SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); */
SDL_SendKeyboardKey((keys & keymap_psp[i].id) ? SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]));
SDL_SendKeyboardKey(0, (keys & keymap_psp[i].id) ? SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]));
}
}
}
+1 -1
View File
@@ -244,7 +244,7 @@ static int RPI_WarpMouseGlobal(int x, int y)
}
/* Update internal mouse position. */
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y);
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, x, y);
curdata = (RPI_CursorData *)mouse->cur_cursor->driverdata;
if (curdata->element == DISPMANX_NO_HANDLE) {
+4 -4
View File
@@ -58,7 +58,7 @@ void RISCOS_PollKeyboard(_THIS)
for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) {
if (driverdata->key_pressed[i] != 255) {
if ((_kernel_osbyte(129, driverdata->key_pressed[i] ^ 0xff, 0xff) & 0xff) != 255) {
SDL_SendKeyboardKey(SDL_RELEASED, SDL_RISCOS_translate_keycode(driverdata->key_pressed[i]));
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_RISCOS_translate_keycode(driverdata->key_pressed[i]));
driverdata->key_pressed[i] = 255;
}
}
@@ -81,7 +81,7 @@ void RISCOS_PollKeyboard(_THIS)
break;
default:
SDL_SendKeyboardKey(SDL_PRESSED, SDL_RISCOS_translate_keycode(key));
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_RISCOS_translate_keycode(key));
/* Record the press so we can detect release later. */
for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) {
@@ -126,12 +126,12 @@ void RISCOS_PollMouse(_THIS)
buttons = regs.r[2];
if (mouse->x != x || mouse->y != y) {
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y);
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, x, y);
}
if (driverdata->last_mouse_buttons != buttons) {
for (i = 0; i < SDL_arraysize(mouse_button_map); i++) {
SDL_SendMouseButton(mouse->focus, mouse->mouseID, (buttons & (1 << i)) ? SDL_PRESSED : SDL_RELEASED, mouse_button_map[i]);
SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, (buttons & (1 << i)) ? SDL_PRESSED : SDL_RELEASED, mouse_button_map[i]);
}
driverdata->last_mouse_buttons = buttons;
}
+3
View File
@@ -21,8 +21,11 @@
#ifndef SDL_uikitevents_h_
#define SDL_uikitevents_h_
#import <UIKit/UIKit.h>
#include "../SDL_sysvideo.h"
extern Uint64 UIKit_GetEventTimestamp(NSTimeInterval nsTimestamp);
extern void UIKit_PumpEvents(_THIS);
extern void SDL_InitGCKeyboard(void);
+22 -4
View File
@@ -108,6 +108,24 @@ static BOOL UIKit_EventPumpEnabled = YES;
@end
Uint64 UIKit_GetEventTimestamp(NSTimeInterval nsTimestamp)
{
static Uint64 timestamp_offset;
Uint64 timestamp = (Uint64)(nsTimestamp * SDL_NS_PER_SECOND);
Uint64 now = SDL_GetTicksNS();
if (!timestamp_offset) {
timestamp_offset = (now - timestamp);
}
timestamp += timestamp_offset;
if (timestamp > now) {
timestamp_offset -= (timestamp - now);
timestamp = now;
}
return timestamp;
}
void SDL_iPhoneSetEventPump(SDL_bool enabled)
{
UIKit_EventPumpEnabled = enabled;
@@ -161,7 +179,7 @@ static void OnGCKeyboardConnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0
{
keyboard_connected = SDL_TRUE;
keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput *kbrd, GCControllerButtonInput *key, GCKeyCode keyCode, BOOL pressed) {
SDL_SendKeyboardKey(pressed ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)keyCode);
SDL_SendKeyboardKey(0, pressed ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)keyCode);
};
dispatch_queue_t queue = dispatch_queue_create("org.libsdl.input.keyboard", DISPATCH_QUEUE_SERIAL);
@@ -275,7 +293,7 @@ static int SetGCMouseRelativeMode(SDL_bool enabled)
static void OnGCMouseButtonChanged(SDL_MouseID mouseID, Uint8 button, BOOL pressed)
{
SDL_SendMouseButton(SDL_GetMouseFocus(), mouseID, pressed ? SDL_PRESSED : SDL_RELEASED, button);
SDL_SendMouseButton(0, SDL_GetMouseFocus(), mouseID, pressed ? SDL_PRESSED : SDL_RELEASED, button);
}
static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0))
@@ -302,12 +320,12 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput *mouseInput, float deltaX, float deltaY) {
if (SDL_GCMouseRelativeMode()) {
SDL_SendMouseMotion(SDL_GetMouseFocus(), mouseID, 1, (int)deltaX, -(int)deltaY);
SDL_SendMouseMotion(0, SDL_GetMouseFocus(), mouseID, 1, (int)deltaX, -(int)deltaY);
}
};
mouse.mouseInput.scroll.valueChangedHandler = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) {
SDL_SendMouseWheel(SDL_GetMouseFocus(), 0, xValue, yValue, SDL_MOUSEWHEEL_NORMAL);
SDL_SendMouseWheel(0, SDL_GetMouseFocus(), 0, xValue, yValue, SDL_MOUSEWHEEL_NORMAL);
};
dispatch_queue_t queue = dispatch_queue_create("org.libsdl.input.mouse", DISPATCH_QUEUE_SERIAL);
+16 -13
View File
@@ -158,7 +158,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
point.x -= origin.x;
point.y -= origin.y;
SDL_SendMouseMotion(sdlwindow, 0, 0, (int)point.x, (int)point.y);
SDL_SendMouseMotion(0, sdlwindow, 0, 0, (int)point.x, (int)point.y);
}
return [UIPointerRegion regionWithRect:self.bounds identifier:nil];
}
@@ -250,7 +250,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
button = (Uint8)i;
break;
}
SDL_SendMouseButton(sdlwindow, 0, SDL_PRESSED, button);
SDL_SendMouseButton(UIKit_GetEventTimestamp([event timestamp]), sdlwindow, 0, SDL_PRESSED, button);
}
}
}
@@ -270,7 +270,8 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
/* FIXME, need to send: int clicks = (int) touch.tapCount; ? */
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch), sdlwindow,
SDL_SendTouch(UIKit_GetEventTimestamp([event timestamp]),
touchId, (SDL_FingerID)((size_t)touch), sdlwindow,
SDL_TRUE, locationInView.x, locationInView.y, pressure);
}
}
@@ -305,7 +306,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
button = (Uint8)i;
break;
}
SDL_SendMouseButton(sdlwindow, 0, SDL_RELEASED, button);
SDL_SendMouseButton(UIKit_GetEventTimestamp([event timestamp]), sdlwindow, 0, SDL_RELEASED, button);
}
}
}
@@ -325,7 +326,8 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
/* FIXME, need to send: int clicks = (int) touch.tapCount; ? */
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch), sdlwindow,
SDL_SendTouch(UIKit_GetEventTimestamp([event timestamp]),
touchId, (SDL_FingerID)((size_t)touch), sdlwindow,
SDL_FALSE, locationInView.x, locationInView.y, pressure);
}
}
@@ -359,7 +361,8 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
}
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
SDL_SendTouchMotion(touchId, (SDL_FingerID)((size_t)touch), sdlwindow,
SDL_SendTouchMotion(UIKit_GetEventTimestamp([event timestamp]),
touchId, (SDL_FingerID)((size_t)touch), sdlwindow,
locationInView.x, locationInView.y, pressure);
}
}
@@ -411,7 +414,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
if (!SDL_HasGCKeyboard()) {
for (UIPress *press in presses) {
SDL_Scancode scancode = [self scancodeFromPress:press];
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_PRESSED, scancode);
}
}
[super pressesBegan:presses withEvent:event];
@@ -422,7 +425,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
if (!SDL_HasGCKeyboard()) {
for (UIPress *press in presses) {
SDL_Scancode scancode = [self scancodeFromPress:press];
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_RELEASED, scancode);
}
}
[super pressesEnded:presses withEvent:event];
@@ -433,7 +436,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
if (!SDL_HasGCKeyboard()) {
for (UIPress *press in presses) {
SDL_Scancode scancode = [self scancodeFromPress:press];
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_RELEASED, scancode);
}
}
[super pressesCancelled:presses withEvent:event];
@@ -458,16 +461,16 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
* which better maps to swipe gestures. */
switch (gesture.direction) {
case UISwipeGestureRecognizerDirectionUp:
SDL_SendKeyboardKeyAutoRelease(SDL_SCANCODE_UP);
SDL_SendKeyboardKeyAutoRelease(0, SDL_SCANCODE_UP);
break;
case UISwipeGestureRecognizerDirectionDown:
SDL_SendKeyboardKeyAutoRelease(SDL_SCANCODE_DOWN);
SDL_SendKeyboardKeyAutoRelease(0, SDL_SCANCODE_DOWN);
break;
case UISwipeGestureRecognizerDirectionLeft:
SDL_SendKeyboardKeyAutoRelease(SDL_SCANCODE_LEFT);
SDL_SendKeyboardKeyAutoRelease(0, SDL_SCANCODE_LEFT);
break;
case UISwipeGestureRecognizerDirectionRight:
SDL_SendKeyboardKeyAutoRelease(SDL_SCANCODE_RIGHT);
SDL_SendKeyboardKeyAutoRelease(0, SDL_SCANCODE_RIGHT);
break;
}
}
+5 -5
View File
@@ -313,7 +313,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
}
if (scancode != SDL_SCANCODE_UNKNOWN) {
SDL_SendKeyboardKeyAutoRelease(scancode);
SDL_SendKeyboardKeyAutoRelease(0, scancode);
}
}
@@ -409,8 +409,8 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
size_t deleteLength = SDL_utf8strlen([[committedText substringFromIndex:matchLength] UTF8String]);
while (deleteLength > 0) {
/* Send distinct down and up events for each backspace action */
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
--deleteLength;
}
}
@@ -422,7 +422,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
* convert them to key presses */
NSUInteger i;
for (i = 0; i < pendingText.length; i++) {
SDL_SendKeyboardUnicodeKey([pendingText characterAtIndex:i]);
SDL_SendKeyboardUnicodeKey(0, [pendingText characterAtIndex:i]);
}
}
SDL_SendKeyboardText([pendingText UTF8String]);
@@ -480,7 +480,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
/* Terminates the editing session */
- (BOOL)textFieldShouldReturn:(UITextField *)_textField
{
SDL_SendKeyboardKeyAutoRelease(SDL_SCANCODE_RETURN);
SDL_SendKeyboardKeyAutoRelease(0, SDL_SCANCODE_RETURN);
if (keyboardVisible &&
SDL_GetHintBoolean(SDL_HINT_RETURN_KEY_HIDES_IME, SDL_FALSE)) {
SDL_StopTextInput();

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