From a2b2813b9391564254bf91b5931975132b21de0a Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 30 Jun 2025 16:20:36 +0100 Subject: [PATCH] Windows: Update window style flags when toggling kiosk mode This is a different approach to the change introduced in 04f87320d5f80b101f867c8314253aef994ff6e5. Instead of completely recreating the window, we now just update the window's style flags. This should ensure that window and component focus are preserved. --- .../native/juce_Windowing_windows.cpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp index bbb6e2e28e..b418afbb58 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp @@ -5875,13 +5875,25 @@ void Desktop::setKioskComponent (Component* kioskModeComp, bool enableOrDisable, if (auto* peer = dynamic_cast (kioskModeComp->getPeer())) { const auto prevFlags = (DWORD) GetWindowLong (peer->getHWND(), GWL_STYLE); - const auto nextFlags = peer->computeNativeStyleFlags(); + const auto nextVisibility = prevFlags & WS_VISIBLE; + const auto nextFlags = peer->computeNativeStyleFlags() | nextVisibility; if (nextFlags != prevFlags) { - const auto styleFlags = peer->getStyleFlags(); - kioskModeComp->removeFromDesktop(); - kioskModeComp->addToDesktop (styleFlags); + SetWindowLong (peer->getHWND(), GWL_STYLE, nextFlags); + + // After changing the window style flags, the window border visibility may have changed. + // Call SetWindowPos with no changes other than SWP_FRAMECHANGED to ensure that + // GetWindowInfo returns up-to-date border-size values. + static constexpr auto frameChangeOnly = SWP_NOSIZE + | SWP_NOMOVE + | SWP_NOZORDER + | SWP_NOREDRAW + | SWP_NOACTIVATE + | SWP_FRAMECHANGED + | SWP_NOOWNERZORDER + | SWP_NOSENDCHANGING; + SetWindowPos (peer->getHWND(), nullptr, 0, 0, 0, 0, frameChangeOnly); } } else