SDL: Ignore the first hover event with a stale position on iOS

From 70d436389095709f5a4341352d3cc6be7b486bd1 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 25 Apr 2026 07:24:53 -0700
Subject: [PATCH] Ignore the first hover event with a stale position on iOS

Fixes https://github.com/libsdl-org/SDL/issues/15450

(cherry picked from commit 3c02de2f7cd4c42eaa71f9a0ad9e7d9dfa26b000)
---
 src/video/uikit/SDL_uikitpen.m | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/video/uikit/SDL_uikitpen.m b/src/video/uikit/SDL_uikitpen.m
index f2975c4e31259..ba4c629f1ba82 100644
--- a/src/video/uikit/SDL_uikitpen.m
+++ b/src/video/uikit/SDL_uikitpen.m
@@ -124,6 +124,11 @@ static void UIKit_HandlePenAxes(SDL_Window *window, NSTimeInterval nstimestamp,
         // rotation is in radians, and only available on a later iOS.
         const float rotation = rollAngle * radians_to_degrees;  // !!! FIXME: this might need adjustment, I don't have a pencil that supports it.
 
+        if (force == 0.0f && (SDL_GetPenStatus(penId, NULL, 0) & SDL_PEN_INPUT_DOWN)) {
+            // The first hover as the pen is being released has a stale position, so ignore it
+            return;
+        }
+
         SDL_SendPenMotion(timestamp, penId, window, point->x, point->y);
         SDL_SendPenAxis(timestamp, penId, window, SDL_PEN_AXIS_PRESSURE, pressure);
         SDL_SendPenAxis(timestamp, penId, window, SDL_PEN_AXIS_XTILT, xtilt);