From eb072d89286a4d1f2935ab3140c32303d5d6e7a4 Mon Sep 17 00:00:00 2001 From: Hasan Mohsin Date: Thu, 25 Jan 2024 00:48:23 +0000 Subject: [PATCH] [Windows] Set cursor immediately when framework requests update (flutter/engine#49784) On Windows, when using a `MouseRegion` widget to change the cursor it is not actually updated until the cursor is moved. This is because the Windows embedder only updates the `current_cursor_` field but does not actually set the cursor until the window receives the `WM_SETCURSOR` message when the mouse moves. This change makes it set the cursor immediately. Fixes flutter/flutter#76622 --- .../src/flutter/shell/platform/windows/flutter_window.cc | 2 +- .../shell/platform/windows/flutter_window_unittests.cc | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/windows/flutter_window.cc b/engine/src/flutter/shell/platform/windows/flutter_window.cc index 63299b891c..e4361191aa 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window.cc @@ -173,7 +173,7 @@ PhysicalWindowBounds FlutterWindow::GetPhysicalWindowBounds() { } void FlutterWindow::UpdateFlutterCursor(const std::string& cursor_name) { - current_cursor_ = GetCursorByName(cursor_name); + SetFlutterCursor(GetCursorByName(cursor_name)); } void FlutterWindow::SetFlutterCursor(HCURSOR cursor) { diff --git a/engine/src/flutter/shell/platform/windows/flutter_window_unittests.cc b/engine/src/flutter/shell/platform/windows/flutter_window_unittests.cc index 36972b3321..be820f42ef 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window_unittests.cc @@ -435,5 +435,12 @@ TEST(FlutterWindowTest, PosthumousWindowMessage) { EXPECT_GE(msg_count, 1); } +TEST(FlutterWindowTest, UpdateCursor) { + FlutterWindow win32window(100, 100); + win32window.UpdateFlutterCursor("text"); + HCURSOR cursor = ::GetCursor(); + EXPECT_EQ(cursor, ::LoadCursor(nullptr, IDC_IBEAM)); +} + } // namespace testing } // namespace flutter