Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@RBT22
Copy link
Contributor

@RBT22 RBT22 commented Jul 30, 2024

This draft PR aims to address the lack of multi-touch support under Linux, leveraging the existing implementation used for Windows. As I am not an expert in this domain, I would greatly appreciate feedback on the implementation.

flutter/flutter#133239
flutter/flutter#52202

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

int32_t device_id,
int modifiers_state);

void SendPointerEventWithData(FlEngine* engine,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be called fl_engine_send_pointer_event

double scroll_delta_y,
int64_t buttons);

void OnPointerDown(FlEngine* self,
Copy link
Contributor

Choose a reason for hiding this comment

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

FlEngine shouldn't contain handlers like this, instead look at fl_scrolling_manager.cc as an example of how to handle this in a separate class.

// Struct holding the state of an individual pointer. The engine doesn't keep
// track of which buttons have been pressed, so it's the embedding's
// responsibility.
struct PointerState {
Copy link
Contributor

Choose a reason for hiding this comment

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

This struct seems to be in the wrong place, as it relates to the engine, not the renderer. To match existing code like fl_engine_send_mouse_pointer_event this should probably be an internal struct and not in a header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it to the engine, but not 100% sure what you meant.. Can you help me with this, please?

Copy link
Contributor

Choose a reason for hiding this comment

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

This structure is only used in fl_engine.cc, therefore it should be defined in there. It's currently in a header, which suggests it's part of external API for a module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thanks for the clarification!

static constexpr int32_t kPointerPanZoomDeviceId = 1;

// Keeps track of pointer states in relation to the window.
std::unordered_map<int32_t, std::unique_ptr<PointerState>> pointer_states_;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be inside a class and use GHashTable (it gets too confusing mixing C++ and GObject).

@robert-ancell
Copy link
Contributor

Thanks for working on this! I did a quick first review, the main issues seem to be moving this logic into it's own class and using GObject style instead of C++ style.

@RBT22
Copy link
Contributor Author

RBT22 commented Aug 21, 2024

Thank you for the feedback! I’ll try to allocate some time for the restructuring next week.

I’ve been testing the code since the PR was opened, and I found an issue with the current implementation on Ubuntu 24.04. When using a three-finger gesture to switch between applications, the touch_event_cb's GDK_TOUCH_END part is not triggered when focus is lost. This results in various unexpected behaviors because the pointers are not removed. Do you have a suggestion for which signal handler could be used to handle this? Thanks in advance!

@robert-ancell
Copy link
Contributor

Based on the behaviour of the other GTK input events I think you just have to handle the missing events and synthesize any that are missing. This is because Flutter expects a perfect input stream and GTK doesn't seem to guarantee this. I expect the event was intercepted by the shell or another layer in GTK and will not be reported to the application.

If you do think it's a mistake in GTK though please make a test case and report at https://gitlab.gnome.org/GNOME/gtk/ - that should clarify if we need to handle this ourselves.

@chrisDexfo
Copy link

@RBT22 Are you planning on resuming the work for this soon ?

The lack of multi-touch handling on linux is currently a blocking issue here...

@RBT22
Copy link
Contributor Author

RBT22 commented Sep 6, 2024

Sorry for the inconvenience, everyone. Something urgent has come up, and I likely won’t be able to finish this in the next 2-3 weeks.

@chrisDexfo
Copy link

@RBT22 Any chances you'll resume work on this soon ?

@RBT22
Copy link
Contributor Author

RBT22 commented Sep 27, 2024

@chrisDexfo I'm still having higher priority tasks at the moment. It will likely take about two more weeks to resolve. I'll be sure to get back to this project as soon as possible after that. Thanks for your understanding!

@flutter-dashboard
Copy link

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

@RBT22 RBT22 force-pushed the linux-multi-touch branch from 0c5aaff to 8c74a1e Compare October 22, 2024 09:02
@RBT22
Copy link
Contributor Author

RBT22 commented Oct 22, 2024

I’ve done some refactoring. @robert-ancell, could you please take a look?

The issue I mentioned earlier with the missing GDK_TOUCH_END events still persists. We use our app with GNOME gestures disabled, so I didn’t explore that further. I’m not entirely sure where the event synthesis should occur. What I did find is that the leave_notify_event_cb is being triggered in those cases, but with a time value of zero.

}
}

void fl_engine_send_pointer_event(FlEngine* self,
Copy link
Contributor

Choose a reason for hiding this comment

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

The engine has methods for each type of event, e.g. fl_engine_send_pointer_pan_zoom_event - adding this general event method doesn't fit in with the existing architecture. How many new pointer events are required? Could there be specific methods for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel the naming could be clearer. It might make more sense as fl_engine_send_touch_pointer_event. Otherwise, if I'm getting this right, we’d end up needing five separate methods for each phase we use. Should I go ahead with that approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say yes, make five methods to match the existing code. We can always consolidate them later if necessary.

struct _FlTouchManager {
GObject parent_instance;

GWeakRef view_delegate;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be replaced with a reference to the engine - the view delegate only forwards the events to the engine. The existing delegates have been reduced or removed as part of the multi-view work.

@@ -0,0 +1,77 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

This class makes this very hard to understand. It's copied from another project, it's in C++ style which doesn't fit in well with the other code. A number of methods aren't being used. It's not used by any other code. I think this could be simplified and merged into FlTouchManager, though that's not a blocker and could be done at a later stage.

Copy link
Contributor

@robert-ancell robert-ancell left a comment

Choose a reason for hiding this comment

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

I think with the removal of the view delegate this should be pretty close to landing. I can see some parts of it being refactored later, but it's not worth blocking on. You will need to add some tests though. Thanks for your patience!

@RBT22 RBT22 force-pushed the linux-multi-touch branch from 0e416b6 to 45e850f Compare December 2, 2024 08:56
@RBT22 RBT22 requested a review from robert-ancell December 2, 2024 08:59
@RBT22 RBT22 force-pushed the linux-multi-touch branch from 3e02739 to 1ae0500 Compare December 2, 2024 13:40
@dkwingsmt
Copy link
Contributor

I wonder how you see the relationship between the touch manager and the pointer manager.

  • I was guessing that you'd like touch manager manages touch screens, while the pointer manager manages mouse. (There will be some duplicate code but it might be acceptable, since handling multi-pointer is different from handling buttons.) However, in this case the touch manager should not need to handle buttons at all.
  • Or you might want to create a unified handler that handles both multi-pointer and buttons. But then you'll want to remove the pointer manager, which this PR doesn't.

@RBT22
Copy link
Contributor Author

RBT22 commented Dec 3, 2024

@dkwingsmt I see what you mean about the relationship between the touch manager and pointer manager. Maybe it’d make sense to move a simplified state to the fl_touch_manager from the engine to clean things up a bit?

As for a unified handler, I get the idea, but I’m not up for tackling that myself right now. :)

@RBT22 RBT22 force-pushed the linux-multi-touch branch from 49ceb1d to 59190a5 Compare December 10, 2024 08:39
@RBT22
Copy link
Contributor Author

RBT22 commented Dec 11, 2024

I moved and simplified the state to FtTouchManager. Also, I integrated the ID generation.

Copy link
Contributor

@robert-ancell robert-ancell left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@robert-ancell
Copy link
Contributor

@dkwingsmt do want to do a review before landing this?

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your contribution!

EXPECT_EQ(pointer_events[4].timestamp,
1000lu); // Milliseconds -> Microseconds
EXPECT_EQ(pointer_events[4].phase, kRemove);
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that EOF empty line isn't enforced. Just if you're interested:

Suggested change
}
}

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 11, 2024
@auto-submit auto-submit bot merged commit 0b34fae into flutter:main Dec 11, 2024
31 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 11, 2024
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Dec 12, 2024
…160128)

flutter/engine@b8034f1...e352461

2024-12-11 jonahwilliams@google.com [Impeller] remove std::vector usage
in render pass vk. (flutter/engine#57132)
2024-12-11 43723477+RBT22@users.noreply.github.com [Linux] Add
Multi-Touch Support for Linux (flutter/engine#54214)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jonahwilliams@google.com,zra@google.com on the revert to
ensure that a human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@RBT22 RBT22 deleted the linux-multi-touch branch December 12, 2024 07:33
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
This draft PR aims to address the lack of multi-touch support under Linux, leveraging the existing implementation used for Windows. As I am not an expert in this domain, I would greatly appreciate feedback on the implementation.

flutter#133239
flutter#52202

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
@chrisDexfo
Copy link

will this be included in next official release ?

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

Labels

affects: desktop autosubmit Merge PR when tree becomes green via auto submit App platform-linux

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants