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

Add support for forward and back mouse buttons #1826

Merged
merged 3 commits into from
Nov 18, 2024

Conversation

CendioHalim
Copy link
Contributor

This is a continuation of the work initially done by manny33 in #1711:

This PR intends to add support for forward and back mouse buttons by extending RFB with the pseudo-encoding ExtendedMouseButtons, which is IANA registered and has an open draft PR on rfbproto:

In its current state, this PR has a working implementation that works on Windows, Mac and Linux (with some issues that are being worked on).

I'm quite content with the RFB implementation on the VNC side, but the client-side implementation in Viewport.cxx is currently being re-written quite extensively so that all mouse events are handled with native code instead of using a combination of FLTK and native code.

This is still a work in progress, and commits will be cleaned up / rebased.

@Neustradamus
Copy link

To follow this new PR :)

@CendioHalim
Copy link
Contributor Author

I've now updated Viewport.cxx so that all* mouse handling is done using native platform code: 30e4e9e

(*) There is still a known bug where FL_ENTER and FL_LEAVE in Viewport::handle() are still reached. I think that these should be removed completely, as they are pointer events that should be handled entirely in handleSystemPointerEvent().

@CendioHalim
Copy link
Contributor Author

Seems like the close button is not respected on macOS (minimize/maximize works), will have to do some digging to find out why that is.

@CendioHalim
Copy link
Contributor Author

I've fixed the issued and updated my branch. Most of the work was done in cfe40cc, which has a very hacky solution to fix resizing on macOS.

@CendioHalim CendioHalim changed the title Draft: Add support for forward and back mouse buttons Add support for forward and back mouse buttons Sep 6, 2024
@CendioHalim
Copy link
Contributor Author

There appears to still be some issues:

When I start vncviewer on Linux, the cursor is invisible until I enter and leave the window once.

On Windows, the window buttons (minimize, maximize, close) don't work (we should return 0 instead of consuming the events). Also, the viewer doesn't detect WM_MOUSELEAVE / mouse-enter unless I lose focus and get window focus again.

On macOS, the resizing is still a bit buggy and can leave the window in a broken state where the viewer can't be resized / loses input.

@CendioHalim
Copy link
Contributor Author

There is also a bug on all platforms where pressing the forward button while moving the mouse will trigger a push/release/push instantly. Haven't looked into why this happens, but I've seen it on all platforms with three different mice.

@CendioHalim
Copy link
Contributor Author

CendioHalim commented Sep 10, 2024

On Windows, the window buttons (minimize, maximize, close) don't work (we should return 0 instead of consuming the events). Also, the viewer doesn't detect WM_MOUSELEAVE / mouse-enter unless I lose focus and get window focus again.

Fixed in 2f8fe06 and f82a074.

@CendioHalim
Copy link
Contributor Author

I've opened a PR to FLTK to fix forward/back mouse button support for macOS and Windows:

With this fix in FLTK, the TigerVNC code can be immensely simplified. I've updated my branch to reflect the changes done in the PR.

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.

Looks really nice! Great work!

There are some minor tweaks, but we are pretty much done.

Please also organise the commit history to something more final.

common/rfb/CMsgWriter.cxx Outdated Show resolved Hide resolved
common/rfb/CMsgWriter.cxx Outdated Show resolved Hide resolved
common/rfb/SMsgReader.cxx Show resolved Hide resolved
common/rfb/SMsgReader.cxx Outdated Show resolved Hide resolved
common/rfb/SMsgWriter.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.h Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
@CendioHalim CendioHalim force-pushed the mouse-button-support branch 4 times, most recently from 02b065c to d62899d Compare September 24, 2024 14:45
@CendioHalim
Copy link
Contributor Author

I've addressed most of the comments and rebased/cleaned up my commits.

@CendioHalim CendioHalim force-pushed the mouse-button-support branch 2 times, most recently from 1747194 to dc3dcbe Compare September 25, 2024 14:04
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.

For the commit message; full URLs are preferred to references that only work in GitHub. Or perhaps omit that reference to the old PR and just like it here in the new PR?

Same with using GitHub usernames. If it's a commit message, then a name (and possibly email) is best. Just like for git's author/committer.

common/rfb/CMsgWriter.cxx Show resolved Hide resolved
unix/xserver/hw/vnc/vncInput.c Outdated Show resolved Hide resolved
@@ -207,6 +207,24 @@ static int vncPointerProc(DeviceIntPtr pDevice, int onoff)
btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);

/*
Copy link
Member

Choose a reason for hiding this comment

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

Indentation is off here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, looks like the file uses tabs and not spaces.

@@ -50,7 +50,7 @@ extern const unsigned int code_map_qnum_to_xorgevdev_len;
extern const unsigned short code_map_qnum_to_xorgkbd[];
extern const unsigned int code_map_qnum_to_xorgkbd_len;

#define BUTTONS 7
#define BUTTONS 9
Copy link
Member

Choose a reason for hiding this comment

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

Does this implicitly also make unknown bits ignored? Or are they just unlabeled and perhaps wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've explicitly labelled and initialized 9 buttons. We then loop through the mask, bits set in the higher range are ignored:

void vncPointerButtonAction(int buttonMask)
{
	int i;
	ValuatorMask mask;

	for (i = 0; i < BUTTONS; i++) {
		if ((buttonMask ^ oldButtonMask) & (1 << i)) {
			int action = (buttonMask & (1<<i)) ?
				     ButtonPress : ButtonRelease;
			valuator_mask_set_range(&mask, 0, 0, NULL);
			QueuePointerEvents(vncPointerDev, action, i + 1,
					   POINTER_RELATIVE, &mask);
		}
	}

	oldButtonMask = buttonMask;
}

common/rfb/CMsgWriter.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.h Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
@CendioHalim CendioHalim force-pushed the mouse-button-support branch 6 times, most recently from 2fbc92b to bfece3f Compare October 4, 2024 10:15
vncviewer/DesktopWindow.cxx Outdated Show resolved Hide resolved
common/rfb/CMsgWriter.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
vncviewer/Viewport.cxx Outdated Show resolved Hide resolved
@CendioHalim CendioHalim force-pushed the mouse-button-support branch 3 times, most recently from 3202331 to 7a34e39 Compare October 21, 2024 14:48
@CendioOssman
Copy link
Member

Almost complete. x0vncserver doesn't work correctly for some reason. Only the back button works, not the forward button.

@CendioHalim
Copy link
Contributor Author

Almost complete. x0vncserver doesn't work correctly for some reason. Only the back button works, not the forward button.

1c2f07f fixes this, but this would have to be updated if we want to add support for more buttons in the future.

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.

Seems to work correctly now. Good work!

But I think a tweak is needed on which change is in which commit.

win/rfb_win32/SDisplay.cxx Show resolved Hide resolved
@CendioHalim CendioHalim force-pushed the mouse-button-support branch 2 times, most recently from 152e92b to d57a33b Compare October 22, 2024 12:49
This commit adds support for the pseudo-encoding ExtendedMouseButtons in
Xvnc and x0vncserver, which makes it possible to use to use the
back/forward mouse buttons.

This commit contains work originally done by
PixelSmith <manny33@frontbuffer.com>.
It makes more sense to use bit shifts instead of decimals for each
button.
This commit implements the pseudo-encoding ExtendedMouseButtons which
makes it possible to use the back/forward mouse buttons.

This commit contains work originally done by
PixelSmith <manny33@frontbuffer.com>.
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.

Looks good!

When can we expect fltk/fltk#1083 to be merged? I don't want to risk the API changing.

And @bphinz, I assume you can easily add that PR to your FLTK build?

@CendioHalim
Copy link
Contributor Author

When can we expect fltk/fltk#1083 to be merged? I don't want to risk the API changing.

The FLTK fix has already been merged into master: fltk/fltk#1081 and should be part of the upcoming 1.4.0 API.

Regarding the backport to 1.3 , it looks like it might be a while: fltk/fltk#1083 (comment)

@CendioOssman
Copy link
Member

We are targeting FLTK 1.3, not 1.4, so we need to have some confirmation that we can start relying on this API. Otherwise we might end up in a mess where there are several version with subtle differences that we somehow need to handle.

@Albrecht-S
Copy link
Contributor

We are targeting FLTK 1.3, not 1.4, so we need to have some confirmation that we can start relying on this API. Otherwise we might end up in a mess where there are several version with subtle differences that we somehow need to handle.

Sorry, our release process for 1.4.0 will take a while, depending on the number of RC's we need to publish. RC2 will certainly follow because we do already have one essential fix. Each RC is scheduled one week after the previous one and the final release will typically be two weeks after the last RC, i.e. the final release will be published if we don't have any issues for two weeks.

I can't backport the changes to 1.3.10 (i.e. merge the existing PR) before 1.4.0 has been released which will not be before about 3 weeks from now (or later if more RC's are required, see above).

@CendioOssman
Copy link
Member

We don't have to wait for a 1.3.10 release. We can apply a patch to our builds until then. But we need to know that you are happy with the API, and we won't have to change things once 1.3.10 is out.

@Albrecht-S
Copy link
Contributor

we need to know that you are happy with the API,

I am happy with it, as it stands now, but ...

and we won't have to change things once 1.3.10 is out.

As you certainly know the future is hard to predict. Therefore I can't give any guarantees that the API doesn't have to be changed later, but I'm pretty confident that this won't happen.

Once 1.4.0 is finally released chances are even better that the API won't be changed in incompatible ways and I'll begin to verify and merge the open PR to 1.3.10. That's all I can say for sure. Sorry.

@CendioOssman CendioOssman merged commit 5816986 into TigerVNC:master Nov 18, 2024
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.

4 participants