mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-29 21:07:23 +02:00
pen: Only create touch emulation device when a pen is present
This commit is contained in:
committed by
Ryan C. Gordon
parent
e1e6cbe6ec
commit
1aa72247af
@@ -194,16 +194,9 @@ static void SDLCALL SDL_PenTouchEventsChanged(void *userdata, const char *name,
|
||||
|
||||
mouse->pen_touch_events = SDL_GetStringBoolean(hint, true);
|
||||
|
||||
if (mouse->pen_touch_events) {
|
||||
if (!mouse->added_pen_touch_device) {
|
||||
SDL_AddTouch(SDL_PEN_TOUCHID, SDL_TOUCH_DEVICE_DIRECT, "pen_input");
|
||||
mouse->added_pen_touch_device = true;
|
||||
}
|
||||
} else {
|
||||
if (mouse->added_pen_touch_device) {
|
||||
SDL_DelTouch(SDL_PEN_TOUCHID);
|
||||
mouse->added_pen_touch_device = false;
|
||||
}
|
||||
if (!mouse->pen_touch_events && mouse->added_pen_touch_device) {
|
||||
SDL_DelTouch(SDL_PEN_TOUCHID);
|
||||
mouse->added_pen_touch_device = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -228,6 +228,7 @@ SDL_PenID SDL_AddPenDevice(Uint64 timestamp, const char *name, SDL_Window *windo
|
||||
|
||||
SDL_LockRWLockForWriting(pen_device_rwlock);
|
||||
|
||||
bool first_device = false;
|
||||
SDL_Pen *pen = NULL;
|
||||
void *ptr = SDL_realloc(pen_devices, (pen_device_count + 1) * sizeof (*pen));
|
||||
if (ptr) {
|
||||
@@ -236,6 +237,8 @@ SDL_PenID SDL_AddPenDevice(Uint64 timestamp, const char *name, SDL_Window *windo
|
||||
pen = &pen_devices[pen_device_count];
|
||||
pen_device_count++;
|
||||
|
||||
first_device = (pen_device_count == 1);
|
||||
|
||||
SDL_zerop(pen);
|
||||
pen->instance_id = result;
|
||||
pen->name = namecpy;
|
||||
@@ -251,6 +254,14 @@ SDL_PenID SDL_AddPenDevice(Uint64 timestamp, const char *name, SDL_Window *windo
|
||||
SDL_free(namecpy);
|
||||
}
|
||||
|
||||
if (first_device) {
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
if (mouse->pen_touch_events && !mouse->added_pen_touch_device) {
|
||||
SDL_AddTouch(SDL_PEN_TOUCHID, SDL_TOUCH_DEVICE_DIRECT, "pen_input");
|
||||
mouse->added_pen_touch_device = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (result && in_proximity) {
|
||||
SDL_SendPenProximity(timestamp, result, window, true, true);
|
||||
}
|
||||
@@ -267,6 +278,7 @@ void SDL_RemovePenDevice(Uint64 timestamp, SDL_Window *window, SDL_PenID instanc
|
||||
SDL_SendPenProximity(timestamp, instance_id, window, false, true); // bye bye
|
||||
|
||||
SDL_LockRWLockForWriting(pen_device_rwlock);
|
||||
bool last_device = false;
|
||||
SDL_Pen *pen = FindPenByInstanceId(instance_id);
|
||||
if (pen) {
|
||||
SDL_free(pen->name);
|
||||
@@ -288,9 +300,18 @@ void SDL_RemovePenDevice(Uint64 timestamp, SDL_Window *window, SDL_PenID instanc
|
||||
} else {
|
||||
SDL_free(pen_devices);
|
||||
pen_devices = NULL;
|
||||
last_device = true;
|
||||
}
|
||||
}
|
||||
SDL_UnlockRWLock(pen_device_rwlock);
|
||||
|
||||
if (last_device) {
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
if (mouse->added_pen_touch_device) {
|
||||
SDL_DelTouch(SDL_PEN_TOUCHID);
|
||||
mouse->added_pen_touch_device = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This presumably is happening during video quit, so we don't send PROXIMITY_OUT events here.
|
||||
|
||||
Reference in New Issue
Block a user