Deal with fullscreen limitations under windowed Android environments (Chromebook, DeX, etc.) (Thanks Rachel!)
authorSam Lantinga <slouken@libsdl.org>
Tue, 12 Jun 2018 13:22:58 -0700
changeset 12017d8a165136edf
parent 12016 f3d8b8456e7b
child 12018 812b05d074fe
Deal with fullscreen limitations under windowed Android environments (Chromebook, DeX, etc.) (Thanks Rachel!)
src/video/SDL_video.c
src/video/android/SDL_androidwindow.c
     1.1 --- a/src/video/SDL_video.c	Tue Jun 12 14:00:15 2018 +0300
     1.2 +++ b/src/video/SDL_video.c	Tue Jun 12 13:22:58 2018 -0700
     1.3 @@ -1289,8 +1289,15 @@
     1.4  
     1.5                  /* Generate a mode change event here */
     1.6                  if (resized) {
     1.7 +#ifndef ANDROID
     1.8 +                    // Android may not resize the window to exactly what our fullscreen mode is, especially on
     1.9 +                    // windowed Android environments like the Chromebook or Samsung DeX.  Given this, we shouldn't
    1.10 +                    // use fullscreen_mode.w and fullscreen_mode.h, but rather get our current native size.  As such,
    1.11 +                    // Android's SetWindowFullscreen will generate the window event for us with the proper final size.
    1.12 +
    1.13                      SDL_SendWindowEvent(other, SDL_WINDOWEVENT_RESIZED,
    1.14                                          fullscreen_mode.w, fullscreen_mode.h);
    1.15 +#endif
    1.16                  } else {
    1.17                      SDL_OnWindowResized(other);
    1.18                  }
     2.1 --- a/src/video/android/SDL_androidwindow.c	Tue Jun 12 14:00:15 2018 +0300
     2.2 +++ b/src/video/android/SDL_androidwindow.c	Tue Jun 12 13:22:58 2018 -0700
     2.3 @@ -26,6 +26,7 @@
     2.4  #include "../SDL_sysvideo.h"
     2.5  #include "../../events/SDL_keyboard_c.h"
     2.6  #include "../../events/SDL_mouse_c.h"
     2.7 +#include "../../events/SDL_windowevents_c.h"
     2.8  
     2.9  #include "SDL_androidvideo.h"
    2.10  #include "SDL_androidwindow.h"
    2.11 @@ -101,6 +102,28 @@
    2.12  Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
    2.13  {
    2.14      Android_JNI_SetWindowStyle(fullscreen);
    2.15 +
    2.16 +    // Ensure our size matches reality after we've executed the window style change.
    2.17 +    //
    2.18 +    // It is possible that we've set width and height to the full-size display, but on
    2.19 +    // Samsung DeX or Chromebooks or other windowed Android environemtns, our window may 
    2.20 +    // still not be the full display size.
    2.21 +    //
    2.22 +    SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
    2.23 +
    2.24 +    if (!data || !data->native_window) {
    2.25 +        return;
    2.26 +    }
    2.27 +
    2.28 +    int old_w = window->w;
    2.29 +    int old_h = window->h;
    2.30 +
    2.31 +    int new_w = ANativeWindow_getWidth(data->native_window);
    2.32 +    int new_h = ANativeWindow_getHeight(data->native_window);
    2.33 +
    2.34 +    if (old_w != new_w || old_h != new_h) {
    2.35 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, new_w, new_h);
    2.36 +    }
    2.37  }
    2.38  
    2.39  void