Skip to content

Commit

Permalink
[util] Improve scrolling on high-DPI screens (Fixes JB#29417)
Browse files Browse the repository at this point in the history
The scrolling code was just scrolling at most one line at a time, and even when
the touch point moved even just one pixel.

Fix that by using the font size as a scale factor (that's still not 100%
correct, but it improves the situation, and the bias scales well with changing
font size) and by actually accumulating not consumed offsets, so small moves
(smaller than the font size) are not discarded, but actually accumulate.
  • Loading branch information
thp committed Jun 2, 2015
1 parent 5c74711 commit 2b2385a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
23 changes: 15 additions & 8 deletions util.cpp
Expand Up @@ -275,8 +275,7 @@ void Util::mouseMove(float eventX, float eventY) {
return;

if(settingsValue("ui/dragMode")=="scroll") {
scrollBackBuffer(eventPos, dragOrigin);
dragOrigin = eventPos;
dragOrigin = scrollBackBuffer(eventPos, dragOrigin);
}
else if(settingsValue("ui/dragMode")=="select" && iRenderer) {
selectionHelper(eventPos);
Expand Down Expand Up @@ -326,18 +325,26 @@ void Util::selectionHelper(QPointF scenePos)
}
}

void Util::scrollBackBuffer(QPointF now, QPointF last)
QPointF Util::scrollBackBuffer(QPointF now, QPointF last)
{
if(!iTerm)
return;
return last;

int xdist = qAbs(now.x() - last.x());
int ydist = qAbs(now.y() - last.y());
int fontSize = settingsValue("ui/fontSize").toInt();

int lines = ydist / fontSize;

if(lines > 0 && now.y() < last.y() && xdist < ydist*2) {
iTerm->scrollBackBufferFwd(lines);
last = QPointF(now.x(), last.y() - lines * fontSize);
} else if(lines > 0 && now.y() > last.y() && xdist < ydist*2) {
iTerm->scrollBackBufferBack(lines);
last = QPointF(now.x(), last.y() + lines * fontSize);
}

if(now.y() < last.y() && xdist < ydist*2)
iTerm->scrollBackBufferFwd(1);
else if(now.y() > last.y() && xdist < ydist*2)
iTerm->scrollBackBufferBack(1);
return last;
}

void Util::doGesture(Util::PanGesture gesture)
Expand Down
9 changes: 8 additions & 1 deletion util.h
Expand Up @@ -91,7 +91,14 @@ public slots:
bool swipeModeSet;
bool swipeAllowed;

void scrollBackBuffer(QPointF now, QPointF last);
/**
* Scroll the back buffer on drag.
*
* @param now The current position
* @param last The last position (or start position)
* @return The new value for last (modified by any consumed offset)
**/
QPointF scrollBackBuffer(QPointF now, QPointF last);
void doGesture(PanGesture gesture);
void clearNotifications();
void selectionHelper(QPointF scenePos);
Expand Down

0 comments on commit 2b2385a

Please sign in to comment.