Skip to content

Commit

Permalink
[windows] Add g_is_frameless_before_fullscreen var.
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Mar 24, 2022
1 parent b6f3734 commit 686d702
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
49 changes: 27 additions & 22 deletions windows/window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 10 additions & 10 deletions windows/window_manager_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,21 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd,
std::optional<LRESULT> result = std::nullopt;

if (message == WM_NCCALCSIZE) {
if (wParam && window_manager->IsFullScreen()) {
if (wParam && window_manager->IsFullScreen()) {
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(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<NCCALCSIZE_PARAMS*>(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);
}
Expand Down

0 comments on commit 686d702

Please sign in to comment.