Skip to content

Add support for stylus buttons#183369

Merged
auto-submit[bot] merged 8 commits into
flutter:masterfrom
CodeDoctorDE:windows/pointer-buttons
Jun 3, 2026
Merged

Add support for stylus buttons#183369
auto-submit[bot] merged 8 commits into
flutter:masterfrom
CodeDoctorDE:windows/pointer-buttons

Conversation

@CodeDoctorDE
Copy link
Copy Markdown
Contributor

@CodeDoctorDE CodeDoctorDE commented Mar 8, 2026

Continuation of #165323.

Now we have stylus support on windows with the last pull request.

This pull request now adds support for invertedStylus and stylus buttons (primary + secondary).

The pull request shouldn't have any breaking changes other than the pointer event shows the correct button bitmap instead of 1 always on a stylus input.

Should completly fix: #102836.

Tested on my notebook:
grafik
repo for the demo code: https://github.com/CodeDoctorDE/flutter-input-demo

This pull request is currently a draft and my next steps is to add tests

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-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.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically a: desktop Running on desktop team-windows Owned by the Windows platform team labels Mar 8, 2026
@CodeDoctorDE CodeDoctorDE changed the title Windows/pointer buttons Add support for stylus buttons Mar 8, 2026
@Piinks
Copy link
Copy Markdown
Contributor

Piinks commented May 11, 2026

@flutter/windows-reviewers can someone take a look?

@CodeDoctorDE CodeDoctorDE force-pushed the windows/pointer-buttons branch from 85c78f0 to a356acd Compare May 12, 2026 04:01
@CodeDoctorDE
Copy link
Copy Markdown
Contributor Author

I updated it again and improved the tracking of the button.
Additionally I added tests for this new stylus button detection.

This pr also sucessfully works on my flutter input demo:
grafik

@CodeDoctorDE CodeDoctorDE marked this pull request as ready for review May 12, 2026 05:40
@CodeDoctorDE CodeDoctorDE requested review from a team and loic-sharma as code owners May 12, 2026 05:40
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 adds support for inverted stylus devices and specific stylus buttons to the Windows embedder by refactoring pointer event handling to track button states per pointer ID. This allows for the detection of button transitions during pointer updates. The changes include new enums in the embedder API, helper functions for Win32 flag translation, and expanded unit tests. Feedback identifies a misleading comment in the flag translation logic, a redundant code block in the pointer info processing, and suggests simplifying the logic for identifying released buttons during pointer-up events.

Comment thread engine/src/flutter/shell/platform/windows/flutter_window.cc Outdated
Comment thread engine/src/flutter/shell/platform/windows/flutter_window.cc Outdated
Comment thread engine/src/flutter/shell/platform/windows/flutter_window.cc Outdated
@jmagman jmagman added the CICD Run CI/CD label May 12, 2026
@loic-sharma
Copy link
Copy Markdown
Member

cc @mattkae

Comment thread engine/src/flutter/shell/platform/embedder/embedder.h
Comment thread engine/src/flutter/shell/platform/windows/flutter_window.cc Outdated
Comment thread engine/src/flutter/shell/platform/windows/flutter_window.cc Outdated
Comment thread engine/src/flutter/shell/platform/windows/flutter_window.h Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label May 16, 2026
@CodeDoctorDE
Copy link
Copy Markdown
Contributor Author

Addressed the reviews, ran the tests and tested it also in my flutter input demo.

Theoretically I can also add button detection on pointer hover but I'm not sure if this is also implemented on other platforms. In this case, the first bit in the button mask is 0.

@CodeDoctorDE CodeDoctorDE requested a review from loic-sharma May 19, 2026 21:21
@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label May 22, 2026
@CodeDoctorDE
Copy link
Copy Markdown
Contributor Author

I didn't touched any mac cis, so i think these fails can be ignored?

@loic-sharma
Copy link
Copy Markdown
Member

@CodeDoctorDE I restarted those tests. If they fail again, please rebase your changes off the latest master commit.

Comment thread engine/src/flutter/shell/platform/embedder/embedder.h
Comment thread engine/src/flutter/shell/platform/embedder/embedder.h
mattkae
mattkae previously approved these changes May 26, 2026
Copy link
Copy Markdown
Contributor

@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 have no hardware with which to test this, but the code looks sensible to me!

loic-sharma
loic-sharma previously approved these changes May 26, 2026
Copy link
Copy Markdown
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

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

Thanks for the excellent patch, LGTM!

@CodeDoctorDE CodeDoctorDE force-pushed the windows/pointer-buttons branch from ac91962 to df4c9d5 Compare May 29, 2026 12:54
@github-actions github-actions Bot removed the CICD Run CI/CD label May 29, 2026
@CodeDoctorDE
Copy link
Copy Markdown
Contributor Author

i saw it was downgraded yesterday, i rebased based on the latest master

@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label May 30, 2026
Copy link
Copy Markdown
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

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

Re-LGTM

@CodeDoctorDE
Copy link
Copy Markdown
Contributor Author

I'm confused right now, last time i checked this page the linux ci failed? But if everything is green then i don't need to do something :)

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 3, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jun 3, 2026
Merged via the queue into flutter:master with commit f2877c6 Jun 3, 2026
206 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 3, 2026
@loic-sharma
Copy link
Copy Markdown
Member

loic-sharma commented Jun 4, 2026

Reason for revert: This PR causes the Windows windows_host_engine_test to fail. cc @CodeDoctorDE

Example failures:

https://ci.chromium.org/ui/p/flutter/builders/prod/Windows%20windows_host_engine_test/7765/overview

Example failures:

Note: Google Test filter = FlutterWindowTest.OnMousePointerDown
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from FlutterWindowTest
[ RUN      ] FlutterWindowTest.OnMousePointerDown
[ERROR:flutter/shell/platform/windows/direct_manipulation.cc(182)] CoCreateInstance(CLSID_DirectManipulationManager, nullptr, CLSCTX_INPROC_SERVER, IID_IDirectManipulationManager, &manager_) failed

GMOCK WARNING:
Uninteresting mock function call - returning directly.
    Function call: OnWindowStateEvent(4-byte object <00-00 00-00>)
NOTE: You can safely ignore the above warning unless this call should not happen.  Do not suppress it by adding an EXPECT_CALL() if you don't mean to enforce the call.  See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details.
../../../flutter/shell/platform/windows/flutter_window_unittests.cc(845): error: Actual function call count doesn't match EXPECT_CALL(delegate, OnPointerDown(45, 50, kFlutterPointerDeviceKindMouse, kDefaultPointerDeviceId, kFlutterPointerButtonMousePrimary, 0, 0))...
         Expected: to be called once
           Actual: never called - unsatisfied and active

[  FAILED  ] FlutterWindowTest.OnMousePointerDown (8 ms)
[----------] 1 test from FlutterWindowTest (8 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (8 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] FlutterWindowTest.OnMousePointerDown

 1 FAILED TEST
[145/740] FlutterWindowTest.OnMousePointerDown returned/aborted with exit code 1 (75 ms)
[146/740] FlutterWindowTest.OnMousePointerDown (76 ms)

@loic-sharma loic-sharma added the revert_wf Revert using Github Workflow label Jun 4, 2026
@flutteractionsbot
Copy link
Copy Markdown
Contributor

Successfully created revert PR: #187581

@flutteractionsbot flutteractionsbot removed the revert_wf Revert using Github Workflow label Jun 4, 2026
@CodeDoctorDE
Copy link
Copy Markdown
Contributor Author

Oh strange, I ran the tests before commiting. I will investigate it

@loic-sharma
Copy link
Copy Markdown
Member

@CodeDoctorDE No worries! Normally our presubmit checks would've caught this, but the Windows embedder unit tests are currently suppressed due to capacity issues: #186597

This is what the test looks like currently if it fails, it's very easy to miss a failure:

image

@CodeDoctorDE
Copy link
Copy Markdown
Contributor Author

CodeDoctorDE commented Jun 4, 2026

I looked at it again and these problems seems like to be because of wrong test code (I added) where I don't have POINTER_FLAG_FIRSTBUTTON added to the pointer flags:

-          pointer_info->pointerFlags = POINTER_FLAG_INCONTACT;
+          pointer_info->pointerFlags = POINTER_FLAG_INCONTACT |
+                                       POINTER_FLAG_FIRSTBUTTON |
+                                       POINTER_FLAG_DOWN;

This should be the correct pointer flags since down and first button should be always there
https://learn.microsoft.com/windows/win32/inputmsg/pointer-flags-contants

With these changes the tests succeed again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically team-windows Owned by the Windows platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter on Windows ignores stylus input

8 participants