Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/desktop_multi_window/windows/flutter_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ bool FlutterWindow::OnCreate() {
RECT frame = GetClientArea();

flutter::DartProject project(L"data");
// Avoid Windows fullscreen freezes in recent Flutter engines when
// window_manager changes styles from a platform-channel call.
project.set_ui_thread_policy(flutter::UIThreadPolicy::RunOnSeparateThread);
std::vector<std::string> entrypoint_args = {"multi_window", id_,
window_argument_};
project.set_dart_entrypoint_arguments(entrypoint_args);
Expand Down
42 changes: 32 additions & 10 deletions packages/desktop_multi_window/windows/win32_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace {
constexpr const wchar_t kWindowClassName[] =
L"FLUTTER_MULTI_WINDOW_WIN32_WINDOW";

constexpr UINT kResizeChildContentMessage = WM_APP + 0x3D1;

/// Registry key for app theme preference.
///
/// A value of 0 indicates apps should use dark mode. A non-zero or missing
Expand Down Expand Up @@ -207,18 +209,21 @@ Win32Window::MessageHandler(HWND hwnd,

SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
QueueChildContentResize();

return 0;
}
case WM_SIZE: {
RECT rect = GetClientArea();
if (child_content_ != nullptr) {
// Size and position the child window.
MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top, TRUE);
}
ResizeChildContent();
return 0;
}
case WM_WINDOWPOSCHANGED:
QueueChildContentResize();
break;
case kResizeChildContentMessage:
child_resize_pending_ = false;
ResizeChildContent();
return 0;

case WM_ACTIVATE:
if (child_content_ != nullptr) {
Expand Down Expand Up @@ -254,10 +259,7 @@ Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
void Win32Window::SetChildContent(HWND content) {
child_content_ = content;
SetParent(content, window_handle_);
RECT frame = GetClientArea();

MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
frame.bottom - frame.top, true);
ResizeChildContent();

SetFocus(child_content_);
}
Expand All @@ -276,6 +278,26 @@ void Win32Window::SetQuitOnClose(bool quit_on_close) {
quit_on_close_ = quit_on_close;
}

void Win32Window::QueueChildContentResize() {
if (window_handle_ == nullptr || child_content_ == nullptr ||
child_resize_pending_) {
return;
}
child_resize_pending_ = true;
if (!PostMessage(window_handle_, kResizeChildContentMessage, 0, 0)) {
child_resize_pending_ = false;
}
}

void Win32Window::ResizeChildContent() {
if (child_content_ == nullptr) {
return;
}
RECT frame = GetClientArea();
MoveWindow(child_content_, frame.left, frame.top, frame.right - frame.left,
frame.bottom - frame.top, TRUE);
}

bool Win32Window::OnCreate() {
// No-op; provided for subclasses.
return true;
Expand Down
4 changes: 4 additions & 0 deletions packages/desktop_multi_window/windows/win32_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ class Win32Window {
// Update the window frame's theme to match the system theme.
static void UpdateTheme(HWND const window);

void QueueChildContentResize();
void ResizeChildContent();

bool quit_on_close_ = false;
bool child_resize_pending_ = false;

// window handle for top level window.
HWND window_handle_ = nullptr;
Expand Down