forked from mumble-voip/mumble
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX(client): Fix using the keyboad to change local volume adjustment
Previously, when using keyboard arrows or the mouse wheel, the new slider widget action applied the new local volume but did not save it. That was because it used the sliderReleased event to save the value, which is not triggered by keyboard or mouse wheel updates. We could simply save the local volume on every sliderChange instead of on sliderRelease, but that would cause many writes to the disk in a short period of time and possibly lag the client. Additionally, the ListenerVolumeSlider would spam packets to the server, as the listener volume is saved server-side. This commit introduces event filters in addition to the sliderChanged event, which are observing key releases and mouse wheel events. It also introduces a delay timer for packets send to the server from the ListenerVolumeSlider. Fixes mumble-voip#6211
- Loading branch information
Showing
9 changed files
with
198 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2023 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#include "EventFilters.h" | ||
|
||
#include <algorithm> | ||
|
||
#include <QKeyEvent> | ||
#include <QWheelEvent> | ||
#include <QWidget> | ||
|
||
KeyEventObserver::KeyEventObserver(QObject *parent, QEvent::Type eventType, bool consume, | ||
std::vector< Qt::Key > keys) | ||
: QObject(parent), m_eventType(eventType), m_consume(consume), m_keys(std::move(keys)) { | ||
} | ||
|
||
bool KeyEventObserver::eventFilter(QObject *obj, QEvent *event) { | ||
QWidget *widget = static_cast< QWidget * >(obj); | ||
|
||
if (!widget || !widget->hasFocus()) { | ||
return false; | ||
} | ||
|
||
QKeyEvent *keyEvent = static_cast< QKeyEvent * >(event); | ||
|
||
if (!keyEvent || keyEvent->type() != m_eventType) { | ||
return false; | ||
} | ||
|
||
Qt::Key key = static_cast< Qt::Key >(keyEvent->key()); | ||
|
||
if (std::find(m_keys.begin(), m_keys.end(), key) == m_keys.end()) { | ||
return false; | ||
} | ||
|
||
emit keyEventObserved(); | ||
|
||
return m_consume; | ||
} | ||
|
||
MouseWheelEventObserver::MouseWheelEventObserver(QObject *parent, std::vector< Qt::ScrollPhase > phases, | ||
bool consume) | ||
: QObject(parent), m_phases(std::move(phases)), m_consume(consume) { | ||
} | ||
|
||
bool MouseWheelEventObserver::eventFilter(QObject *obj, QEvent *event) { | ||
QWidget *widget = static_cast< QWidget * >(obj); | ||
|
||
if (!widget || !widget->isVisible()) { | ||
return false; | ||
} | ||
|
||
QWheelEvent *wheelEvent = static_cast< QWheelEvent * >(event); | ||
|
||
if (!wheelEvent) { | ||
return false; | ||
} | ||
|
||
Qt::ScrollPhase phase = wheelEvent->phase(); | ||
|
||
if (std::find(m_phases.begin(), m_phases.end(), phase) == m_phases.end()) { | ||
return false; | ||
} | ||
|
||
emit wheelEventObserved(wheelEvent->pixelDelta()); | ||
|
||
return m_consume; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#ifndef MUMBLE_MUMBLE_WIDGETS_EVENTFILTERS_H_ | ||
#define MUMBLE_MUMBLE_WIDGETS_EVENTFILTERS_H_ | ||
|
||
#include <vector> | ||
|
||
#include <QEvent> | ||
#include <QObject> | ||
#include <QPoint> | ||
|
||
class KeyEventObserver : public QObject { | ||
Q_OBJECT | ||
|
||
public: | ||
KeyEventObserver(QObject *parent, QEvent::Type eventType, bool consume, std::vector< Qt::Key > keys); | ||
|
||
protected: | ||
bool eventFilter(QObject *obj, QEvent *event) override; | ||
|
||
signals: | ||
void keyEventObserved(); | ||
|
||
private: | ||
QEvent::Type m_eventType; | ||
bool m_consume; | ||
std::vector< Qt::Key > m_keys; | ||
}; | ||
|
||
class MouseWheelEventObserver : public QObject { | ||
Q_OBJECT | ||
|
||
public: | ||
MouseWheelEventObserver(QObject *parent, std::vector< Qt::ScrollPhase > phases, bool consume); | ||
|
||
protected: | ||
bool eventFilter(QObject *obj, QEvent *event) override; | ||
|
||
signals: | ||
void wheelEventObserved(QPoint delta); | ||
|
||
private: | ||
std::vector< Qt::ScrollPhase > m_phases; | ||
bool m_consume; | ||
}; | ||
|
||
#endif |