FlutterWindowsView::SendWindowMetrics now reliably sends the display_id (#179053)

fixes https://github.com/flutter/flutter/issues/178982

This payload used to not matter (since the display ID was always zero),
but now not setting the display ID results in the display ID to be set
to zero. That is unfortunate, but this is a good fix for now!

## 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.
- [x] All existing and new tests are passing.
This commit is contained in:
Matthew Kosarek 2025-11-25 09:36:49 -05:00 committed by GitHub
parent 68115a705f
commit 2778dfd2cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View File

@ -369,11 +369,13 @@ void FlutterWindowsView::OnResetImeComposing() {
void FlutterWindowsView::SendWindowMetrics(size_t width,
size_t height,
double pixel_ratio) const {
FlutterEngineDisplayId display_id = binding_handler_->GetDisplayId();
FlutterWindowMetricsEvent event = {};
event.struct_size = sizeof(event);
event.width = width;
event.height = height;
event.pixel_ratio = pixel_ratio;
event.display_id = display_id;
event.view_id = view_id_;
engine_->SendWindowMetricsEvent(event);
}

View File

@ -1749,5 +1749,29 @@ TEST(FlutterWindowsViewTest, WindowMetricsEventContainsDisplayId) {
FlutterWindowMetricsEvent event = view.CreateWindowMetricsEvent();
EXPECT_EQ(event.display_id, 12);
}
TEST(FlutterWindowsViewTest, SizeChangeTriggersMetricsEventWhichHasDisplayId) {
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
EngineModifier modifier(engine.get());
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
EXPECT_CALL(*window_binding_handler, GetDisplayId)
.WillOnce(testing::Return(12));
FlutterWindowsView view{kImplicitViewId, engine.get(),
std::move(window_binding_handler)};
bool received_metrics = false;
modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
SendWindowMetricsEvent,
([&received_metrics](auto engine,
const FlutterWindowMetricsEvent* event) {
received_metrics = true;
EXPECT_EQ(event->display_id, 12);
return kSuccess;
}));
view.OnWindowSizeChanged(100, 100);
EXPECT_TRUE(received_metrics);
}
} // namespace testing
} // namespace flutter