From 686d702da4d058d700400f100c2018c1187c25ea Mon Sep 17 00:00:00 2001 From: LiJianying Date: Thu, 24 Mar 2022 17:33:26 +0800 Subject: [PATCH] [windows] Add g_is_frameless_before_fullscreen var. --- windows/window_manager.cpp | 49 +++++++++++++++++-------------- windows/window_manager_plugin.cpp | 20 ++++++------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/windows/window_manager.cpp b/windows/window_manager.cpp index 66eed29f..e1b5892e 100644 --- a/windows/window_manager.cpp +++ b/windows/window_manager.cpp @@ -106,6 +106,7 @@ class WindowManager { private: bool g_is_window_fullscreen = false; std::string g_title_bar_style_before_fullscreen; + bool g_is_frameless_before_fullscreen; RECT g_frame_before_fullscreen; bool g_maximized_before_fullscreen; LONG g_style_before_fullscreen; @@ -129,7 +130,9 @@ void WindowManager::SetAsFrameless() { MARGINS margins = {0, 0, 0, 0}; GetWindowRect(hWnd, &rect); - SetWindowLong(hWnd, GWL_STYLE, WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_VISIBLE); + SetWindowLong(hWnd, GWL_STYLE, + WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | + WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_VISIBLE); DwmExtendFrameIntoClientArea(hWnd, &margins); SetWindowPos(hWnd, nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, @@ -296,7 +299,7 @@ void WindowManager::SetFullScreen(const flutter::EncodableMap& args) { g_ex_style_before_fullscreen = GetWindowLong(mainWindow, GWL_EXSTYLE); ::GetWindowRect(mainWindow, &g_frame_before_fullscreen); g_title_bar_style_before_fullscreen = title_bar_style_; - g_is_frameless_before_fullscreen = is_frameless_; + g_is_frameless_before_fullscreen = is_frameless_; } if (isFullScreen) { @@ -324,14 +327,14 @@ void WindowManager::SetFullScreen(const flutter::EncodableMap& args) { SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); ::SendMessage(mainWindow, WM_SYSCOMMAND, SC_MAXIMIZE, 0); } else { - if (g_is_frameless_before_fullscreen) { - SetAsFrameless(); - } else { - flutter::EncodableMap args2 = flutter::EncodableMap(); - args2[flutter::EncodableValue("titleBarStyle")] = - flutter::EncodableValue(g_title_bar_style_before_fullscreen); - SetTitleBarStyle(args2); - } + if (g_is_frameless_before_fullscreen) { + SetAsFrameless(); + } else { + flutter::EncodableMap args2 = flutter::EncodableMap(); + args2[flutter::EncodableValue("titleBarStyle")] = + flutter::EncodableValue(g_title_bar_style_before_fullscreen); + SetTitleBarStyle(args2); + } ::SetWindowLong(mainWindow, GWL_STYLE, g_style_before_fullscreen); ::SetWindowLong(mainWindow, GWL_EXSTYLE, g_ex_style_before_fullscreen); @@ -569,21 +572,23 @@ void WindowManager::SetTitleBarStyle(const flutter::EncodableMap& args) { HWND hWnd = GetMainWindow(); DWORD gwlStyle = GetWindowLong(hWnd, GWL_STYLE); - // Enables the ability to go from setAsFrameless() to TitleBarStyle.normal/hidden + // Enables the ability to go from setAsFrameless() to + // TitleBarStyle.normal/hidden is_frameless_ = false; if (title_bar_style_ == "hidden") { - gwlStyle = WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_VISIBLE; + gwlStyle = WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | + WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_VISIBLE; SetWindowLong(hWnd, GWL_STYLE, gwlStyle); - BOOL composition_enabled = FALSE; - bool success = DwmIsCompositionEnabled(&composition_enabled) == S_OK; - if (composition_enabled && success) { - static const MARGINS shadow_state[2]{ { 0,0,0,0 },{ 1,1,1,1 } }; - DwmExtendFrameIntoClientArea(hWnd, &shadow_state[0]); - ShowWindow(hWnd, SW_SHOW); - } - } - else { - gwlStyle = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE; + BOOL composition_enabled = FALSE; + bool success = DwmIsCompositionEnabled(&composition_enabled) == S_OK; + if (composition_enabled && success) { + static const MARGINS shadow_state[2]{{0, 0, 0, 0}, {1, 1, 1, 1}}; + DwmExtendFrameIntoClientArea(hWnd, &shadow_state[0]); + ShowWindow(hWnd, SW_SHOW); + } + } else { + gwlStyle = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | + WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE; SetWindowLong(hWnd, GWL_STYLE, gwlStyle); } diff --git a/windows/window_manager_plugin.cpp b/windows/window_manager_plugin.cpp index 8e112a8b..7664b747 100644 --- a/windows/window_manager_plugin.cpp +++ b/windows/window_manager_plugin.cpp @@ -109,21 +109,21 @@ std::optional WindowManagerPlugin::HandleWindowProc(HWND hWnd, std::optional result = std::nullopt; if (message == WM_NCCALCSIZE) { - if (wParam && window_manager->IsFullScreen()) { + if (wParam && window_manager->IsFullScreen()) { NCCALCSIZE_PARAMS* sz = reinterpret_cast(lParam); - sz->rgrc[0].bottom -= 3; + sz->rgrc[0].bottom -= 3; return (WVR_HREDRAW | WVR_VREDRAW); - } - + } + if (wParam && window_manager->is_frameless_) { SetWindowLong(hWnd, 0, 0); NCCALCSIZE_PARAMS* sz = reinterpret_cast(lParam); - if (window_manager->IsMaximized()) { - sz->rgrc[0].left += 8; - sz->rgrc[0].top += 8; - sz->rgrc[0].right -= 8; - sz->rgrc[0].bottom -= 9; - } + if (window_manager->IsMaximized()) { + sz->rgrc[0].left += 8; + sz->rgrc[0].top += 8; + sz->rgrc[0].right -= 8; + sz->rgrc[0].bottom -= 9; + } sz->rgrc[0].bottom += 1; return (WVR_HREDRAW | WVR_VREDRAW); }