diff --git a/sources/base/schema/schema-general.json b/sources/base/schema/schema-general.json index c13a9125c..1c30fc9e0 100644 --- a/sources/base/schema/schema-general.json +++ b/sources/base/schema/schema-general.json @@ -32,6 +32,15 @@ "hidden":true }, "propertyOrder" : 4 + }, + "disableOnLocked" : + { + "type" : "boolean", + "format": "checkbox", + "title" : "edt_conf_gen_disableOnLocked_title", + "default" : false, + "required" : true, + "propertyOrder" : 5 } }, diff --git a/sources/hyperhdr/HyperHdrDaemon.cpp b/sources/hyperhdr/HyperHdrDaemon.cpp index 08a38ff29..a8fa1eeec 100644 --- a/sources/hyperhdr/HyperHdrDaemon.cpp +++ b/sources/hyperhdr/HyperHdrDaemon.cpp @@ -177,7 +177,11 @@ HyperHdrDaemon::HyperHdrDaemon(const QString& rootPath, QApplication* parent, bo // power management #if defined(HAVE_POWER_MANAGEMENT) - _suspendHandler = std::unique_ptr(new SuspendHandler()); + auto genSet = getSetting(settings::type::GENERAL); + const QJsonObject& genConfig = genSet.object(); + bool lockedEnable = genConfig["disableOnLocked"].toBool(false); + + _suspendHandler = std::unique_ptr(new SuspendHandler(lockedEnable)); connect(_suspendHandler.get(), &SuspendHandler::SignalHibernate, _instanceManager.get(), &HyperHdrManager::hibernate); #ifdef _WIN32 diff --git a/sources/hyperhdr/SuspendHandlerLinux.cpp b/sources/hyperhdr/SuspendHandlerLinux.cpp index 46b45a96d..9692edda4 100644 --- a/sources/hyperhdr/SuspendHandlerLinux.cpp +++ b/sources/hyperhdr/SuspendHandlerLinux.cpp @@ -46,7 +46,7 @@ namespace { const QString UPOWER_INTER = QStringLiteral("org.freedesktop.login1.Manager"); } -SuspendHandler::SuspendHandler() +SuspendHandler::SuspendHandler(bool sessionLocker) { QDBusConnection bus = QDBusConnection::systemBus(); diff --git a/sources/hyperhdr/SuspendHandlerLinux.h b/sources/hyperhdr/SuspendHandlerLinux.h index 9f76d6f10..fb46b61b8 100644 --- a/sources/hyperhdr/SuspendHandlerLinux.h +++ b/sources/hyperhdr/SuspendHandlerLinux.h @@ -37,7 +37,7 @@ class SuspendHandler : public QObject { void SignalHibernate(bool wakeUp); public: - SuspendHandler(); + SuspendHandler(bool sessionLocker = false); ~SuspendHandler(); public slots: diff --git a/sources/hyperhdr/SuspendHandlerMacOS.h b/sources/hyperhdr/SuspendHandlerMacOS.h index aca0904ed..182ec5263 100644 --- a/sources/hyperhdr/SuspendHandlerMacOS.h +++ b/sources/hyperhdr/SuspendHandlerMacOS.h @@ -37,6 +37,6 @@ class SuspendHandler : public QObject { void SignalHibernate(bool wakeUp); public: - SuspendHandler(); + SuspendHandler(bool sessionLocker = false); ~SuspendHandler(); }; diff --git a/sources/hyperhdr/SuspendHandlerMacOS.mm b/sources/hyperhdr/SuspendHandlerMacOS.mm index 018410c2f..ab7770d39 100644 --- a/sources/hyperhdr/SuspendHandlerMacOS.mm +++ b/sources/hyperhdr/SuspendHandlerMacOS.mm @@ -89,7 +89,7 @@ - (void)goingWake: (NSNotification*)note @end -SuspendHandler::SuspendHandler() +SuspendHandler::SuspendHandler(bool sessionLocker) { _macSuspendHandlerInstance = [MacSuspendHandler new]; _suspendHandler = this; diff --git a/sources/hyperhdr/SuspendHandlerWindows.cpp b/sources/hyperhdr/SuspendHandlerWindows.cpp index 9e910b05b..baed1d029 100644 --- a/sources/hyperhdr/SuspendHandlerWindows.cpp +++ b/sources/hyperhdr/SuspendHandlerWindows.cpp @@ -37,8 +37,11 @@ #include #include #include +#include -SuspendHandler::SuspendHandler() +#pragma comment (lib, "WtsApi32.Lib") + +SuspendHandler::SuspendHandler(bool sessionLocker) { auto handle = reinterpret_cast (_widget.winId()); _notifyHandle = RegisterSuspendResumeNotification(handle, DEVICE_NOTIFY_WINDOW_HANDLE); @@ -46,7 +49,19 @@ SuspendHandler::SuspendHandler() if (_notifyHandle == NULL) std::cout << "COULD NOT REGISTER SLEEP HANDLER!" << std::endl; else - std::cout << "SLEEP HANDLER REGISTERED!" << std::endl; + std::cout << "Sleep handler registered!" << std::endl; + + _sessionLocker = sessionLocker; + if (_sessionLocker) + { + if (WTSRegisterSessionNotification(handle, NOTIFY_FOR_THIS_SESSION)) + std::cout << "Session handler registered!" << std::endl; + else + { + std::cout << "COULD NOT REGISTER SESSION HANDLER!" << std::endl; + _sessionLocker = false; + } + } } SuspendHandler::~SuspendHandler() @@ -54,9 +69,15 @@ SuspendHandler::~SuspendHandler() if (_notifyHandle != NULL) { UnregisterSuspendResumeNotification(_notifyHandle); - std::cout << "SLEEP HANDLER DEREGISTERED!" << std::endl; + std::cout << "Sleep handler deregistered!" << std::endl; } _notifyHandle = NULL; + + if (_sessionLocker) + { + auto handle = reinterpret_cast (_widget.winId()); + WTSUnRegisterSessionNotification(handle); + } } #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) @@ -81,6 +102,34 @@ bool SuspendHandler::nativeEventFilter(const QByteArray& eventType, void* messag break; } } + + if (_sessionLocker) + { + if (msg->message == WM_WTSSESSION_CHANGE) + { + switch (msg->wParam) + { + case WTS_SESSION_UNLOCK: + emit SignalHibernate(true); + return true; + break; + + case WTS_SESSION_LOCK: + + if (GetSystemMetrics(SM_REMOTESESSION) != 0) + { + std::cout << "Detected RDP session. Skipping disable on lock." << std::endl; + } + else + { + emit SignalHibernate(false); + return true; + } + break; + } + } + } + return false; } diff --git a/sources/hyperhdr/SuspendHandlerWindows.h b/sources/hyperhdr/SuspendHandlerWindows.h index 0b7903d01..979aa8dd0 100644 --- a/sources/hyperhdr/SuspendHandlerWindows.h +++ b/sources/hyperhdr/SuspendHandlerWindows.h @@ -40,12 +40,13 @@ class SuspendHandler : public QObject, public QAbstractNativeEventFilter { QWidget _widget; HPOWERNOTIFY _notifyHandle; + bool _sessionLocker; signals: void SignalHibernate(bool wakeUp); public: - SuspendHandler(); + SuspendHandler(bool sessionLocker = false); ~SuspendHandler(); #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) Q_DECL_OVERRIDE; diff --git a/www/i18n/en.json b/www/i18n/en.json index a32b093a6..c60d86433 100644 --- a/www/i18n/en.json +++ b/www/i18n/en.json @@ -1237,5 +1237,7 @@ "edt_conf_hardware_expl" : "Enable hardware acceleration, for example: pixel and vertex shaders on Windows", "edt_conf_monitor_nits_title" : "HDR brightness correction", "edt_conf_monitor_nits_expl" : "SDR target brightness used for HDR to SDR conversion. If 0, it disables hardware color conversion while maintaining accelerated scaling.", - "edt_append_nits" : "nits" -} + "edt_append_nits" : "nits", + "edt_conf_gen_disableOnLocked_title" : "Disable when locked", + "edt_conf_gen_disableOnLocked_expl" : "Turn off processing when the user has locked the system" +} diff --git a/www/js/general.js b/www/js/general.js index 930635ccd..67a9abea3 100644 --- a/www/js/general.js +++ b/www/js/general.js @@ -235,5 +235,15 @@ $(document).ready(function() createHint("intro", $.i18n('conf_general_inst_desc'), "inst_desc_cont"); } + if (window.serverInfo.grabbers != null && window.serverInfo.grabbers != undefined && + window.serverInfo.grabbers.active != null && window.serverInfo.grabbers.active != undefined) + { + var grabbers = window.serverInfo.grabbers.active; + if (grabbers.indexOf('Media Foundation') < 0) + { + conf_editor.getEditor('root.general.disableOnLocked').disable(); + } + } + removeOverlay(); });