diff --git a/src/arch_switch.c b/src/arch_switch.c index 15342a7b..df03af69 100644 --- a/src/arch_switch.c +++ b/src/arch_switch.c @@ -26,6 +26,9 @@ static nxAtExitFn g_nxAtExitFn = NULL; static char g_programDir[FS_MAX_PATH] = {0}; static AppletHookCookie g_hookCookie; +static s32 g_initialScreenWidth = 1920; +static s32 g_initialScreenHeight = 1080; + static void onAppletHook(AppletHookType hook, void *param) { switch (hook) { case AppletHookType_OnExitRequest: @@ -51,6 +54,7 @@ void userAppInit(void) { NX_LOG("nxlink enabled"); #endif + appletGetDefaultDisplayResolution(&g_initialScreenWidth, &g_initialScreenHeight); appletInitializeGamePlayRecording(); appletSetGamePlayRecordingState(1); @@ -112,3 +116,11 @@ void noreturn nxAbort(void) { const char* nxGetProgramDir(void) { return g_programDir; } + +int nxGetInitialScreenWidth(void) { + return g_initialScreenWidth; +} + +int nxGetInitialScreenHeight(void) { + return g_initialScreenHeight; +} diff --git a/src/arch_switch.h b/src/arch_switch.h index 4118854a..ec182918 100644 --- a/src/arch_switch.h +++ b/src/arch_switch.h @@ -16,3 +16,6 @@ int nxAtExit(nxAtExitFn fn); void noreturn nxExit(int rc); void noreturn nxAbort(void); const char* nxGetProgramDir(void); + +int nxGetInitialScreenWidth(void); +int nxGetInitialScreenHeight(void); diff --git a/src/config.c b/src/config.c index 1ebfc4fb..1462df39 100644 --- a/src/config.c +++ b/src/config.c @@ -499,6 +499,8 @@ void config_load(void) { #ifdef __SWITCH__ config_set_int(CONFIG_GAMEPAD_ENABLED, true); config_set_str(CONFIG_GAMEPAD_DEVICE, "any"); + config_set_int(CONFIG_VID_WIDTH, nxGetInitialScreenWidth()); + config_set_int(CONFIG_VID_HEIGHT, nxGetInitialScreenHeight()); #endif } diff --git a/src/video.c b/src/video.c index a08b1d17..001f1d79 100644 --- a/src/video.c +++ b/src/video.c @@ -140,6 +140,26 @@ static VideoCapabilityState video_query_capability_alwaysfullscreen(VideoCapabil UNREACHABLE; } +static VideoCapabilityState video_query_capability_switch(VideoCapability cap) { + switch(cap) { + // We want the window to be resizable and resized internally by SDL + // when the Switch gets docked/undocked + case VIDEO_CAP_FULLSCREEN: + return VIDEO_NEVER_AVAILABLE; + + case VIDEO_CAP_EXTERNAL_RESIZE: + return VIDEO_AVAILABLE; + + case VIDEO_CAP_CHANGE_RESOLUTION: + return VIDEO_NEVER_AVAILABLE; + + case VIDEO_CAP_VSYNC_ADAPTIVE: + return VIDEO_NEVER_AVAILABLE; + } + + UNREACHABLE; +} + static VideoCapabilityState video_query_capability_webcanvas(VideoCapability cap) { switch(cap) { case VIDEO_CAP_EXTERNAL_RESIZE: @@ -757,6 +777,12 @@ static bool video_handle_window_event(SDL_Event *event, void *arg) { // It's followed by SDL_WINDOWEVENT_RESIZED for external resizes (from the WM or the // user). We only need to handle external resizes. log_debug("SDL_WINDOWEVENT_SIZE_CHANGED: %ix%i", event->window.data1, event->window.data2); + + // Catch resizes by the SDL portlib itself, when the console is docked/undocked + // https://github.com/devkitPro/SDL/issues/31 + if(video_get_backend() == VIDEO_BACKEND_SWITCH) { + video_handle_resize(event->window.data1, event->window.data2); + } break; case SDL_WINDOWEVENT_RESIZED: @@ -862,7 +888,7 @@ void video_init(void) { video_query_capability = video_query_capability_alwaysfullscreen; } else if(!strcmp(driver, "Switch")) { video.backend = VIDEO_BACKEND_SWITCH; - video_query_capability = video_query_capability_alwaysfullscreen; + video_query_capability = video_query_capability_switch; } else { video.backend = VIDEO_BACKEND_OTHER; }