Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MouseEvent.buttons for button state tracking #1921

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CendioHalim
Copy link

@CendioHalim CendioHalim commented Nov 29, 2024

Instead of keeping track of button states ourselves by looking at MouseEvent.button, we can use the MouseEvent.buttons which already contains the state of all buttons.

Note that in MouseEvent.button, button numbers are mapped as follows:

0 -> Left
1 -> Middle
2 -> Right
3 -> Back
4 -> Forward

But when looking at the MouseEvent.buttons property, the bits middle and right are switched, which is confusing:

0 -> Left
1 -> Right
2 -> Middle
3 -> Back
4 -> Forward

With this change, #1919 could be modified to work with Safari as well.

Unfortunately, the internal _mouseButtonStateMask state is not removed in this PR as it would require a large rewrite of the general architecture.

Tested on:

  • Linux
    • Firefox
    • Chrome
    • Epiphany
  • Windows 11
    • Edge
    • Chrome
    • Firefox
  • macOS
    • Safari
    • Edge
    • Chrome
    • Firefox
  • iPad
    • Safari

core/rfb.js Show resolved Hide resolved
core/rfb.js Outdated Show resolved Hide resolved
core/rfb.js Show resolved Hide resolved
core/rfb.js Outdated Show resolved Hide resolved
core/rfb.js Outdated Show resolved Hide resolved
tests/test.rfb.js Outdated Show resolved Hide resolved
@samhed samhed added this to the v1.6.0 milestone Jan 7, 2025
@CendioHalim CendioHalim force-pushed the mouse-buttonstate-remove branch from 278742b to 0925be1 Compare January 8, 2025 12:27
@CendioHalim
Copy link
Author

I've updated my branch and addressed all comments

Instead of keeping track of button states ourselves by looking at
MouseEvent.button, we can use the MouseEvent.buttons which already
contains the state of all buttons.
@CendioHalim CendioHalim force-pushed the mouse-buttonstate-remove branch from 0925be1 to 19c2b83 Compare January 8, 2025 12:51
Comment on lines 1126 to +1129
// Otherwise we treat this as a mouse click event.
// Send the button down event here, as the button up
// event is sent at the end of this function.
this._sendMouse(x, y, bmask);
this._sendMouse(x, y, this._mouseButtonMask);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the comment here has been considered. Can you still click in place with dragging active?

I guess that means we are lacking at least one unit test.

Copy link
Member

Choose a reason for hiding this comment

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

This drag handling might be on the wrong layer. Perhaps it should be moved up one level in the stack.

this._handleMouseButton(pos.x, pos.y, true, 1 << 5);
this._handleMouseButton(pos.x, pos.y, false, 1 << 5);
this._handleMouseButton(pos.x, pos.y, true, bmask | 1 << 5);
this._handleMouseButton(pos.x, pos.y, false, bmask);
Copy link
Member

Choose a reason for hiding this comment

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

Looks good. Do we have unit tests that make sure that buttons + wheel work at the same time?

@@ -1307,33 +1333,36 @@ export default class RFB extends EventTargetMixin {
case 'longpress':
this._fakeMouseMove(ev, pos.x, pos.y);
break;
case 'twodrag':
case 'twodrag': {
let bmask = RFB._convertButtonMask(ev.detail.buttons);
Copy link
Member

Choose a reason for hiding this comment

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

There is no buttons attribute for gesture events. I'm concerned that this passes the unit tests. Something must be missing/wrong there.

// Always scroll in the same position.
// We don't know if the mouse was moved so we need to move it
// every update.
this._fakeMouseMove(ev, pos.x, pos.y);
while ((ev.detail.magnitudeY - this._gestureLastMagnitudeY) > GESTURE_SCRLSENS) {
this._handleMouseButton(pos.x, pos.y, true, 0x8);
this._handleMouseButton(pos.x, pos.y, false, 0x8);
this._handleMouseButton(pos.x, pos.y, true, bmask | 0x8);
Copy link
Member

Choose a reason for hiding this comment

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

You should probably rather keep using the known mouse state. I.e. this._mouseButtonMask.

this._handleMouseButton(pos.x, pos.y, true, 0x8);
this._handleMouseButton(pos.x, pos.y, false, 0x8);
this._handleMouseButton(pos.x, pos.y, true, bmask | 0x8);
this._handleMouseButton(pos.x, pos.y, false, 0x0);
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants