MacOS lock/unlock added

This commit is contained in:
Paulchen-Panther
2023-11-14 16:12:21 +01:00
parent 114282ff70
commit a238ebffc0
14 changed files with 107 additions and 33 deletions

View File

@@ -22,7 +22,7 @@
#include <grabber/QtGrabber.h>
#include <utils/WeakConnect.h>
#include <events/Event.h>
#include <events/EventEnum.h>
#if defined(ENABLE_MF)
#include <grabber/MFGrabber.h>

View File

@@ -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

View File

@@ -3,8 +3,6 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <events/Event.h>
#include <utils/Logger.h>
#include <utils/Process.h>
#include <hyperion/HyperionIManager.h>

View File

@@ -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