distribution/packages/graphics/SDL2/patches/RK3566/0004-fix-touch-mouse.patch

75 lines
3.1 KiB
Diff
Raw Normal View History

diff -rupN SDL2.orig/src/events/SDL_touch.c SDL2-2.28.1/src/events/SDL_touch.c
--- SDL2.orig/src/events/SDL_touch.c 2023-07-01 17:04:05.000000000 +0000
+++ SDL2-2.28.1/src/events/SDL_touch.c 2023-07-26 00:04:30.039436068 +0000
@@ -34,6 +34,7 @@ static SDL_Touch **SDL_touchDevices = NU
#define SYNTHESIZE_TOUCH_TO_MOUSE 1
#if SYNTHESIZE_TOUCH_TO_MOUSE
+static SDL_bool cursor_init = SDL_FALSE;
static SDL_bool finger_touching = SDL_FALSE;
static SDL_FingerID track_fingerid;
static SDL_TouchID track_touchid;
@@ -245,6 +246,11 @@ int SDL_SendTouch(SDL_TouchID id, SDL_Fi
return -1;
}
+ if (!window) {
+ // Fallback to the main application window.
+ window = SDL_GetWindowFromID(1);
+ }
+
mouse = SDL_GetMouse();
#if SYNTHESIZE_TOUCH_TO_MOUSE
@@ -259,6 +265,13 @@ int SDL_SendTouch(SDL_TouchID id, SDL_Fi
/* FIXME: maybe we should only restrict to a few SDL_TouchDeviceType */
if (id != SDL_MOUSE_TOUCHID) {
if (window) {
+ if (cursor_init == SDL_FALSE) {
+ // TODO - Initialization hack to reset cursor position to <0, 0>
+ SDL_SendMouseMotion(window, 0, SDL_TRUE, -window->w, -window->h);
+ mouse->x = 0; mouse->y = 0;
+ x = 0.0f; y = 0.0f;
+ cursor_init = SDL_TRUE;
+ }
if (down) {
if (finger_touching == SDL_FALSE) {
int pos_x = (int)(x * (float)window->w);
@@ -275,12 +288,12 @@ int SDL_SendTouch(SDL_TouchID id, SDL_Fi
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(window, 0, 0, pos_x, pos_y);
+ SDL_SendMouseButton(window, 0, 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(window, 0, SDL_RELEASED, SDL_BUTTON_LEFT);
}
}
}
@@ -374,6 +387,11 @@ int SDL_SendTouchMotion(SDL_TouchID id,
return -1;
}
+ if (!window) {
+ // Fallback to the main application window.
+ window = SDL_GetWindowFromID(1);
+ }
+
mouse = SDL_GetMouse();
#if SYNTHESIZE_TOUCH_TO_MOUSE
@@ -397,7 +415,7 @@ int SDL_SendTouchMotion(SDL_TouchID id,
if (pos_y > window->h - 1) {
pos_y = window->h - 1;
}
- SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
+ SDL_SendMouseMotion(window, 0, 0, pos_x, pos_y);
}
}
}