Browse Source

WIP switch to fullscreen when switching mode

Tobias Hieta 8 years ago
parent
commit
8c5ab9f7ca

+ 9 - 3
src/main.cpp

@@ -81,7 +81,7 @@ void ShowLicenseInfo()
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
-QStringList g_qtFlags = {"--enable-viewport", "--enable-viewport-meta", "--disable-gpu", "--disable-web-security"};
+QStringList g_qtFlags = {"--enable-viewport", "--disable-gpu", "--disable-web-security"};
 
 /////////////////////////////////////////////////////////////////////////////////////////
 int main(int argc, char *argv[])
@@ -92,8 +92,12 @@ int main(int argc, char *argv[])
     parser.setApplicationDescription("Plex Media Player");
     parser.addHelpOption();
     parser.addVersionOption();
-    parser.addOptions({{{"l", "licenses"}, "Show license information"}});
-    parser.addOptions({{{"a", "from-auto-update"}, "When invoked from auto-update"}});
+    parser.addOptions({{{"l", "licenses"},         "Show license information"},
+                       {{"a", "from-auto-update"}, "When invoked from auto-update"},
+                       {"desktop",                 "Start in desktop mode"},
+                       {"tv",                      "Start in TV mode"},
+                       {"windowed",                "Start in windowed mode"},
+                       {"fullscreen",              "Start in fullscreen"}});
 
     char **newArgv = appendCommandLineArguments(argc, argv, g_qtFlags);
     argc += g_qtFlags.size();
@@ -170,6 +174,8 @@ int main(int argc, char *argv[])
     //
     ComponentManager::Get().initialize();
 
+    SettingsComponent::Get().setCommandLineValues(parser.optionNames());
+
     // enable remote inspection if we have the correct setting for it.
     if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool())
       qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992");

+ 17 - 0
src/settings/SettingsComponent.cpp

@@ -740,3 +740,20 @@ QString SettingsComponent::getWebClientUrl()
   return url;
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////
+void SettingsComponent::setCommandLineValues(const QStringList& values)
+{
+  QLOG_DEBUG() << values;
+  for (const QString& value : values)
+  {
+    if (value == "fullscreen")
+      setValue(SETTINGS_SECTION_MAIN, "fullscreen", true);
+    else if (value == "windowed")
+      setValue(SETTINGS_SECTION_MAIN, "fullscreen", false);
+    else if (value == "desktop")
+      setValue(SETTINGS_SECTION_MAIN, "webMode", "desktop");
+    else if (value == "tv")
+      setValue(SETTINGS_SECTION_MAIN, "webMode", "tv");
+  }
+}
+

+ 2 - 0
src/settings/SettingsComponent.h

@@ -43,6 +43,8 @@ public:
     return m_sections.value(sectionID, nullptr);
   }
 
+  void setCommandLineValues(const QStringList& values);
+
   // JS interface
   Q_INVOKABLE void setValue(const QString& sectionID, const QString& key, const QVariant& value);
   Q_INVOKABLE void setValues(const QVariantMap& options);

+ 20 - 5
src/ui/KonvergoWindow.cpp

@@ -222,9 +222,9 @@ QRect KonvergoWindow::loadGeometry()
 QRect KonvergoWindow::loadGeometryRect()
 {
   // if we dont have anything, default to 720p in the middle of the screen
-  QRect defaultRect = QRect((screen()->geometry().width() - webUISize().width()) / 2,
-                            (screen()->geometry().height() - webUISize().height()) / 2,
-                            webUISize().width(), webUISize().height());
+  QRect defaultRect = QRect((screen()->geometry().width() - WEBUI_SIZE.width()) / 2,
+                            (screen()->geometry().height() - WEBUI_SIZE.height()) / 2,
+                            WEBUI_SIZE.width(), WEBUI_SIZE.height());
 
   QVariantMap map = SettingsComponent::Get().value(SETTINGS_SECTION_STATE, "geometry").toMap();
   if (map.isEmpty())
@@ -303,7 +303,7 @@ void KonvergoWindow::updateMainSectionSettings(const QVariantMap& values)
     SystemComponent::Get().setCursorVisibility(!SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "disablemouse").toBool());
   }
 
-  if (values.contains("alwaysOnTop") || values.contains("fullscreen") || values.contains("webMode"))
+  if (values.contains("alwaysOnTop") || values.contains("fullscreen"))
   {
     InputComponent::Get().cancelAutoRepeat();
     updateWindowState();
@@ -311,12 +311,27 @@ void KonvergoWindow::updateMainSectionSettings(const QVariantMap& values)
 
   if (values.contains("webMode"))
   {
+    InputComponent::Get().cancelAutoRepeat();
+    bool oldDesktopMode = m_webDesktopMode;
+
     m_webDesktopMode = (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "webMode").toString() == "desktop");
     emit webDesktopModeChanged();
     emit webUrlChanged();
     SystemComponent::Get().setCursorVisibility(true);
-
     updateWindowState();
+    notifyScale(size());
+
+    bool fullscreen = SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "fullscreen").toBool();
+
+    if (oldDesktopMode && !m_webDesktopMode)
+      fullscreen = true;
+    else if (!oldDesktopMode && m_webDesktopMode)
+      fullscreen = false;
+
+    QTimer::singleShot(0, [=]
+    {
+      SettingsComponent::Get().setValue(SETTINGS_SECTION_MAIN, "fullscreen", fullscreen);
+    });
   }
 
   if (values.contains("startupurl"))

+ 16 - 2
src/ui/KonvergoWindow.h

@@ -31,12 +31,13 @@ class KonvergoWindow : public QQuickWindow
   Q_PROPERTY(QString videoInfo MEMBER m_videoInfo NOTIFY debugInfoChanged)
   Q_PROPERTY(qreal webScale READ webScale NOTIFY webScaleChanged)
   Q_PROPERTY(qreal webHeightMax READ webHeightMax NOTIFY webScaleChanged)
-  Q_PROPERTY(QSize webUISize READ webUISize NOTIFY webScaleChanged)
   Q_PROPERTY(qreal windowScale READ windowScale NOTIFY webScaleChanged)
   Q_PROPERTY(QSize windowMinSize READ windowMinSize NOTIFY webScaleChanged)
   Q_PROPERTY(bool alwaysOnTop READ isAlwaysOnTop WRITE setAlwaysOnTop)
   Q_PROPERTY(bool webDesktopMode MEMBER m_webDesktopMode NOTIFY webDesktopModeChanged)
   Q_PROPERTY(QString webUrl READ webUrl NOTIFY webUrlChanged)
+  Q_PROPERTY(qreal webUIWidth READ webUIWidth NOTIFY webScaleChanged)
+  Q_PROPERTY(qreal webUIHeight READ webUIHeight NOTIFY webScaleChanged)
 
 public:
   static void RegisterClass();
@@ -88,12 +89,25 @@ public:
   qreal windowScale() { return CalculateScale(size()); }
   qreal webScale() { return CalculateWebScale(size(), devicePixelRatio()); }
   qreal webHeightMax() { return WEBUI_MAX_HEIGHT; }
-  QSize webUISize() { return WEBUI_SIZE; }
   QSize windowMinSize() { return WINDOWW_MIN_SIZE; }
   static qreal CalculateScale(const QSize& size);
   static qreal CalculateWebScale(const QSize& size, qreal devicePixelRatio);
   QString webUrl();
 
+  qreal webUIWidth()
+  {
+    if (!m_webDesktopMode)
+      return qRound64(qMin((qreal)(height() * 16) / 9, (qreal)width()));
+    return width();
+  }
+
+  qreal webUIHeight()
+  {
+    if (!m_webDesktopMode)
+      return qRound64(qMin((qreal)(width() * 9) / 16, (qreal)height()));
+    return height();
+  }
+
 Q_SIGNALS:
   void fullScreenSwitched();
   void webScaleChanged();

+ 2 - 25
src/ui/webview.qml

@@ -140,32 +140,9 @@ KonvergoWindow
     focus: true
     property string currentHoveredUrl: ""
     onLinkHovered: web.currentHoveredUrl = hoveredUrl
+    width: mainWindow.webUIWidth
+    height: mainWindow.webUIHeight
 
-    width:
-    {
-      if (!mainWindow.webDesktopMode)
-      {
-        return Math.round(Math.min((parent.height * 16) / 9, parent.width));
-      }
-      else
-      {
-        return parent.width;
-      }
-    }
-
-    height:
-    {
-      if (!mainWindow.webDesktopMode)
-      {
-        return Math.round(Math.min((parent.width * 9) / 16, parent.height));
-      }
-      else
-      {
-        return parent.height;
-      }
-
-    }
-    
     scale:
     {
       if (mainWindow.webDesktopMode)