diff --git a/dependencies/external/mbedtls b/dependencies/external/mbedtls index 1873d3bfc..edb8fec98 160000 --- a/dependencies/external/mbedtls +++ b/dependencies/external/mbedtls @@ -1 +1 @@ -Subproject commit 1873d3bfc2da771672bd8e7e8f41f57e0af77f33 +Subproject commit edb8fec9882084344a314368ac7fd957a187519c diff --git a/include/api/JsonAPI.h b/include/api/JsonAPI.h index 04d432701..8e36b1580 100644 --- a/include/api/JsonAPI.h +++ b/include/api/JsonAPI.h @@ -2,7 +2,7 @@ // parent class #include -#include +#include // hyperion includes #include diff --git a/include/cec/CECHandler.h b/include/cec/CECHandler.h index 6f2b7c5de..3d118a884 100644 --- a/include/cec/CECHandler.h +++ b/include/cec/CECHandler.h @@ -9,7 +9,7 @@ #include #include -#include +#include using CECCallbacks = CEC::ICECCallbacks; using CECAdapter = CEC::ICECAdapter; diff --git a/include/events/Event.h b/include/events/EventEnum.h similarity index 95% rename from include/events/Event.h rename to include/events/EventEnum.h index 9a0ea39bb..54f9c2c87 100644 --- a/include/events/Event.h +++ b/include/events/EventEnum.h @@ -1,5 +1,5 @@ -#ifndef EVENT_H -#define EVENT_H +#ifndef EVENTENUM_H +#define EVENTENUM_H #include @@ -47,4 +47,4 @@ inline Event stringToEvent(const QString& event) } -#endif // EVENT_H +#endif // EVENTENUM_H diff --git a/include/events/EventHandler.h b/include/events/EventHandler.h index 3ad644203..794b08a73 100644 --- a/include/events/EventHandler.h +++ b/include/events/EventHandler.h @@ -2,24 +2,23 @@ #define EVENTHANDLER_H #include -#include +#include #include class Logger; -class EventHandler : public QObject { +class EventHandler : public QObject +{ Q_OBJECT public: - EventHandler(); ~EventHandler() override; static EventHandler* getInstance(); public slots: - virtual void handleSettingsUpdate(settings::type type, const QJsonDocument& config); void suspend(bool sleep); @@ -36,15 +35,12 @@ public slots: void handleEvent(Event event); signals: - void signalEvent(Event event); protected: - Logger * _log {}; private: - bool _isSuspended; bool _isIdle; }; diff --git a/include/events/OsEventHandler.h b/include/events/OsEventHandler.h index f3cd590b2..3ca05c799 100644 --- a/include/events/OsEventHandler.h +++ b/include/events/OsEventHandler.h @@ -3,7 +3,7 @@ #include #include -#include +#include #if defined(_WIN32) #include @@ -16,7 +16,8 @@ class Logger; -class OsEventHandlerBase : public QObject { +class OsEventHandlerBase : public QObject +{ Q_OBJECT public: @@ -24,18 +25,15 @@ class OsEventHandlerBase : public QObject { ~OsEventHandlerBase() override; public slots: - void suspend(bool sleep); void lock(bool isLocked); virtual void handleSettingsUpdate(settings::type type, const QJsonDocument& config); signals: - void signalEvent(Event event); protected: - virtual bool registerOsEventHandler() { return true; } virtual void unregisterOsEventHandler() {} virtual bool registerLockHandler() { return true; } @@ -49,14 +47,12 @@ public slots: bool _isLockRegistered; Logger * _log {}; - -private: - }; #if defined(_WIN32) -class OsEventHandlerWindows : public OsEventHandlerBase, public QAbstractNativeEventFilter { +class OsEventHandlerWindows : public OsEventHandlerBase, public QAbstractNativeEventFilter +{ public: OsEventHandlerWindows(); @@ -70,7 +66,6 @@ class OsEventHandlerWindows : public OsEventHandlerBase, public QAbstractNativeE #endif private: - bool registerOsEventHandler() override; void unregisterOsEventHandler() override; bool registerLockHandler() override; @@ -83,7 +78,8 @@ class OsEventHandlerWindows : public OsEventHandlerBase, public QAbstractNativeE using OsEventHandler = OsEventHandlerWindows; #elif defined(__linux__) -class OsEventHandlerLinux : public OsEventHandlerBase { +class OsEventHandlerLinux : public OsEventHandlerBase +{ Q_OBJECT static void static_signaleHandler(int signum) @@ -109,6 +105,33 @@ class OsEventHandlerLinux : public OsEventHandlerBase { using OsEventHandler = OsEventHandlerLinux; +#elif defined(__APPLE__) +#include + +class OsEventHandlerMacOS : public OsEventHandlerBase +{ + Q_OBJECT + + static void notificationCenterCallBack(CFNotificationCenterRef center, void* observer, CFStringRef name, const void* object, CFDictionaryRef userInfo) + { + OsEventHandlerMacOS::getInstance()->handleSignal(name); + } + +public: + void handleSignal (CFStringRef lock_unlock); + +private: + static OsEventHandlerMacOS* getInstance(); + + CFStringRef lockSignal = CFSTR("com.apple.screenIsLocked"); + CFStringRef unlockSignal = CFSTR("com.apple.screenIsUnlocked"); + bool registerLockHandler() override; + void unregisterLockHandler() override; + +}; + +using OsEventHandler = OsEventHandlerMacOS; + #else using OsEventHandler = OsEventHandlerBase; #endif diff --git a/include/grabber/V4L2Grabber.h b/include/grabber/V4L2Grabber.h index b4e044f16..4d4c2cb7c 100644 --- a/include/grabber/V4L2Grabber.h +++ b/include/grabber/V4L2Grabber.h @@ -24,7 +24,7 @@ // Determine the cmake options #include -#include +#include /// /// Capture class for V4L2 devices diff --git a/include/hyperion/Grabber.h b/include/hyperion/Grabber.h index e3f12604e..3408e3b8b 100644 --- a/include/hyperion/Grabber.h +++ b/include/hyperion/Grabber.h @@ -11,7 +11,7 @@ #include #include -#include +#include /// /// @brief The Grabber class is responsible to apply image resizes (with or without ImageResampler) diff --git a/include/hyperion/GrabberWrapper.h b/include/hyperion/GrabberWrapper.h index 742c70717..5254c011b 100644 --- a/include/hyperion/GrabberWrapper.h +++ b/include/hyperion/GrabberWrapper.h @@ -18,7 +18,7 @@ #include -#include +#include class Grabber; class GlobalSignals; diff --git a/include/hyperion/HyperionIManager.h b/include/hyperion/HyperionIManager.h index 5b628dc86..03e716903 100644 --- a/include/hyperion/HyperionIManager.h +++ b/include/hyperion/HyperionIManager.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include // qt #include diff --git a/libsrc/api/JsonAPI.cpp b/libsrc/api/JsonAPI.cpp index 9b7872622..65eff139e 100644 --- a/libsrc/api/JsonAPI.cpp +++ b/libsrc/api/JsonAPI.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #if defined(ENABLE_MF) #include diff --git a/libsrc/events/CMakeLists.txt b/libsrc/events/CMakeLists.txt index 9d239db4b..a0d41ae6d 100644 --- a/libsrc/events/CMakeLists.txt +++ b/libsrc/events/CMakeLists.txt @@ -3,7 +3,7 @@ SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/events) SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/events) add_library(events - ${CURRENT_HEADER_DIR}/Event.h + ${CURRENT_HEADER_DIR}/EventEnum.h ${CURRENT_HEADER_DIR}/EventHandler.h ${CURRENT_SOURCE_DIR}/EventHandler.cpp ${CURRENT_HEADER_DIR}/OsEventHandler.h diff --git a/libsrc/events/EventHandler.cpp b/libsrc/events/EventHandler.cpp index e2181c885..5b4bf7ecb 100644 --- a/libsrc/events/EventHandler.cpp +++ b/libsrc/events/EventHandler.cpp @@ -3,8 +3,6 @@ #include #include -#include - #include #include #include diff --git a/libsrc/events/OsEventHandler.cpp b/libsrc/events/OsEventHandler.cpp index c4771439f..c7ea05647 100644 --- a/libsrc/events/OsEventHandler.cpp +++ b/libsrc/events/OsEventHandler.cpp @@ -445,4 +445,61 @@ void OsEventHandlerLinux::unregisterLockHandler() } #endif // HYPERION_HAS_DBUS -#endif // __linux__ +#elif defined(__APPLE__) + +OsEventHandlerMacOS* OsEventHandlerMacOS::getInstance() +{ + static OsEventHandlerMacOS instance; + return &instance; +} + +void OsEventHandlerMacOS::handleSignal (CFStringRef lock_unlock) +{ + if (CFEqual(lock_unlock, CFSTR("com.apple.screenIsLocked"))) + { + lock(true); + } + else if (CFEqual(lock_unlock, CFSTR("com.apple.screenIsUnlocked"))) + { + lock(false); + } +} + +bool OsEventHandlerMacOS::registerLockHandler() +{ + bool isRegistered{ _isLockRegistered }; + if (!_isLockRegistered) + { + CFNotificationCenterRef distCenter; + + distCenter = CFNotificationCenterGetDistributedCenter(); + if (distCenter != nullptr) + { + CFNotificationCenterAddObserver(distCenter, this, &OsEventHandlerMacOS::notificationCenterCallBack, lockSignal, nullptr, CFNotificationSuspensionBehaviorDeliverImmediately); + CFNotificationCenterAddObserver(distCenter, this, &OsEventHandlerMacOS::notificationCenterCallBack, unlockSignal, nullptr, CFNotificationSuspensionBehaviorDeliverImmediately); + isRegistered = true; + } + else + { + Error(_log, "Could not register for lock/unlock events!"); + } + + } + + if (isRegistered) + { + _isLockRegistered = true; + } + return isRegistered; +} + +void OsEventHandlerMacOS::unregisterLockHandler() +{ + if (_isLockRegistered) + { + CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDistributedCenter(), this); + _isLockRegistered = false; + } +} + +#endif