Skip to content

[rcore_android] Allow setting window size on Android.#5810

Open
StupidRepo wants to merge 1 commit intoraysan5:masterfrom
StupidRepo:patch-1
Open

[rcore_android] Allow setting window size on Android.#5810
StupidRepo wants to merge 1 commit intoraysan5:masterfrom
StupidRepo:patch-1

Conversation

@StupidRepo
Copy link
Copy Markdown

@StupidRepo StupidRepo commented Apr 26, 2026

My situation

  1. User rotates device while app is open.
  2. Android sends APP_CMD_CONFIG_CHANGED.
  3. Resizing the framebuffer and setting screen sizes to reflect the new 'window size' causes stretching due to Android-reported width and height still (usually - see below) reporting with values from before the orientation change.

Why not just add this in AndroidCommandCallback's APP_CMD_CONFIG_CHANGED case?

Android does not send the correct width and height in time, therefore leading to you having to manually switch the height and width. This is fine, until you notice that Android has a somewhat-common chance to send the correct width and height and then everything gets stretched because you swapped the width to be the height to account for the wrong timing.

You could make a variable to mark the window as dirty then in a place that is triggered every frame, if that variable is true and the Android-reported size != current window size, set the variable to false and then update to the new size.

The solution for devs using raylib

  1. Allow SetWindowSize to be usable, via this patch, on android.
  2. Devs can now use the NDK themselves to check every frame if a resize occured:
extern struct android_app* GetAndroidApp();

static int ndk_window_width() {
	struct android_app* app = GetAndroidApp();
	if (!app || !app->window) return 0;

    return ANativeWindow_getWidth(app->window);
}
static int ndk_window_height() {
    struct android_app* app = GetAndroidApp();
    if (!app || !app->window) return 0;

    return ANativeWindow_getHeight(app->window);
}
  1. Devs call these every frame, and do manual resize checking. If a resize is detected, call SetWindowSize(int width, int height).

Additional comments

Let me know if this is okay - personally I wouldn't accept this PR as I'm sure there is a solution that allows putting this code in APP_CMD_CONFIG_CHANGED while receiving correct sizes from Android (see my 'Why not ...' above for why we can't do this already).

This also is a better solution as it also correctly sets the size when INIT_WINDOW happens. So, if the app is in landscape and the users turns off the phone screen then turns it back on with the orientation in portrait, then that is also handled as the size change is detected.

Demos

Fix from this PR:

fixed.by.this.pr.mp4

Default behaviour:

app.stretch.mp4

@StupidRepo StupidRepo changed the title Allow setting window size on Android. [rcore_android] Allow setting window size on Android. Apr 26, 2026
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.

1 participant