From 266cbf4d8a91f8d0336795433e12ba53eaf016e4 Mon Sep 17 00:00:00 2001 From: damywise Date: Mon, 21 Mar 2022 11:07:50 +0700 Subject: [PATCH 1/3] setAsFrameless: TitleBarStyle, resizing jitter - Enables resetting window style to TitleBarStyle.normal/hidden - Removes crazy jittering when resizing window --- windows/window_manager.cpp | 11 +++++++---- windows/window_manager_plugin.cpp | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/windows/window_manager.cpp b/windows/window_manager.cpp index 9bb515a1..7f84c353 100644 --- a/windows/window_manager.cpp +++ b/windows/window_manager.cpp @@ -129,7 +129,7 @@ void WindowManager::SetAsFrameless() { MARGINS margins = {0, 0, 0, 0}; GetWindowRect(hWnd, &rect); - SetWindowLong(hWnd, GWL_STYLE, WS_POPUP | WS_CAPTION | WS_VISIBLE); + SetWindowLong(hWnd, GWL_STYLE, WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX); DwmExtendFrameIntoClientArea(hWnd, &margins); SetWindowPos(hWnd, nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, @@ -564,11 +564,14 @@ 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 + is_frameless_ = false; if (title_bar_style_ == "hidden") { - gwlStyle = gwlStyle | WS_POPUP; + gwlStyle = WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; SetWindowLong(hWnd, GWL_STYLE, gwlStyle); - } else { - gwlStyle = gwlStyle & ~WS_POPUP; + } + else { + gwlStyle = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; SetWindowLong(hWnd, GWL_STYLE, gwlStyle); } diff --git a/windows/window_manager_plugin.cpp b/windows/window_manager_plugin.cpp index f61db530..5189cff5 100644 --- a/windows/window_manager_plugin.cpp +++ b/windows/window_manager_plugin.cpp @@ -111,7 +111,9 @@ std::optional WindowManagerPlugin::HandleWindowProc(HWND hWnd, if (message == WM_NCCALCSIZE) { if (wParam && window_manager->is_frameless_) { SetWindowLong(hWnd, 0, 0); - return 1; + NCCALCSIZE_PARAMS* sz = reinterpret_cast(lParam); + sz->rgrc[0].bottom += 1; + return (WVR_HREDRAW | WVR_VREDRAW); } if (wParam && window_manager->title_bar_style_ == "hidden") { From 6b7ea7ff51e3ff8261c95dac96b82061c33aec7d Mon Sep 17 00:00:00 2001 From: damywise Date: Mon, 21 Mar 2022 11:26:36 +0700 Subject: [PATCH 2/3] Remove window border Removes window border so it's possible to implement custom window border --- windows/window_manager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/windows/window_manager.cpp b/windows/window_manager.cpp index 7f84c353..60994c63 100644 --- a/windows/window_manager.cpp +++ b/windows/window_manager.cpp @@ -569,6 +569,13 @@ void WindowManager::SetTitleBarStyle(const flutter::EncodableMap& args) { if (title_bar_style_ == "hidden") { gwlStyle = WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; 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; From b41d70cbf70fdfb68ba2cf32fca0534ee11262c7 Mon Sep 17 00:00:00 2001 From: damywise Date: Mon, 21 Mar 2022 11:48:58 +0700 Subject: [PATCH 3/3] Forgot to add WS_VISIBLE --- windows/window_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/windows/window_manager.cpp b/windows/window_manager.cpp index 60994c63..d78178b9 100644 --- a/windows/window_manager.cpp +++ b/windows/window_manager.cpp @@ -129,7 +129,7 @@ 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); + 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, @@ -567,7 +567,7 @@ void WindowManager::SetTitleBarStyle(const flutter::EncodableMap& args) { // 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; + 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; @@ -578,7 +578,7 @@ void WindowManager::SetTitleBarStyle(const flutter::EncodableMap& args) { } } else { - gwlStyle = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; + gwlStyle = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE; SetWindowLong(hWnd, GWL_STYLE, gwlStyle); }