From c1237b53dd7e646127140d2a0287b2699dec4215 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Mon, 22 Jul 2019 12:16:40 -0500 Subject: [PATCH] Correctly handle window size and docking/undocking on Switch --- CMakeLists.txt | 2 ++ SourceX/miniwin/misc_msg.cpp | 9 ++++++ SourceX/platform/switch/docking.cpp | 49 +++++++++++++++++++++++++++++ SourceX/platform/switch/docking.h | 7 +++++ 4 files changed, 67 insertions(+) create mode 100644 SourceX/platform/switch/docking.cpp create mode 100644 SourceX/platform/switch/docking.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e435830f8..fd947e1ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -282,6 +282,8 @@ endif() set(BIN_TARGET devilutionx) if(SWITCH) + list(APPEND devilutionx_SRCS + SourceX/platform/switch/docking.cpp) set(BIN_TARGET devilutionx.elf) endif() diff --git a/SourceX/miniwin/misc_msg.cpp b/SourceX/miniwin/misc_msg.cpp index d391f9c5c..472145773 100644 --- a/SourceX/miniwin/misc_msg.cpp +++ b/SourceX/miniwin/misc_msg.cpp @@ -11,6 +11,11 @@ #include "controls/touch.h" #include "miniwin/ddraw.h" +#ifdef __SWITCH__ +#include "platform/switch/docking.h" +#include +#endif + /** @file * * * Windows message handling and keyboard event conversion for SDL. @@ -322,6 +327,10 @@ void BlurInventory() WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) { +#ifdef __SWITCH__ + HandleDocking(); +#endif + if (wMsgFilterMin != 0) UNIMPLEMENTED(); if (wMsgFilterMax != 0) diff --git a/SourceX/platform/switch/docking.cpp b/SourceX/platform/switch/docking.cpp new file mode 100644 index 000000000..631c65743 --- /dev/null +++ b/SourceX/platform/switch/docking.cpp @@ -0,0 +1,49 @@ +#include +#include +#include "miniwin/ddraw.h" +#include "platform/switch/docking.h" + +namespace dvl { + +static int currently_docked = -1; // keep track of docked or handheld mode + +/** + * @brief Do a manual window resize when docking/undocking the Switch + */ +void HandleDocking() +{ + int docked; + switch (appletGetOperationMode()) { + case AppletOperationMode_Handheld: + docked = 0; + break; + case AppletOperationMode_Docked: + docked = 1; + break; + default: + docked = 0; + } + + int display_width; + int display_height; + if ((currently_docked == -1) || (docked && !currently_docked) || (!docked && currently_docked)) { + // docked mode has changed, update window size + if (docked) { + display_width = 1920; + display_height = 1080; + currently_docked = 1; + } else { + display_width = 1280; + display_height = 720; + currently_docked = 0; + } + // remove leftover-garbage on screen + for (int i = 0; i < 3; i++) { + SDL_RenderClear(renderer); + SDL_RenderPresent(renderer); + } + SDL_SetWindowSize(window, display_width, display_height); + } +} + +} // namespace dvl diff --git a/SourceX/platform/switch/docking.h b/SourceX/platform/switch/docking.h new file mode 100644 index 000000000..5a81a1e24 --- /dev/null +++ b/SourceX/platform/switch/docking.h @@ -0,0 +1,7 @@ +#pragma once + +namespace dvl { + +void HandleDocking(); + +} // namespace dvl