improved how it handles the multitouch

This commit is contained in:
MULTidll 2025-11-17 22:00:40 +05:30
parent ffd1717b42
commit 0e133f1534

View File

@ -2296,36 +2296,22 @@ static void PollMouseEvents(void)
{ {
CORE.Input.Mouse.currentPosition.x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; // Scale according to absRange CORE.Input.Mouse.currentPosition.x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; // Scale according to absRange
bool hasMultitouch = false; // Update single touch position only if it's active and no MT events are being used
for (int i = 1; i < MAX_TOUCH_POINTS; i++) { if (platform.touchActive[0]) {
if (platform.touchActive[i]) {
hasMultitouch = true;
break;
}
}
if (!hasMultitouch && platform.touchActive[0]) {
CORE.Input.Touch.position[0].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; CORE.Input.Touch.position[0].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width;
touchAction = 2; // TOUCH_ACTION_MOVE
} }
touchAction = 2; // TOUCH_ACTION_MOVE
} }
if (event.code == ABS_Y) if (event.code == ABS_Y)
{ {
CORE.Input.Mouse.currentPosition.y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; // Scale according to absRange CORE.Input.Mouse.currentPosition.y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; // Scale according to absRange
bool hasMultitouch = false; // Update single touch position only if it's active and no MT events are being used
for (int i = 1; i < MAX_TOUCH_POINTS; i++) { if (platform.touchActive[0]) {
if (platform.touchActive[i]) {
hasMultitouch = true;
break;
}
}
if (!hasMultitouch && platform.touchActive[0]) {
CORE.Input.Touch.position[0].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; CORE.Input.Touch.position[0].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height;
touchAction = 2; // TOUCH_ACTION_MOVE
} }
touchAction = 2; // TOUCH_ACTION_MOVE
} }
// Multitouch movement // Multitouch movement
@ -2335,6 +2321,7 @@ static void PollMouseEvents(void)
{ {
if (platform.touchSlot < MAX_TOUCH_POINTS && platform.touchActive[platform.touchSlot]) { if (platform.touchSlot < MAX_TOUCH_POINTS && platform.touchActive[platform.touchSlot]) {
CORE.Input.Touch.position[platform.touchSlot].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; CORE.Input.Touch.position[platform.touchSlot].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width;
touchAction = 2; // TOUCH_ACTION_MOVE
} }
} }
@ -2342,6 +2329,7 @@ static void PollMouseEvents(void)
{ {
if (platform.touchSlot < MAX_TOUCH_POINTS && platform.touchActive[platform.touchSlot]) { if (platform.touchSlot < MAX_TOUCH_POINTS && platform.touchActive[platform.touchSlot]) {
CORE.Input.Touch.position[platform.touchSlot].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; CORE.Input.Touch.position[platform.touchSlot].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height;
touchAction = 2; // TOUCH_ACTION_MOVE
} }
} }
@ -2353,6 +2341,7 @@ static void PollMouseEvents(void)
{ {
// Touch has started for this point // Touch has started for this point
platform.touchActive[platform.touchSlot] = true; platform.touchActive[platform.touchSlot] = true;
touchAction = 1; // TOUCH_ACTION_DOWN
} }
else else
{ {
@ -2360,8 +2349,9 @@ static void PollMouseEvents(void)
platform.touchActive[platform.touchSlot] = false; platform.touchActive[platform.touchSlot] = false;
CORE.Input.Touch.position[platform.touchSlot].x = -1; CORE.Input.Touch.position[platform.touchSlot].x = -1;
CORE.Input.Touch.position[platform.touchSlot].y = -1; CORE.Input.Touch.position[platform.touchSlot].y = -1;
touchAction = 0; // TOUCH_ACTION_UP
CompactTouchPoints(); // Note: CompactTouchPoints() will be called after all events are processed
} }
} }
} }
@ -2371,30 +2361,20 @@ static void PollMouseEvents(void)
{ {
int previousMouseLeftButtonState = platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT]; int previousMouseLeftButtonState = platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT];
bool hasMultitouch = false; if (!event.value && previousMouseLeftButtonState)
for (int i = 1; i < MAX_TOUCH_POINTS; i++) { {
if (platform.touchActive[i]) { platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 0;
hasMultitouch = true; platform.touchActive[0] = false;
break; CORE.Input.Touch.position[0].x = -1;
} CORE.Input.Touch.position[0].y = -1;
touchAction = 0; // TOUCH_ACTION_UP
} }
if (!hasMultitouch) {
if (!event.value && previousMouseLeftButtonState)
{
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 0;
platform.touchActive[0] = false;
CORE.Input.Touch.position[0].x = -1;
CORE.Input.Touch.position[0].y = -1;
touchAction = 0; // TOUCH_ACTION_UP
}
if (event.value && !previousMouseLeftButtonState) if (event.value && !previousMouseLeftButtonState)
{ {
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 1; platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 1;
platform.touchActive[0] = true; platform.touchActive[0] = true;
touchAction = 1; // TOUCH_ACTION_DOWN touchAction = 1; // TOUCH_ACTION_DOWN
}
} }
} }
@ -2408,27 +2388,17 @@ static void PollMouseEvents(void)
{ {
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = event.value; platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = event.value;
bool hasMultitouch = false; if (event.value > 0)
for (int i = 1; i < MAX_TOUCH_POINTS; i++) { {
if (platform.touchActive[i]) { platform.touchActive[0] = true;
hasMultitouch = true; touchAction = 1; // TOUCH_ACTION_DOWN
break;
}
} }
else
if (!hasMultitouch) { {
if (event.value > 0) platform.touchActive[0] = false;
{ CORE.Input.Touch.position[0].x = -1;
platform.touchActive[0] = true; CORE.Input.Touch.position[0].y = -1;
touchAction = 1; // TOUCH_ACTION_DOWN touchAction = 0; // TOUCH_ACTION_UP
}
else
{
platform.touchActive[0] = false;
CORE.Input.Touch.position[0].x = -1;
CORE.Input.Touch.position[0].y = -1;
touchAction = 0; // TOUCH_ACTION_UP
}
} }
} }
@ -2450,6 +2420,10 @@ static void PollMouseEvents(void)
if (CORE.Input.Mouse.currentPosition.y > CORE.Window.screen.height/CORE.Input.Mouse.scale.y) CORE.Input.Mouse.currentPosition.y = CORE.Window.screen.height/CORE.Input.Mouse.scale.y; if (CORE.Input.Mouse.currentPosition.y > CORE.Window.screen.height/CORE.Input.Mouse.scale.y) CORE.Input.Mouse.currentPosition.y = CORE.Window.screen.height/CORE.Input.Mouse.scale.y;
} }
// Compact touch points if any were removed
static bool needsCompaction = false;
if (touchAction == 0) needsCompaction = true; // Touch up event
// Update touch point count // Update touch point count
CORE.Input.Touch.pointCount = 0; CORE.Input.Touch.pointCount = 0;
for (int i = 0; i < MAX_TOUCH_POINTS; i++) for (int i = 0; i < MAX_TOUCH_POINTS; i++)
@ -2457,12 +2431,17 @@ static void PollMouseEvents(void)
if (platform.touchActive[i]) CORE.Input.Touch.pointCount++; if (platform.touchActive[i]) CORE.Input.Touch.pointCount++;
} }
// Debug logging for touch state (can be removed later) // Compact after counting to avoid disrupting gesture events
if (touchAction > -1) { if (needsCompaction && touchAction != 1) { // Don't compact during touch down
TRACELOG(LOG_DEBUG, "TOUCH: Action=%d, Count=%d, Active=[%d,%d,%d,%d,%d,%d,%d,%d]", CompactTouchPoints();
touchAction, CORE.Input.Touch.pointCount, needsCompaction = false;
platform.touchActive[0], platform.touchActive[1], platform.touchActive[2], platform.touchActive[3],
platform.touchActive[4], platform.touchActive[5], platform.touchActive[6], platform.touchActive[7]); // Recount after compaction
CORE.Input.Touch.pointCount = 0;
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
{
if (platform.touchActive[i]) CORE.Input.Touch.pointCount++;
}
} }
#if defined(SUPPORT_GESTURES_SYSTEM) #if defined(SUPPORT_GESTURES_SYSTEM)