From 389b24e69522f986296817818f2f2ab1803fc1bb Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 13 Mar 2023 10:36:55 +0100 Subject: [PATCH] windisplay: Fix issues switching fullscreen while maximized Fixes #1469 --- panda/src/windisplay/winGraphicsWindow.cxx | 79 +++++++++++++++------- panda/src/windisplay/winGraphicsWindow.h | 2 + 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/panda/src/windisplay/winGraphicsWindow.cxx b/panda/src/windisplay/winGraphicsWindow.cxx index 1ca0425273..7878484a79 100644 --- a/panda/src/windisplay/winGraphicsWindow.cxx +++ b/panda/src/windisplay/winGraphicsWindow.cxx @@ -283,15 +283,34 @@ process_events() { */ void WinGraphicsWindow:: set_properties_now(WindowProperties &properties) { - if (properties.has_fullscreen() && !properties.get_fullscreen() && - is_fullscreen()) { - if (do_windowed_switch()) { - _properties.set_fullscreen(false); - properties.clear_fullscreen(); - } else { - windisplay_cat.warning() - << "Switching to windowed mode failed!\n"; + if (properties.has_fullscreen()) { + if (!properties.get_fullscreen() && is_fullscreen()) { + if (do_windowed_switch()) { + _properties.set_fullscreen(false); + } else { + windisplay_cat.warning() + << "Switching to windowed mode failed!\n"; + } } + else if (properties.get_fullscreen() && !is_fullscreen()) { + int x_size; + int y_size; + if (properties.has_size()) { + x_size = properties.get_x_size(); + y_size = properties.get_y_size(); + } else { + x_size = _properties.get_x_size(); + y_size = _properties.get_y_size(); + } + if (do_fullscreen_switch(x_size, y_size)) { + _properties.set_fullscreen(true); + properties.clear_size(); + } else { + windisplay_cat.warning() + << "Switching to fullscreen mode failed!\n"; + } + } + properties.clear_fullscreen(); } GraphicsWindow::set_properties_now(properties); @@ -917,8 +936,8 @@ do_fullscreen_resize(int x_size, int y_size) { * Called in the set_properties_now function to switch to fullscreen. */ bool WinGraphicsWindow:: -do_fullscreen_switch() { - if (!do_fullscreen_enable()) { +do_fullscreen_switch(int x_size, int y_size) { + if (!do_fullscreen_enable(x_size, y_size)) { // Couldn't get fullscreen. return false; } @@ -928,17 +947,21 @@ do_fullscreen_switch() { DWORD window_style = make_style(props); SetWindowLong(_hWnd, GWL_STYLE, window_style); - WINDOW_METRICS metrics; - bool has_origin; - if (!calculate_metrics(true, window_style, metrics, has_origin)){ - return false; - } - - SetWindowPos(_hWnd, HWND_NOTOPMOST, 0, 0, metrics.width, metrics.height, + SetWindowPos(_hWnd, HWND_NOTOPMOST, 0, 0, x_size, y_size, SWP_FRAMECHANGED | SWP_SHOWWINDOW); + + handle_reshape(); return true; } +/** + * Called in the set_properties_now function to switch to fullscreen. + */ +bool WinGraphicsWindow:: +do_fullscreen_switch() { + return do_fullscreen_switch(_properties.get_x_size(), _properties.get_y_size()); +} + /** * Called in the set_properties_now function to switch to windowed mode. */ @@ -1188,8 +1211,8 @@ open_graphic_window() { // somehow, but I need the window's black background to cover up the desktop // during the mode change. - if (fullscreen){ - if (!do_fullscreen_enable()){ + if (fullscreen) { + if (!do_fullscreen_enable()) { return false; } } @@ -1202,7 +1225,7 @@ open_graphic_window() { * Not to confuse with do_fullscreen_switch(). */ bool WinGraphicsWindow:: -do_fullscreen_enable() { +do_fullscreen_enable(int x_size, int y_size) { HWND hDesktopWindow = GetDesktopWindow(); HDC scrnDC = GetDC(hDesktopWindow); @@ -1212,8 +1235,8 @@ do_fullscreen_enable() { // GetDeviceCaps(scrnDC, VERTRES); ReleaseDC(hDesktopWindow, scrnDC); - DWORD dwWidth = _properties.get_x_size(); - DWORD dwHeight = _properties.get_y_size(); + DWORD dwWidth = x_size; + DWORD dwHeight = y_size; DWORD dwFullScreenBitDepth = cur_bitdepth; DEVMODE dm; @@ -1241,12 +1264,16 @@ do_fullscreen_enable() { } _fullscreen_display_mode = dm; - - _properties.set_origin(0, 0); - _properties.set_size(dwWidth, dwHeight); - return true; +} +/** + * This is a low-level function that just puts Windows in fullscreen mode. + * Not to confuse with do_fullscreen_switch(). + */ +bool WinGraphicsWindow:: +do_fullscreen_enable() { + return do_fullscreen_enable(_properties.get_x_size(), _properties.get_y_size()); } /** diff --git a/panda/src/windisplay/winGraphicsWindow.h b/panda/src/windisplay/winGraphicsWindow.h index 083508087b..a0416a873f 100644 --- a/panda/src/windisplay/winGraphicsWindow.h +++ b/panda/src/windisplay/winGraphicsWindow.h @@ -111,8 +111,10 @@ protected: virtual void handle_reshape(); virtual bool do_fullscreen_resize(int x_size, int y_size); + bool do_fullscreen_switch(int x_size, int y_size); virtual bool do_fullscreen_switch(); virtual bool do_windowed_switch(); + bool do_fullscreen_enable(int x_size, int y_size); virtual bool do_fullscreen_enable(); virtual bool do_fullscreen_disable();