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();
219Q_CORE_EXPORT
bool qt_mac_processHasEntitlement(
const QString &entitlement);
220#ifdef QT_BUILD_INTERNAL
221Q_AUTOTEST_EXPORT
void qt_mac_ensureResponsible();
225#ifndef QT_NO_DEBUG_STREAM
226Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QMacAutoReleasePool *pool);
227Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QCFString &string);
233#if !defined(QT_BOOTSTRAPPED)
238@interface NSObject (QtExtras)
239- (id)qt_valueForPrivateKey:(NSString *)key;
245#if !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WATCHOS)
247# if defined(Q_OS_MACOS)
252using AppleApplication = UIApplication;
255Q_CORE_EXPORT AppleApplication *qt_apple_sharedApplication();
260#if !defined(QT_BOOTSTRAPPED)
261#define QT_USE_APPLE_UNIFIED_LOGGING
270 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
271 const QString &message)
272 {
return messageHandler(msgType, context, message, QString()); }
273 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
274 const QString &message,
const QString &subsystem);
275 static bool preventsStderrLogging();
277 static os_log_type_t logTypeForMessageType(QtMsgType msgType);
278 static os_log_t cachedLog(
const QString &subsystem,
const QString &category);
288#include <os/activity.h>
291template <
typename T>
using QAppleOsType = QAppleRefCounted<T,
void *, os_retain, os_release>;
296 QAppleLogActivity() : activity(
nullptr) {}
297 QAppleLogActivity(os_activity_t activity) : activity(activity) {}
298 ~QAppleLogActivity() {
if (activity) leave(); }
300 Q_DISABLE_COPY(QAppleLogActivity)
302 QAppleLogActivity(QAppleLogActivity &&other)
303 : activity(std::exchange(other.activity,
nullptr)), state(other.state)
307 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QAppleLogActivity)
309 QAppleLogActivity &&enter()
312 os_activity_scope_enter(
static_cast<os_activity_t>(*
this), &state);
313 return std::move(*
this);
319 os_activity_scope_leave(&state);
322 operator os_activity_t()
324 return reinterpret_cast<os_activity_t>(
static_cast<
void *>(activity));
327 void swap(QAppleLogActivity &other)
329 activity.swap(other.activity);
330 std::swap(state, other.state);
335 QAppleOsType<
void *> activity;
336 os_activity_scope_state_s state;
339#define QT_APPLE_LOG_ACTIVITY_CREATE(condition, description, parent) []() {
341 return QAppleLogActivity();
342 return QAppleLogActivity(os_activity_create(description, parent, OS_ACTIVITY_FLAG_DEFAULT));
354#define QT_APPLE_SCOPED_LOG_ACTIVITY(...) QAppleLogActivity scopedLogActivity = QT_APPLE_LOG_ACTIVITY(__VA_ARGS__).enter();
363 QMacNotificationObserver() {}
365#if defined( __OBJC__)
366 template<
typename Functor>
367 QMacNotificationObserver(NSObject *object, NSNotificationName name, Functor callback) {
368 observer = [[NSNotificationCenter defaultCenter] addObserverForName:name
369 object:object queue:nil usingBlock:^(NSNotification *notification) {
370 if constexpr (std::is_invocable_v<Functor, NSNotification *>)
371 callback(notification);
379 QMacNotificationObserver(
const QMacNotificationObserver &other) =
delete;
380 QMacNotificationObserver(QMacNotificationObserver &&other)
381 : observer(std::exchange(other.observer,
nullptr))
385 QMacNotificationObserver &operator=(
const QMacNotificationObserver &other) =
delete;
386 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacNotificationObserver)
388 void swap(QMacNotificationObserver &other)
noexcept
390 std::swap(observer, other.observer);
394 ~QMacNotificationObserver() { remove(); }
397 NSObject *observer =
nullptr;
407 using Callback = std::function<
void()>;
409 QMacKeyValueObserver() =
default;
411#if defined( __OBJC__)
412 QMacKeyValueObserver(NSObject *object, NSString *keyPath, Callback callback,
413 NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew)
414 : object(object), keyPath(keyPath), callback(
new Callback(callback))
416 addObserver(options);
420 QMacKeyValueObserver(
const QMacKeyValueObserver &other);
422 QMacKeyValueObserver(QMacKeyValueObserver &&other)
noexcept { swap(other); }
424 ~QMacKeyValueObserver() { removeObserver(); }
426 QMacKeyValueObserver &operator=(
const QMacKeyValueObserver &other)
428 QMacKeyValueObserver tmp(other);
433 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacKeyValueObserver)
435 void removeObserver();
437 void swap(QMacKeyValueObserver &other)
noexcept
439 std::swap(object, other.object);
440 std::swap(keyPath, other.keyPath);
441 callback.swap(other.callback);
445#if defined( __OBJC__)
446 void addObserver(NSKeyValueObservingOptions options);
449 QObjCWeakPointer<NSObject> object;
450 NSString *keyPath =
nullptr;
451 std::unique_ptr<Callback> callback;
453 static KeyValueObserver *observer;
466 static QOperatingSystemVersion buildSDK(VersionTarget target = ApplicationBinary);
467 static QOperatingSystemVersion deploymentTarget(VersionTarget target = ApplicationBinary);
468 static QOperatingSystemVersion currentRuntime();
471 QMacVersion() =
default;
472 using VersionTuple = std::pair<QOperatingSystemVersion, QOperatingSystemVersion>;
473 static VersionTuple versionsForImage(
const mach_header *machHeader);
474 static VersionTuple applicationVersion();
475 static VersionTuple libraryVersion();
482typename std::enable_if<std::is_pointer<T>::value, T>::type
483qt_objc_cast(id object)
485 if ([object isKindOfClass:[
typename std::remove_pointer<T>::type
class]])
486 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)