Repository navigation
[Linux] Cancel input when events stop being delivered - #192277
Conversation
A view can stop receiving input events while a pointer button is down or a touch is in contact with the screen, and the button release or touch end that completes the interaction is then never delivered. Flutter was left believing the button or touch was still down, which made the next press be dropped and left drags and highlights stuck. This happens when: - The pointer grab is taken by the window manager, e.g. a window starts an interactive move or resize with gtk_window_begin_move_drag() or gtk_window_begin_resize_drag(), so the button release that ends the drag is delivered to the window manager. This is reported by GtkWidget::grab-broken-event. - GDK aborts a touch sequence, e.g. the compositor took the touch to move or resize the window, reported with a touch cancel event. - A GTK grab is taken by another widget, e.g. a menu or a modal dialog. Events are redirected without breaking the GDK grab, so this is only reported by GtkWidget::grab-notify. - The view is unmapped, e.g. its window is hidden or closed while a button is down. Handle each of these by cancelling the pointer and touch state so no input is left stuck down. As a compositor may not always report a broken grab, also treat a press of a button that is already down as evidence that the release was lost and cancel the stale press rather than dropping the new one. A pointer that left the view while a button was down had its remove event delayed until the button was released, so send that delayed remove when the input is cancelled instead of leaving the pointer inside the view at a stale position.
There was a problem hiding this comment.
Code Review
This pull request implements input cancellation handling for touch and pointer events on Linux when a grab is broken, a view is unmapped, or a touch sequence is aborted. The review feedback recommends zero-initializing the stack-allocated FlutterPointerEvent struct to avoid undefined behavior from uninitialized fields, and refactoring the touch manager's grab-broken handler to use GHashTableIter for more efficient and idiomatic GLib hash table iteration.
33584a9 to
ce7c03f
Compare
The touch events are stack allocated and only the fields being used are set, so the remaining fields are filled with whatever was on the stack. The engine is told the full size of the struct, so it reads these fields and sees garbage in them, e.g. a random pressure or scroll delta. Zero the events when they are declared, as is already done for the mouse pointer events.
Getting the keys of the table and looking each one up again allocates a list and does a lookup per touch, while a GHashTableIter gives both the key and the value. Every touch point is cancelled, so the table is cleared in one go afterwards rather than an entry at a time.
ce7c03f to
9c22145
Compare
|
Once this is landed I will propose the fix in https://github.com/robert-ancell/flutter/tree/linux-per-device-pointers |
Co-authored-by: Matthew Kosarek <[email protected]>
|
autosubmit label was removed for flutter/flutter/192277, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Moving or resizing a window hands the pointer to the window system, which finishes the drag without telling the app the button was released. On X11 the grab is broken and the press is already cancelled, but on Wayland the compositor runs the drag and no grab is involved, so the button was left pressed forever. Everything after that looked like a drag, which stopped the app receiving hover events. Cancel the press if the pointer comes back with nothing pressed.
The pointer manager is now asked to cancel input when a stale press is detected and when the pointer returns without its button, and on Wayland neither of these is a broken grab. Name these functions after what they do rather than one of the things that trigger them.
|
autosubmit label was removed for flutter/flutter/192277, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/flutter/192277, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/flutter/192277, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Roll Flutter from 63b9518f16bc to 2553f89be1ef (62 revisions) flutter/flutter@63b9518...2553f89 2026-09-12 [email protected] Roll clang to 07d67299a15ce03b053736e2d31a668ee0576987 (flutter/flutter#192607) 2026-09-12 [email protected] Roll Dart SDK from b24b352c29db to 7863887acbfb (3 revisions) (flutter/flutter#192665) 2026-09-12 [email protected] fix(tree): et format --all (flutter/flutter#192669) 2026-09-12 [email protected] Support activity-alias in Android launcher activity detection (flutter/flutter#187251) 2026-09-12 [email protected] fix: regenerate gradle lockfiles for external_textures integration test (flutter/flutter#192657) 2026-09-12 [email protected] Roll Skia from 51aa02b2c195 to e5e96533b732 (4 revisions) (flutter/flutter#192646) 2026-09-12 [email protected] [WebParagraph] Fix text pixelation, glyph clipping, and snapping offsets to avoid subpixel raster caching (flutter/flutter#191736) 2026-09-12 [email protected] fix(tests): Add ruby dep to Mac windowing_test (flutter/flutter#192656) 2026-09-12 [email protected] Remove some `unawaited_futures` outdated ignores (flutter/flutter#192026) 2026-09-11 [email protected] Bump Dart to 3.13, reformat, re-enable formatting check (flutter/flutter#192649) 2026-09-11 [email protected] [android] Isolate API-34 high contrast listener in AccessibilityBridge behind Api34Impl (flutter/flutter#192502) 2026-09-11 [email protected] Update style guide for Dart 3.13 (flutter/flutter#192639) 2026-09-11 [email protected] ci(bringups): remove bringup from these tests (flutter/flutter#192637) 2026-09-11 [email protected] Unmark new_gallery_windows_impeller__transition_perf as bringup (flutter/flutter#192633) 2026-09-11 [email protected] Unmark new_gallery_windows_skia__transition_perf as bringup (flutter/flutter#192635) 2026-09-11 [email protected] Roll Skia from f446aec4ce9e to 51aa02b2c195 (2 revisions) (flutter/flutter#192631) 2026-09-11 [email protected] fix(ci): mac verify binaries still racing (flutter/flutter#192634) 2026-09-11 [email protected] Roll Packages from 8a35b16 to 9caa77c (8 revisions) (flutter/flutter#192630) 2026-09-11 [email protected] Roll Dart SDK from a76fee2722e0 to b24b352c29db (2 revisions) (flutter/flutter#192627) 2026-09-11 [email protected] [tool] Migrate PackagesCommand and Pub to modular dependency injection (flutter/flutter#192460) 2026-09-11 [email protected] [tool] Migrate Darwin framework commands to modular dependency injection (flutter/flutter#192252) 2026-09-11 [email protected] [tool] Migrate Upgrade, Downgrade, and UpdatePackages commands to modular dependency injection (flutter/flutter#190787) 2026-09-11 [email protected] Roll Skia from b3fa80a0e168 to f446aec4ce9e (55 revisions) (flutter/flutter#192620) 2026-09-11 [email protected] Roll Dart SDK from d20d59cfa664 to a76fee2722e0 (2 revisions) (flutter/flutter#192616) 2026-09-11 [email protected] remove deeplink integration tests from bringup (flutter/flutter#192459) 2026-09-11 [email protected] Revert: [devicelab] Clean up Chrome profile directories and trap abort signals in web benchmarks (flutter/flutter#192615) 2026-09-11 [email protected] Roll Fuchsia Linux SDK from C0j8F-_Iy-OQZ6YyI... to m69nfK-wnHaMTe8P9... (flutter/flutter#192608) 2026-09-11 [email protected] Fix Wasm build cache mismatch in ResidentWebRunner and browser 404 fallbacks (flutter/flutter#190786) 2026-09-11 [email protected] Roll Dart SDK from 3ce3116bc9ec to d20d59cfa664 (1 revision) (flutter/flutter#192588) 2026-09-11 [email protected] [Linux] Keep the frame at the top of a resizing subsurface (flutter/flutter#192408) 2026-09-10 [email protected] [devicelab] Clean up Chrome profile directories and trap abort signals in web benchmarks (flutter/flutter#192584) 2026-09-10 [email protected] [web] Keep ImageSource alive until Picture disposal (flutter/flutter#192516) 2026-09-10 [email protected] Remove the accessibility evaluations feature flag (flutter/flutter#192266) 2026-09-10 [email protected] Promote Windows gradient benchmark tests to non-bringup (flutter/flutter#192581) 2026-09-10 [email protected] Remove commented out export in `text_input.dart` since the dart compiler has the correct behavior now (flutter/flutter#191539) 2026-09-10 [email protected] [flutter_tools] Do not mistake server-initiated requests for responses to client requests in AnalysisServer (flutter/flutter#192546) 2026-09-10 [email protected] Roll Packages from 36e088a to 8a35b16 (12 revisions) (flutter/flutter#192550) 2026-09-10 [email protected] Roll pub packages (flutter/flutter#192517) 2026-09-10 [email protected] feat(web): support --web-content-hash for entrypoint files (flutter/flutter#190153) 2026-09-10 [email protected] [web] Stop iOS auto-zoom by sizing semantic inputs at 16px (flutter/flutter#192328) 2026-09-10 [email protected] Roll Dart SDK from 0d55b7a6a9ee to 3ce3116bc9ec (2 revisions) (flutter/flutter#192534) 2026-09-10 [email protected] Update more enum instances comparison to use equality == since dart has the correct behavior now (flutter/flutter#191788) 2026-09-10 [email protected] Fix specify_nonobvious_local_variable_types lints in luci_resultdb_test.dart (flutter/flutter#192543) 2026-09-10 [email protected] Roll ICU from 8cc91d9b6ab9 to 6ebb40c59477 (1 revision) (flutter/flutter#192527) 2026-09-10 [email protected] [Linux] Make the framebuffer depth/stencil buffer optional (flutter/flutter#192156) 2026-09-10 [email protected] [Linux] Cancel input when events stop being delivered (flutter/flutter#192277) ...
A view can stop receiving input events while a pointer button is down or a touch is in contact with the screen, and the button release or touch end that completes the interaction is then never delivered. Flutter was left believing the button or touch was still down, which made the next press be dropped and left drags and highlights stuck.
This happens when:
Handle each of these by cancelling the pointer and touch state so no input is left stuck down. As a compositor may not always report a broken grab, also treat a press of a button that is already down as evidence that the release was lost and cancel the stale press rather than dropping the new one.
A pointer that left the view while a button was down had its remove event delayed until the button was released, so send that delayed remove when the input is cancelled instead of leaving the pointer inside the view at a stale position.