Skip to content

Commit

Permalink
[thumbnailview] fix smothscroll with libinput 1.19
Browse files Browse the repository at this point in the history
[thumbwidget] re-enable cacheMode for non-fractional scale factor
  • Loading branch information
easymodo committed Sep 26, 2021
1 parent 4404d74 commit d4e2c95
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
11 changes: 6 additions & 5 deletions qimgv/gui/customwidgets/thumbnailview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ThumbnailView::ThumbnailView(ThumbnailViewOrientation orient, QWidget *parent)
setRenderHint(QPainter::Antialiasing, false);
setRenderHint(QPainter::SmoothPixmapTransform, false);

lastTouchpadScroll.start();

connect(&loadTimer, &QTimer::timeout, this, &ThumbnailView::loadVisibleThumbnails);
loadTimer.setInterval(static_cast<const int>(LOAD_DELAY));
Expand Down Expand Up @@ -457,20 +458,20 @@ void ThumbnailView::fitSceneToContents() {
//################### scrolling ######################
void ThumbnailView::wheelEvent(QWheelEvent *event) {
event->accept();
// alright, i officially gave up on fixing libinput scrolling
// let's just hope it gets done in Qt while I am still alive
int pixelDelta = event->pixelDelta().y();
int angleDelta = event->angleDelta().ry();
bool isWheel = angleDelta && !(angleDelta % 120) && lastTouchpadScroll.elapsed() > 100;
if(!isWheel)
lastTouchpadScroll.restart();

if(!settings->enableSmoothScroll()) {
if(pixelDelta)
scrollPrecise(pixelDelta);
else if(angleDelta)
scrollPrecise(angleDelta);
} else {
if(pixelDelta)
if(!isWheel && pixelDelta)
scrollPrecise(pixelDelta);
else if(abs(angleDelta) < SMOOTH_SCROLL_THRESHOLD)
scrollPrecise(angleDelta);
else if(angleDelta)
scrollSmooth(angleDelta, SCROLL_MULTIPLIER, SCROLL_ACCELERATION, true);
}
Expand Down
5 changes: 1 addition & 4 deletions qimgv/gui/customwidgets/thumbnailview.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ public slots:

QTimer loadTimer;
bool blockThumbnailLoading;
// let's say mouse wheel scroll always sends angleDelta = 120
// then we can treat anything smaller as a touchpad scroll
// TODO: tune this value
const int SMOOTH_SCROLL_THRESHOLD = 120;

int mDrawScrollbarIndicator, lastScrollFrameTime;
QList<int> mSelection;
Expand All @@ -97,6 +93,7 @@ public slots:
void createScrollTimeLine();
QElapsedTimer scrollFrameTimer;
std::function<void(int)> centerOn;
QElapsedTimer lastTouchpadScroll;

protected:
QGraphicsScene scene;
Expand Down
4 changes: 3 additions & 1 deletion qimgv/gui/customwidgets/thumbnailwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ ThumbnailWidget::ThumbnailWidget(QGraphicsItem *parent) :
thumbStyle(THUMB_SIMPLE)
{
setAttribute(Qt::WA_OpaquePaintEvent, true);
//setCacheMode(QGraphicsItem::DeviceCoordinateCache); breaks hidpi fractional scaling
float dpr = qApp->devicePixelRatio();
if(trunc(dpr) == dpr) // don't enable for fractional scaling
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
setAcceptHoverEvents(true);
font.setBold(false);
QFontMetrics fm(font);
Expand Down

0 comments on commit d4e2c95

Please sign in to comment.