Skip to content

Android restore fullscreen after resume#15218

Open
Farmer-Markus wants to merge 1 commit intolibsdl-org:SDL2from
Farmer-Markus:SDL2
Open

Android restore fullscreen after resume#15218
Farmer-Markus wants to merge 1 commit intolibsdl-org:SDL2from
Farmer-Markus:SDL2

Conversation

@Farmer-Markus
Copy link

Description

Just a small fix to reapply the full screen mode after resuming if full screen flags are set.

Always had issues when android would send an window hide event to the sdl java activity which would then exit full screen mode and won't restore it after resuming.

@slouken slouken requested a review from 1bsyl March 16, 2026 22:14
@slouken
Copy link
Collaborator

slouken commented Mar 16, 2026

@1bsyl, does this seem correct? If so, should we do something similar in SDL3?

@1bsyl
Copy link
Contributor

1bsyl commented Mar 17, 2026

If we do this in SDL2, this has also to be done in the non-block function too.
( Android_PumpEvents_NonBlocking(_THIS) )

I wanted to tested it ... but I couldn't get SDL2 compiled on Android ...
what the fastest command to get testsprite2 running ?

On SDL3, it seems to works correctly both with RPC branch and main. Not sure why SDL2 has an issue...

@madebr
Copy link
Contributor

madebr commented Mar 17, 2026

I wanted to tested it ... but I couldn't get SDL2 compiled on Android ... what the fastest command to get testsprite2 running ?

SDL2 can create a gradle project using build-scripts/androidbuild.sh.

@1bsyl
Copy link
Contributor

1bsyl commented Mar 17, 2026

with SDL3, I have a script that does:

mkdir -p build
cmake -B build
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake
-DANDROID_ABI=arm64-v8a -DSDL_ANDROID_HOME=$ANDROID_HOME
-DANDROID_PLATFORM=25
-DSDL_TESTS=ON

cmake --build build --target SDL3-jar
cmake --build build --target testsprite-apk

can this also compile for SDL2 ?

@madebr
Copy link
Contributor

madebr commented Mar 17, 2026

can this also compile for SDL2 ?

No, apks are only in SDL3.

@1bsyl
Copy link
Contributor

1bsyl commented Mar 18, 2026

ok, thanks!

So I built SDL2 and testsprite2 with:

./build-scripts/androidbuild.sh  lib.sdl.testsprite test/testsprite2.c test/testutils.c test/testutils.h
mkdir build/lib.sdl.testsprite/app/src/main/assets
cp test/icon.bmp build/lib.sdl.testsprite/app/src/main/assets/
cd ./build/lib.sdl.testsprite/
./gradlew installDebug

and added this to go to fullscreen

   for (i = 0; i < state->num_windows; ++i) {
         SDL_SetWindowFullscreen(state->windows[i], SDL_WINDOW_FULLSCREEN_DESKTOP);
    )
 

And it seemed to work when resuming. So not sure why adding this patch ...

@Farmer-Markus
Copy link
Author

And it seemed to work when resuming. So not sure why adding this patch ...

I'll try the test app but the Issue started after changing the targetSDK version to 36. Thr bug happens on my samsung phone(also after switching to a custom android rom) and sometimes in the android studio emulator with an sdk 36 phone but not with an 28 sdk phone. This might be a newer android problem.

I'll try the test app and post the results here

@Farmer-Markus
Copy link
Author

Farmer-Markus commented Mar 18, 2026

And it seemed to work when resuming. So not sure why adding this patch ...

Found the real reason this won't work on my app. I've ported a game to android which uses SDL_WINDOW_FULLSCREEN Instead of SDL_WINDOW_FULLSCREEN_DESKTOP which also triggers the bug in the test app.

SDL_GetClosestDisplayModeForDisplay() (SDL_video.c) will fail at line 1006 (if (current->h && (current->h < mode->h)) {)
for me with h = 720 and w = 1600 "Couldn't find display mode match"

Should I change the commit to add the SDL_WINDOW_FULLSCREEN option when compiling for android or just treat it as desktop fullscreen? Or is this wanted?

SDL/src/video/SDL_video.c

Lines 1347 to 1355 in e0307aa

/* if in desktop size mode, just return the size of the desktop */
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
fullscreen_mode = display->desktop_mode;
} else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
&fullscreen_mode,
&fullscreen_mode)) {
SDL_zerop(mode);
return SDL_SetError("Couldn't find display mode match");
}

@1bsyl
Copy link
Contributor

1bsyl commented Mar 19, 2026

I can't tell.
SDL_WINDOW_FULLSCREEN seemed to have no effect to me,
SDL_WINDOW_FULLSCREEN_DESKTOP was really going to fullscreen on an API 36 device

Not sure if you still consider the patch relevant, if so you need to add the same thing for the non-block function.

@Farmer-Markus
Copy link
Author

@1bsyl I think my new commit is the best approach. Android does not support resolution changes anyway so why not just use desktop full screen, as intended

@1bsyl
Copy link
Contributor

1bsyl commented Mar 20, 2026

@Farmer-Markus
not sure exactly the difference of those modes. @slouken knows better this now that this only touch SDL_video.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants