Browse Source

Fixed right mouse button emulation when using a pen

Pen button 1 is typically used as right click. Pen button 2 (Wacom eraser) doesn't have a specific mapping, but we'll use middle click for now.

(cherry picked from commit e3df61b070ef11ae16ea4b792fe5d9596e8c55f6)
Sam Lantinga 3 months ago
parent
commit
337f012de2
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/events/SDL_pen.c

+ 10 - 1
src/events/SDL_pen.c

@@ -568,7 +568,16 @@ void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, SDL_Window *wind
             if (window && (!pen_touching || (pen_touching == instance_id))) {
                 SDL_Mouse *mouse = SDL_GetMouse();
                 if (mouse && mouse->pen_mouse_events) {
-                    SDL_SendMouseButton(timestamp, window, SDL_PEN_MOUSEID, button + 1, down);
+                    static const Uint8 mouse_buttons[] = {
+                        SDL_BUTTON_LEFT,
+                        SDL_BUTTON_RIGHT,
+                        SDL_BUTTON_MIDDLE,
+                        SDL_BUTTON_X1,
+                        SDL_BUTTON_X2
+                    };
+                    if (button < SDL_arraysize(mouse_buttons)) {
+                        SDL_SendMouseButton(timestamp, window, SDL_PEN_MOUSEID, mouse_buttons[button], down);
+                    }
                 }
             }
         }