Browse Source

Add a simpler screensaver API for web-client

Give web-client complete control over the screensaver state. Add a
setScreensaverEnabled() API, which simply enables/disables the OS
screensaver directly.

Remove all the other code. This requires web-client to manage the
screensaver state itself, including responsibilities as checking
fullscreen state or acting upon fullscreen changes.

The old API, the screenSaverEnabled/screenSaverDisabled are still left
in and do nothing. They're here to avoid that older web-client versions
crash at initialization.
Vincent Lang 8 năm trước cách đây
mục cha
commit
73f70f6381
3 tập tin đã thay đổi với 12 bổ sung67 xóa
  1. 9 46
      src/power/PowerComponent.cpp
  2. 3 15
      src/power/PowerComponent.h
  3. 0 6
      src/ui/KonvergoWindow.cpp

+ 9 - 46
src/power/PowerComponent.cpp

@@ -3,7 +3,6 @@
 //
 
 #include "PowerComponent.h"
-#include "player/PlayerComponent.h"
 #include "input/InputComponent.h"
 #include "settings/SettingsComponent.h"
 
@@ -43,58 +42,22 @@ PowerComponent& PowerComponent::Get()
 /////////////////////////////////////////////////////////////////////////////////////////
 bool PowerComponent::componentInitialize()
 {
-  PlayerComponent* player = &PlayerComponent::Get();
-
-  connect(player, &PlayerComponent::videoPlaybackActive, this, &PowerComponent::videoPlaybackActive);
-
   return true;
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
-void PowerComponent::setFullscreenState(bool fullscreen)
-{
-  m_fullscreenState = fullscreen;
-  redecideScreeensaverState();
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-void PowerComponent::redecideScreeensaverState()
+void PowerComponent::setScreensaverEnabled(bool enabled)
 {
-  bool enableOsScreensaver = !m_videoPlaying;
-
-  // by default we don't allow the fullscreen state affect sleep state, but we want to
-  // have a hidden option to allow system sleep and screensaver when in fullscreen.
-  //
-  bool preventSystemScreensaver = SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "preventSystemScreensaver").toBool();
-#ifdef KONVERGO_OPENELEC
-  preventSystemScreensaver = true;
-#endif
-  if (preventSystemScreensaver)
-    enableOsScreensaver &= !m_fullscreenState;
-
-  if (m_currentScreensaverEnabled != enableOsScreensaver)
+  if (enabled)
   {
-    m_currentScreensaverEnabled = enableOsScreensaver;
-    if (enableOsScreensaver)
-    {
-      QLOG_DEBUG() << "Enabling OS screensaver";
-      doEnableScreensaver();
-      emit screenSaverEnabled();
-    }
-    else
-    {
-      QLOG_DEBUG() << "Disabling OS screensaver";
-      doDisableScreensaver();
-      emit screenSaverDisabled();
-    }
+    QLOG_DEBUG() << "Enabling OS screensaver";
+    doEnableScreensaver();
+  }
+  else
+  {
+    QLOG_DEBUG() << "Disabling OS screensaver";
+    doDisableScreensaver();
   }
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-void PowerComponent::videoPlaybackActive(bool active)
-{
-  m_videoPlaying = active;
-  redecideScreeensaverState();
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////

+ 3 - 15
src/power/PowerComponent.h

@@ -20,10 +20,7 @@ public:
   static PowerComponent& Get();
 
   explicit PowerComponent(QObject* parent = nullptr)
-  : ComponentBase(parent),
-    m_currentScreensaverEnabled(true),
-    m_fullscreenState(false),
-    m_videoPlaying(false)
+  : ComponentBase(parent)
     { }
 
   bool componentInitialize() override;
@@ -31,8 +28,6 @@ public:
   const char* componentName() override { return "power"; }
   void componentPostInitialize() override;
 
-  void setFullscreenState(bool fullscreen);
-
 public Q_SLOTS:
   bool checkCap(PowerCapabilities capability);
 
@@ -47,23 +42,16 @@ public Q_SLOTS:
   virtual bool Reboot() { return false; }
   virtual bool Suspend() { return false; }
 
-private Q_SLOTS:
-  void videoPlaybackActive(bool active);
+  void setScreensaverEnabled(bool enabled);
 
 Q_SIGNALS:
+  // Short-term compatibility with old web-client. Does nothing.
   void screenSaverEnabled();
   void screenSaverDisabled();
 
 protected:
   virtual void doDisableScreensaver() {};
   virtual void doEnableScreensaver() {};
-
-private:
-  void redecideScreeensaverState();
-
-  bool m_currentScreensaverEnabled;
-  bool m_fullscreenState;
-  bool m_videoPlaying;
 };
 
 

+ 0 - 6
src/ui/KonvergoWindow.cpp

@@ -13,7 +13,6 @@
 #include "player/PlayerQuickItem.h"
 #include "display/DisplayComponent.h"
 #include "QsLog.h"
-#include "power/PowerComponent.h"
 #include "utils/Utils.h"
 #include "Globals.h"
 #include "EventFilter.h"
@@ -303,11 +302,6 @@ void KonvergoWindow::onVisibilityChanged(QWindow::Visibility visibility)
     SettingsComponent::Get().setValue(SETTINGS_SECTION_MAIN, "fullscreen", fs);
   }
 
-  if (visibility == QWindow::FullScreen)
-    PowerComponent::Get().setFullscreenState(true);
-  else if (visibility == QWindow::Windowed)
-    PowerComponent::Get().setFullscreenState(false);
-
   notifyScale(size());
 }