Skip to content

Commit

Permalink
Merge pull request #3165 from daschuer/touchfix
Browse files Browse the repository at this point in the history
Fix touch control
  • Loading branch information
Be-ing authored Oct 31, 2020
2 parents 4ac7d04 + 8563d47 commit 9a3a1e7
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: c++
matrix:
include:
- os: linux
dist: trusty
dist: xenial
sudo: required
compiler: gcc

Expand Down Expand Up @@ -37,7 +37,7 @@ addons:
- libtag1-dev
- libupower-glib-dev
- libusb-1.0-0-dev
- libvamp-hostsdk3
- libvamp-hostsdk3v5
- libwavpack-dev
- portaudio19-dev
- protobuf-compiler
Expand Down Expand Up @@ -65,7 +65,7 @@ install:
- export COMMON="-j4 qt5=1 test=1 mad=1 faad=1 ffmpeg=1 opus=1 modplug=1 wv=1 hss1394=0 virtualize=0 debug_assertions_fatal=1 verbose=0"

#####
# Ubuntu Trusty Build
# Ubuntu Xenial Build

####
# OS X Build
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Use 6 instead of only 4 compatible musical keys (major/minor) #3205
* Fix possible memory corruption using JACK on Linux
* Fix possible crash when trying to refocus the tracks table while another Mixxx window has focus #3201
* Fix touch control lp:1895431

==== 2.2.4 2020-05-10 ====

Expand Down
21 changes: 0 additions & 21 deletions src/mixxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,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_pChannelHandleFactory = new ChannelHandleFactory();
Expand Down Expand Up @@ -1365,26 +1364,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
Expand Down
5 changes: 2 additions & 3 deletions src/mixxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ class MixxxMainWindow : public QMainWindow {

protected:
// Event filter to block certain events (eg. tooltips if tooltips are disabled)
virtual bool eventFilter(QObject *obj, QEvent *event);
virtual void closeEvent(QCloseEvent *event);
virtual bool event(QEvent* e);
bool eventFilter(QObject *obj, QEvent *event) override;
void closeEvent(QCloseEvent *event) override;

private:
void initialize(QApplication *app, const CmdlineArgs& args);
Expand Down
58 changes: 53 additions & 5 deletions src/mixxxapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,24 @@ Q_IMPORT_PLUGIN(qtaccessiblewidgets)
#endif
#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();
}

Expand Down Expand Up @@ -207,10 +218,47 @@ bool MixxxApplication::notify(QObject* target, QEvent* event) {
#endif // QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#endif // Q_OS_MAC

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();
}
6 changes: 3 additions & 3 deletions src/mixxxapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class MixxxApplication : public QApplication {
#endif
#endif

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;

};
Expand Down
10 changes: 6 additions & 4 deletions src/widget/wwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ WWidget::~WWidget() {
}

bool WWidget::touchIsRightButton() {
return (m_pTouchShift->get() != 0.0);
return m_pTouchShift->toBool();
}

bool WWidget::event(QEvent* e) {
Expand Down Expand Up @@ -91,11 +91,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);
}
Expand Down

0 comments on commit 9a3a1e7

Please sign in to comment.