Changing SDL_WINDOW_RESIZABLE of an existing window

Hi.
I’m trying to change the value of the SDL_WINDOW_RESIZABLE flag during runtime, using SDL_SetWindowResizable. But the window is not changing it’s behaviour.

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 destroying the windows and recreating it with the appropriate value on the RESIZABLE flag.
But is seems a little too much, is there a way to change the setting and force the change of the behaviour without having to recreate it?

I tested a bit more… If I read the flags before and after the 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?

Hi Ugh,

On Android/SDL2, It don’t think it’s currently possible to change orientation capabilities at runtime. (eg. ‘locked’ vs non ‘locked orientation’).

But you could be able to do by overloading the java method:
public void setOrientationBis(int w, int h, boolean resizable, String hint)
in ‘SDLActivity.java’ and calling it with correct parameter.

you can do that with JNI code.

you may be able to do that without JNI, if you use
SDL_AndroidSendMessage(Uint32 command, int param); (in SDL_system.h )
and add some specific user message in the java side .

1 Like

Thank you for your answer Sylvain.

I already tried to use Android’s functions for this issue, but with underwhelming results… I may have not fully explored the issue but I even tried manipulating the screen size passed to SDL, trying to trick it to believe the size had not changed :smiley:
It didn’t work, I got the idea that SDL is getting it’s data directly from the hardware (accelerometer). Not sure if I’m right, but from my experiments, I got that impression.
That’s the reason I wanted to go down this path, using SDL_SetWindowResizable. Unfortunately it’s also not working, and the only alternative I have is destroying and rebuilding the window with the new flag value. Of course this is a pain as I have to rebuild all the textures…

@Ugh
ok, I’ve just added and tested it, please give also a try:

It’s working in my test app, I’ll now try to adapt to the main project.
I’ll keep in touch if something seems off.

Thank you very much, you just saved me a few headaches, for sure.

EDIT: Working also in the main project. Thank you, was exactly what I was looking for.