1
0
Fork 0

Merge branch 'fullscreen-api-nonrecreate' into dev

This commit is contained in:
Henrik Hautakoski 2022-09-13 20:39:02 +02:00
commit 3a7f91cb07
7 changed files with 136 additions and 20 deletions

View file

@ -41,7 +41,7 @@ Win32Display::~Win32Display()
bool Win32Display::create(DisplayDescription description)
{
DWORD flags = getWin32Flags(description.decoration);
DWORD flags;
Vector2i pos;
if (firstTime) {
@ -49,7 +49,9 @@ bool Win32Display::create(DisplayDescription description)
firstTime = false;
}
// Set window to center and set decoration flags.
pos = centerWindow(description.mode.width, description.mode.height);
flags = getWin32Flags(description.decoration);
// Create window.
m_handle = CreateWindowExA(0, WND_CLASSNAME, "", flags,
@ -128,6 +130,11 @@ void Win32Display::setVisible(bool visible)
::ShowWindow(m_handle, visible ? SW_SHOW : SW_HIDE);
}
void Win32Display::setDecoration(unsigned decoration)
{
::SetWindowLong(m_handle, GWL_STYLE, getWin32Flags(decoration));
}
void Win32Display::minimize()
{
::ShowWindow(m_handle, SW_MINIMIZE);
@ -277,6 +284,60 @@ Vector2i Win32Display::centerWindow(int width, int height)
return v;
}
void Win32Display::enterFullscreen(DisplayMode mode)
{
LONG rc;
::DEVMODEW dev;
dev.dmSize = sizeof(dev);
dev.dmPelsWidth = mode.width;
dev.dmPelsHeight = mode.height;
dev.dmBitsPerPel = mode.bpp;
dev.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
rc = ::ChangeDisplaySettingsW(&dev, CDS_FULLSCREEN);
if (rc != DISP_CHANGE_SUCCESSFUL) {
const char *msg;
switch(rc) {
case DISP_CHANGE_BADDUALVIEW :
msg = "The system is DualView capable"; break;
case DISP_CHANGE_BADFLAGS :
msg = "Invalid flags given"; break;
case DISP_CHANGE_BADPARAM :
msg = "Invalid parameter"; break;
case DISP_CHANGE_BADMODE :
msg = "Resolution not supported"; break;
case DISP_CHANGE_FAILED :
msg = "Display driver failed to set mode"; break;
case DISP_CHANGE_NOTUPDATED :
msg = "Unable to write settings to the registry"; break;
case DISP_CHANGE_RESTART :
msg = "System restart required"; break;
default :
msg = "Unkown error";
}
sp::Log::error("Win32: Failed to switch to fullscreen mode: %s.", msg);
return;
}
::SetWindowLong(m_handle, GWL_STYLE, WS_VISIBLE | WS_POPUP);
::SetWindowPos(m_handle, HWND_TOP, 0, 0, mode.width, mode.height, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
grabCursor(true);
m_fs_mode = mode;
}
void Win32Display::exitFullscreen()
{
if (!m_fs_mode.empty()) {
// Restore to previous mode.
::ChangeDisplaySettingsW(NULL, 0);
m_fs_mode = DisplayMode();
}
}
void Win32Display::processResizeMessage(const Vector2u& new_size)
{
// Check if the size has actually changed.
@ -301,9 +362,22 @@ void Win32Display::processMessage(UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_SETFOCUS :
Log::debug("WM_SETFOCUS");
if (m_fs_mode.empty() == false) {
enterFullscreen(m_fs_mode);
}
break;
case WM_KILLFOCUS :
Log::debug("WM_KILLFOCUS");
// If in fullscreen mode.
if (m_fs_mode.empty() == false) {
// Switch to window mode.
::ChangeDisplaySettingsW(NULL, 0);
// also minimize the window to get it out of the way.
minimize();
}
grabCursor(false);
break;
case WM_SIZE :