diff --git a/modules/juce_events/native/juce_win32_Messaging.cpp b/modules/juce_events/native/juce_win32_Messaging.cpp index b68fdce461..8275fc1e67 100644 --- a/modules/juce_events/native/juce_win32_Messaging.cpp +++ b/modules/juce_events/native/juce_win32_Messaging.cpp @@ -28,6 +28,9 @@ extern HWND juce_messageWindowHandle; typedef bool (*CheckEventBlockedByModalComps) (const MSG&); CheckEventBlockedByModalComps isEventBlockedByModalComps = nullptr; +typedef void (*SettingChangeCallbackFunc) (void); +SettingChangeCallbackFunc settingChangeCallback = nullptr; + //============================================================================== namespace WindowsMessageHelpers { @@ -101,6 +104,11 @@ namespace WindowsMessageHelpers handleBroadcastMessage (reinterpret_cast (lParam)); return 0; } + else if (message == WM_SETTINGCHANGE) + { + if (settingChangeCallback != nullptr) + settingChangeCallback(); + } } return DefWindowProc (h, message, wParam, lParam); diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 0e28452007..0321f107db 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -303,6 +303,9 @@ static void checkForPointerAPI() && getPointerPenInfo != nullptr); } +typedef void (*SettingChangeCallbackFunc) (void); +extern SettingChangeCallbackFunc settingChangeCallback; + static Rectangle rectangleFromRECT (const RECT& r) noexcept { return Rectangle::leftTopRightBottom ((int) r.left, (int) r.top, (int) r.right, (int) r.bottom); @@ -1772,6 +1775,11 @@ private: updateBorderSize(); checkForPointerAPI(); + // This is needed so that our plugin window gets notified of WM_SETTINGCHANGE messages + // and can respond to display scale changes + if (! JUCEApplication::isStandaloneApp()) + settingChangeCallback = forceDisplayUpdate; + // Calling this function here is (for some reason) necessary to make Windows // correctly enable the menu items that we specify in the wm_initmenu message. GetSystemMenu (hwnd, false); @@ -2918,19 +2926,23 @@ private: void doSettingChange() { - auto& desktop = Desktop::getInstance(); - - const_cast (desktop.getDisplays()).refresh(); + forceDisplayUpdate(); if (fullScreen && ! isMinimised()) { - auto& display = desktop.getDisplays().getDisplayContaining (component.getScreenBounds().getCentre()); + auto& display = Desktop::getInstance().getDisplays() + .getDisplayContaining (component.getScreenBounds().getCentre()); setWindowPos (hwnd, display.userArea * display.scale, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING); } } + static void forceDisplayUpdate() + { + const_cast (Desktop::getInstance().getDisplays()).refresh(); + } + void handleDPIChange() // happens when a window moves to a screen with a different DPI. { } @@ -3596,7 +3608,6 @@ JUCE_API ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component& compo JUCE_IMPLEMENT_SINGLETON (HWNDComponentPeer::WindowClassHolder) - //============================================================================== void ModifierKeys::updateCurrentModifiers() noexcept {