mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
MacOS lock/unlock added
This commit is contained in:
@@ -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>
|
||||
|
@@ -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
|
||||
|
@@ -3,8 +3,6 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <events/Event.h>
|
||||
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/Process.h>
|
||||
#include <hyperion/HyperionIManager.h>
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user