MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / inhibitIdleSleep

Function inhibitIdleSleep

app/src/Platform/AppPlatform.cpp:477–510  ·  view source on GitHub ↗

* @brief Keeps the system and display awake for the process lifetime so long recording * sessions survive an untouched laptop; the OS releases every inhibition on exit. * Call after QApplication exists (the Linux path needs the session D-Bus). * No-op when "App/InhibitIdleSleep" (Misc::ModuleManager) is disabled. */

Source from the content-addressed store, hash-verified

475 * No-op when "App/InhibitIdleSleep" (Misc::ModuleManager) is disabled.
476 */
477void inhibitIdleSleep()
478{
479 if (!QSettings().value("App/InhibitIdleSleep", true).toBool())
480 return;
481
482#if defined(Q_OS_WIN)
483 (void)SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
484#elif defined(Q_OS_MACOS)
485 static IOPMAssertionID assertion = kIOPMNullAssertionID;
486 if (assertion == kIOPMNullAssertionID)
487 (void)IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
488 kIOPMAssertionLevelOn,
489 CFSTR("Serial Studio data acquisition session"),
490 &assertion);
491#elif defined(Q_OS_LINUX)
492 if (!QDBusConnection::sessionBus().isConnected())
493 return;
494
495 const auto app = QStringLiteral("Serial Studio");
496 const auto reason = QStringLiteral("Data acquisition session in progress");
497
498 QDBusInterface screenSaver(QStringLiteral("org.freedesktop.ScreenSaver"),
499 QStringLiteral("/org/freedesktop/ScreenSaver"),
500 QStringLiteral("org.freedesktop.ScreenSaver"));
501 if (screenSaver.isValid())
502 (void)screenSaver.call(QStringLiteral("Inhibit"), app, reason);
503
504 QDBusInterface powerManagement(QStringLiteral("org.freedesktop.PowerManagement"),
505 QStringLiteral("/org/freedesktop/PowerManagement/Inhibit"),
506 QStringLiteral("org.freedesktop.PowerManagement.Inhibit"));
507 if (powerManagement.isValid())
508 (void)powerManagement.call(QStringLiteral("Inhibit"), app, reason);
509#endif
510}
511
512/**
513 * @brief Registers .ssproj with this executable in the Windows registry (HKCU).

Callers 1

mainFunction · 0.85

Calls 5

QSettingsClass · 0.85
valueMethod · 0.45
isConnectedMethod · 0.45
isValidMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected