History

Fix cmd-leftclick not working correctly on Mac OS

On Mac OS, Cmd+LeftClick is treated as a RightClick (more specifically, it seems to be Cmd+RightClick without the modifier being dropped). Starting in Qt 5.12, only on Mac, the MouseButtonRelease event for these mouse presses are sent to the top level QWidgetWindow, but are not propagated further. The change here gets around this problem by capturing these pseudo-RightClicks, and re-emitting them as "pure" RightClicks.

Ryan Huffman committed 7 years ago

Commit 8097ece1 parent afc98631 file · +33 −2Browse files

Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Application.cpp+33−2
@@ -4235,12 +4235,43 @@ bool Application::event(QEvent* event) { · 4234 unmodified lines
4235}4235}
4236 4236
4237bool Application::eventFilter(QObject* object, QEvent* event) {4237bool Application::eventFilter(QObject* object, QEvent* event) {
4238 auto eventType = event->type();
4238 4239
4239 if (_aboutToQuit && event->type() != QEvent::DeferredDelete && event->type() != QEvent::Destroy) {4240 if (_aboutToQuit && eventType != QEvent::DeferredDelete && eventType != QEvent::Destroy) {
4240 return true;4241 return true;
4241 }4242 }
4242 4243
4243 auto eventType = event->type();4244#if defined(Q_OS_MAC)
4245 // On Mac OS, Cmd+LeftClick is treated as a RightClick (more specifically, it seems to
4246 // be Cmd+RightClick without the modifier being dropped). Starting in Qt 5.12, only
4247 // on Mac, the MouseButtonRelease event for these mouse presses is sent to the top
4248 // level QWidgetWindow, but are not propagated further. This means that the Application
4249 // will see a MouseButtonPress, but no MouseButtonRelease, causing the client to get
4250 // stuck in "mouse-look." The cause of the problem is in the way QWidgetWindow processes
4251 // events where QMouseEvent::button() is not equal to QMouseEvent::buttons(). In this case
4252 // QMouseEvent::button() is Qt::RightButton, while QMouseEvent::buttons() is (correctly?)
4253 // Qt::LeftButton.
4254 //
4255 // The change here gets around this problem by capturing these
4256 // pseudo-RightClicks, and re-emitting them as "pure" RightClicks, where
4257 // QMouseEvent::button() == QMouseEvent::buttons() == Qt::RightButton.
4258 //
4259 if (eventType == QEvent::MouseButtonPress) {
4260 auto mouseEvent = static_cast<QMouseEvent*>(event);
4261 if (mouseEvent->button() == Qt::RightButton
4262 && mouseEvent->buttons() == Qt::LeftButton
4263 && mouseEvent->modifiers() == Qt::MetaModifier) {
4264
4265 QMouseEvent* newEvent = new QMouseEvent(
4266 QEvent::MouseButtonPress, mouseEvent->localPos(), mouseEvent->windowPos(),
4267 mouseEvent->screenPos(), Qt::RightButton, Qt::MouseButtons(Qt::RightButton),
4268 mouseEvent->modifiers());
4269 QApplication::postEvent(object, newEvent);
4270 return true;
4271 }
4272 }
4273#endif
4274
4244 if (eventType == QEvent::KeyPress || eventType == QEvent::KeyRelease || eventType == QEvent::MouseMove) {4275 if (eventType == QEvent::KeyPress || eventType == QEvent::KeyRelease || eventType == QEvent::MouseMove) {
4245 getRefreshRateManager().resetInactiveTimer();4276 getRefreshRateManager().resetInactiveTimer();
4246 }4277 }