Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor multi-window support #1

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

hbatagelo
Copy link

@hbatagelo hbatagelo commented Dec 10, 2024

This pull request refactors the multi-window support in the Windows embedder, originally introduced in the series of four PRs starting from flutter#56090. It consolidates features introduced across the four PRs (support for regular windows, popups, dialogs, and satellites) into a single PR to facilitate faster iteration during review. Once the code stabilizes, these changes will be split and propagated to the relevant branches.

See also the corresponding framework PR: canonical/flutter#12

What's New:

  • The changes from the multi-view patch on Windows introduced in the first PR have been reverted. The multi-window C API is now non-public again.
  • The window controller, previously a singleton, is now instantiated once per engine and uniquely owned by it.
  • Applications can opt in for multi-window support by using the --enable-multi-window command-line option. No changes are required in the runner code.
  • The engine now directly registers the platform channel for windowing communication. This channel is only registered for applications that opt in for multi-window support.
  • Several fixes and improvements (prevented leakage of registered window classes, improved the behavior of modal dialogs by ensuring disabled windows do not appear active when selected via the task switcher, refactored tests, aligned the behavior of dialogs according to the spec, updated code style, improved comments).

Since the multi-window API remains non-public, windows cannot yet be created or destroyed from the runner code.

How It Works (In a Nutshell):

When multi-window support is enabled, FlutterWindowsEngine creates a uniquely owned FlutterHostWindowController that is responsible for managing the lifecycle of windows associated with the engine. The engine registers the "flutter/windowing" channel using WindowingHandler.

When the Dart app requests a new window using the createX methods, WindowingHandler calls FlutterHostWindowController::CreateHostWindow with the decoded arguments. The controller creates a uniquely owned FlutterHostWindow object which manages a native Win32 window with a child Flutter view in its client area. Each view, represented by FlutterWindowsViewController, is owned by its corresponding FlutterHostWindow. When the Dart app requests the destruction of a window (given a view ID) or when the native window is closed from the system, the controller destroys the corresponding FlutterHostWindow, which, in turn, cleans up the associated view controller.

Window messages are first handled by a static FlutterHostWindow::WndProc function that initializes the native Win32 window upon receiving WM_NCCREATE. Other messages are forwarded to FlutterHostWindowController::HandleMessage to manage global behaviors (e.g., hiding satellites of inactive top-level windows). Finally, messages are passed back to FlutterHostWindow::HandleMessage for window-specific behavior.

Things To Do:

This is a work in progress. Things that still need to be done include:

  • Updating the code to align with the newest spec.
  • Defining a consistent data format for the windowing channel.
  • Reusing and extending the geometry types available in Flutter (shell/platform/common/geometry.h) instead of defining new types in windowing.h.
  • Adding tests for popups, dialogs, and satellites.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link

@robert-ancell robert-ancell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some small details.

Copy link

@mattkae mattkae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have one main thought, but this all looks reasonable to me. Much easier to read 😄

shell/common/switches.cc Show resolved Hide resolved
shell/platform/common/windowing.h Show resolved Hide resolved
@wanjm
Copy link

wanjm commented Dec 12, 2024

thanks everyone for your work, I just want to know how much work left?
I am very wait for multi-window support;

@hbatagelo hbatagelo merged commit 69bdf97 into 1-multi-win-foundation Dec 16, 2024
1 check passed
@hbatagelo hbatagelo deleted the refactor-multi-win-foundation branch December 16, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants