Implement SDL_GetPenDeviceType() for Android

This commit is contained in:
Susko3
2025-05-17 15:33:30 +02:00
committed by Ryan C. Gordon
parent 23b487ceda
commit e2bbbdc515
12 changed files with 75 additions and 12 deletions

View File

@@ -137,7 +137,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativePen)(
JNIEnv *env, jclass jcls,
jint pen_id_in, jint button, jint action, jfloat x, jfloat y, jfloat p);
jint pen_id_in, jint device_type, jint button, jint action, jfloat x, jfloat y, jfloat p);
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
JNIEnv *env, jclass jcls,
@@ -235,7 +235,7 @@ static JNINativeMethod SDLActivity_tab[] = {
{ "onNativePinchUpdate", "(F)V", SDL_JAVA_INTERFACE(onNativePinchUpdate) },
{ "onNativePinchEnd", "()V", SDL_JAVA_INTERFACE(onNativePinchEnd) },
{ "onNativeMouse", "(IIFFZ)V", SDL_JAVA_INTERFACE(onNativeMouse) },
{ "onNativePen", "(IIIFFF)V", SDL_JAVA_INTERFACE(onNativePen) },
{ "onNativePen", "(IIIIFFF)V", SDL_JAVA_INTERFACE(onNativePen) },
{ "onNativeAccel", "(FFF)V", SDL_JAVA_INTERFACE(onNativeAccel) },
{ "onNativeClipboardChanged", "()V", SDL_JAVA_INTERFACE(onNativeClipboardChanged) },
{ "nativeLowMemory", "()V", SDL_JAVA_INTERFACE(nativeLowMemory) },
@@ -1431,11 +1431,11 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
// Pen
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativePen)(
JNIEnv *env, jclass jcls,
jint pen_id_in, jint button, jint action, jfloat x, jfloat y, jfloat p)
jint pen_id_in, jint device_type, jint button, jint action, jfloat x, jfloat y, jfloat p)
{
SDL_LockMutex(Android_ActivityMutex);
Android_OnPen(Android_Window, pen_id_in, button, action, x, y, p);
Android_OnPen(Android_Window, pen_id_in, device_type, button, action, x, y, p);
SDL_UnlockMutex(Android_ActivityMutex);
}

View File

@@ -1265,6 +1265,7 @@ SDL3_0.0.0 {
SDL_SavePNG_IO;
SDL_SavePNG;
SDL_GetSystemPageSize;
SDL_GetPenDeviceType;
# extra symbols go here (don't modify this line)
local: *;
};

View File

@@ -1291,3 +1291,4 @@
#define SDL_SavePNG_IO SDL_SavePNG_IO_REAL
#define SDL_SavePNG SDL_SavePNG_REAL
#define SDL_GetSystemPageSize SDL_GetSystemPageSize_REAL
#define SDL_GetPenDeviceType SDL_GetPenDeviceType_REAL

View File

@@ -1299,3 +1299,4 @@ SDL_DYNAPI_PROC(SDL_Surface*,SDL_LoadPNG,(const char *a),(a),return)
SDL_DYNAPI_PROC(bool,SDL_SavePNG_IO,(SDL_Surface *a,SDL_IOStream *b,bool c),(a,b,c),return)
SDL_DYNAPI_PROC(bool,SDL_SavePNG,(SDL_Surface *a,const char *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetSystemPageSize,(void),(),return)
SDL_DYNAPI_PROC(SDL_PenDeviceType,SDL_GetPenDeviceType,(SDL_PenID a),(a),return)

View File

@@ -199,6 +199,15 @@ SDL_PenInputFlags SDL_GetPenStatus(SDL_PenID instance_id, float *axes, int num_a
return result;
}
SDL_PenDeviceType SDL_GetPenDeviceType(SDL_PenID instance_id)
{
SDL_LockRWLockForReading(pen_device_rwlock);
const SDL_Pen *pen = FindPenByInstanceId(instance_id);
const SDL_PenDeviceType result = pen ? pen->info.device_type : SDL_PEN_DEVICE_TYPE_INVALID;
SDL_UnlockRWLock(pen_device_rwlock);
return result;
}
SDL_PenCapabilityFlags SDL_GetPenCapabilityFromAxis(SDL_PenAxis axis)
{
// the initial capability bits happen to match up, but as

View File

@@ -36,6 +36,8 @@ typedef Uint32 SDL_PenCapabilityFlags;
#define SDL_PEN_CAPABILITY_TANGENTIAL_PRESSURE (1u << 6) /**< Provides barrel pressure on SDL_PEN_AXIS_TANGENTIAL_PRESSURE. */
#define SDL_PEN_CAPABILITY_ERASER (1u << 7) /**< Pen also has an eraser tip. */
// Rename before making this public as it clashes with SDL_PenDeviceType.
// Prior art in Android calls this "tool type".
typedef enum SDL_PenSubtype
{
SDL_PEN_TYPE_UNKNOWN, /**< Unknown pen device */
@@ -53,6 +55,7 @@ typedef struct SDL_PenInfo
Uint32 wacom_id; /**< For Wacom devices: wacom tool type ID, otherwise 0 (useful e.g. with libwacom) */
int num_buttons; /**< Number of pen buttons (not counting the pen tip), or -1 if unknown. */
SDL_PenSubtype subtype; /**< type of pen device */
SDL_PenDeviceType device_type;
} SDL_PenInfo;
// Backend calls this when a new pen device is hotplugged, plus once for each pen already connected at startup.

View File

@@ -33,7 +33,7 @@
#define ACTION_POINTER_UP 6
#define ACTION_HOVER_EXIT 10
void Android_OnPen(SDL_Window *window, int pen_id_in, int button, int action, float x, float y, float p)
void Android_OnPen(SDL_Window *window, int pen_id_in, SDL_PenDeviceType device_type, int button, int action, float x, float y, float p)
{
if (!window) {
return;
@@ -50,6 +50,7 @@ void Android_OnPen(SDL_Window *window, int pen_id_in, int button, int action, fl
peninfo.capabilities = SDL_PEN_CAPABILITY_PRESSURE | SDL_PEN_CAPABILITY_ERASER;
peninfo.num_buttons = 2;
peninfo.subtype = SDL_PEN_TYPE_PEN;
peninfo.device_type = device_type;
pen = SDL_AddPenDevice(0, NULL, &peninfo, (void *) (size_t) pen_id_in);
if (!pen) {
SDL_Log("error: can't add a pen device %d", pen_id_in);

View File

@@ -22,4 +22,4 @@
#include "SDL_androidvideo.h"
extern void Android_OnPen(SDL_Window *window, int pen_id_in, int button, int action, float x, float y, float p);
extern void Android_OnPen(SDL_Window *window, int pen_id_in, SDL_PenDeviceType device_type, int button, int action, float x, float y, float p);