Fix scrollbar sometimes reappearing when set to 'hidden' and scrolling using the touchpad
AbandonedPublic

Authored by yrlf on Feb 2 2020, 8:12 PM.

Details

Reviewers
hindenburg
tcanabrava
Group Reviewers
Konsole
Summary

On Wayland, sometimes the scrollbar reappears on the left side of the screen even when the scrollbar is set to 'hidden'.
This happens when scrolling twice using the touchpad.

Qt 5.14 changed some parts of the QScrollBar::wheelEvent(QWheelEvent*) function, which now sometimes calls QScrollBarPrivate::setTransient(false), which calls QWidget::show(), which calls QWidget::setVisible(true).

This change works around this new behaviour that results in the QScrollBar not staying hidden when events are propagated to it by setting it to hidden again after each event propagated to the scroll bar.

BUG: 415508

Test Plan

I tested it on ArchLinux using Sway, with Qt versions 5.13.2, 5.14.0, and 5.14.1, and it seems to work.

Diff Detail

Repository
R319 Konsole
Lint
Lint Skipped
Unit
Unit Tests Skipped
yrlf created this revision.Feb 2 2020, 8:12 PM
Restricted Application added a project: Konsole. · View Herald TranscriptFeb 2 2020, 8:12 PM
Restricted Application added a subscriber: konsole-devel. · View Herald Transcript
yrlf requested review of this revision.Feb 2 2020, 8:12 PM
ngraham edited the summary of this revision. (Show Details)

Looks fine - thanks - I'll commit shortly

I'm having problems updating my laptop - can anyone confirm the issue and fix?

yrlf added a comment.EditedMay 1 2020, 11:14 PM

I have looked at this a bit more today, in order to help people reproduce this:

  • the bug only appears on Wayland, not on X11 or XWayland

when looking at the differences between the QWheelEvents between X11 and Wayland, I noticed that the Qt::ScrollPhase of the events is different!

  • Mouse scrolling on Wayland: phase is always 0 (NoScrollPhase, phase not supported)
  • Touchpad scrolling on Wayland: phase is 1, then 2, then 3 (ScrollBegin, ScrollUpdate, ScrollEnd)
  • Mouse scrolling on X11: phase is always 0
  • Touchpad scrolling on X11: phase is always 0

This is most likely what triggers the scrollbar becoming visible, because of this code in qscrollbar.cpp in Qt 5.14

void QScrollBar::wheelEvent(QWheelEvent *event)
{
    event->ignore();
    bool horizontal = qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y());
    // The vertical wheel can be used to scroll a horizontal scrollbar, but only if
    // there is no simultaneous horizontal wheel movement.  This is to avoid chaotic
    // scrolling on touchpads.
    if (!horizontal && event->angleDelta().x() != 0 && orientation() == Qt::Horizontal)
        return;
    // scrollbar is a special case - in vertical mode it reaches minimum
    // value in the upper position, however QSlider's minimum value is on
    // the bottom. So we need to invert the value, but since the scrollbar is
    // inverted by default, we need to invert the delta value only for the
    // horizontal orientation.
    int delta = horizontal ? -event->angleDelta().x() : event->angleDelta().y();
    Q_D(QScrollBar);
    if (d->scrollByDelta(horizontal ? Qt::Horizontal : Qt::Vertical, event->modifiers(), delta))
        event->accept();

    if (event->phase() == Qt::ScrollBegin)
        d->setTransient(false);
    else if (event->phase() == Qt::ScrollEnd)
        d->setTransient(true);
}

note the check of event->phase() near the bottom. d->setTransient(false) subsequently calls q-show(), which makes the scrollbar visible.

I wasn't able to debug this yet, but I think the scroll phase for wayland was just not yet implemented yet for Qt 5.13.2, since the code that checks the phase and calls q->setTransient(false) is also in 5.13.2, but doesn't get run there.

yrlf added a comment.EditedMay 1 2020, 11:24 PM

Reproducing System Config:

  • ArchLinux with sway, Qt 5.14 (my daily driver)
  • Fedora KDE Rawhide (tested with nightly from 2020.04.28) note: this starts KDE in X11 by default, need to install plasma-workspace-wayland, exit the X11 session, and run startplasma-wayland on a tty to get KDE in wayland mode

most likely, any system with Wayland and Qt 5.14 should do, but these are the two I tested it with.

I didn't find a distro yet that ships a working wayland and Qt 5.14 on their live install media, so this convoluted testing setup is all I have as of now. Fedora Workstation Rawhide *should* work directly in the Live ISO, but the current nightly has a broken GDM and I haven't found a working one yet, so I tried the KDE variant.

yrlf edited the summary of this revision. (Show Details)May 14 2020, 6:20 PM
yrlf added a comment.May 14 2020, 6:28 PM

sure. I just didn't know the GitLab existed until today.

Cool, thanks! Can you Abandon this patch then?

yrlf abandoned this revision.May 15 2020, 10:27 AM

Patch moved to GitLab