]> Some of my projects - aniplayer.git/commitdiff
Quick hack to disable screensaver during playback
authorAPTX <marek321@gmail.com>
Sun, 26 Mar 2017 14:06:13 +0000 (16:06 +0200)
committerAPTX <marek321@gmail.com>
Sun, 26 Mar 2017 14:06:13 +0000 (16:06 +0200)
Works on windows only, is located in Player. Should
be moved to instance manager to correctly account for
multiple instances.

core/player.cpp

index 6aa70854d86bc988053c6c8e9693c2df34b4b312..8ff8a1c4e0617fe31a49995588dc8e4671400e81 100644 (file)
@@ -3,6 +3,10 @@
 #include <QLoggingCategory>
 #include <QQmlApplicationEngine>
 
+#ifdef Q_OS_WIN
+#include <Windows.h>
+#endif
+
 Q_LOGGING_CATEGORY(playerCategory, "Player")
 
 Player::Player(BackendPluginBase *backendPlugin, QObject *parent)
@@ -36,7 +40,12 @@ Player::Player(BackendPluginBase *backendPlugin, QObject *parent)
   Q_CHECK_PTR(m_chapterModel);
 }
 
-Player::~Player() { qCDebug(playerCategory) << "Destroying player" << this; }
+Player::~Player() {
+  qCDebug(playerCategory) << "Destroying player" << this;
+#ifdef Q_OS_WIN
+  SetThreadExecutionState(ES_CONTINUOUS);
+#endif
+}
 
 BackendInstance *Player::backend() const { return m_backend; }
 
@@ -199,11 +208,18 @@ void Player::rendererReady() {
 
 void Player::playStateChanged(PlayerPluginInterface::PlayState state) {
   auto s = static_cast<PlayState>(state);
-  // if (currentSource().isEmpty()) s = PlayState::Stopped;
   if (m_state == s)
     return;
   m_state = s;
   qCDebug(playerCategory) << "Play state changed to" << s;
+
+#ifdef Q_OS_WIN
+  if (m_state == PlayState::Playing)
+    SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
+  else
+    SetThreadExecutionState(ES_CONTINUOUS);
+#endif
+
   emit stateChanged(s);
 }