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)
84#if defined(Q_OS_MACOS)
94template <
typename T,
typename U,
auto RetainFunction,
auto ReleaseFunction>
98 Q_NODISCARD_CTOR QAppleRefCounted() : value() {}
99 Q_NODISCARD_CTOR QAppleRefCounted(
const T &t) : value(t) {}
100 Q_NODISCARD_CTOR QAppleRefCounted(T &&t)
101 noexcept(std::is_nothrow_move_constructible<T>::value)
102 : value(std::move(t)) {}
103 Q_NODISCARD_CTOR QAppleRefCounted(QAppleRefCounted &&other)
104 noexcept(std::is_nothrow_move_assignable<T>::value &&
105 std::is_nothrow_move_constructible<T>::value)
106 : value(std::exchange(other.value, T())) {}
107 Q_NODISCARD_CTOR QAppleRefCounted(
const QAppleRefCounted &other)
109 {
if (value) RetainFunction(value); }
110 ~QAppleRefCounted() {
if (value) ReleaseFunction(value); }
111 operator T()
const {
return value; }
112 void swap(QAppleRefCounted &other)
noexcept(
noexcept(qSwap(value, other.value)))
113 { qSwap(value, other.value); }
114 QAppleRefCounted &operator=(
const QAppleRefCounted &other)
115 { QAppleRefCounted copy(other); swap(copy);
return *
this; }
116 QAppleRefCounted &operator=(QAppleRefCounted &&other)
117 noexcept(std::is_nothrow_move_assignable<T>::value &&
118 std::is_nothrow_move_constructible<T>::value)
119 { QAppleRefCounted moved(std::move(other)); swap(moved);
return *
this; }
120 T *operator&() {
return &value; }
136class QMacRootLevelAutoReleasePool
139 Q_NODISCARD_CTOR QMacRootLevelAutoReleasePool();
140 ~QMacRootLevelAutoReleasePool();
142 std::optional<QMacAutoReleasePool> pool = std::nullopt;
147
148
149
150
151
152
153
154
155
156
157
165 template <
typename X> X
as()
const {
return reinterpret_cast<X>(
this->value); }
176class QIOType :
public QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease>
178 using QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease>::QAppleRefCounted;
199 QObjCWeakPointerBase(NSObject *object = nil);
200 QObjCWeakPointerBase(
const QObjCWeakPointerBase &other);
201 QObjCWeakPointerBase &operator=(
const QObjCWeakPointerBase &other);
204 ~QObjCWeakPointerBase();
205 NSObject *get()
const;
207 NSObject *m_object = nil;
210 __weak id m_weakReference;
220 operator T*()
const {
return static_cast<T*>(get()); }
226Q_CORE_EXPORT
bool qt_mac_runningUnderRosetta();
227Q_CORE_EXPORT std::optional<uint32_t> qt_mac_sipConfiguration();
228Q_CORE_EXPORT
bool qt_mac_processHasEntitlement(
const QString &entitlement);
229#ifdef QT_BUILD_INTERNAL
230Q_AUTOTEST_EXPORT
void qt_mac_ensureResponsible();
234#ifndef QT_NO_DEBUG_STREAM
235Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QMacAutoReleasePool *pool);
236Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QCFString &string);
237Q_CORE_EXPORT
QDebug operator<<(QDebug, CGPoint);
238Q_CORE_EXPORT
QDebug operator<<(QDebug, CGSize);
239Q_CORE_EXPORT
QDebug operator<<(QDebug, CGRect);
240#if defined(Q_OS_MACOS)
241Q_CORE_EXPORT QDebug operator<<(QDebug, NSEdgeInsets);
243Q_CORE_EXPORT
QDebug operator<<(QDebug, UIEdgeInsets);
250#if !defined(QT_BOOTSTRAPPED)
255@interface NSObject (QtExtras)
256- (id)qt_valueForPrivateKey:(NSString *)key;
262#if !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WATCHOS)
264# if defined(Q_OS_MACOS)
269using AppleApplication = UIApplication;
272Q_CORE_EXPORT AppleApplication *qt_apple_sharedApplication();
277#if !defined(QT_BOOTSTRAPPED)
278#define QT_USE_APPLE_UNIFIED_LOGGING
287 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
288 const QString &message)
289 {
return messageHandler(msgType, context, message, QString()); }
290 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
291 const QString &message,
const QString &subsystem);
292 static bool preventsStderrLogging();
294 static os_log_type_t logTypeForMessageType(QtMsgType msgType);
295 static os_log_t cachedLog(
const QString &subsystem,
const QString &category);
305#include <os/activity.h>
308template <
typename T>
using QAppleOsType = QAppleRefCounted<T,
void *, os_retain, os_release>;
313 QAppleLogActivity() : activity(
nullptr) {}
314 QAppleLogActivity(os_activity_t activity) : activity(activity) {}
315 ~QAppleLogActivity() {
if (activity) leave(); }
317 Q_DISABLE_COPY(QAppleLogActivity)
319 QAppleLogActivity(QAppleLogActivity &&other)
320 : activity(std::exchange(other.activity,
nullptr)), state(other.state)
324 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QAppleLogActivity)
326 QAppleLogActivity &&enter()
329 os_activity_scope_enter(
static_cast<os_activity_t>(*
this), &state);
330 return std::move(*
this);
336 os_activity_scope_leave(&state);
339 operator os_activity_t()
341 return reinterpret_cast<os_activity_t>(
static_cast<
void *>(activity));
344 void swap(QAppleLogActivity &other)
346 activity.swap(other.activity);
347 std::swap(state, other.state);
352 QAppleOsType<
void *> activity;
353 os_activity_scope_state_s state;
356#define QT_APPLE_LOG_ACTIVITY_CREATE(condition, description, parent) []() {
358 return QAppleLogActivity();
359 return QAppleLogActivity(os_activity_create(description, parent, OS_ACTIVITY_FLAG_DEFAULT));
371#define QT_APPLE_SCOPED_LOG_ACTIVITY(...) QAppleLogActivity scopedLogActivity = QT_APPLE_LOG_ACTIVITY(__VA_ARGS__).enter();
380 QMacNotificationObserver() {}
382#if defined( __OBJC__)
383 template<
typename Functor>
384 QMacNotificationObserver(NSObject *object, NSNotificationName name, Functor callback) {
385 observer = [[NSNotificationCenter defaultCenter] addObserverForName:name
386 object:object queue:nil usingBlock:^(NSNotification *notification) {
387 if constexpr (std::is_invocable_v<Functor, NSNotification *>)
388 callback(notification);
396 QMacNotificationObserver(
const QMacNotificationObserver &other) =
delete;
397 QMacNotificationObserver(QMacNotificationObserver &&other)
398 : observer(std::exchange(other.observer,
nullptr))
402 QMacNotificationObserver &operator=(
const QMacNotificationObserver &other) =
delete;
403 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacNotificationObserver)
405 void swap(QMacNotificationObserver &other)
noexcept
407 std::swap(observer, other.observer);
411 ~QMacNotificationObserver() { remove(); }
414 NSObject *observer =
nullptr;
424 using Callback = std::function<
void()>;
426 QMacKeyValueObserver() =
default;
428#if defined( __OBJC__)
429 QMacKeyValueObserver(NSObject *object, NSString *keyPath, Callback callback,
430 NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew)
431 : object(object), keyPath(keyPath), callback(
new Callback(callback))
433 addObserver(options);
437 QMacKeyValueObserver(
const QMacKeyValueObserver &other);
439 QMacKeyValueObserver(QMacKeyValueObserver &&other)
noexcept { swap(other); }
441 ~QMacKeyValueObserver() { removeObserver(); }
443 QMacKeyValueObserver &operator=(
const QMacKeyValueObserver &other)
445 QMacKeyValueObserver tmp(other);
450 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacKeyValueObserver)
452 void removeObserver();
454 void swap(QMacKeyValueObserver &other)
noexcept
456 std::swap(object, other.object);
457 std::swap(keyPath, other.keyPath);
458 callback.swap(other.callback);
462#if defined( __OBJC__)
463 void addObserver(NSKeyValueObservingOptions options);
466 QObjCWeakPointer<NSObject> object;
467 NSString *keyPath =
nullptr;
468 std::unique_ptr<Callback> callback;
470 static KeyValueObserver *observer;
483 static QOperatingSystemVersion buildSDK(VersionTarget target = ApplicationBinary);
484 static QOperatingSystemVersion deploymentTarget(VersionTarget target = ApplicationBinary);
485 static QOperatingSystemVersion currentRuntime();
488 QMacVersion() =
default;
489 using VersionTuple = std::pair<QOperatingSystemVersion, QOperatingSystemVersion>;
490 static VersionTuple versionsForImage(
const mach_header *machHeader);
491 static VersionTuple applicationVersion();
492 static VersionTuple libraryVersion();
499typename std::enable_if<std::is_pointer<T>::value, T>::type
500qt_objc_cast(id object)
502 if ([object isKindOfClass:[
typename std::remove_pointer<T>::type
class]])
503 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)
#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)