Skip to content

Add touch input as a flag to Button's button_mask #15163

Description

@ace24713

Problem or limitation

In Godot 4.7 BaseButton was given touch support . With this change, now all buttons automatically respond to touch inputs, whether the user wants them to or not. This was actually causing bugs in my project after upgrading because I was relying on the old behavior, and with no way to turn it off I was forced to downgrade.

Additionally the current interaction with touch inputs against Mouse Right or Mouse Middle masking is unintuitive. As of this PR the behavior is that taps will trigger any button, regardless of it's mask setting. This can be undesirable, especially if the user has enable_long_press_as_right_click turned on. The root cause being that a touch input can't be categorized as a left/middle/right mouse button.

Proposed improvement

Both problems can be solved by adding TOUCH_INPUT as a possible mask option to BaseButton's button_mask property. The BitField name MouseButtonMask will probably need to be renamed in this case too. This would solve both problems by allowing users to configure which Buttons are expected to respond to screen taps and which aren't.

It should work like this:

  • If button_mask has both LEFT_MOUSE and TOUCH_INPUT set, then the button should respond to both, but ignore emulated events to prevent double triggering.
  • If button_mask does not have the TOUCH_INPUT flag set, the behavior should basically be the same as the 4.6 code, and emulated events should be processed in this case. This is also useful as a compatibility setting.
  • In any other combination Buttons should respond to emulated events as well since there's no overlap.

I would also like to mention that if the above change is not acceptable, I would instead propose a smaller but less functional alternative: touch inputs should be categorized as "left mouse" inputs for the purposes of button_masking. This at least addresses the more pressing issue about touch inputs unintuitively triggering "right mouse only" buttons.

Proposal review

  • Yes, this proposal is highly specific and actionable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions