Skip to content

Commit

Permalink
Viewer: Send horizontal scroll wheel events
Browse files Browse the repository at this point in the history
On macOS and Windows, these are communicated to applications as vertical
scroll wheel events with the Shift key held down.  (The operating system
acts as if the Shift key is held down, but no Shift key press/release
events are actually fired.)  We use RFB Buttons 6 and 7 for,
respectively, left and right scroll wheel events, since X11 Buttons 6
and 7 are used for the same purpose.  (Thus, implementing this feature
in the TurboVNC Server simply required incrementing the loop limit in
PtrAddEvent().)  Java doesn't need to use Java Buttons 4 and 5 for
vertical scroll wheel events, since those events have a separate
subclass.  Thus, X11 Buttons 6 and 7 map to Java Buttons 4 and 5, and we
simply map Java Buttons 4 and 5 to RFB Buttons 6 and 7 in order to
implement horizontal scrolling for X11 clients.

Server and macOS/Windows viewer implementation based on:
rsparlin@77e266d

Closes #416
  • Loading branch information
dcommander committed Jul 1, 2024
1 parent d099a4d commit 32f5969
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ if all viewer connections originate from the loopback IP address.) The
TurboVNC Server now also logs the total number of simultaneously connected
viewers.

2. The TurboVNC Viewer now sends horizontal scroll wheel events to the VNC
server. (These events can be generated with horizontal scroll gestures on a
trackpad or, with certain mice, by side-clicking the scroll wheel.)


3.1.1
=====
Expand Down
2 changes: 2 additions & 0 deletions java/com/turbovnc/rfb/RFB.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ public static String encodingName(int num) {
public static final int BUTTON3_MASK = 4;
public static final int BUTTON4_MASK = 8;
public static final int BUTTON5_MASK = 16;
public static final int BUTTON6_MASK = 32;
public static final int BUTTON7_MASK = 64;

//***************************************************************************
// GII
Expand Down
38 changes: 32 additions & 6 deletions java/com/turbovnc/vncviewer/CConn.java
Original file line number Diff line number Diff line change
Expand Up @@ -2825,11 +2825,20 @@ public void writePointerEvent(MouseEvent ev) {
buttonMask |= RFB.BUTTON2_MASK; break;
case 3:
buttonMask |= RFB.BUTTON3_MASK; break;
case 4:
// X11 uses Buttons 6 and 7 for (respectively) left and right
// scroll wheel events, but Java/X11 uses Buttons 4 and 5.
if (!Utils.isX11()) return;
buttonMask |= RFB.BUTTON6_MASK; break;
case 5:
if (!Utils.isX11()) return;
buttonMask |= RFB.BUTTON7_MASK; break;
default:
return;
}
vlog.debug("mouse PRESS, button " + ev.getButton() +
", coords " + ev.getX() + "," + ev.getY());
if (ev.getButton() <= 3)
vlog.debug("mouse PRESS, button " + ev.getButton() +
", coords " + ev.getX() + "," + ev.getY());
break;
case MouseEvent.MOUSE_RELEASED:
switch (ev.getButton()) {
Expand All @@ -2839,11 +2848,18 @@ public void writePointerEvent(MouseEvent ev) {
buttonMask &= ~RFB.BUTTON2_MASK; break;
case 3:
buttonMask &= ~RFB.BUTTON3_MASK; break;
case 4:
if (!Utils.isX11()) return;
buttonMask &= ~RFB.BUTTON6_MASK; break;
case 5:
if (!Utils.isX11()) return;
buttonMask &= ~RFB.BUTTON7_MASK; break;
default:
return;
}
vlog.debug("mouse release, button " + ev.getButton() +
", coords " + ev.getX() + "," + ev.getY());
if (ev.getButton() <= 3)
vlog.debug("mouse release, button " + ev.getButton() +
", coords " + ev.getX() + "," + ev.getY());
break;
}

Expand Down Expand Up @@ -2881,10 +2897,20 @@ public void writeWheelEvent(MouseWheelEvent ev) {
if (params.reverseScroll.get()) {
clicks = -clicks;
}
// On macOS and Windows, horizontal scroll wheel events are simply vertical
// scroll wheel events with the Shift key held down. (The operating system
// acts as if the Shift key is held down, but no Shift key press/release
// events are actually fired.)
boolean isHorizontal =
(Utils.isMac() || Utils.isWindows()) && ev.isShiftDown();
// X11 uses Buttons 4, 5, 6, and 7 for (respectively) up, down, left, and
// right scroll wheel events.
if (clicks < 0) {
wheelMask = buttonMask | RFB.BUTTON4_MASK;
wheelMask = buttonMask |
(isHorizontal ? RFB.BUTTON6_MASK : RFB.BUTTON4_MASK);
} else {
wheelMask = buttonMask | RFB.BUTTON5_MASK;
wheelMask = buttonMask |
(isHorizontal ? RFB.BUTTON7_MASK : RFB.BUTTON5_MASK);
}

if (cp.width != desktop.scaledWidth ||
Expand Down
2 changes: 1 addition & 1 deletion unix/Xvnc/programs/Xserver/hw/vnc/kbdptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ void PtrAddEvent(int buttonMask, int x, int y, rfbClientPtr cl)
cursorPosY = y;
}

for (i = 0; i < 5; i++) {
for (i = 0; i < 7; i++) {
if ((buttonMask ^ oldButtonMask) & (1 << i)) {
if (buttonMask & (1 << i)) {
valuator_mask_set_range(&mask, 0, 0, NULL);
Expand Down

0 comments on commit 32f5969

Please sign in to comment.