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)
85#if defined(Q_OS_MACOS)
95template <
typename T,
typename U,
auto RetainFunction,
auto ReleaseFunction>
99 Q_NODISCARD_CTOR QAppleRefCounted() : value() {}
100 Q_NODISCARD_CTOR QAppleRefCounted(
const T &t) : value(t) {}
101 Q_NODISCARD_CTOR QAppleRefCounted(T &&t)
102 noexcept(std::is_nothrow_move_constructible<T>::value)
103 : value(std::move(t)) {}
104 Q_NODISCARD_CTOR QAppleRefCounted(QAppleRefCounted &&other)
105 noexcept(std::is_nothrow_move_assignable<T>::value &&
106 std::is_nothrow_move_constructible<T>::value)
107 : value(std::exchange(other.value, T())) {}
108 Q_NODISCARD_CTOR QAppleRefCounted(
const QAppleRefCounted &other)
110 {
if (value) RetainFunction(value); }
111 ~QAppleRefCounted() {
if (value) ReleaseFunction(value); }
112 operator T()
const {
return value; }
113 void swap(QAppleRefCounted &other)
noexcept(
noexcept(qSwap(value, other.value)))
114 { qSwap(value, other.value); }
115 QAppleRefCounted &operator=(
const QAppleRefCounted &other)
116 { QAppleRefCounted copy(other); swap(copy);
return *
this; }
117 QAppleRefCounted &operator=(QAppleRefCounted &&other)
118 noexcept(std::is_nothrow_move_assignable<T>::value &&
119 std::is_nothrow_move_constructible<T>::value)
120 { QAppleRefCounted moved(std::move(other)); swap(moved);
return *
this; }
121 T *operator&() {
return &value; }
137class QMacRootLevelAutoReleasePool
140 Q_NODISCARD_CTOR QMacRootLevelAutoReleasePool();
141 ~QMacRootLevelAutoReleasePool();
143 std::optional<QMacAutoReleasePool> pool = std::nullopt;
148
149
150
151
152
153
154
155
156
157
158
166 template <
typename X> X
as()
const {
return reinterpret_cast<X>(
this->value); }
177class QIOType :
public QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease>
179 using QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease>::QAppleRefCounted;
200 QObjCWeakPointerBase(NSObject *object = nil);
201 QObjCWeakPointerBase(
const QObjCWeakPointerBase &other);
202 QObjCWeakPointerBase &operator=(
const QObjCWeakPointerBase &other);
205 ~QObjCWeakPointerBase();
206 NSObject *get()
const;
208 NSObject *m_object = nil;
211 __weak id m_weakReference;
221 operator T*()
const {
return static_cast<T*>(get()); }
227Q_CORE_EXPORT
bool qt_mac_runningUnderRosetta();
228Q_CORE_EXPORT std::optional<uint32_t> qt_mac_sipConfiguration();
229Q_CORE_EXPORT
bool qt_mac_processHasEntitlement(
const QString &entitlement);
230#ifdef QT_BUILD_INTERNAL
231Q_AUTOTEST_EXPORT
void qt_mac_ensureResponsible();
235#ifndef QT_NO_DEBUG_STREAM
236Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QMacAutoReleasePool *pool);
237Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QCFString &string);
238Q_CORE_EXPORT
QDebug operator<<(QDebug, CGPoint);
239Q_CORE_EXPORT
QDebug operator<<(QDebug, CGSize);
240Q_CORE_EXPORT
QDebug operator<<(QDebug, CGRect);
241#if defined(Q_OS_MACOS)
242Q_CORE_EXPORT QDebug operator<<(QDebug, NSEdgeInsets);
244Q_CORE_EXPORT
QDebug operator<<(QDebug, UIEdgeInsets);
251#if !defined(QT_BOOTSTRAPPED)
256@interface NSObject (QtExtras)
257- (id)qt_valueForPrivateKey:(NSString *)key;
263#if !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WATCHOS)
265# if defined(Q_OS_MACOS)
270using AppleApplication = UIApplication;
273Q_CORE_EXPORT AppleApplication *qt_apple_sharedApplication();
278#if !defined(QT_BOOTSTRAPPED)
279#define QT_USE_APPLE_UNIFIED_LOGGING
288 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
289 const QString &message)
290 {
return messageHandler(msgType, context, message, QString()); }
291 static bool messageHandler(QtMsgType msgType,
const QMessageLogContext &context,
292 const QString &message,
const QString &subsystem);
293 static bool preventsStderrLogging();
295 static os_log_type_t logTypeForMessageType(QtMsgType msgType);
296 static os_log_t cachedLog(
const QString &subsystem,
const QString &category);
306#include <os/activity.h>
309template <
typename T>
using QAppleOsType = QAppleRefCounted<T,
void *, os_retain, os_release>;
314 QAppleLogActivity() : activity(
nullptr) {}
315 QAppleLogActivity(os_activity_t activity) : activity(activity) {}
316 ~QAppleLogActivity() {
if (activity) leave(); }
318 Q_DISABLE_COPY(QAppleLogActivity)
320 QAppleLogActivity(QAppleLogActivity &&other)
321 : activity(std::exchange(other.activity,
nullptr)), state(other.state)
325 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QAppleLogActivity)
327 QAppleLogActivity &&enter()
330 os_activity_scope_enter(
static_cast<os_activity_t>(*
this), &state);
331 return std::move(*
this);
337 os_activity_scope_leave(&state);
340 operator os_activity_t()
342 return reinterpret_cast<os_activity_t>(
static_cast<
void *>(activity));
345 void swap(QAppleLogActivity &other)
347 activity.swap(other.activity);
348 std::swap(state, other.state);
353 QAppleOsType<
void *> activity;
354 os_activity_scope_state_s state;
357#define QT_APPLE_LOG_ACTIVITY_CREATE(condition, description, parent) []() {
359 return QAppleLogActivity();
360 return QAppleLogActivity(os_activity_create(description, parent, OS_ACTIVITY_FLAG_DEFAULT));
372#define QT_APPLE_SCOPED_LOG_ACTIVITY(...) QAppleLogActivity scopedLogActivity = QT_APPLE_LOG_ACTIVITY(__VA_ARGS__).enter();
381 QMacNotificationObserver() {}
383#if defined( __OBJC__)
384 template<
typename Functor>
385 QMacNotificationObserver(NSObject *object, NSNotificationName name, Functor callback) {
386 observer = [[NSNotificationCenter defaultCenter] addObserverForName:name
387 object:object queue:nil usingBlock:^(NSNotification *notification) {
388 if constexpr (std::is_invocable_v<Functor, NSNotification *>)
389 callback(notification);
397 QMacNotificationObserver(
const QMacNotificationObserver &other) =
delete;
398 QMacNotificationObserver(QMacNotificationObserver &&other)
399 : observer(std::exchange(other.observer,
nullptr))
403 QMacNotificationObserver &operator=(
const QMacNotificationObserver &other) =
delete;
404 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacNotificationObserver)
406 void swap(QMacNotificationObserver &other)
noexcept
408 std::swap(observer, other.observer);
412 ~QMacNotificationObserver() { remove(); }
415 NSObject *observer =
nullptr;
425 using Callback = std::function<
void()>;
427 QMacKeyValueObserver() =
default;
429#if defined( __OBJC__)
430 QMacKeyValueObserver(NSObject *object, NSString *keyPath, Callback callback,
431 NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew)
432 : object(object), keyPath(keyPath), callback(
new Callback(callback))
434 addObserver(options);
438 QMacKeyValueObserver(
const QMacKeyValueObserver &other);
440 QMacKeyValueObserver(QMacKeyValueObserver &&other)
noexcept { swap(other); }
442 ~QMacKeyValueObserver() { removeObserver(); }
444 QMacKeyValueObserver &operator=(
const QMacKeyValueObserver &other)
446 QMacKeyValueObserver tmp(other);
451 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMacKeyValueObserver)
453 void removeObserver();
455 void swap(QMacKeyValueObserver &other)
noexcept
457 std::swap(object, other.object);
458 std::swap(keyPath, other.keyPath);
459 callback.swap(other.callback);
463#if defined( __OBJC__)
464 void addObserver(NSKeyValueObservingOptions options);
467 QObjCWeakPointer<NSObject> object;
468 NSString *keyPath =
nullptr;
469 std::unique_ptr<Callback> callback;
471 static KeyValueObserver *observer;
484 static QOperatingSystemVersion buildSDK(VersionTarget target = ApplicationBinary);
485 static QOperatingSystemVersion deploymentTarget(VersionTarget target = ApplicationBinary);
486 static QOperatingSystemVersion currentRuntime();
489 QMacVersion() =
default;
490 using VersionTuple = std::pair<QOperatingSystemVersion, QOperatingSystemVersion>;
491 static VersionTuple versionsForImage(
const mach_header *machHeader);
492 static VersionTuple applicationVersion();
493 static VersionTuple libraryVersion();
500typename std::enable_if<std::is_pointer<T>::value, T>::type
501qt_objc_cast(id object)
503 if ([object isKindOfClass:[
typename std::remove_pointer<T>::type
class]])
504 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)