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,37 +2296,23 @@ 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
bool hasMultitouch = false;
for (int i = 1; i < MAX_TOUCH_POINTS; i++) {
if (platform.touchActive[i]) {
hasMultitouch = true;
break;
}
}
if (!hasMultitouch && platform.touchActive[0]) {
// Update single touch position only if it's active and no MT events are being used
if (platform.touchActive[0]) {
CORE.Input.Touch.position[0].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width;
}
touchAction = 2; // TOUCH_ACTION_MOVE
}
}
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
bool hasMultitouch = false;
for (int i = 1; i < MAX_TOUCH_POINTS; i++) {
if (platform.touchActive[i]) {
hasMultitouch = true;
break;
}
}
if (!hasMultitouch && platform.touchActive[0]) {
// Update single touch position only if it's active and no MT events are being used
if (platform.touchActive[0]) {
CORE.Input.Touch.position[0].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height;
}
touchAction = 2; // TOUCH_ACTION_MOVE
}
}
// Multitouch movement
if (event.code == ABS_MT_SLOT) platform.touchSlot = event.value; // Remember the slot number for the folowing events
@ -2335,6 +2321,7 @@ static void PollMouseEvents(void)
{
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;
touchAction = 2; // TOUCH_ACTION_MOVE
}
}
@ -2342,6 +2329,7 @@ static void PollMouseEvents(void)
{
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;
touchAction = 2; // TOUCH_ACTION_MOVE
}
}
@ -2353,6 +2341,7 @@ static void PollMouseEvents(void)
{
// Touch has started for this point
platform.touchActive[platform.touchSlot] = true;
touchAction = 1; // TOUCH_ACTION_DOWN
}
else
{
@ -2360,8 +2349,9 @@ static void PollMouseEvents(void)
platform.touchActive[platform.touchSlot] = false;
CORE.Input.Touch.position[platform.touchSlot].x = -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,15 +2361,6 @@ static void PollMouseEvents(void)
{
int previousMouseLeftButtonState = platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT];
bool hasMultitouch = false;
for (int i = 1; i < MAX_TOUCH_POINTS; i++) {
if (platform.touchActive[i]) {
hasMultitouch = true;
break;
}
}
if (!hasMultitouch) {
if (!event.value && previousMouseLeftButtonState)
{
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 0;
@ -2396,7 +2377,6 @@ static void PollMouseEvents(void)
touchAction = 1; // TOUCH_ACTION_DOWN
}
}
}
}
@ -2408,15 +2388,6 @@ static void PollMouseEvents(void)
{
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = event.value;
bool hasMultitouch = false;
for (int i = 1; i < MAX_TOUCH_POINTS; i++) {
if (platform.touchActive[i]) {
hasMultitouch = true;
break;
}
}
if (!hasMultitouch) {
if (event.value > 0)
{
platform.touchActive[0] = true;
@ -2430,7 +2401,6 @@ static void PollMouseEvents(void)
touchAction = 0; // TOUCH_ACTION_UP
}
}
}
if (event.code == BTN_RIGHT) platform.currentButtonStateEvdev[MOUSE_BUTTON_RIGHT] = event.value;
if (event.code == BTN_MIDDLE) platform.currentButtonStateEvdev[MOUSE_BUTTON_MIDDLE] = event.value;
@ -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;
}
// Compact touch points if any were removed
static bool needsCompaction = false;
if (touchAction == 0) needsCompaction = true; // Touch up event
// Update touch point count
CORE.Input.Touch.pointCount = 0;
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++;
}
// Debug logging for touch state (can be removed later)
if (touchAction > -1) {
TRACELOG(LOG_DEBUG, "TOUCH: Action=%d, Count=%d, Active=[%d,%d,%d,%d,%d,%d,%d,%d]",
touchAction, CORE.Input.Touch.pointCount,
platform.touchActive[0], platform.touchActive[1], platform.touchActive[2], platform.touchActive[3],
platform.touchActive[4], platform.touchActive[5], platform.touchActive[6], platform.touchActive[7]);
// Compact after counting to avoid disrupting gesture events
if (needsCompaction && touchAction != 1) { // Don't compact during touch down
CompactTouchPoints();
needsCompaction = false;
// 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)