Search code examples
androidcsdl

Changing SDL_WINDOW_RESIZABLE of an existing window


I’m trying to change the value of the SDL_WINDOW_RESIZABLE flag during runtime, using SDL_SetWindowResizable. But the window is not changing its behavior.

I want to make my app (Android) responsive to the changes on the auto-rotation setting, and the only way I’m able to do that, for now, is by destroying the window and recreating it with the appropriate value on the RESIZABLE flag. But it seems a little too much, is there a way to change the setting and force the change of the behavior without having to recreate it?

[EDIT:] I tested a bit more... If I read the flags before and after the SDL_SetWindowResizable.

SDL_SetWindowResizable, there's no change at all... 
if (os_android_isOrientationEnabled()) {
    SDL_SetWindowResizable(gWindow, SDL_TRUE);
    uint32_t flgs=SDL_GetWindowFlags(gWindow);
    __android_log_print(ANDROID_LOG_DEBUG,"TXT", "Debug %08x" ,(flgs&SDL_WINDOW_RESIZABLE));
    }
else {
    SDL_SetWindowResizable(gWindow, SDL_FALSE);
    uint32_t flgs=SDL_GetWindowFlags(gWindow);
    __android_log_print(ANDROID_LOG_DEBUG,"TXT", "Debug %08x" ,(flgs&SDL_WINDOW_RESIZABLE));
}

Same result all the time.

2022-03-22 10:46:26.559 29164-29247/com.example.texturerender D/TXT: Debug 00000020
2022-03-22 10:47:03.464 29164-29247/com.example.texturerender D/TXT: Debug 00000020

No matter if if sets RESIZABLE to true or false...

I even tried to set fullscreen to 0, before doing the resizable, as in the documentation states that it won't work in a fullscreen window.

if (os_android_isOrientationEnabled()) {
    SDL_SetWindowFullscreen(gWindow,0);
    SDL_SetWindowResizable(gWindow, SDL_TRUE);
    SDL_SetWindowFullscreen(gWindow,SDL_WINDOW_FULLSCREEN_DESKTOP);
    uint32_t flgs=SDL_GetWindowFlags(gWindow);
    __android_log_print(ANDROID_LOG_DEBUG,"TXT", "Debug %08x" ,(flgs&SDL_WINDOW_RESIZABLE));
}
else {
    SDL_SetWindowFullscreen(gWindow,0);
    SDL_SetWindowResizable(gWindow, SDL_FALSE);
    SDL_SetWindowFullscreen(gWindow,SDL_WINDOW_FULLSCREEN_DESKTOP);
    uint32_t flgs=SDL_GetWindowFlags(gWindow);
    __android_log_print(ANDROID_LOG_DEBUG,"TXT", "Debug %08x" ,(flgs&SDL_WINDOW_RESIZABLE));
}

Is this not working for Android, or am I missing something?


Solution

  • A patch was just released that fixes SDL_SetWindowResizable for Android: https://github.com/libsdl-org/SDL/commit/f5a980448ed3a525a68cd844e37f9384c21e7e8e

    It's necessary to set Fullscreen to 0 before changing the resizable flag.