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

Merged
merged 11 commits into from
Jan 14, 2025

Conversation

CendioHalim
Copy link
Contributor

@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 Outdated 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
Contributor Author

I've updated my branch and addressed all comments

@CendioHalim CendioHalim force-pushed the mouse-buttonstate-remove branch from 0925be1 to 19c2b83 Compare January 8, 2025 12:51
core/rfb.js Outdated Show resolved Hide resolved
core/rfb.js Outdated Show resolved Hide resolved
core/rfb.js Outdated Show resolved Hide resolved
core/rfb.js Outdated Show resolved Hide resolved
core/rfb.js Outdated Show resolved Hide resolved
@CendioHalim CendioHalim force-pushed the mouse-buttonstate-remove branch 8 times, most recently from b14d32e to 173de1b Compare January 13, 2025 14:46
tests/test.rfb.js Outdated Show resolved Hide resolved
tests/test.rfb.js Outdated Show resolved Hide resolved
tests/test.rfb.js Show resolved Hide resolved
core/rfb.js Outdated Show resolved Hide resolved
Copy link
Member

@CendioOssman CendioOssman left a comment

Choose a reason for hiding this comment

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

Really nice improvements to the tests! But I have some questions on the new changes.

core/rfb.js Outdated Show resolved Hide resolved
tests/test.rfb.js Outdated Show resolved Hide resolved
tests/test.rfb.js Show resolved Hide resolved
tests/test.rfb.js Outdated Show resolved Hide resolved
core/rfb.js Show resolved Hide resolved
@CendioHalim CendioHalim force-pushed the mouse-buttonstate-remove branch 3 times, most recently from 471a456 to 5f2d0d7 Compare January 14, 2025 08:43
These functions can be used elsewhere in the tests. We want to use these
in the dragging tests in the future instead of directly calling private
methods.
@CendioHalim CendioHalim force-pushed the mouse-buttonstate-remove branch from 5f2d0d7 to 55409ab Compare January 14, 2025 09:43
This makes our tests reflect the real world better, as we now send real
mouse events instead of calling private methods directly.
Previously, these unit tests did not check which events were sent to the
server, only how many events were sent. This commit adds checks to see
that the expected button events are sent.
This is needed if we want to test gestures with dragging.
There were no test for viewport dragging using gesture previously, so
let's add some.

Note that there currently are some viewport dragging behaviours that we
don't want to have, so some tests have commented out what our desired
behaviour should be.
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.
We don't want to send any mouse events to the server when dragging the
viewport. Instead, we treat them as a client-only operation.
We want to flush pending mouse moves before we initiate viewport
dragging.

Before this commit, there were scenarios where the _mouseButtonMask
would track a released button as being down.
@CendioHalim CendioHalim force-pushed the mouse-buttonstate-remove branch from 55409ab to 6383fa6 Compare January 14, 2025 11:39
@CendioOssman CendioOssman merged commit 9cdbd28 into novnc:master Jan 14, 2025
11 checks passed
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