Added support for the third stylus button on Android

This commit is contained in:
Sam Lantinga
2026-02-05 09:08:45 -08:00
parent 273a093032
commit cd7fc90c87
3 changed files with 12 additions and 6 deletions

View File

@@ -755,6 +755,9 @@ class SDLGenericMotionListener_API14 implements View.OnGenericMotionListener {
// BUTTON_STYLUS_PRIMARY is 2^5, so shift by 4, and apply SDL_PEN_INPUT_DOWN/SDL_PEN_INPUT_ERASER_TIP
int buttons = (event.getButtonState() >> 4) | (1 << (toolType == MotionEvent.TOOL_TYPE_STYLUS ? 0 : 30));
if ((event.getButtonState() & MotionEvent.BUTTON_TERTIARY) != 0) {
buttons |= 0x08;
}
SDLActivity.onNativePen(event.getPointerId(i), getPenDeviceType(event.getDevice()), buttons, action, x, y, p);
consumed = true;

View File

@@ -280,6 +280,9 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
// BUTTON_STYLUS_PRIMARY is 2^5, so shift by 4, and apply SDL_PEN_INPUT_DOWN/SDL_PEN_INPUT_ERASER_TIP
int buttonState = (event.getButtonState() >> 4) | (1 << (toolType == MotionEvent.TOOL_TYPE_STYLUS ? 0 : 30));
if ((event.getButtonState() & MotionEvent.BUTTON_TERTIARY) != 0) {
buttonState |= 0x08;
}
SDLActivity.onNativePen(pointerId, SDLActivity.getMotionListener().getPenDeviceType(event.getDevice()), buttonState, action, x, y, p);
} else { // MotionEvent.TOOL_TYPE_FINGER or MotionEvent.TOOL_TYPE_UNKNOWN

View File

@@ -66,12 +66,12 @@ void Android_OnPen(SDL_Window *window, int pen_id_in, SDL_PenDeviceType device_t
SDL_PenInputFlags current = SDL_GetPenStatus(pen, NULL, 0);
int diff = current ^ button;
if (diff != 0) {
// Android only exposes BUTTON_STYLUS_PRIMARY and BUTTON_STYLUS_SECONDARY
if (diff & SDL_PEN_INPUT_BUTTON_1)
SDL_SendPenButton(0, pen, window, 1, (button & SDL_PEN_INPUT_BUTTON_1) != 0);
if (diff & SDL_PEN_INPUT_BUTTON_2)
SDL_SendPenButton(0, pen, window, 2, (button & SDL_PEN_INPUT_BUTTON_2) != 0);
for (Uint8 i = 1; i <= 5; ++i) {
Uint8 mask = (1 << i);
if (diff & mask) {
SDL_SendPenButton(0, pen, window, i, (button & mask) != 0);
}
}
}
// button contains DOWN/ERASER_TIP on DOWN/UP regardless of pressed state, use action to distinguish