1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Windows: Avoid changing window size after display settings change

Previously, a 'system info' change could cause the window size to
change, which was unexpected.
This commit is contained in:
reuk 2024-07-29 17:14:38 +01:00
parent 66aa42c9c0
commit d7bfecae28
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -719,23 +719,6 @@ JUCE_API double getScaleFactorForWindow (HWND h)
return (double) localGetDPIForWindow (h) / USER_DEFAULT_SCREEN_DPI; return (double) localGetDPIForWindow (h) / USER_DEFAULT_SCREEN_DPI;
return 1.0; return 1.0;
}
//==============================================================================
static void setWindowPos (HWND hwnd, Rectangle<int> bounds, UINT flags, bool adjustTopLeft = false)
{
ScopedThreadDPIAwarenessSetter setter { hwnd };
if (isPerMonitorDPIAwareWindow (hwnd))
{
if (adjustTopLeft)
bounds = convertLogicalScreenRectangleToPhysical (bounds, hwnd)
.withPosition (Desktop::getInstance().getDisplays().logicalToPhysical (bounds.getTopLeft()));
else
bounds = convertLogicalScreenRectangleToPhysical (bounds, hwnd);
}
SetWindowPos (hwnd, nullptr, bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), flags);
} }
static RECT getWindowScreenRect (HWND hwnd) static RECT getWindowScreenRect (HWND hwnd)
@ -1617,6 +1600,9 @@ public:
if (inHandlePositionChanged) if (inHandlePositionChanged)
return; return;
if (isNowFullScreen != isFullScreen())
setFullScreen (isNowFullScreen);
// This is more of a guess than a certainty, but if we've captured the mouse and we're also // This is more of a guess than a certainty, but if we've captured the mouse and we're also
// updating the bounds, there's a good chance we're in a client-initiated resize. // updating the bounds, there's a good chance we're in a client-initiated resize.
// The resizing flag will be unset by WM_CAPTURECHANGED. // The resizing flag will be unset by WM_CAPTURECHANGED.
@ -1626,8 +1612,6 @@ public:
const ScopedValueSetter<bool> scope (shouldIgnoreModalDismiss, true); const ScopedValueSetter<bool> scope (shouldIgnoreModalDismiss, true);
fullScreen = isNowFullScreen;
const auto borderSize = findPhysicalBorderSize(); const auto borderSize = findPhysicalBorderSize();
auto newBounds = borderSize.addedTo ([&] auto newBounds = borderSize.addedTo ([&]
{ {
@ -1776,10 +1760,13 @@ public:
if (constrainer != nullptr) if (constrainer != nullptr)
constrainer->resizeStart(); constrainer->resizeStart();
fullScreen = shouldBeFullScreen;
const WeakReference<Component> deletionChecker (&component); const WeakReference<Component> deletionChecker (&component);
if (! fullScreen) if (shouldBeFullScreen)
{
ShowWindow (hwnd, SW_SHOWMAXIMIZED);
}
else
{ {
auto boundsCopy = lastNonFullscreenBounds; auto boundsCopy = lastNonFullscreenBounds;
@ -1788,10 +1775,6 @@ public:
if (! boundsCopy.isEmpty()) if (! boundsCopy.isEmpty())
setBounds (detail::ScalingHelpers::scaledScreenPosToUnscaled (component, boundsCopy), false); setBounds (detail::ScalingHelpers::scaledScreenPosToUnscaled (component, boundsCopy), false);
} }
else
{
ShowWindow (hwnd, SW_SHOWMAXIMIZED);
}
if (deletionChecker != nullptr) if (deletionChecker != nullptr)
handleMovedOrResized(); handleMovedOrResized();
@ -2290,7 +2273,7 @@ private:
std::unique_ptr<DropShadower> shadower; std::unique_ptr<DropShadower> shadower;
uint32 lastPaintTime = 0; uint32 lastPaintTime = 0;
ULONGLONG lastMagnifySize = 0; ULONGLONG lastMagnifySize = 0;
bool fullScreen = false, isDragging = false, isMouseOver = false, bool isDragging = false, isMouseOver = false,
hasCreatedCaret = false, constrainerIsResizing = false; hasCreatedCaret = false, constrainerIsResizing = false;
IconConverters::IconPtr currentWindowIcon; IconConverters::IconPtr currentWindowIcon;
FileDropTarget* dropTarget = nullptr; FileDropTarget* dropTarget = nullptr;
@ -3666,11 +3649,6 @@ private:
{ {
forceDisplayUpdate(); forceDisplayUpdate();
if (fullScreen && ! isMinimised())
setWindowPos (hwnd, detail::ScalingHelpers::scaledScreenPosToUnscaled (component, Desktop::getInstance().getDisplays()
.getDisplayForRect (component.getScreenBounds())->userArea),
SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
auto* dispatcher = VBlankDispatcher::getInstance(); auto* dispatcher = VBlankDispatcher::getInstance();
dispatcher->reconfigureDisplays(); dispatcher->reconfigureDisplays();
updateCurrentMonitorAndRefreshVBlankDispatcher (ForceRefreshDispatcher::yes); updateCurrentMonitorAndRefreshVBlankDispatcher (ForceRefreshDispatcher::yes);