summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.h9
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.mm9
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h3
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm10
-rw-r--r--src/widgets/kernel/qapplication.cpp28
5 files changed, 59 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
index b1b8dccca5..ca84312059 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
@@ -112,6 +112,15 @@ private:
// Embedding NSViews as child QWindows
static void setWindowContentView(QPlatformWindow *window, void *nsViewContentView);
+
+ // Register if a window should deliver touch events. Enabling
+ // touch events has implications for delivery of other events,
+ // for example by causing scrolling event lag.
+ //
+ // The registration is ref-counted: multiple widgets can enable
+ // touch events, which then will be delivered until the widget
+ // deregisters.
+ static void registerTouchWindow(QWindow *window, bool enable);
};
#endif // QCOCOANATIVEINTERFACE_H
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
index a7f4d3b823..ededb63487 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
@@ -119,6 +119,8 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::cgImageToQImage);
if (resource.toLower() == "setwindowcontentview")
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setWindowContentView);
+ if (resource.toLower() == "registertouchwindow")
+ return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerTouchWindow);
return 0;
}
@@ -227,4 +229,11 @@ void QCocoaNativeInterface::setWindowContentView(QPlatformWindow *window, void *
cocoaPlatformWindow->setContentView(reinterpret_cast<NSView *>(contentView));
}
+void QCocoaNativeInterface::registerTouchWindow(QWindow *window, bool enable)
+{
+ QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
+ if (cocoaWindow)
+ cocoaWindow->registerTouch(enable);
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index 5029321247..e1de5f0add 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -147,6 +147,8 @@ public:
void setMenubar(QCocoaMenuBar *mb);
QCocoaMenuBar *menubar() const;
+ void registerTouch(bool enable);
+
qreal devicePixelRatio() const;
void exposeWindow();
void obscureWindow();
@@ -187,6 +189,7 @@ public: // for QNSView
bool m_hasModalSession;
bool m_frameStrutEventsEnabled;
bool m_isExposed;
+ int m_registerTouchCount;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 9988cea597..e74f9dcfe0 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -201,6 +201,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
, m_hasModalSession(false)
, m_frameStrutEventsEnabled(false)
, m_isExposed(false)
+ , m_registerTouchCount(0)
{
#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
qDebug() << "QCocoaWindow::QCocoaWindow" << this;
@@ -899,6 +900,15 @@ QCocoaMenuBar *QCocoaWindow::menubar() const
return m_menubar;
}
+void QCocoaWindow::registerTouch(bool enable)
+{
+ m_registerTouchCount += enable ? 1 : -1;
+ if (m_registerTouchCount == 1)
+ [m_contentView setAcceptsTouchEvents:YES];
+ else if (m_registerTouchCount == 0)
+ [m_contentView setAcceptsTouchEvents:NO];
+}
+
qreal QCocoaWindow::devicePixelRatio() const
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 22133214df..ac25d3ed7f 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -3367,6 +3367,34 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
break;
}
#endif // QT_NO_GESTURES
+#ifdef Q_OS_MAC
+ // Enable touch events on enter, disable on leave.
+ typedef void (*RegisterTouchWindowFn)(QWindow *, bool);
+ case QEvent::Enter:
+ if (receiver->isWidgetType()) {
+ QWidget *w = static_cast<QWidget *>(receiver);
+ if (w->testAttribute(Qt::WA_AcceptTouchEvents)) {
+ RegisterTouchWindowFn registerTouchWindow = reinterpret_cast<RegisterTouchWindowFn>
+ (platformNativeInterface()->nativeResourceFunctionForIntegration("registertouchwindow"));
+ if (registerTouchWindow)
+ registerTouchWindow(w->window()->windowHandle(), true);
+ }
+ }
+ res = d->notify_helper(receiver, e);
+ break;
+ case QEvent::Leave:
+ if (receiver->isWidgetType()) {
+ QWidget *w = static_cast<QWidget *>(receiver);
+ if (w->testAttribute(Qt::WA_AcceptTouchEvents)) {
+ RegisterTouchWindowFn registerTouchWindow = reinterpret_cast<RegisterTouchWindowFn>
+ (platformNativeInterface()->nativeResourceFunctionForIntegration("registertouchwindow"));
+ if (registerTouchWindow)
+ registerTouchWindow(w->window()->windowHandle(), false);
+ }
+ }
+ res = d->notify_helper(receiver, e);
+ break;
+#endif
default:
res = d->notify_helper(receiver, e);
break;