diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/mixxx.cpp | 21 | ||||
-rw-r--r-- | src/mixxx.h | 1 | ||||
-rw-r--r-- | src/mixxxapplication.cpp | 58 | ||||
-rw-r--r-- | src/mixxxapplication.h | 6 | ||||
-rw-r--r-- | src/widget/wwidget.cpp | 10 |
6 files changed, 63 insertions, 34 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 946fd50af8..5be0032ffa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ * Use 6 instead of only 4 compatible musical keys (major/minor) [#3205](https://github.com/mixxxdj/mixxx/pull/3205) * Fix possible memory corruption using JACK on Linux [#3160](https://github.com/mixxxdj/mixxx/pull/3160) * Fix possible crash when trying to refocus the tracks table while another Mixxx window has focus [#3201](https://github.com/mixxxdj/mixxx/pull/3201) +* Fix touch control [lp:1895431](https://bugs.launchpad.net/mixxx/+bug/1895431) ## [2.2.4](https://launchpad.net/mixxx/+milestone/2.2.4) (2020-06-27) diff --git a/src/mixxx.cpp b/src/mixxx.cpp index d81ba5edd3..be6c6dedb7 100644 --- a/src/mixxx.cpp +++ b/src/mixxx.cpp @@ -233,7 +233,6 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) { pConfig->getValue(ConfigKey("[Controls]", "Tooltips"), static_cast<int>(mixxx::TooltipsPreference::TOOLTIPS_ON))); - setAttribute(Qt::WA_AcceptTouchEvents); m_pTouchShift = new ControlPushButton(ConfigKey("[Controls]", "touch_shift")); m_pDbConnectionPool = MixxxDb(pConfig).connectionPool(); @@ -1536,26 +1535,6 @@ bool MixxxMainWindow::eventFilter(QObject* obj, QEvent* event) { return QObject::eventFilter(obj, event); } -bool MixxxMainWindow::event(QEvent* e) { - switch(e->type()) { - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: - { - // If the touch event falls through to the main widget, no touch widget - // was touched, so we resend it as a mouse event. - // We have to accept it here, so QApplication will continue to deliver - // the following events of this touch point as well. - QTouchEvent* touchEvent = static_cast<QTouchEvent*>(e); - touchEvent->accept(); - return true; - } - default: - break; - } - return QWidget::event(e); -} - void MixxxMainWindow::closeEvent(QCloseEvent *event) { // WARNING: We can receive a CloseEvent while only partially // initialized. This is because we call QApplication::processEvents to diff --git a/src/mixxx.h b/src/mixxx.h index dea2bc6bfa..ecfce6e135 100644 --- a/src/mixxx.h +++ b/src/mixxx.h @@ -99,7 +99,6 @@ class MixxxMainWindow : public QMainWindow { // Event filter to block certain events (eg. tooltips if tooltips are disabled) bool eventFilter(QObject *obj, QEvent *event) override; void closeEvent(QCloseEvent *event) override; - bool event(QEvent* e) override; private: void initialize(QApplication *app, const CmdlineArgs& args); diff --git a/src/mixxxapplication.cpp b/src/mixxxapplication.cpp index b75a1b0250..f7ab822f24 100644 --- a/src/mixxxapplication.cpp +++ b/src/mixxxapplication.cpp @@ -36,13 +36,24 @@ Q_IMPORT_PLUGIN(QGifPlugin) //Q_IMPORT_PLUGIN(AccessibleFactory) #endif +namespace { + +/// This class allows to change the button of a mouse event on the fly. +/// This is required because we want to change the behaviour of Qts mouse +/// buttony synthesizer without duplicate all the code. +class QMouseEventEditable : public QMouseEvent { + public: + void setButton(Qt::MouseButton button) { + b = button; + } +}; + +} // anonymous namespace MixxxApplication::MixxxApplication(int& argc, char** argv) : QApplication(argc, argv), - m_fakeMouseSourcePointId(0), - m_fakeMouseWidget(NULL), - m_activeTouchButton(Qt::NoButton), - m_pTouchShift(NULL) { + m_rightPressedButtons(0), + m_pTouchShift(nullptr) { registerMetaTypes(); // Increase the size of the global thread pool to at least @@ -86,10 +97,47 @@ void MixxxApplication::registerMetaTypes() { qRegisterMetaType<std::optional<mixxx::RgbColor>>("std::optional<mixxx::RgbColor>"); } +bool MixxxApplication::notify(QObject* target, QEvent* event) { + // All touch events are translated into two simultaneous events: one for + // the target QWidgetWindow and one for the target QWidget. + // A second touch becomes a mouse move without additional press and release + // events. + switch (event->type()) { + case QEvent::MouseButtonPress: { + QMouseEventEditable* mouseEvent = static_cast<QMouseEventEditable*>(event); + if (mouseEvent->source() == Qt::MouseEventSynthesizedByQt && + mouseEvent->button() == Qt::LeftButton && + touchIsRightButton()) { + // Assert the assumption that QT synthesizes only one click at a time + // = two events (see above) + VERIFY_OR_DEBUG_ASSERT(m_rightPressedButtons < 2) { + break; + } + mouseEvent->setButton(Qt::RightButton); + m_rightPressedButtons++; + } + break; + } + case QEvent::MouseButtonRelease: { + QMouseEventEditable* mouseEvent = static_cast<QMouseEventEditable*>(event); + if (mouseEvent->source() == Qt::MouseEventSynthesizedByQt && + mouseEvent->button() == Qt::LeftButton && + m_rightPressedButtons > 0) { + mouseEvent->setButton(Qt::RightButton); + m_rightPressedButtons--; + } + break; + } + default: + break; + } + return QApplication::notify(target, event); +} + bool MixxxApplication::touchIsRightButton() { if (!m_pTouchShift) { m_pTouchShift = new ControlProxy( "[Controls]", "touch_shift", this); } - return (m_pTouchShift->get() != 0.0); + return m_pTouchShift->toBool(); } diff --git a/src/mixxxapplication.h b/src/mixxxapplication.h index 1348de29e2..a9a5a67524 100644 --- a/src/mixxxapplication.h +++ b/src/mixxxapplication.h @@ -11,13 +11,13 @@ class MixxxApplication : public QApplication { MixxxApplication(int& argc, char** argv); ~MixxxApplication() override = default; + bool notify(QObject*, QEvent*) override; + private: bool touchIsRightButton(); void registerMetaTypes(); - int m_fakeMouseSourcePointId; - QWidget* m_fakeMouseWidget; - enum Qt::MouseButton m_activeTouchButton; + int m_rightPressedButtons; ControlProxy* m_pTouchShift; }; diff --git a/src/widget/wwidget.cpp b/src/widget/wwidget.cpp index 4f05531072..40b006e1ac 100644 --- a/src/widget/wwidget.cpp +++ b/src/widget/wwidget.cpp @@ -38,7 +38,7 @@ WWidget::~WWidget() { } bool WWidget::touchIsRightButton() { - return (m_pTouchShift->get() != 0.0); + return m_pTouchShift->toBool(); } bool WWidget::event(QEvent* e) { @@ -92,11 +92,13 @@ bool WWidget::event(QEvent* e) { const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first(); QMouseEvent mouseEvent(eventType, - touchPoint.pos().toPoint(), - touchPoint.screenPos().toPoint(), + touchPoint.pos(), + touchPoint.pos(), + touchPoint.screenPos(), m_activeTouchButton, // Button that causes the event Qt::NoButton, // Not used, so no need to fake a proper value. - touchEvent->modifiers()); + touchEvent->modifiers(), + Qt::MouseEventSynthesizedByApplication); return QWidget::event(&mouseEvent); } |