Fixed bug 4581 - mouse events with SDL_TOUCH_MOUSEID make window lost focus
authorSylvain Becker <sylvain.becker@gmail.com>
Mon, 08 Apr 2019 21:27:24 +0200
changeset 127001223f50edde3
parent 12699 c6356921b02b
child 12701 3477a301a5a8
Fixed bug 4581 - mouse events with SDL_TOUCH_MOUSEID make window lost focus
Virtual mouse events should never leave the window or change focus for single window applications.
src/events/SDL_touch.c
     1.1 --- a/src/events/SDL_touch.c	Mon Apr 08 13:43:48 2019 +0200
     1.2 +++ b/src/events/SDL_touch.c	Mon Apr 08 21:27:24 2019 +0200
     1.3 @@ -257,12 +257,18 @@
     1.4                          if (finger_touching == SDL_FALSE) {
     1.5                              int pos_x = (int)(x * (float)window->w);
     1.6                              int pos_y = (int)(y * (float)window->h);
     1.7 -                            SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
     1.8 -                            SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
     1.9 +                            if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) {
    1.10 +                                SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    1.11 +                                SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.12 +                            }
    1.13                          }
    1.14                      } else {
    1.15                          if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
    1.16 -                            SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.17 +                            int pos_x = (int)(x * (float)window->w);
    1.18 +                            int pos_y = (int)(y * (float)window->h);
    1.19 +                            if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) {
    1.20 +                                SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.21 +                            }
    1.22                          }
    1.23                      }
    1.24                  }
    1.25 @@ -355,7 +361,9 @@
    1.26                      if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
    1.27                          int pos_x = (int)(x * (float)window->w);
    1.28                          int pos_y = (int)(y * (float)window->h);
    1.29 -                        SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    1.30 +                        if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) {
    1.31 +                            SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    1.32 +                        }
    1.33                      }
    1.34                  }
    1.35              }