Skip to content

Commit

Permalink
Viewer/bump scrolling: Handle MOUSE_EXITED events
Browse files Browse the repository at this point in the history
A fast fling of the mouse toward one of the edges of the viewer window
may not register any MOUSE_DRAGGED or MOUSE_MOVED events near the edge,
so we need to extend the bump scrolling code to cover MOUSE_EXITED
events as well.
  • Loading branch information
dcommander committed Jan 13, 2025
1 parent 2fe11de commit 98ded85
Showing 1 changed file with 56 additions and 53 deletions.
109 changes: 56 additions & 53 deletions java/com/turbovnc/vncviewer/DesktopWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,60 @@ public synchronized void checkClipboard() {
}
}

private void bumpScroll(MouseEvent e) {
if (!cc.params.fullScreen.get() || !cc.params.bumpScroll.get())
return;

Rectangle viewRect = cc.viewport.sp.getViewport().getViewRect();
lastScreenX = e.getXOnScreen() - cc.viewport.getLocation().x;
lastScreenY = e.getYOnScreen() - cc.viewport.getLocation().y;
int bumpScrollMarginX = (int)((double)viewRect.width / 16 + 0.5);
int bumpScrollMarginY = (int)((double)viewRect.height / 16 + 0.5);

if ((scaledWidth > viewRect.width &&
(viewRect.x > 0 && lastScreenX < bumpScrollMarginX) ||
(viewRect.x < scaledWidth - viewRect.width &&
lastScreenX > viewRect.width - bumpScrollMarginX)) ||
(scaledHeight > viewRect.height &&
(viewRect.y > 0 && lastScreenY < bumpScrollMarginY) ||
(viewRect.y < scaledHeight - viewRect.height &&
lastScreenY > viewRect.height - bumpScrollMarginY))) {
if (bumpScrollTimer == null || !bumpScrollTimer.isRunning()) {
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
Rectangle viewRect = cc.viewport.sp.getViewport().getViewRect();
int bumpScrollMarginX = (int)((double)viewRect.width / 16 + 0.5);
int bumpScrollMarginY = (int)((double)viewRect.height / 16 + 0.5);
int dx = 0, dy = 0;
java.awt.Point viewPos =
cc.viewport.sp.getViewport().getViewPosition();

if (viewRect.x > 0 && lastScreenX < bumpScrollMarginX)
dx = -Math.min(viewRect.x, BUMP_SCROLL_PIXELS);
if (viewRect.x < scaledWidth - viewRect.width &&
lastScreenX > viewRect.width - bumpScrollMarginX)
dx = Math.min(scaledWidth - viewRect.width - viewRect.x,
BUMP_SCROLL_PIXELS);
if (viewRect.y > 0 && lastScreenY < bumpScrollMarginY)
dy = -Math.min(viewRect.y, BUMP_SCROLL_PIXELS);
if (viewRect.y < scaledHeight - viewRect.height &&
lastScreenY > viewRect.height - bumpScrollMarginY)
dy = Math.min(scaledHeight - viewRect.height - viewRect.y,
BUMP_SCROLL_PIXELS);
if (dx != 0 || dy != 0) {
viewPos.translate(dx, dy);
cc.viewport.sp.getViewport().setViewPosition(viewPos);
} else
((Timer)e.getSource()).stop();
}
};
bumpScrollTimer = new Timer(BUMP_SCROLL_MS, actionListener);
bumpScrollTimer.start();
}
} else if (bumpScrollTimer != null && bumpScrollTimer.isRunning())
bumpScrollTimer.stop();
}

// EDT: Mouse motion callback function
private void mouseMotionCB(MouseEvent e) {
int x = (cc.viewport == null) ? 0 : cc.viewport.dx;
Expand Down Expand Up @@ -551,58 +605,7 @@ private void mouseMotionCB(MouseEvent e) {
}
lastX = e.getX();
lastY = e.getY();

if (cc.params.fullScreen.get() && cc.params.bumpScroll.get()) {
Rectangle viewRect = cc.viewport.sp.getViewport().getViewRect();
lastScreenX = e.getXOnScreen() - cc.viewport.getLocation().x;
lastScreenY = e.getYOnScreen() - cc.viewport.getLocation().y;
int bumpScrollMarginX = (int)((double)viewRect.width / 16 + 0.5);
int bumpScrollMarginY = (int)((double)viewRect.height / 16 + 0.5);

if ((scaledWidth > viewRect.width &&
(viewRect.x > 0 && lastScreenX < bumpScrollMarginX) ||
(viewRect.x < scaledWidth - viewRect.width &&
lastScreenX > viewRect.width - bumpScrollMarginX)) ||
(scaledHeight > viewRect.height &&
(viewRect.y > 0 && lastScreenY < bumpScrollMarginY) ||
(viewRect.y < scaledHeight - viewRect.height &&
lastScreenY > viewRect.height - bumpScrollMarginY))) {
if (bumpScrollTimer == null || !bumpScrollTimer.isRunning()) {
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
Rectangle viewRect = cc.viewport.sp.getViewport().getViewRect();
int bumpScrollMarginX = (int)((double)viewRect.width / 16 + 0.5);
int bumpScrollMarginY =
(int)((double)viewRect.height / 16 + 0.5);
int dx = 0, dy = 0;
java.awt.Point viewPos =
cc.viewport.sp.getViewport().getViewPosition();

if (viewRect.x > 0 && lastScreenX < bumpScrollMarginX)
dx = -Math.min(viewRect.x, BUMP_SCROLL_PIXELS);
if (viewRect.x < scaledWidth - viewRect.width &&
lastScreenX > viewRect.width - bumpScrollMarginX)
dx = Math.min(scaledWidth - viewRect.width - viewRect.x,
BUMP_SCROLL_PIXELS);
if (viewRect.y > 0 && lastScreenY < bumpScrollMarginY)
dy = -Math.min(viewRect.y, BUMP_SCROLL_PIXELS);
if (viewRect.y < scaledHeight - viewRect.height &&
lastScreenY > viewRect.height - bumpScrollMarginY)
dy = Math.min(scaledHeight - viewRect.height - viewRect.y,
BUMP_SCROLL_PIXELS);
if (dx != 0 || dy != 0) {
viewPos.translate(dx, dy);
cc.viewport.sp.getViewport().setViewPosition(viewPos);
} else
((Timer)e.getSource()).stop();
}
};
bumpScrollTimer = new Timer(BUMP_SCROLL_MS, actionListener);
bumpScrollTimer.start();
}
} else if (bumpScrollTimer != null && bumpScrollTimer.isRunning())
bumpScrollTimer.stop();
}
bumpScroll(e);
}
public void mouseDragged(MouseEvent e) { mouseMotionCB(e); }
public void mouseMoved(MouseEvent e) { mouseMotionCB(e); }
Expand Down Expand Up @@ -654,7 +657,7 @@ public void mousePressed(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseExited(MouseEvent e) { bumpScroll(e); }

// EDT: Mouse wheel callback function
private void mouseWheelCB(MouseWheelEvent e) {
Expand Down

0 comments on commit 98ded85

Please sign in to comment.