Browse Source

pen: Only allow one pen on Emscripten.

Same deal as the current Windows code: this "fixes" proximity but limits you
to a single pen device. But this is probably okay for most reasonable use
cases.
Ryan C. Gordon 3 weeks ago
parent
commit
3dee60d65f
1 changed files with 6 additions and 6 deletions
  1. 6 6
      src/video/emscripten/SDL_emscriptenevents.c

+ 6 - 6
src/video/emscripten/SDL_emscriptenevents.c

@@ -763,7 +763,7 @@ static void Emscripten_UpdateTouchFromEvent(SDL_WindowData *window_data, const E
 static void Emscripten_UpdatePenFromEvent(SDL_WindowData *window_data, const Emscripten_PointerEvent *event)
 static void Emscripten_UpdatePenFromEvent(SDL_WindowData *window_data, const Emscripten_PointerEvent *event)
 {
 {
     SDL_assert(event->pointer_type == PTRTYPE_PEN);
     SDL_assert(event->pointer_type == PTRTYPE_PEN);
-    const SDL_PenID pen = SDL_FindPenByHandle((void *) (size_t) event->pointerid);
+    const SDL_PenID pen = SDL_FindPenByHandle((void *) (size_t) 1);   // something > 0 for the single pen handle.
     if (pen) {
     if (pen) {
         // rescale (in case canvas is being scaled)
         // rescale (in case canvas is being scaled)
         double client_w, client_h;
         double client_w, client_h;
@@ -849,9 +849,10 @@ static void Emscripten_HandlePenEnter(SDL_WindowData *window_data, const Emscrip
 {
 {
     SDL_assert(event->pointer_type == PTRTYPE_PEN);
     SDL_assert(event->pointer_type == PTRTYPE_PEN);
 
 
-SDL_Log("PEN ENTER pointerid=%d", event->pointerid);
+    // event->pointerid is one continuous interaction; it doesn't necessarily track a specific tool over time, like the same finger's ID changed on each new touch event.
+    // as such, we only expose a single pen, and when the touch ends, we say it lost proximity instead of the calling SDL_RemovePenDevice().
 
 
-    SDL_PenID pen = SDL_FindPenByHandle((void *) (size_t) event->pointerid);
+    SDL_PenID pen = SDL_FindPenByHandle((void *) (size_t) 1);  // something > 0 for the single pen handle.
     if (pen) {
     if (pen) {
         SDL_SendPenProximity(0, pen, window_data->window, true);
         SDL_SendPenProximity(0, pen, window_data->window, true);
     } else {
     } else {
@@ -862,7 +863,7 @@ SDL_Log("PEN ENTER pointerid=%d", event->pointerid);
         peninfo.max_tilt = 90.0f;
         peninfo.max_tilt = 90.0f;
         peninfo.num_buttons = 2;
         peninfo.num_buttons = 2;
         peninfo.subtype = SDL_PEN_TYPE_PEN;
         peninfo.subtype = SDL_PEN_TYPE_PEN;
-        SDL_AddPenDevice(0, NULL, window_data->window, &peninfo, (void *) (size_t) event->pointerid, true);
+        SDL_AddPenDevice(0, NULL, window_data->window, &peninfo, (void *) (size_t) 1, true);
     }
     }
 
 
     Emscripten_UpdatePenFromEvent(window_data, event);
     Emscripten_UpdatePenFromEvent(window_data, event);
@@ -884,8 +885,7 @@ EMSCRIPTEN_KEEPALIVE void Emscripten_HandlePointerEnter(SDL_WindowData *window_d
 
 
 static void Emscripten_HandlePenLeave(SDL_WindowData *window_data, const Emscripten_PointerEvent *event)
 static void Emscripten_HandlePenLeave(SDL_WindowData *window_data, const Emscripten_PointerEvent *event)
 {
 {
-SDL_Log("PEN LEAVE pointerid=%d", event->pointerid);
-    const SDL_PenID pen = SDL_FindPenByHandle((void *) (size_t) event->pointerid);
+    const SDL_PenID pen = SDL_FindPenByHandle((void *) (size_t) 1);   // something > 0 for the single pen handle.
     if (pen) {
     if (pen) {
         Emscripten_UpdatePointerFromEvent(window_data, event);  // last data updates?
         Emscripten_UpdatePointerFromEvent(window_data, event);  // last data updates?
         SDL_SendPenProximity(0, pen, window_data->window, false);
         SDL_SendPenProximity(0, pen, window_data->window, false);