From 98ded853872b401f2e5a8eaa1715540f5fe6ab26 Mon Sep 17 00:00:00 2001 From: DRC Date: Mon, 13 Jan 2025 18:15:44 -0500 Subject: [PATCH] Viewer/bump scrolling: Handle MOUSE_EXITED events 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. --- .../com/turbovnc/vncviewer/DesktopWindow.java | 109 +++++++++--------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/java/com/turbovnc/vncviewer/DesktopWindow.java b/java/com/turbovnc/vncviewer/DesktopWindow.java index bf7e7765d..53b822f60 100644 --- a/java/com/turbovnc/vncviewer/DesktopWindow.java +++ b/java/com/turbovnc/vncviewer/DesktopWindow.java @@ -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; @@ -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); } @@ -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) {