19#include "private/qglobal_p.h"
21#include <QtCore/qoperatingsystemversion.h>
28typedef int kern_return_t;
29typedef mach_port_t io_object_t;
31kern_return_t IOObjectRetain(io_object_t object);
32kern_return_t IOObjectRelease(io_object_t object);
36#ifndef __IMAGECAPTURE__
37# define __IMAGECAPTURE__
42#if defined(QT_BOOTSTRAPPED)
43#include <ApplicationServices/ApplicationServices.h>
45#include <CoreFoundation/CoreFoundation.h>
49#include <Foundation/Foundation.h>
56#if defined( __OBJC__) && defined(QT_NAMESPACE)
57#define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__) @compatibility_alias __KLASS__ QT_MANGLE_NAMESPACE(__KLASS__)
59#define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__)
62#define QT_MAC_WEAK_IMPORT(symbol) extern "C" decltype(symbol) symbol __attribute__((weak_import));
65#define QT_DECLARE_NAMESPACED_OBJC_INTERFACE(classname, definition)
66 @interface QT_MANGLE_NAMESPACE(classname) :
69 QT_NAMESPACE_ALIAS_OBJC_CLASS(classname);
71#define QT_DECLARE_NAMESPACED_OBJC_INTERFACE(classname, definition)
72 Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(classname));
73 using classname = QT_MANGLE_NAMESPACE(classname);
76#define QT_FORWARD_DECLARE_OBJC_ENUM(name, type)
86#if defined(Q_OS_MACOS)
96template <
typename T,
typename U,
auto RetainFunction,
auto ReleaseFunction>
100 Q_NODISCARD_CTOR QAppleRefCounted() : value() {}
101 Q_NODISCARD_CTOR QAppleRefCounted(
const T &t) : value(t) {}
102 Q_NODISCARD_CTOR QAppleRefCounted(T &&t)
103 noexcept(std::is_nothrow_move_constructible<T>::value)
104 : value(std::move(t)) {}
105 Q_NODISCARD_CTOR QAppleRefCounted(QAppleRefCounted &&other)
106 noexcept(std::is_nothrow_move_assignable<T>::value &&
107 std::is_nothrow_move_constructible<T>::value)
108 : value(std::exchange(other.value, T())) {}
109 Q_NODISCARD_CTOR QAppleRefCounted(
const QAppleRefCounted &other)
111 {
if (value) RetainFunction(value); }
112 ~QAppleRefCounted() {
if (value) ReleaseFunction(value); }
113 operator T()
const {
return value; }
114 void swap(QAppleRefCounted &other)
noexcept(
noexcept(qSwap(value, other.value)))
115 { qSwap(value, other.value); }
116 QAppleRefCounted &operator=(
const QAppleRefCounted &other)
117 { QAppleRefCounted copy(other); swap(copy);
return *
this; }
118 QAppleRefCounted &operator=(QAppleRefCounted &&other)
119 noexcept(std::is_nothrow_move_assignable<T>::value &&
120 std::is_nothrow_move_constructible<T>::value)
121 { QAppleRefCounted moved(std::move(other)); swap(moved);
return *
this; }
122 T *operator&() {
return &value; }
138class QMacRootLevelAutoReleasePool
141 Q_NODISCARD_CTOR QMacRootLevelAutoReleasePool();
142 ~QMacRootLevelAutoReleasePool();
144 std::optional<QMacAutoReleasePool> pool = std::nullopt;
149
150
151
152
153
154
155
156
157
158
159
167 template <
typename X> X
as()
const {
return reinterpret_cast<X>(
this->value); }
178class QIOType :
public QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease>
180 using QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease>::QAppleRefCounted;
201 QObjCWeakPointerBase(NSObject *object = nil);
202 QObjCWeakPointerBase(
const QObjCWeakPointerBase &other);
203 QObjCWeakPointerBase &operator=(
const QObjCWeakPointerBase &other);
206 ~QObjCWeakPointerBase();
207 NSObject *get()
const;
209 NSObject *m_object = nil;
212 __weak id m_weakReference;
222 operator T*()
const {
return static_cast<T*>(get()); }
228Q_CORE_EXPORT
bool qt_mac_runningUnderRosetta();
229Q_CORE_EXPORT std::optional<uint32_t> qt_mac_sipConfiguration();
230Q_CORE_EXPORT
bool qt_mac_processHasEntitlement(
const QString &entitlement);
231#ifdef QT_BUILD_INTERNAL
232Q_AUTOTEST_EXPORT
void qt_mac_ensureResponsible();
236#ifndef QT_NO_DEBUG_STREAM
237Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QMacAutoReleasePool *pool);
238Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QCFString &string);
239Q_CORE_EXPORT
QDebug operator<<(QDebug, CGPoint);
240Q_CORE_EXPORT
QDebug operator<<(QDebug, CGSize);
241Q_CORE_EXPORT
QDebug operator<<(QDebug, CGRect);
242#if defined(Q_OS_MACOS)
243Q_CORE_EXPORT QDebug operator<<(QDebug, NSEdgeInsets);
245Q_CORE_EXPORT
QDebug operator<<(QDebug, UIEdgeInsets);
251Q_CORE_EXPORT std::optional<UTType *> qt_apple_bundleType(
const QString &path);
253#if !defined(QT_BOOTSTRAPPED)
258@interface NSObject (QtExtras)
259- (id)qt_valueForPrivateKey:(NSString *)key;
265#if !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WATCHOS)
267# if defined(Q_OS_MACOS)
272using AppleApplication = UIApplication;
275Q_CORE_EXPORT AppleApplication *qt_apple_sharedApplication();
280#if !defined(QT_BOOTSTRAPPED)
281#define QT_USE_APPLE_UNIFIED_LOGGING
290 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
291 const QString &message)
292 {
return messageHandler(msgType, context, message, QString()); }
293 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
294 const QString &message,
const QString &subsystem);
295 static bool preventsStderrLogging();
297 static os_log_type_t logTypeForMessageType(QtMsgType msgType);
298 static os_log_t cachedLog(
const QString &subsystem,
const QString &category);
308#include <os/activity.h>
311template <
typename T>
using QAppleOsType = QAppleRefCounted<T,
void *, os_retain, os_release>;
316 QAppleLogActivity() : activity(
nullptr) {}
317 QAppleLogActivity(os_activity_t activity) : activity(activity) {}
318 ~QAppleLogActivity() {
if (activity) leave(); }
320 Q_DISABLE_COPY(QAppleLogActivity)
322 QAppleLogActivity(QAppleLogActivity &&other)
323 : activity(std::exchange(other.activity,
nullptr)), state(other.state)
327 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QAppleLogActivity)
329 QAppleLogActivity &&enter()
332 os_activity_scope_enter(
static_cast<os_activity_t>(*
this), &state);
333 return std::move(*
this);
339 os_activity_scope_leave(&state);
342 operator os_activity_t()
344 return reinterpret_cast<os_activity_t>(
static_cast<
void *>(activity));
347 void swap(QAppleLogActivity &other)
349 activity.swap(other.activity);
350 std::swap(state, other.state);
355 QAppleOsType<
void *> activity;
356 os_activity_scope_state_s state;
359#define QT_APPLE_LOG_ACTIVITY_CREATE(condition, description, parent) []() {
361 return QAppleLogActivity();
362 return QAppleLogActivity(os_activity_create(description, parent, OS_ACTIVITY_FLAG_DEFAULT));
374#define QT_APPLE_SCOPED_LOG_ACTIVITY(...) QAppleLogActivity scopedLogActivity = QT_APPLE_LOG_ACTIVITY(__VA_ARGS__).enter();
383 QMacNotificationObserver() {}
385#if defined( __OBJC__)
386 template<
typename Functor>
387 QMacNotificationObserver(NSObject *object, NSNotificationName name, Functor callback) {
388 observer = [[NSNotificationCenter defaultCenter] addObserverForName:name
389 object:object queue:nil usingBlock:^(NSNotification *notification) {
390 if constexpr (std::is_invocable_v<Functor, NSNotification *>)
391 callback(notification);
399 QMacNotificationObserver(
const QMacNotificationObserver &other) =
delete;
400 QMacNotificationObserver(QMacNotificationObserver &&other)
401 : observer(std::exchange(other.observer,
nullptr))
405 QMacNotificationObserver &operator=(
const QMacNotificationObserver &other) =
delete;
406 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacNotificationObserver)
408 void swap(QMacNotificationObserver &other)
noexcept
410 std::swap(observer, other.observer);
414 ~QMacNotificationObserver() { remove(); }
417 NSObject *observer =
nullptr;
427 using Callback = std::function<
void()>;
429 QMacKeyValueObserver() =
default;
431#if defined( __OBJC__)
432 QMacKeyValueObserver(NSObject *object, NSString *keyPath, Callback callback,
433 NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew)
434 : object(object), keyPath(keyPath), callback(
new Callback(callback))
436 addObserver(options);
440 QMacKeyValueObserver(
const QMacKeyValueObserver &other);
442 QMacKeyValueObserver(QMacKeyValueObserver &&other)
noexcept { swap(other); }
444 ~QMacKeyValueObserver() { removeObserver(); }
446 QMacKeyValueObserver &operator=(
const QMacKeyValueObserver &other)
448 QMacKeyValueObserver tmp(other);
453 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacKeyValueObserver)
455 void removeObserver();
457 void swap(QMacKeyValueObserver &other)
noexcept
459 std::swap(object, other.object);
460 std::swap(keyPath, other.keyPath);
461 callback.swap(other.callback);
465#if defined( __OBJC__)
466 void addObserver(NSKeyValueObservingOptions options);
469 QObjCWeakPointer<NSObject> object;
470 NSString *keyPath =
nullptr;
471 std::unique_ptr<Callback> callback;
473 static KeyValueObserver *observer;
486 static QOperatingSystemVersion buildSDK(VersionTarget target = ApplicationBinary);
487 static QOperatingSystemVersion deploymentTarget(VersionTarget target = ApplicationBinary);
488 static QOperatingSystemVersion currentRuntime();
491 QMacVersion() =
default;
492 using VersionTuple = std::pair<QOperatingSystemVersion, QOperatingSystemVersion>;
493 static VersionTuple versionsForImage(
const mach_header *machHeader);
494 static VersionTuple applicationVersion();
495 static VersionTuple libraryVersion();
502typename std::enable_if<std::is_pointer<T>::value, T>::type
503qt_objc_cast(id object)
505 if ([object isKindOfClass:[
typename std::remove_pointer<T>::type
class]])
506 return static_cast<T>(object);
static QCFType constructFromGet(const T &t)
Q_CORE_EXPORT ~QMacAutoReleasePool()
Combined button and popup list for selecting options.
const QString & asString(const QString &s)
Q_FORWARD_DECLARE_OBJC_CLASS(UTType)
#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 void callBackFunction(ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[])
static QT_BEGIN_NAMESPACE bool isSameTimestampAndMode(const QT_STATBUF &statbuff, const QFseventsFileSystemWatcherEngine::Info &info)
#define qPrintable(string)