-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[macOS] Implement regular window #176361
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
[macOS] Implement regular window #176361
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces the implementation for regular window management on macOS, including creating, destroying, and manipulating windows. The changes are split between the engine's native macOS implementation, the framework's Dart FFI bindings, and a new example application. My review focuses on correctness and style. I've found a couple of critical bugs in the Dart and Objective-C++ code that would lead to incorrect behavior, and some style guide violations in the new Swift example code. Overall, the direction is good, but these issues should be addressed.
| if (constraints.max_width > 0 && constraints.max_height > 0) { | ||
| [self setContentMaxSize:NSMakeSize(constraints.max_width, constraints.max_height)]; | ||
| } else { | ||
| [self setContentMaxSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)]; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic for setting maximum constraints is incorrect. It fails to apply a constraint if maxWidth or maxHeight is 0, which is a valid constraint. It also incorrectly removes all maximum constraints if only one of the dimensions is unconstrained (or constrained to a non-positive value).
A better approach is to handle each dimension's constraint independently, checking for infinity and mapping it to CGFLOAT_MAX.
For example:
double max_width = isinf(constraints.max_width) ? CGFLOAT_MAX : constraints.max_width;
double max_height = isinf(constraints.max_height) ? CGFLOAT_MAX : constraints.max_height;
[self setContentMaxSize:NSMakeSize(max_width, max_height)];You may need to #include <cmath> to use isinf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disagree. I don't think there's much value in being able to specify maximum window size 0 in either dimension given that NSWindow has normally minimum height of 1 and minimum width at least the size of traffic lights.
mattkae
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few notes, but looks solid to me. I would get a macOS expert in here for a review of that side though
dev/integration_tests/windowing_test/macos/Runner/AppDelegate.swift
Outdated
Show resolved
Hide resolved
mattkae
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some further nits
| /// Returns window handle for the current window. | ||
| /// The handle is a pointer to NSWindow instance. | ||
| Pointer<Void> getWindowHandle() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Returns window handle for the current window. | |
| /// The handle is a pointer to NSWindow instance. | |
| Pointer<Void> getWindowHandle() { | |
| /// Returns window handle for the current window. | |
| /// | |
| /// The handle is a pointer to an NSWindow instance. | |
| Pointer<Void> getWindowHandle() { |
| /// Creates a new regular window controller for macOS. When this constructor | ||
| /// completes the FlutterView is created and framework is aware of it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Creates a new regular window controller for macOS. When this constructor | |
| /// completes the FlutterView is created and framework is aware of it. | |
| /// Creates a new regular window controller for macOS. | |
| /// | |
| /// When this constructor completes the FlutterView is created and framework is aware of it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the general format of flutter constructors
|
Exception has occurred. |
35b8f62 to
f1b2919
Compare
mattkae
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add the integration tests to CI (if possible) and see if they pass.
To run the integration tests in CI, please add a devicelab runner similar to the one found at devicelab/bin/tasks/windowing_test_windows.dart.
Also, you will need to add it to .ci.yaml, e.g.
Line 7009 in cd189a1
| - name: Windows windowing_test |
| Future<void> awaitNotification( | ||
| VoidCallback act, | ||
| bool Function() predicate, | ||
| ) async { | ||
| final StreamController<bool> streamController = StreamController(); | ||
| void notificationHandler() { | ||
| streamController.add(true); | ||
| } | ||
|
|
||
| controller.addListener(notificationHandler); | ||
|
|
||
| act(); | ||
| await for (final _ in streamController.stream) { | ||
| if (predicate()) { | ||
| break; | ||
| } | ||
| } | ||
| controller.removeListener(notificationHandler); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of removing this, can we make it not wait on the MacOS platform only? This awaiting is very useful to prove the Win32 and Linux platforms. I would rather just do something different on MacOS in this method then have the other platforms change to accommodate MacOS
00e727a to
6ac811c
Compare
Co-authored-by: Matthew Kosarek <matt.kosarek@canonical.com>
1365195 to
f8a76bf
Compare
mattkae
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good by me! Looks like you have some CI things to address though
f8a76bf to
9f72068
Compare
TESTOWNERS
Outdated
| /dev/devicelab/bin/tasks/windows_home_scroll_perf__timeline_summary.dart @jonahwilliams @flutter/engine | ||
| /dev/devicelab/bin/tasks/windows_startup_test.dart @loic-sharma @flutter/desktop | ||
| /dev/devicelab/bin/tasks/windowing_test_linux.dart @robert-ancell @flutter/desktop | ||
| /dev/devicelab/bin/tasks/windowing_test_mnacos.dart @knopp @flutter/desktop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /dev/devicelab/bin/tasks/windowing_test_mnacos.dart @knopp @flutter/desktop | |
| /dev/devicelab/bin/tasks/windowing_test_macos.dart @knopp @flutter/desktop |
Roll Flutter from 75004a6 to cb18290 (48 revisions) flutter/flutter@75004a6...cb18290 2025-10-24 116356835+AbdeMohlbi@users.noreply.github.com Remove unnecessary `deprecated` withOpacity in `text_button.0.dart` in examples (flutter/flutter#177374) 2025-10-24 engine-flutter-autoroll@skia.org Roll Packages from 9ec29b6 to 53d6138 (3 revisions) (flutter/flutter#177502) 2025-10-24 engine-flutter-autoroll@skia.org Roll Dart SDK from d3248b00f545 to a0480f399f8f (1 revision) (flutter/flutter#177498) 2025-10-24 engine-flutter-autoroll@skia.org Roll Skia from a47931d09585 to 3ed332b77bec (3 revisions) (flutter/flutter#177487) 2025-10-24 jason-simmons@users.noreply.github.com Roll Abseil to Chromium's 5b92b04a2e (based on Abseil commit fc4481e968) (flutter/flutter#177059) 2025-10-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Reverts "Enhance PR template with changelog and impact details (#177333)" (#177468)" (flutter/flutter#177499) 2025-10-24 bruno.leroux@gmail.com Document DropdownMenu showTrailingIcon and decorationBuilder interaction (flutter/flutter#177488) 2025-10-24 engine-flutter-autoroll@skia.org Roll Dart SDK from 4a65fb890852 to d3248b00f545 (1 revision) (flutter/flutter#177486) 2025-10-24 huy@nevercode.io Fix bottom sheet Semantics route label for mismatched platforms (flutter/flutter#177094) 2025-10-24 engine-flutter-autoroll@skia.org Roll Skia from eba11de00d5b to a47931d09585 (5 revisions) (flutter/flutter#177481) 2025-10-24 huy@nevercode.io Fix Dialog Semantics label and flags for mismatched platforms (flutter/flutter#176781) 2025-10-24 huy@nevercode.io Fix drawer Semantics for mismatched platforms (flutter/flutter#177095) 2025-10-24 engine-flutter-autoroll@skia.org Roll Dart SDK from f7751ccea102 to 4a65fb890852 (2 revisions) (flutter/flutter#177480) 2025-10-23 jason-simmons@users.noreply.github.com Change the root path of the license crawl to engine/src (flutter/flutter#177352) 2025-10-23 43054281+camsim99@users.noreply.github.com [Material] Change default mouse cursor of buttons to basic arrow instead of click (except on web) (flutter/flutter#171796) 2025-10-23 loic.peron@inetum.com [Desktop] Propagate SemanticsNode::identifier to AXPlatformNodeDelegate::AuthorUniqueId (flutter/flutter#175405) 2025-10-23 engine-flutter-autoroll@skia.org Roll Skia from 59ef57f4104e to eba11de00d5b (5 revisions) (flutter/flutter#177461) 2025-10-23 737941+loic-sharma@users.noreply.github.com Roll customer tests (flutter/flutter#177409) 2025-10-23 1063596+reidbaker@users.noreply.github.com Update CHANGELOG 3.35.7 notes (flutter/flutter#177463) 2025-10-23 fluttergithubbot@gmail.com Marks Mac module_uiscene_test_ios to be unflaky (flutter/flutter#177378) 2025-10-23 31859944+LongCatIsLooong@users.noreply.github.com Allow empty dart defines in `flutter assemble` (flutter/flutter#177198) 2025-10-23 engine-flutter-autoroll@skia.org Roll Packages from d113bbc to 9ec29b6 (12 revisions) (flutter/flutter#177455) 2025-10-23 zhongliu88889@gmail.com Implements engine-side declarative pointer event handling for semantics. (flutter/flutter#176974) 2025-10-23 jason-simmons@users.noreply.github.com Fix the platform name of the windowing_test target for macOS in ci.yaml (flutter/flutter#177472) 2025-10-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Enhance PR template with changelog and impact details (#177333)" (flutter/flutter#177468) 2025-10-23 kjlubick@users.noreply.github.com Change Flutter APIs to use spans (flutter/flutter#177272) 2025-10-23 engine-flutter-autoroll@skia.org Roll Dart SDK from 020988602772 to f7751ccea102 (4 revisions) (flutter/flutter#177449) 2025-10-23 matej.knopp@gmail.com [macOS] Implement regular window (flutter/flutter#176361) 2025-10-23 1063596+reidbaker@users.noreply.github.com Enhance PR template with changelog and impact details (flutter/flutter#177333) 2025-10-23 engine-flutter-autoroll@skia.org Roll Skia from 6e6acf6644ef to 59ef57f4104e (2 revisions) (flutter/flutter#177436) 2025-10-23 sokolovskyi.konstantin@gmail.com Add directional static members to AlignmentGeometry. (flutter/flutter#176571) 2025-10-23 engine-flutter-autoroll@skia.org Roll ICU from 1b2e3e8a421e to ff35c4f9df23 (5 revisions) (flutter/flutter#177434) 2025-10-23 goderbauer@google.com Adds a new CI build for Linux host DDM-enabled artifacts (flutter/flutter#177252) 2025-10-23 engine-flutter-autoroll@skia.org Roll Skia from 920cdcadd74c to 6e6acf6644ef (1 revision) (flutter/flutter#177432) 2025-10-23 engine-flutter-autoroll@skia.org Roll Skia from 8cd449e4953b to 920cdcadd74c (6 revisions) (flutter/flutter#177426) 2025-10-23 30870216+gaaclarke@users.noreply.github.com Added ahem license (flutter/flutter#177423) 2025-10-23 engine-flutter-autoroll@skia.org Roll Dart SDK from 75f6ccb9bdc5 to 020988602772 (1 revision) (flutter/flutter#177421) 2025-10-23 1961493+harryterkelsen@users.noreply.github.com [web] Set `pointer-events: none` for img-element-backed images (flutter/flutter#177418) 2025-10-22 jason-simmons@users.noreply.github.com Remove the x64 version of build_ios_framework_module_test (flutter/flutter#177136) 2025-10-22 robert.ancell@canonical.com Fix accessibility events not being correctly translated to ATK (flutter/flutter#176991) 2025-10-22 engine-flutter-autoroll@skia.org Roll Skia from b55bd60ed95b to 8cd449e4953b (8 revisions) (flutter/flutter#177405) 2025-10-22 engine-flutter-autoroll@skia.org Roll Dart SDK from c23010c4f9e6 to 75f6ccb9bdc5 (4 revisions) (flutter/flutter#177399) 2025-10-22 47866232+chunhtai@users.noreply.github.com Fixes crash when adding and removing mulitple page-based route (flutter/flutter#177338) 2025-10-22 61709763+cuteUtya@users.noreply.github.com Move child parameter to end of RefreshIndicator constructor (flutter/flutter#177019) 2025-10-22 34465683+rkishan516@users.noreply.github.com refactor: migrate OpenUpwardsPageTransitionsBuilder to widgets (flutter/flutter#177080) 2025-10-22 1961493+harryterkelsen@users.noreply.github.com Delete stray 'text' file (flutter/flutter#177355) ...
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> *Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Matthew Kosarek <matt.kosarek@canonical.com>
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> *Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Matthew Kosarek <matt.kosarek@canonical.com>
Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.
List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.