emscripten: force resize event when pixel ratio changes
authorSebastian Krzyszkowiak
Sat, 16 Mar 2019 19:08:59 -0700
changeset 12652b3c652757f97
parent 12651 d188272453ce
child 12654 cd9fe6a3126c
emscripten: force resize event when pixel ratio changes
Without this, applications can't react to changed canvas size on window zoom.
src/video/emscripten/SDL_emscriptenevents.c
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Sat Mar 16 19:07:34 2019 -0700
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Sat Mar 16 19:08:59 2019 -0700
     1.3 @@ -586,10 +586,14 @@
     1.4  Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
     1.5  {
     1.6      SDL_WindowData *window_data = userData;
     1.7 +    SDL_bool force = SDL_FALSE;
     1.8  
     1.9      /* update pixel ratio */
    1.10      if (window_data->window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
    1.11 -        window_data->pixel_ratio = emscripten_get_device_pixel_ratio();
    1.12 +        if (window_data->pixel_ratio != emscripten_get_device_pixel_ratio()) {
    1.13 +            window_data->pixel_ratio = emscripten_get_device_pixel_ratio();
    1.14 +            force = SDL_TRUE;
    1.15 +        }
    1.16      }
    1.17  
    1.18      if(!(window_data->window->flags & FULLSCREEN_MASK))
    1.19 @@ -611,6 +615,12 @@
    1.20                  emscripten_set_element_css_size(NULL, w, h);
    1.21              }
    1.22  
    1.23 +            if (force) {
    1.24 +               /* force the event to trigger, so pixel ratio changes can be handled */
    1.25 +               window_data->window->w = 0;
    1.26 +               window_data->window->h = 0;
    1.27 +            }
    1.28 +
    1.29              SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
    1.30          }
    1.31      }