KonvergoWindow.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef KONVERGOWINDOW_H
  2. #define KONVERGOWINDOW_H
  3. #include <QQuickWindow>
  4. #include <QEvent>
  5. #include <settings/SettingsComponent.h>
  6. // This controls how big the web view will zoom using semantic zoom
  7. // over a specific number of pixels and we run out of space for on screen
  8. // tiles in chromium. This only happens on OSX since on other platforms
  9. // we can use the GPU to transfer tiles directly but we set the limit on all platforms
  10. // to keep it consistent.
  11. //
  12. // See more discussion in: https://github.com/plexinc/plex-media-player/issues/10
  13. // The number of pixels here are REAL pixels, the code in webview.qml will compensate
  14. // for a higher DevicePixelRatio
  15. //
  16. #define WEBUI_MAX_HEIGHT 1440.0
  17. #define WEBUI_SIZE QSize(1280, 720)
  18. #define WINDOWW_MIN_SIZE QSize(426, 240)
  19. ///////////////////////////////////////////////////////////////////////////////////////////////////
  20. class KonvergoWindow : public QQuickWindow
  21. {
  22. Q_OBJECT
  23. Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenSwitched)
  24. Q_PROPERTY(bool showDebugLayer MEMBER m_debugLayer NOTIFY debugLayerChanged)
  25. Q_PROPERTY(QString debugInfo MEMBER m_debugInfo NOTIFY debugInfoChanged)
  26. Q_PROPERTY(QString videoInfo MEMBER m_videoInfo NOTIFY debugInfoChanged)
  27. Q_PROPERTY(qreal webScale READ webScale NOTIFY webScaleChanged)
  28. Q_PROPERTY(qreal webHeightMax READ webHeightMax NOTIFY webScaleChanged)
  29. Q_PROPERTY(qreal windowScale READ windowScale NOTIFY webScaleChanged)
  30. Q_PROPERTY(QSize windowMinSize READ windowMinSize NOTIFY webScaleChanged)
  31. Q_PROPERTY(bool alwaysOnTop READ isAlwaysOnTop WRITE setAlwaysOnTop)
  32. Q_PROPERTY(bool webDesktopMode MEMBER m_webDesktopMode NOTIFY webDesktopModeChanged)
  33. Q_PROPERTY(QString webUrl READ webUrl NOTIFY webUrlChanged)
  34. Q_PROPERTY(qreal webUIWidth READ webUIWidth NOTIFY webScaleChanged)
  35. Q_PROPERTY(qreal webUIHeight READ webUIHeight NOTIFY webScaleChanged)
  36. public:
  37. static void RegisterClass();
  38. explicit KonvergoWindow(QWindow* parent = nullptr);
  39. ~KonvergoWindow() override;
  40. bool isFullScreen()
  41. {
  42. return ((flags() & Qt::FramelessWindowHint) || (visibility() == QWindow::FullScreen));
  43. }
  44. Q_INVOKABLE void setFullScreen(bool enable);
  45. bool isAlwaysOnTop()
  46. {
  47. Qt::WindowFlags forceOnTopFlags = Qt::WindowStaysOnTopHint;
  48. #ifdef Q_OS_LINUX
  49. forceOnTopFlags = forceOnTopFlags | Qt::X11BypassWindowManagerHint;
  50. #endif
  51. return (flags() & forceOnTopFlags);
  52. }
  53. void setAlwaysOnTop(bool enable);
  54. Q_SLOT void otherAppFocus()
  55. {
  56. setWindowState((Qt::WindowState)((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive));
  57. raise();
  58. }
  59. Q_SLOT void toggleDebug();
  60. Q_SLOT void toggleFullscreen(bool noSwitchMode = false)
  61. {
  62. bool switchMode = (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "layout").toString() == "auto" && !noSwitchMode);
  63. if (switchMode && !m_webDesktopMode && isFullScreen())
  64. SettingsComponent::Get().setValue(SETTINGS_SECTION_MAIN, "webMode", "desktop");
  65. else if (switchMode && m_webDesktopMode && !isFullScreen())
  66. SettingsComponent::Get().setValue(SETTINGS_SECTION_MAIN, "webMode", "tv");
  67. else
  68. setFullScreen(!isFullScreen());
  69. }
  70. Q_SLOT void toggleFullscreenNoSwitch() { toggleFullscreen(true); }
  71. Q_SLOT void toggleAlwaysOnTop()
  72. {
  73. setAlwaysOnTop(!isAlwaysOnTop());
  74. }
  75. Q_SLOT void reloadWeb()
  76. {
  77. emit reloadWebClient();
  78. }
  79. Q_INVOKABLE Q_SLOT void minimizeWindow()
  80. {
  81. if (!isFullScreen())
  82. setVisibility(QWindow::Minimized);
  83. }
  84. qreal windowScale() { return CalculateScale(size()); }
  85. qreal webScale() { return CalculateWebScale(size(), devicePixelRatio()); }
  86. qreal webHeightMax() { return WEBUI_MAX_HEIGHT; }
  87. QSize windowMinSize() { return WINDOWW_MIN_SIZE; }
  88. static qreal CalculateScale(const QSize& size);
  89. static qreal CalculateWebScale(const QSize& size, qreal devicePixelRatio);
  90. QString webUrl();
  91. qreal webUIWidth()
  92. {
  93. if (!m_webDesktopMode)
  94. return qRound64(qMin((qreal)(height() * 16) / 9, (qreal)width()));
  95. return width();
  96. }
  97. qreal webUIHeight()
  98. {
  99. if (!m_webDesktopMode)
  100. return qRound64(qMin((qreal)(width() * 9) / 16, (qreal)height()));
  101. return height();
  102. }
  103. Q_SIGNALS:
  104. void fullScreenSwitched();
  105. void webScaleChanged();
  106. void enableVideoWindowSignal();
  107. void debugLayerChanged();
  108. void debugInfoChanged();
  109. void reloadWebClient();
  110. void webDesktopModeChanged();
  111. void webUrlChanged();
  112. protected:
  113. void focusOutEvent(QFocusEvent* ev) override;
  114. void resizeEvent(QResizeEvent* event) override;
  115. private slots:
  116. void closingWindow();
  117. void enableVideoWindow();
  118. void onVisibilityChanged(QWindow::Visibility visibility);
  119. void updateMainSectionSettings(const QVariantMap& values);
  120. void updateWindowState(bool saveGeo = true);
  121. void onScreenCountChanged(int newCount);
  122. void updateDebugInfo();
  123. void playerWindowVisible(bool visible);
  124. void showUpdateDialog();
  125. private:
  126. void notifyScale(const QSize& size);
  127. void saveGeometry();
  128. QRect loadGeometry();
  129. QRect loadGeometryRect();
  130. bool fitsInScreens(const QRect& rc);
  131. QScreen* loadLastScreen();
  132. bool m_debugLayer;
  133. qreal m_lastScale;
  134. QTimer* m_infoTimer;
  135. QString m_debugInfo, m_systemDebugInfo, m_videoInfo;
  136. int m_ignoreFullscreenSettingsChange;
  137. bool m_webDesktopMode;
  138. bool m_showedUpdateDialog;
  139. unsigned long m_osxPresentationOptions;
  140. void setWebMode(bool newDesktopMode, bool fullscreen);
  141. };
  142. #endif // KONVERGOWINDOW_H