Skip to content

Instantly share code, notes, and snippets.

@M4he
Created February 2, 2023 21:56
Show Gist options
  • Save M4he/9b2b3ba75af658a721afe1381a9cc733 to your computer and use it in GitHub Desktop.
Save M4he/9b2b3ba75af658a721afe1381a9cc733 to your computer and use it in GitHub Desktop.
PCManFM-Qt patch for disabling smooth-scrolling to fix scrolling behavior on touchpad devices, until https://github.com/lxqt/libfm-qt/pull/875 lands in packages
--- src/folderview.cpp.orig 2023-02-02 22:54:09.780036423 +0100
+++ src/folderview.cpp 2023-02-02 22:50:06.284034359 +0100
@@ -1592,9 +1592,6 @@
return true;
}
}
- // row-by-row scrolling when Shift is pressed
- if((QApplication::keyboardModifiers() & Qt::ShiftModifier)
- && (mode == CompactMode || mode == DetailedListMode)) // other modes have smooth scroling
{
QScrollBar *sbar = (mode == CompactMode ? view->horizontalScrollBar()
: view->verticalScrollBar());
@@ -1629,54 +1626,6 @@
return true;
}
}
- // This is to fix #85: Scrolling doesn't work in compact view
- // Actually, I think it's the bug of Qt, not ours.
- // When in compact mode, only the horizontal scroll bar is used and the vertical one is hidden.
- // So, when a user scroll his mouse wheel, it's reasonable to scroll the horizontal scollbar.
- // Qt does not implement such a simple feature, unfortunately.
- // We do it by forwarding the scroll event in the viewport to the horizontal scrollbar.
- // FIXME: if someday Qt supports this, we have to disable the workaround.
- else if(mode == CompactMode) {
-#if (QT_VERSION < QT_VERSION_CHECK(5,14,0))
- QScrollBar* scroll = view->horizontalScrollBar();
- if(scroll) {
- QApplication::sendEvent(scroll, event);
- return true;
- }
-#else
- return false; // the problem with horizontal wheel scrolling from inside view is fixed in Qt 5.14
-#endif
- }
- // Smooth Scrolling
- // Some tricks are adapted from <https://github.com/zhou13/qsmoothscrollarea>.
- else if(mode != DetailedListMode
- && event->spontaneous()
- && static_cast<QWheelEvent*>(event)->source() == Qt::MouseEventNotSynthesized
- && !(QApplication::keyboardModifiers() & Qt::AltModifier)) {
- if(QScrollBar* vbar = view->verticalScrollBar()) {
- // keep track of the wheel event for smooth scrolling
- int delta = static_cast<QWheelEvent*>(event)->angleDelta().y();
- if(QApplication::keyboardModifiers() & Qt::ShiftModifier) {
- delta /= QApplication::wheelScrollLines(); // row-by-row scrolling
- }
- if((delta > 0 && vbar->value() == vbar->minimum()) || (delta < 0 && vbar->value() == vbar->maximum())) {
- break; // the scrollbar can't move
- }
-
- if(!smoothScrollTimer_) {
- smoothScrollTimer_ = new QTimer();
- connect(smoothScrollTimer_, &QTimer::timeout, this, &FolderView::scrollSmoothly);
- }
-
- // set the data for smooth scrolling
- scrollData data;
- data.delta = delta;
- data.leftFrames = scrollAnimFrames;
- queuedScrollSteps_.append(data);
- smoothScrollTimer_->start(1000 / SCROLL_FRAMES_PER_SEC);
- return true;
- }
- }
break;
default:
break;
@M4he
Copy link
Author

M4he commented Feb 2, 2023

Here's a quick rundown on how to apply this on Debian 11 for reference:

# download the source code package
# (this will also automatically extract it in a subfolder)
apt source libfm-qt

# install necessary packages to compile libfm-qt
sudo apt build-dep libfm-qt

# enter the extracted source code directory (version number may differ)
cd libfm-qt-0.16.0/

# create a file using any editor (e.g. nano) and paste the patch into it
nano pcmanfm-qt_disable_smooth_scrolling.patch

# apply the patch
patch -p0 < pcmanfm-qt_disable_smooth_scrolling.patch

# build the modified libfm-qt package
dpkg-buildpackage -rfakeroot -uc -b

# install the patched version (version numbers may differ)
sudo dpkg -i ../libfm-qt8_0.16.0-3_amd64.deb
sudo dpkg -i ../libfm-qt-l10n_0.16.0-3_all.deb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment