mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-08-28 01:21:35 +00:00
Updated raw input events to match SDL style
Also added raw keyboard events, and implemented raw input events on iOS, OpenBSD console, Linux console, and X11
This commit is contained in:
@@ -187,7 +187,9 @@ static void OnGCKeyboardConnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0
|
||||
SDL_AddKeyboard(keyboardID, NULL, true);
|
||||
|
||||
keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput *kbrd, GCControllerButtonInput *key, GCKeyCode keyCode, BOOL pressed) {
|
||||
SDL_SendKeyboardKey(0, keyboardID, 0, (SDL_Scancode)keyCode, pressed);
|
||||
Uint64 timestamp = SDL_GetTicksNS();
|
||||
SDL_SendRawKeyboardKey(timestamp, keyboardID, 0, (SDL_Scancode)keyCode, pressed);
|
||||
SDL_SendKeyboardKey(timestamp, keyboardID, 0, (SDL_Scancode)keyCode, pressed);
|
||||
};
|
||||
|
||||
dispatch_queue_t queue = dispatch_queue_create("org.libsdl.input.keyboard", DISPATCH_QUEUE_SERIAL);
|
||||
@@ -318,7 +320,9 @@ static bool SetGCMouseRelativeMode(bool enabled)
|
||||
|
||||
static void OnGCMouseButtonChanged(SDL_MouseID mouseID, Uint8 button, BOOL pressed)
|
||||
{
|
||||
SDL_SendMouseButton(0, SDL_GetMouseFocus(), mouseID, button, pressed);
|
||||
Uint64 timestamp = SDL_GetTicksNS();
|
||||
SDL_SendRawMouseButton(timestamp, mouseID, button, pressed);
|
||||
SDL_SendMouseButton(timestamp, SDL_GetMouseFocus(), mouseID, button, pressed);
|
||||
}
|
||||
|
||||
static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0))
|
||||
@@ -346,12 +350,19 @@ 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(0, SDL_GetMouseFocus(), mouseID, 1, deltaX, -deltaY);
|
||||
}
|
||||
Uint64 timestamp = SDL_GetTicksNS();
|
||||
|
||||
// FIXME: Do we get non-integer deltas here?
|
||||
SDL_SendRawMouseMotion(timestamp, mouseID, (int)deltaX, (int)-deltaY, 1.0f, 1.0f);
|
||||
|
||||
if (SDL_GCMouseRelativeMode()) {
|
||||
SDL_SendMouseMotion(timestamp, SDL_GetMouseFocus(), mouseID, true, deltaX, -deltaY);
|
||||
}
|
||||
};
|
||||
|
||||
mouse.mouseInput.scroll.valueChangedHandler = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) {
|
||||
Uint64 timestamp = SDL_GetTicksNS();
|
||||
|
||||
/* Raw scroll values come in here, vertical values in the first axis, horizontal values in the second axis.
|
||||
* The vertical values are negative moving the mouse wheel up and positive moving it down.
|
||||
* The horizontal values are negative moving the mouse wheel left and positive moving it right.
|
||||
@@ -359,12 +370,16 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
|
||||
*/
|
||||
float vertical = -xValue;
|
||||
float horizontal = yValue;
|
||||
|
||||
// FIXME: Do we get non-integer deltas here?
|
||||
SDL_SendRawMouseWheel(timestamp, mouseID, (int)horizontal, (int)vertical, 1.0f, 1.0f);
|
||||
|
||||
if (mouse_scroll_direction == SDL_MOUSEWHEEL_FLIPPED) {
|
||||
// Since these are raw values, we need to flip them ourselves
|
||||
vertical = -vertical;
|
||||
horizontal = -horizontal;
|
||||
}
|
||||
SDL_SendMouseWheel(0, SDL_GetMouseFocus(), mouseID, horizontal, vertical, mouse_scroll_direction);
|
||||
SDL_SendMouseWheel(timestamp, SDL_GetMouseFocus(), mouseID, horizontal, vertical, mouse_scroll_direction);
|
||||
};
|
||||
UpdateScrollDirection();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user