-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed volume change with hi-res mice and touchpad scrolling #1857
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
|
||
#include <XdgIcon> | ||
|
||
#include <QTimer> | ||
#include <QSlider> | ||
#include <QStyleOptionButton> | ||
#include <QPushButton> | ||
|
@@ -47,7 +48,8 @@ VolumePopup::VolumePopup(QWidget* parent): | |
QDialog(parent, Qt::Dialog | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::Popup | Qt::X11BypassWindowManagerHint), | ||
m_pos(0,0), | ||
m_anchor(Qt::TopLeftCorner), | ||
m_device(nullptr) | ||
m_device(nullptr), | ||
mWheelTimer(new QTimer(this)) | ||
{ | ||
// Under some Wayland compositors, setting window flags in the c-tor of the base class | ||
// may not be enough for a correct positioning of the popup. | ||
|
@@ -84,6 +86,15 @@ VolumePopup::VolumePopup(QWidget* parent): | |
connect(m_mixerButton, &QPushButton::released, this, &VolumePopup::launchMixer); | ||
connect(m_volumeSlider, &QSlider::valueChanged, this, &VolumePopup::handleSliderValueChanged); | ||
connect(m_muteToggleButton, &QPushButton::clicked, this, &VolumePopup::handleMuteToggleClicked); | ||
|
||
mWheelTimer->setSingleShot(true); | ||
mWheelTimer->setInterval(350); // "QStyle::SH_ToolTip_WakeUpDelay" is 700 by default | ||
connect(mWheelTimer, &QTimer::timeout, this, [this] { | ||
QTimer::singleShot(0, this, [this] { | ||
if (!QToolTip::isVisible()) | ||
QToolTip::showText(QCursor::pos(), m_volumeSlider->toolTip()); | ||
}); | ||
}); | ||
} | ||
|
||
bool VolumePopup::event(QEvent *event) | ||
|
@@ -127,7 +138,10 @@ void VolumePopup::handleSliderValueChanged(int value) | |
return; | ||
// qDebug("VolumePopup::handleSliderValueChanged: %d\n", value); | ||
m_device->setVolume(value); | ||
QTimer::singleShot(0, this, [this] { QToolTip::showText(QCursor::pos(), m_volumeSlider->toolTip()); }); | ||
QTimer::singleShot(0, this, [this] { | ||
if (!mWheelTimer->isActive()) // a wheel event immediately hides the tooltip | ||
QToolTip::showText(QCursor::pos(), m_volumeSlider->toolTip()); | ||
}); | ||
} | ||
|
||
void VolumePopup::handleMuteToggleClicked() | ||
|
@@ -197,8 +211,21 @@ void VolumePopup::openAt(QPoint pos, Qt::Corner anchor) | |
|
||
void VolumePopup::handleWheelEvent(QWheelEvent *event) | ||
{ | ||
m_volumeSlider->setSliderPosition(m_volumeSlider->sliderPosition() | ||
+ (event->angleDelta().y() / QWheelEvent::DefaultDeltasPerStep * m_volumeSlider->singleStep())); | ||
static int _delta = 0; // for high-resolution mice and touchpad scrolling | ||
|
||
int delta = event->angleDelta().y(); | ||
if ((_delta ^ delta) < 0) | ||
_delta = delta; // the wheel direction is reversed | ||
else | ||
_delta += delta; | ||
if (qAbs(_delta) >= QWheelEvent::DefaultDeltasPerStep) { | ||
m_volumeSlider->setSliderPosition(m_volumeSlider->sliderPosition() | ||
+ (_delta / QWheelEvent::DefaultDeltasPerStep * m_volumeSlider->singleStep())); | ||
_delta = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the same reason as above, I suggest to write this as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be very wrong. → #1856 (comment) → 2 and especially 4 |
||
} | ||
|
||
// show the tooltip only after the wheel rotation is stopped | ||
mWheelTimer->start(); | ||
} | ||
|
||
void VolumePopup::setDevice(AudioDevice *device) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
|
||
#include <QDialog> | ||
|
||
class QTimer; | ||
class QSlider; | ||
class QPushButton; | ||
class AudioDevice; | ||
|
@@ -81,6 +82,7 @@ private slots: | |
QPoint m_pos; | ||
Qt::Corner m_anchor; | ||
AudioDevice *m_device; | ||
QTimer *mWheelTimer; // for showing tooltip with high-resolution mice | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are adding a member to the class, we could add also the "_delta", and remove the static variable inside the method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. → #1856 (comment) → first paragraph |
||
}; | ||
|
||
#endif // VOLUMEPOPUP_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this case ? Even if the user changes the wheel direction the previous "fraction" of the stroke has to be considered...
As counter example, if you in a normal mouse each tick is emitted every 15°, and you rotate for +14° up and -14° down you don't have any effect. However with your code an hires mouse you have a tick because +14 - -14 = 28 > 15°.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
→ #1856 (comment) → 3
I'm afraid, you misread the code.