Skip to content

Commit

Permalink
improve scrolling with middle click drag (fixes #4529)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Sep 15, 2024
1 parent 116c512 commit e53e193
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/md/Version-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Changes in [pre-release builds](https://www.sumatrapdfreader.org/prerelease):
- closing a current tab now behaves like in Chrome: selects next tab (to the right). We used to select previously active tab, but that's unpredicable and we prefer to align SumatraPDF behavior with other popular apps.
- swapped key bindings: 'i' is now CmdTogglePageInfo, 'I' is CmdInvertColors. Several people were confused by accidentally typing 'i' to invert colors, is less likely to type it accidentally
- allow creating custom themes in advanced settings in `Themes` section. [See docs](https://www.sumatrapdfreader.org/docs/Customize-theme-colors).
- improve scrolling with middle click drag [#4529](https://github.com/sumatrapdfreader/sumatrapdf/issues/4529)

### 3.5.2 (2023-10-25)

Expand Down
16 changes: 16 additions & 0 deletions src/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ static void OnMouseMiddleButtonDown(MainWindow* win, int x, int y, WPARAM) {
case MouseAction::None:
win->mouseAction = MouseAction::Scrolling;

win->dragStartPending = true;
// record current mouse position, the farther the mouse is moved
// from this position, the faster we scroll the document
win->dragStart = Point(x, y);
Expand All @@ -689,6 +690,17 @@ static void OnMouseMiddleButtonDown(MainWindow* win, int x, int y, WPARAM) {
}
}

static void OnMouseMiddleButtonUp(MainWindow* win, int x, int y, WPARAM) {
switch (win->mouseAction) {
case MouseAction::Scrolling:
if (!win->dragStartPending) {
win->mouseAction = MouseAction::None;
SetCursorCached(IDC_ARROW);
break;
}
}
}

static void OnMouseRightButtonDown(MainWindow* win, int x, int y) {
// lf("Right button clicked on %d %d", x, y);
if (MouseAction::Scrolling == win->mouseAction) {
Expand Down Expand Up @@ -1632,6 +1644,10 @@ static LRESULT WndProcCanvasFixedPageUI(MainWindow* win, HWND hwnd, UINT msg, WP
OnMouseMiddleButtonDown(win, x, y, wp);
return 0;

case WM_MBUTTONUP:
OnMouseMiddleButtonUp(win, x, y, wp);
return 0;

case WM_RBUTTONDOWN:
OnMouseRightButtonDown(win, x, y);
return 0;
Expand Down

0 comments on commit e53e193

Please sign in to comment.