Browse Source

Correctly handle window size and docking/undocking on Switch

pull/497/head
rsn8887 7 years ago committed by Anders Jenbo
parent
commit
c1237b53dd
  1. 2
      CMakeLists.txt
  2. 9
      SourceX/miniwin/misc_msg.cpp
  3. 49
      SourceX/platform/switch/docking.cpp
  4. 7
      SourceX/platform/switch/docking.h

2
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()

9
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 <switch.h>
#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)

49
SourceX/platform/switch/docking.cpp

@ -0,0 +1,49 @@
#include <switch.h>
#include <SDL.h>
#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

7
SourceX/platform/switch/docking.h

@ -0,0 +1,7 @@
#pragma once
namespace dvl {
void HandleDocking();
} // namespace dvl
Loading…
Cancel
Save