You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: add fourth and fifth mouse button to Gesture detector #115641
For desktop applications it would be useful to use the mouse to navigate back and forward in the navigator with the fifths and forth mouse button. It looks like only 1., 2. and 3. mouse buttons are covered in GestureDetector
In this video I covered it with two finger trackpad gesture detector but most desktop users like mice
Since we already have the data in the PointerEvent.buttons bitfield, it is still possible to find out if a tap was made using the fourth and fifth mouse button, but it's not clear that we want to add that to the higher level GestureDetector API, since it would involve increasing the number of parameters and callbacks significantly.
Other gestures do not support buttons this way. But we can always refactor them in the same way as tap. Are there any other gestures you have in mind that need this?
Currently TapGestureReconizer will not recognize the 4th or 5th button since they are not included in addAllowedPointer.
Moreover, adding too many methods to GestureDetector needs careful discussion, because this class is meant to be a hub for common gestures.
However, having tap gestures on the 4th and 5th buttons requires only trivial work already. Here's what you can do:
* Create a `FourthButtonTapGestureRecognizer`, which inherits `BaseTapGestureRecognizer`.
* `BaseTapGestureRecognizer` is created with extensibility in mind and supports any mouse buttons. Check out [the definition for `TapGestureRecognizer`](https://github.com/flutter/flutter/blob/3b15d6a501bd89b2860c116c2ae698d96002522d/packages/flutter/lib/src/gestures/tap.dart#L554).
* Build a `RawGestureDetector` with your `FourthButtonTapGestureRecognizer`.
* Check out [the definition for `GestureDetector`](https://github.com/flutter/flutter/blob/3b15d6a501bd89b2860c116c2ae698d96002522d/packages/flutter/lib/src/widgets/gesture_detector.dart#L1019).
Other gestures do not support buttons this way. But we can always refactor them in the same way as tap. Are there any other gestures you have in mind that need this?
Thanks for the detailed answer! I will try this
No, 4th and 5th mouse button tap/click should be enough here I think :)
Currently TapGestureReconizer will not recognize the 4th or 5th button since they are not included in addAllowedPointer.
Moreover, adding too many methods to GestureDetector needs careful discussion, because this class is meant to be a hub for common gestures.
However, having tap gestures on the 4th and 5th buttons requires only trivial work already. Here's what you can do:
* Create a `FourthButtonTapGestureRecognizer`, which inherits `BaseTapGestureRecognizer`.
* `BaseTapGestureRecognizer` is created with extensibility in mind and supports any mouse buttons. Check out [the definition for `TapGestureRecognizer`](https://github.com/flutter/flutter/blob/3b15d6a501bd89b2860c116c2ae698d96002522d/packages/flutter/lib/src/gestures/tap.dart#L554).
* Build a `RawGestureDetector` with your `FourthButtonTapGestureRecognizer`.
* Check out [the definition for `GestureDetector`](https://github.com/flutter/flutter/blob/3b15d6a501bd89b2860c116c2ae698d96002522d/packages/flutter/lib/src/widgets/gesture_detector.dart#L1019).
Other gestures do not support buttons this way. But we can always refactor them in the same way as tap. Are there any other gestures you have in mind that need this?
Hey 👋
Two years later I actually tried your suggestion :)
For some reason only the 3. button on the mouse wheel click works. Every value higher than 4 in down.buttons is not recognized at all
I struggled with this a bit but for other beginners I'm adding ready to go code, mainly based on dkwingsmt answer and Feichtmeiers published code here and in his other issue, all credits to them:
kBackMouseButton is part of the events.dart class, kForwardMouseButton etc also have the correct value there.
Activity
darshankawar commentedon Nov 18, 2022
Thanks for the report. Treating this as proposal / feature request.
There's another proposal to support middle mouse button scrolling: #66537.
gspencergoog commentedon Dec 1, 2022
Since we already have the data in the
PointerEvent.buttonsbitfield, it is still possible to find out if a tap was made using the fourth and fifth mouse button, but it's not clear that we want to add that to the higher level GestureDetector API, since it would involve increasing the number of parameters and callbacks significantly.(Desktop Triage)
cc @dkwingsmt
dkwingsmt commentedon Dec 1, 2022
Currently
TapGestureReconizerwill not recognize the 4th or 5th button since they are not included in addAllowedPointer.Moreover, adding too many methods to
GestureDetectorneeds careful discussion, because this class is meant to be a hub for common gestures.However, having tap gestures on the 4th and 5th buttons requires only trivial work already. Here's what you can do:
FourthButtonTapGestureRecognizer, which inheritsBaseTapGestureRecognizer.BaseTapGestureRecognizeris created with extensibility in mind and supports any mouse buttons. Check out the definition forTapGestureRecognizer.RawGestureDetectorwith yourFourthButtonTapGestureRecognizer.GestureDetector.Other gestures do not support buttons this way. But we can always refactor them in the same way as tap. Are there any other gestures you have in mind that need this?
Feichtmeier commentedon Dec 1, 2022
Thanks for the detailed answer! I will try this
No, 4th and 5th mouse button tap/click should be enough here I think :)
flutter-triage-bot commentedon Jun 7, 2024
The
triaged-desktoplabel is irrelevant if there is noteam-desktoplabel orfyi-desktoplabel.Feichtmeier commentedon Jul 20, 2024
Hey 👋
Two years later I actually tried your suggestion :)
For some reason only the 3. button on the mouse wheel click works. Every value higher than 4 in down.buttons is not recognized at all
bleroux commentedon Jul 22, 2024
Hey @Feichtmeier,
If you tried it on Linux, this is probably related to the engine not forwarding such events, see https://github.com/flutter/engine/blob/207f088f73cb00fa05aff170030df891d62cadf5/shell/platform/linux/fl_view.cc#L156-L179
Feichtmeier commentedon Jul 22, 2024
Thanks, I created a new issue for this
#152128
Merthan commentedon Aug 4, 2024
Surprising that this hasn't been added/fixed yet
I struggled with this a bit but for other beginners I'm adding ready to go code, mainly based on dkwingsmt answer and Feichtmeiers published code here and in his other issue, all credits to them:
kBackMouseButtonis part of theevents.dartclass,kForwardMouseButtonetc also have the correct value there.And then call it like this for example: