diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 932cf13610..429cc4e97b 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -169,7 +169,15 @@ static void SDLCALL SDL_MouseTouchEventsChanged(void *userdata, const char *name mouse->mouse_touch_events = SDL_GetStringBoolean(hint, default_value); if (mouse->mouse_touch_events) { - SDL_AddTouch(SDL_MOUSE_TOUCHID, SDL_TOUCH_DEVICE_DIRECT, "mouse_input"); + if (!mouse->added_mouse_touch_device) { + SDL_AddTouch(SDL_MOUSE_TOUCHID, SDL_TOUCH_DEVICE_DIRECT, "mouse_input"); + mouse->added_mouse_touch_device = true; + } + } else { + if (mouse->added_mouse_touch_device) { + SDL_DelTouch(SDL_MOUSE_TOUCHID); + mouse->added_mouse_touch_device = false; + } } } @@ -187,7 +195,15 @@ static void SDLCALL SDL_PenTouchEventsChanged(void *userdata, const char *name, mouse->pen_touch_events = SDL_GetStringBoolean(hint, true); if (mouse->pen_touch_events) { - SDL_AddTouch(SDL_PEN_TOUCHID, SDL_TOUCH_DEVICE_DIRECT, "pen_input"); + 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; + } } } @@ -1010,6 +1026,14 @@ void SDL_QuitMouse(void) SDL_Cursor *cursor, *next; SDL_Mouse *mouse = SDL_GetMouse(); + if (mouse->added_mouse_touch_device) { + SDL_DelTouch(SDL_MOUSE_TOUCHID); + } + + if (mouse->added_pen_touch_device) { + SDL_DelTouch(SDL_PEN_TOUCHID); + } + if (mouse->CaptureMouse) { SDL_CaptureMouse(false); SDL_UpdateMouseCapture(true); diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index 01974d9a87..43cc5207da 100644 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -121,6 +121,8 @@ typedef struct bool pen_mouse_events; bool pen_touch_events; bool was_touch_mouse_events; // Was a touch-mouse event pending? + bool added_mouse_touch_device; // did we SDL_AddTouch() a virtual touch device for the mouse? + bool added_pen_touch_device; // did we SDL_AddTouch() a virtual touch device for pens? #ifdef SDL_PLATFORM_VITA Uint8 vita_touch_mouse_device; #endif