Skip to content

Commit 58ae80a

Browse files
committed
Fixed occasional frozen touches on windows.
1 parent ef15e04 commit 58ae80a

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

External/WindowsTouch/WindowsTouch.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void decodeWin8Touches(UINT msg, WPARAM wParam, LPARAM lParam)
104104
ScreenToClient(_currentWindow, &p);
105105

106106
Vector2 position = Vector2(((float)p.x - _offsetX) * _scaleX, _screenHeight - ((float)p.y - _offsetY) * _scaleY);
107-
PointerData data;
107+
PointerData data {};
108108
data.pointerFlags = pointerInfo.pointerFlags;
109109
data.changedButtons = pointerInfo.ButtonChangeType;
110110

@@ -156,7 +156,7 @@ void decodeWin7Touches(UINT msg, WPARAM wParam, LPARAM lParam)
156156
ScreenToClient(_currentWindow, &p);
157157

158158
Vector2 position = Vector2(((float)p.x - _offsetX) * _scaleX, _screenHeight - ((float)p.y - _offsetY) * _scaleY);
159-
PointerData data;
159+
PointerData data {};
160160

161161
if ((touch.dwFlags & TOUCHEVENTF_DOWN) != 0)
162162
{
@@ -165,7 +165,7 @@ void decodeWin7Touches(UINT msg, WPARAM wParam, LPARAM lParam)
165165
}
166166
else if ((touch.dwFlags & TOUCHEVENTF_UP) != 0)
167167
{
168-
msg = WM_POINTERUP;
168+
msg = WM_POINTERLEAVE;
169169
data.changedButtons = POINTER_CHANGE_FIRSTBUTTON_UP;
170170
}
171171
else if ((touch.dwFlags & TOUCHEVENTF_MOVE) != 0)

Source/Assets/TouchScript/Scripts/InputSources/InputHandlers/WindowsPointerHandlers.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public virtual bool UpdateInput()
262262
public virtual void UpdateResolution()
263263
{
264264
setScaling();
265-
TouchManager.Instance.CancelPointer(mousePointer.Id);
265+
if (mousePointer != null) TouchManager.Instance.CancelPointer(mousePointer.Id);
266266
}
267267

268268
/// <inheritdoc />
@@ -500,24 +500,27 @@ private void nativePointer(int id, PointerEvent evt, PointerType type, Vector2 p
500500
}
501501
break;
502502
case PointerType.Touch:
503+
TouchPointer touchPointer;
503504
switch (evt)
504505
{
505-
// Enter/Leave logic is handles in Down/Up
506506
case PointerEvent.Enter:
507+
break;
507508
case PointerEvent.Leave:
509+
// Sometimes Windows might not send Up, so have to execute touch release logic here.
510+
// Has been working fine on test devices so far.
511+
if (winTouchToInternalId.TryGetValue(id, out touchPointer))
512+
{
513+
winTouchToInternalId.Remove(id);
514+
internalRemoveTouchPointer(touchPointer);
515+
}
508516
break;
509517
case PointerEvent.Down:
510-
TouchPointer touchPointer = internalAddTouchPointer(position);
518+
touchPointer = internalAddTouchPointer(position);
511519
touchPointer.Rotation = getTouchRotation(ref data);
512520
touchPointer.Pressure = getTouchPressure(ref data);
513521
winTouchToInternalId.Add(id, touchPointer);
514522
break;
515523
case PointerEvent.Up:
516-
if (winTouchToInternalId.TryGetValue(id, out touchPointer))
517-
{
518-
winTouchToInternalId.Remove(id);
519-
internalRemoveTouchPointer(touchPointer);
520-
}
521524
break;
522525
case PointerEvent.Update:
523526
if (!winTouchToInternalId.TryGetValue(id, out touchPointer)) return;

0 commit comments

Comments
 (0)