Skip to content

Commit

Permalink
switch: use native screen resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
p-sam authored and Akaricchi committed Nov 27, 2023
1 parent 55fd60d commit ca1de9c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/arch_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -51,6 +54,7 @@ void userAppInit(void) {
NX_LOG("nxlink enabled");
#endif

appletGetDefaultDisplayResolution(&g_initialScreenWidth, &g_initialScreenHeight);
appletInitializeGamePlayRecording();
appletSetGamePlayRecordingState(1);

Expand Down Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/arch_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
28 changes: 27 additions & 1 deletion src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ca1de9c

Please sign in to comment.