Skip to content

Commit

Permalink
windisplay: Fix issues switching fullscreen while maximized
Browse files Browse the repository at this point in the history
Fixes #1469
  • Loading branch information
rdb committed Mar 13, 2023
1 parent 68927ca commit 389b24e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 26 deletions.
79 changes: 53 additions & 26 deletions panda/src/windisplay/winGraphicsWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions panda/src/windisplay/winGraphicsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ class EXPCL_PANDAWIN WinGraphicsWindow : public GraphicsWindow {
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();

Expand Down

0 comments on commit 389b24e

Please sign in to comment.