18#include "private/qglobal_p.h"
20#include <QtCore/qoperatingsystemversion.h>
27typedef int kern_return_t;
28typedef mach_port_t io_object_t;
30kern_return_t IOObjectRetain(io_object_t object);
31kern_return_t IOObjectRelease(io_object_t object);
35#ifndef __IMAGECAPTURE__
36# define __IMAGECAPTURE__
41#if defined(QT_BOOTSTRAPPED)
42#include <ApplicationServices/ApplicationServices.h>
44#include <CoreFoundation/CoreFoundation.h>
48#include <Foundation/Foundation.h>
55#if defined( __OBJC__) && defined(QT_NAMESPACE)
56#define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__) @compatibility_alias __KLASS__ QT_MANGLE_NAMESPACE(__KLASS__)
58#define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__)
61#define QT_MAC_WEAK_IMPORT(symbol) extern "C" decltype(symbol) symbol __attribute__((weak_import));
64#define QT_DECLARE_NAMESPACED_OBJC_INTERFACE(classname, definition)
65 @interface QT_MANGLE_NAMESPACE(classname) :
68 QT_NAMESPACE_ALIAS_OBJC_CLASS(classname);
70#define QT_DECLARE_NAMESPACED_OBJC_INTERFACE(classname, definition)
71 Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(classname));
72 using classname = QT_MANGLE_NAMESPACE(classname);
75#define QT_FORWARD_DECLARE_OBJC_ENUM(name, type)
85template <
typename T,
typename U,
auto RetainFunction,
auto ReleaseFunction>
89 Q_NODISCARD_CTOR QAppleRefCounted() : value() {}
90 Q_NODISCARD_CTOR QAppleRefCounted(
const T &t) : value(t) {}
91 Q_NODISCARD_CTOR QAppleRefCounted(T &&t)
92 noexcept(std::is_nothrow_move_constructible<T>::value)
93 : value(std::move(t)) {}
94 Q_NODISCARD_CTOR QAppleRefCounted(QAppleRefCounted &&other)
95 noexcept(std::is_nothrow_move_assignable<T>::value &&
96 std::is_nothrow_move_constructible<T>::value)
97 : value(std::exchange(other.value, T())) {}
98 Q_NODISCARD_CTOR QAppleRefCounted(
const QAppleRefCounted &other)
100 {
if (value) RetainFunction(value); }
101 ~QAppleRefCounted() {
if (value) ReleaseFunction(value); }
102 operator T()
const {
return value; }
103 void swap(QAppleRefCounted &other)
noexcept(
noexcept(qSwap(value, other.value)))
104 { qSwap(value, other.value); }
105 QAppleRefCounted &operator=(
const QAppleRefCounted &other)
106 { QAppleRefCounted copy(other); swap(copy);
return *
this; }
107 QAppleRefCounted &operator=(QAppleRefCounted &&other)
108 noexcept(std::is_nothrow_move_assignable<T>::value &&
109 std::is_nothrow_move_constructible<T>::value)
110 { QAppleRefCounted moved(std::move(other)); swap(moved);
return *
this; }
111 T *operator&() {
return &value; }
127class QMacRootLevelAutoReleasePool
130 Q_NODISCARD_CTOR QMacRootLevelAutoReleasePool();
131 ~QMacRootLevelAutoReleasePool();
133 std::optional<QMacAutoReleasePool> pool = std::nullopt;
138
139
140
141
142
143
144
145
146
147
148
156 template <
typename X> X
as()
const {
return reinterpret_cast<X>(
this->value); }
167class QIOType :
public QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease>
169 using QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease>::QAppleRefCounted;
190 QObjCWeakPointerBase(NSObject *object = nil);
191 QObjCWeakPointerBase(
const QObjCWeakPointerBase &other);
192 QObjCWeakPointerBase &operator=(
const QObjCWeakPointerBase &other);
195 ~QObjCWeakPointerBase();
196 NSObject *get()
const;
198 NSObject *m_object = nil;
201 __weak id m_weakReference;
211 operator T*()
const {
return static_cast<T*>(get()); }
217Q_CORE_EXPORT
bool qt_mac_runningUnderRosetta();
218Q_CORE_EXPORT std::optional<uint32_t> qt_mac_sipConfiguration();
219#ifdef QT_BUILD_INTERNAL
220Q_AUTOTEST_EXPORT
void qt_mac_ensureResponsible();
224#ifndef QT_NO_DEBUG_STREAM
225Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QMacAutoReleasePool *pool);
226Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QCFString &string);
232#if !defined(QT_BOOTSTRAPPED)
237@interface NSObject (QtExtras)
238- (id)qt_valueForPrivateKey:(NSString *)key;
244#if !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WATCHOS)
246# if defined(Q_OS_MACOS)
251using AppleApplication = UIApplication;
254Q_CORE_EXPORT AppleApplication *qt_apple_sharedApplication();
259#if !defined(QT_BOOTSTRAPPED)
260#define QT_USE_APPLE_UNIFIED_LOGGING
269 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
270 const QString &message)
271 {
return messageHandler(msgType, context, message, QString()); }
272 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
273 const QString &message,
const QString &subsystem);
274 static bool preventsStderrLogging();
276 static os_log_type_t logTypeForMessageType(QtMsgType msgType);
277 static os_log_t cachedLog(
const QString &subsystem,
const QString &category);
287#include <os/activity.h>
290template <
typename T>
using QAppleOsType = QAppleRefCounted<T,
void *, os_retain, os_release>;
295 QAppleLogActivity() : activity(
nullptr) {}
296 QAppleLogActivity(os_activity_t activity) : activity(activity) {}
297 ~QAppleLogActivity() {
if (activity) leave(); }
299 Q_DISABLE_COPY(QAppleLogActivity)
301 QAppleLogActivity(QAppleLogActivity &&other)
302 : activity(std::exchange(other.activity,
nullptr)), state(other.state)
306 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QAppleLogActivity)
308 QAppleLogActivity &&enter()
311 os_activity_scope_enter(
static_cast<os_activity_t>(*
this), &state);
312 return std::move(*
this);
318 os_activity_scope_leave(&state);
321 operator os_activity_t()
323 return reinterpret_cast<os_activity_t>(
static_cast<
void *>(activity));
326 void swap(QAppleLogActivity &other)
328 activity.swap(other.activity);
329 std::swap(state, other.state);
334 QAppleOsType<
void *> activity;
335 os_activity_scope_state_s state;
338#define QT_APPLE_LOG_ACTIVITY_CREATE(condition, description, parent) []() {
340 return QAppleLogActivity();
341 return QAppleLogActivity(os_activity_create(description, parent, OS_ACTIVITY_FLAG_DEFAULT));
353#define QT_APPLE_SCOPED_LOG_ACTIVITY(...) QAppleLogActivity scopedLogActivity = QT_APPLE_LOG_ACTIVITY(__VA_ARGS__).enter();
362 QMacNotificationObserver() {}
364#if defined( __OBJC__)
365 template<
typename Functor>
366 QMacNotificationObserver(NSObject *object, NSNotificationName name, Functor callback) {
367 observer = [[NSNotificationCenter defaultCenter] addObserverForName:name
368 object:object queue:nil usingBlock:^(NSNotification *notification) {
369 if constexpr (std::is_invocable_v<Functor, NSNotification *>)
370 callback(notification);
378 QMacNotificationObserver(
const QMacNotificationObserver &other) =
delete;
379 QMacNotificationObserver(QMacNotificationObserver &&other)
380 : observer(std::exchange(other.observer,
nullptr))
384 QMacNotificationObserver &operator=(
const QMacNotificationObserver &other) =
delete;
385 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacNotificationObserver)
387 void swap(QMacNotificationObserver &other)
noexcept
389 std::swap(observer, other.observer);
393 ~QMacNotificationObserver() { remove(); }
396 NSObject *observer =
nullptr;
406 using Callback = std::function<
void()>;
408 QMacKeyValueObserver() =
default;
410#if defined( __OBJC__)
411 QMacKeyValueObserver(NSObject *object, NSString *keyPath, Callback callback,
412 NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew)
413 : object(object), keyPath(keyPath), callback(
new Callback(callback))
415 addObserver(options);
419 QMacKeyValueObserver(
const QMacKeyValueObserver &other);
421 QMacKeyValueObserver(QMacKeyValueObserver &&other)
noexcept { swap(other); }
423 ~QMacKeyValueObserver() { removeObserver(); }
425 QMacKeyValueObserver &operator=(
const QMacKeyValueObserver &other)
427 QMacKeyValueObserver tmp(other);
432 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacKeyValueObserver)
434 void removeObserver();
436 void swap(QMacKeyValueObserver &other)
noexcept
438 std::swap(object, other.object);
439 std::swap(keyPath, other.keyPath);
440 callback.swap(other.callback);
444#if defined( __OBJC__)
445 void addObserver(NSKeyValueObservingOptions options);
448 QObjCWeakPointer<NSObject> object;
449 NSString *keyPath =
nullptr;
450 std::unique_ptr<Callback> callback;
452 static KeyValueObserver *observer;
465 static QOperatingSystemVersion buildSDK(VersionTarget target = ApplicationBinary);
466 static QOperatingSystemVersion deploymentTarget(VersionTarget target = ApplicationBinary);
467 static QOperatingSystemVersion currentRuntime();
470 QMacVersion() =
default;
471 using VersionTuple = std::pair<QOperatingSystemVersion, QOperatingSystemVersion>;
472 static VersionTuple versionsForImage(
const mach_header *machHeader);
473 static VersionTuple applicationVersion();
474 static VersionTuple libraryVersion();
481typename std::enable_if<std::is_pointer<T>::value, T>::type
482qt_objc_cast(id object)
484 if ([object isKindOfClass:[
typename std::remove_pointer<T>::type
class]])
485 return static_cast<T>(object);
static QCFType constructFromGet(const T &t)
Q_CORE_EXPORT ~QMacAutoReleasePool()
const QString & asString(const QString &s)
#define QT_APPLE_LOG_ACTIVITY_2(condition, description)
Q_CORE_EXPORT bool qt_apple_isApplicationExtension()
#define QT_APPLE_LOG_ACTIVITY(...)
#define QT_MAC_WEAK_IMPORT(symbol)
#define QT_APPLE_LOG_ACTIVITY_WITH_PARENT_3(condition, description, parent)
Q_FORWARD_DECLARE_OBJC_CLASS(NSString)
Q_CORE_EXPORT bool qt_apple_isSandboxed()
Q_CORE_EXPORT bool qt_apple_runningWithLiquidGlass()
#define QT_APPLE_LOG_ACTIVITY_CREATE(condition, description, parent)
#define QT_APPLE_LOG_ACTIVITY_WITH_PARENT(...)
#define QT_DECLARE_NAMESPACED_OBJC_INTERFACE(classname, definition)
Q_FORWARD_DECLARE_OBJC_CLASS(NSObject)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(RunLoopModeTracker))
QT_REQUIRE_CONFIG(filesystemwatcher)
static QT_BEGIN_NAMESPACE void callBackFunction(ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[])
#define qPrintable(string)