ソースを参照

mouse: Clean up virtual touch devices as appropriate.

Ryan C. Gordon 8 ヶ月 前
コミット
ebb24eedc8
2 ファイル変更28 行追加2 行削除
  1. 26 2
      src/events/SDL_mouse.c
  2. 2 0
      src/events/SDL_mouse_c.h

+ 26 - 2
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);

+ 2 - 0
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