Rename QMacScopedObserver to the more fittingly QMacNotificationObserver
Change-Id: I1d8280fe88871572a3a27e612de49717b3b9ef77 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
c3571d2922
commit
a67b25067e
@ -295,13 +295,13 @@ QT_MAC_WEAK_IMPORT(_os_activity_current);
|
|||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
#if defined( __OBJC__)
|
#if defined( __OBJC__)
|
||||||
class QMacScopedObserver
|
class QMacNotificationObserver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QMacScopedObserver() {}
|
QMacNotificationObserver() {}
|
||||||
|
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
QMacScopedObserver(id object, NSNotificationName name, Functor callback) {
|
QMacNotificationObserver(id object, NSNotificationName name, Functor callback) {
|
||||||
observer = [[NSNotificationCenter defaultCenter] addObserverForName:name
|
observer = [[NSNotificationCenter defaultCenter] addObserverForName:name
|
||||||
object:object queue:nil usingBlock:^(NSNotification *) {
|
object:object queue:nil usingBlock:^(NSNotification *) {
|
||||||
callback();
|
callback();
|
||||||
@ -309,13 +309,13 @@ public:
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
QMacScopedObserver(const QMacScopedObserver& other) = delete;
|
QMacNotificationObserver(const QMacNotificationObserver& other) = delete;
|
||||||
QMacScopedObserver(QMacScopedObserver&& other) : observer(other.observer) {
|
QMacNotificationObserver(QMacNotificationObserver&& other) : observer(other.observer) {
|
||||||
other.observer = nil;
|
other.observer = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMacScopedObserver &operator=(const QMacScopedObserver& other) = delete;
|
QMacNotificationObserver &operator=(const QMacNotificationObserver& other) = delete;
|
||||||
QMacScopedObserver &operator=(QMacScopedObserver&& other) {
|
QMacNotificationObserver &operator=(QMacNotificationObserver&& other) {
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
remove();
|
remove();
|
||||||
observer = other.observer;
|
observer = other.observer;
|
||||||
@ -329,7 +329,7 @@ public:
|
|||||||
[[NSNotificationCenter defaultCenter] removeObserver:observer];
|
[[NSNotificationCenter defaultCenter] removeObserver:observer];
|
||||||
observer = nil;
|
observer = nil;
|
||||||
}
|
}
|
||||||
~QMacScopedObserver() { remove(); }
|
~QMacNotificationObserver() { remove(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
id observer = nil;
|
id observer = nil;
|
||||||
|
@ -80,7 +80,7 @@ private:
|
|||||||
NSOpenGLContext *m_shareContext = nil;
|
NSOpenGLContext *m_shareContext = nil;
|
||||||
QSurfaceFormat m_format;
|
QSurfaceFormat m_format;
|
||||||
bool m_didCheckForSoftwareContext = false;
|
bool m_didCheckForSoftwareContext = false;
|
||||||
QVarLengthArray<QMacScopedObserver, 3> m_updateObservers;
|
QVarLengthArray<QMacNotificationObserver, 3> m_updateObservers;
|
||||||
QAtomicInt m_needsUpdate = false;
|
QAtomicInt m_needsUpdate = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -404,13 +404,13 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface)
|
|||||||
m_updateObservers.clear();
|
m_updateObservers.clear();
|
||||||
|
|
||||||
if (view.layer) {
|
if (view.layer) {
|
||||||
m_updateObservers.append(QMacScopedObserver(view, NSViewFrameDidChangeNotification, updateCallback));
|
m_updateObservers.append(QMacNotificationObserver(view, NSViewFrameDidChangeNotification, updateCallback));
|
||||||
m_updateObservers.append(QMacScopedObserver(view.window, NSWindowDidChangeScreenNotification, updateCallback));
|
m_updateObservers.append(QMacNotificationObserver(view.window, NSWindowDidChangeScreenNotification, updateCallback));
|
||||||
} else {
|
} else {
|
||||||
m_updateObservers.append(QMacScopedObserver(view, NSViewGlobalFrameDidChangeNotification, updateCallback));
|
m_updateObservers.append(QMacNotificationObserver(view, NSViewGlobalFrameDidChangeNotification, updateCallback));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_updateObservers.append(QMacScopedObserver([NSApplication sharedApplication],
|
m_updateObservers.append(QMacNotificationObserver([NSApplication sharedApplication],
|
||||||
NSApplicationDidChangeScreenParametersNotification, updateCallback));
|
NSApplicationDidChangeScreenParametersNotification, updateCallback));
|
||||||
|
|
||||||
// If any of the observers fire at this point it's fine. We check the
|
// If any of the observers fire at this point it's fine. We check the
|
||||||
|
@ -144,7 +144,7 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
QScopedPointer<QPlatformTheme> mPlatformTheme;
|
QScopedPointer<QPlatformTheme> mPlatformTheme;
|
||||||
QList<QCocoaScreen *> mScreens;
|
QList<QCocoaScreen *> mScreens;
|
||||||
QMacScopedObserver m_screensObserver;
|
QMacNotificationObserver m_screensObserver;
|
||||||
#ifndef QT_NO_CLIPBOARD
|
#ifndef QT_NO_CLIPBOARD
|
||||||
QCocoaClipboard *mCocoaClipboard;
|
QCocoaClipboard *mCocoaClipboard;
|
||||||
#endif
|
#endif
|
||||||
|
@ -207,7 +207,7 @@ QCocoaIntegration::QCocoaIntegration(const QStringList ¶mList)
|
|||||||
// which will resolve to an actual value and result in screen invalidation.
|
// which will resolve to an actual value and result in screen invalidation.
|
||||||
cocoaApplication.presentationOptions = NSApplicationPresentationDefault;
|
cocoaApplication.presentationOptions = NSApplicationPresentationDefault;
|
||||||
|
|
||||||
m_screensObserver = QMacScopedObserver([NSApplication sharedApplication],
|
m_screensObserver = QMacNotificationObserver([NSApplication sharedApplication],
|
||||||
NSApplicationDidChangeScreenParametersNotification, [&]() { updateScreens(); });
|
NSApplicationDidChangeScreenParametersNotification, [&]() { updateScreens(); });
|
||||||
updateScreens();
|
updateScreens();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user