Fix of mouse events in browser without pointer locks
authorTelpeNight <telpe.night@gmail.com>
Tue, 13 Sep 2016 00:03:44 -0700
changeset 10324efa3b17582ce
parent 10323 abfc071013af
child 10325 743e0f5e8ace
Fix of mouse events in browser without pointer locks
src/video/emscripten/SDL_emscriptenevents.c
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Tue Sep 13 00:03:43 2016 -0700
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Tue Sep 13 00:03:44 2016 -0700
     1.3 @@ -305,9 +305,10 @@
     1.4      EmscriptenPointerlockChangeEvent pointerlock_status;
     1.5  
     1.6      /* check for pointer lock */
     1.7 -    emscripten_get_pointerlock_status(&pointerlock_status);
     1.8 +    int isPointerLockSupported = emscripten_get_pointerlock_status(&pointerlock_status);
     1.9 +    int isPointerLocked = isPointerLockSupported == EMSCRIPTEN_RESULT_SUCCESS  ? pointerlock_status.isActive : SDL_FALSE;
    1.10  
    1.11 -    if (pointerlock_status.isActive) {
    1.12 +    if (isPointerLocked) {
    1.13          mx = mouseEvent->movementX;
    1.14          my = mouseEvent->movementY;
    1.15      }
    1.16 @@ -319,7 +320,7 @@
    1.17      mx = mx * (window_data->window->w / (client_w * window_data->pixel_ratio));
    1.18      my = my * (window_data->window->h / (client_h * window_data->pixel_ratio));
    1.19  
    1.20 -    SDL_SendMouseMotion(window_data->window, 0, pointerlock_status.isActive, mx, my);
    1.21 +    SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
    1.22      return 0;
    1.23  }
    1.24  
    1.25 @@ -354,16 +355,17 @@
    1.26      EmscriptenPointerlockChangeEvent pointerlock_status;
    1.27  
    1.28      /* check for pointer lock */
    1.29 -    emscripten_get_pointerlock_status(&pointerlock_status);
    1.30 +    int isPointerLockSupported = emscripten_get_pointerlock_status(&pointerlock_status);
    1.31 +    int isPointerLocked = isPointerLockSupported == EMSCRIPTEN_RESULT_SUCCESS  ? pointerlock_status.isActive : SDL_FALSE;
    1.32  
    1.33 -    if (!pointerlock_status.isActive) {
    1.34 +    if (!isPointerLocked) {
    1.35          /* rescale (in case canvas is being scaled)*/
    1.36          double client_w, client_h;
    1.37          emscripten_get_element_css_size(NULL, &client_w, &client_h);
    1.38  
    1.39          mx = mx * (window_data->window->w / (client_w * window_data->pixel_ratio));
    1.40          my = my * (window_data->window->h / (client_h * window_data->pixel_ratio));
    1.41 -        SDL_SendMouseMotion(window_data->window, 0, pointerlock_status.isActive, mx, my);
    1.42 +        SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
    1.43      }
    1.44  
    1.45      SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL);