Skip to content

Commit

Permalink
Win32: Tweaked widget sizing after mode switches
Browse files Browse the repository at this point in the history
It appears on Windows a visible fullscreen QWidget does not update its geometry
when the display mode changes, so in this situation we'll briefly switch it to
normal show mode and then back to fullscreen mode.

Todo: Check if this approach works on OS X as well.
  • Loading branch information
skyjake committed Apr 7, 2012
1 parent 6abd66e commit 05c5e08
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion doomsday/engine/portable/src/window.cpp
Expand Up @@ -56,7 +56,7 @@
#ifdef MACOSX
static const int POST_MODE_CHANGE_WAIT_BEFORE_UPDATE = 100; // ms
#else
static const int POST_MODE_CHANGE_WAIT_BEFORE_UPDATE = 1; // ms
static const int POST_MODE_CHANGE_WAIT_BEFORE_UPDATE = 10; // ms
#endif

/// Used to determine the valid region for windows on the desktop.
Expand All @@ -83,6 +83,7 @@ struct ddwindow_s
void (*drawFunc)(void); ///< Draws the contents of the canvas.
QRect appliedGeometry; ///< Saved for detecting when changes have occurred.
bool needShowFullscreen;
bool needReshowFullscreen;
bool needShowNormal;

ddwindowtype_t type;
Expand Down Expand Up @@ -214,24 +215,40 @@ struct ddwindow_s
*/
void applyWindowGeometry()
{
LOG_AS("applyWindowGeometry");

assertWindow();

bool modeChanged = applyDisplayMode();

if(flags & DDWF_FULLSCREEN)
{
LOG_DEBUG("fullscreen mode (mode changed? %b)") << modeChanged;

if(!modeChanged) return; // We don't need to do anything.

if(widget->isVisible())
{
needShowFullscreen = !widget->isFullScreen();
#ifdef WIN32
if(widget->isFullScreen())
{
needShowFullscreen = false;
needReshowFullscreen = true;
}
#endif
LOG_DEBUG("widget is visible, need showFS:%b reshowFS:%b")
<< needShowFullscreen << needReshowFullscreen;

// The window is already visible, so let's allow a mode change to resolve itself
// before we go changing the window.
LegacyCore_Timer(de2LegacyCore, POST_MODE_CHANGE_WAIT_BEFORE_UPDATE, updateMainWindowLayout);
}
else
{
LOG_DEBUG("widget is not visible, setting geometry to ")
<< DisplayMode_Current()->width << "x"
<< DisplayMode_Current()->height;
widget->setGeometry(0, 0, DisplayMode_Current()->width, DisplayMode_Current()->height);
}
}
Expand Down Expand Up @@ -464,8 +481,17 @@ static void updateMainWindowLayout(void)
{
Window* win = Window_Main();

if(win->needReshowFullscreen)
{
LOG_DEBUG("Main window re-set to fullscreen mode.");
win->needReshowFullscreen = false;
win->widget->showNormal();
win->widget->showFullScreen();
}

if(win->needShowFullscreen)
{
LOG_DEBUG("Main window to fullscreen mode.");
win->needShowFullscreen = false;
win->widget->showFullScreen();
}
Expand All @@ -485,6 +511,7 @@ static void updateMainWindowLayout(void)

if(win->needShowNormal)
{
LOG_DEBUG("Main window to normal mode.");
win->needShowNormal = false;
win->widget->showNormal();
}
Expand Down

0 comments on commit 05c5e08

Please sign in to comment.