Skip to content

Commit 9a406ce

Browse files
committed
Disable on user lock screen (Windows)
1 parent 83c1f62 commit 9a406ce

10 files changed

+86
-11
lines changed

Diff for: sources/base/schema/schema-general.json

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232
"hidden":true
3333
},
3434
"propertyOrder" : 4
35+
},
36+
"disableOnLocked" :
37+
{
38+
"type" : "boolean",
39+
"format": "checkbox",
40+
"title" : "edt_conf_gen_disableOnLocked_title",
41+
"default" : false,
42+
"required" : true,
43+
"propertyOrder" : 5
3544
}
3645

3746
},

Diff for: sources/hyperhdr/HyperHdrDaemon.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ HyperHdrDaemon::HyperHdrDaemon(const QString& rootPath, QApplication* parent, bo
177177

178178
// power management
179179
#if defined(HAVE_POWER_MANAGEMENT)
180-
_suspendHandler = std::unique_ptr<SuspendHandler>(new SuspendHandler());
180+
auto genSet = getSetting(settings::type::GENERAL);
181+
const QJsonObject& genConfig = genSet.object();
182+
bool lockedEnable = genConfig["disableOnLocked"].toBool(false);
183+
184+
_suspendHandler = std::unique_ptr<SuspendHandler>(new SuspendHandler(lockedEnable));
181185
connect(_suspendHandler.get(), &SuspendHandler::SignalHibernate, _instanceManager.get(), &HyperHdrManager::hibernate);
182186

183187
#ifdef _WIN32

Diff for: sources/hyperhdr/SuspendHandlerLinux.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace {
4646
const QString UPOWER_INTER = QStringLiteral("org.freedesktop.login1.Manager");
4747
}
4848

49-
SuspendHandler::SuspendHandler()
49+
SuspendHandler::SuspendHandler(bool sessionLocker)
5050
{
5151
QDBusConnection bus = QDBusConnection::systemBus();
5252

Diff for: sources/hyperhdr/SuspendHandlerLinux.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SuspendHandler : public QObject {
3737
void SignalHibernate(bool wakeUp);
3838

3939
public:
40-
SuspendHandler();
40+
SuspendHandler(bool sessionLocker = false);
4141
~SuspendHandler();
4242

4343
public slots:

Diff for: sources/hyperhdr/SuspendHandlerMacOS.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ class SuspendHandler : public QObject {
3737
void SignalHibernate(bool wakeUp);
3838

3939
public:
40-
SuspendHandler();
40+
SuspendHandler(bool sessionLocker = false);
4141
~SuspendHandler();
4242
};

Diff for: sources/hyperhdr/SuspendHandlerMacOS.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ - (void)goingWake: (NSNotification*)note
8989

9090
@end
9191

92-
SuspendHandler::SuspendHandler()
92+
SuspendHandler::SuspendHandler(bool sessionLocker)
9393
{
9494
_macSuspendHandlerInstance = [MacSuspendHandler new];
9595
_suspendHandler = this;

Diff for: sources/hyperhdr/SuspendHandlerWindows.cpp

+52-3
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,47 @@
3737
#include <utils/Image.h>
3838
#include <base/HyperHdrManager.h>
3939
#include <windows.h>
40+
#include <wtsapi32.h>
4041

41-
SuspendHandler::SuspendHandler()
42+
#pragma comment (lib, "WtsApi32.Lib")
43+
44+
SuspendHandler::SuspendHandler(bool sessionLocker)
4245
{
4346
auto handle = reinterpret_cast<HWND> (_widget.winId());
4447
_notifyHandle = RegisterSuspendResumeNotification(handle, DEVICE_NOTIFY_WINDOW_HANDLE);
4548

4649
if (_notifyHandle == NULL)
4750
std::cout << "COULD NOT REGISTER SLEEP HANDLER!" << std::endl;
4851
else
49-
std::cout << "SLEEP HANDLER REGISTERED!" << std::endl;
52+
std::cout << "Sleep handler registered!" << std::endl;
53+
54+
_sessionLocker = sessionLocker;
55+
if (_sessionLocker)
56+
{
57+
if (WTSRegisterSessionNotification(handle, NOTIFY_FOR_THIS_SESSION))
58+
std::cout << "Session handler registered!" << std::endl;
59+
else
60+
{
61+
std::cout << "COULD NOT REGISTER SESSION HANDLER!" << std::endl;
62+
_sessionLocker = false;
63+
}
64+
}
5065
}
5166

5267
SuspendHandler::~SuspendHandler()
5368
{
5469
if (_notifyHandle != NULL)
5570
{
5671
UnregisterSuspendResumeNotification(_notifyHandle);
57-
std::cout << "SLEEP HANDLER DEREGISTERED!" << std::endl;
72+
std::cout << "Sleep handler deregistered!" << std::endl;
5873
}
5974
_notifyHandle = NULL;
75+
76+
if (_sessionLocker)
77+
{
78+
auto handle = reinterpret_cast<HWND> (_widget.winId());
79+
WTSUnRegisterSessionNotification(handle);
80+
}
6081
}
6182

6283
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
@@ -81,6 +102,34 @@ bool SuspendHandler::nativeEventFilter(const QByteArray& eventType, void* messag
81102
break;
82103
}
83104
}
105+
106+
if (_sessionLocker)
107+
{
108+
if (msg->message == WM_WTSSESSION_CHANGE)
109+
{
110+
switch (msg->wParam)
111+
{
112+
case WTS_SESSION_UNLOCK:
113+
emit SignalHibernate(true);
114+
return true;
115+
break;
116+
117+
case WTS_SESSION_LOCK:
118+
119+
if (GetSystemMetrics(SM_REMOTESESSION) != 0)
120+
{
121+
std::cout << "Detected RDP session. Skipping disable on lock." << std::endl;
122+
}
123+
else
124+
{
125+
emit SignalHibernate(false);
126+
return true;
127+
}
128+
break;
129+
}
130+
}
131+
}
132+
84133
return false;
85134
}
86135

Diff for: sources/hyperhdr/SuspendHandlerWindows.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ class SuspendHandler : public QObject, public QAbstractNativeEventFilter {
4040

4141
QWidget _widget;
4242
HPOWERNOTIFY _notifyHandle;
43+
bool _sessionLocker;
4344

4445
signals:
4546
void SignalHibernate(bool wakeUp);
4647

4748
public:
48-
SuspendHandler();
49+
SuspendHandler(bool sessionLocker = false);
4950
~SuspendHandler();
5051
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
5152
virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) Q_DECL_OVERRIDE;

Diff for: www/i18n/en.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1237,5 +1237,7 @@
12371237
"edt_conf_hardware_expl" : "Enable hardware acceleration, for example: pixel and vertex shaders on Windows",
12381238
"edt_conf_monitor_nits_title" : "HDR brightness correction",
12391239
"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.",
1240-
"edt_append_nits" : "nits"
1241-
}
1240+
"edt_append_nits" : "nits",
1241+
"edt_conf_gen_disableOnLocked_title" : "Disable when locked",
1242+
"edt_conf_gen_disableOnLocked_expl" : "Turn off processing when the user has locked the system"
1243+
}

Diff for: www/js/general.js

+10
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,15 @@ $(document).ready(function()
235235
createHint("intro", $.i18n('conf_general_inst_desc'), "inst_desc_cont");
236236
}
237237

238+
if (window.serverInfo.grabbers != null && window.serverInfo.grabbers != undefined &&
239+
window.serverInfo.grabbers.active != null && window.serverInfo.grabbers.active != undefined)
240+
{
241+
var grabbers = window.serverInfo.grabbers.active;
242+
if (grabbers.indexOf('Media Foundation') < 0)
243+
{
244+
conf_editor.getEditor('root.general.disableOnLocked').disable();
245+
}
246+
}
247+
238248
removeOverlay();
239249
});

0 commit comments

Comments
 (0)