KonvergoWindow.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. #include "KonvergoWindow.h"
  2. #include <QTimer>
  3. #include <QJsonObject>
  4. #include <QScreen>
  5. #include <QQuickItem>
  6. #include <QGuiApplication>
  7. #include <QMessageBox>
  8. #include <QPushButton>
  9. #include "core/Version.h"
  10. #include "input/InputKeyboard.h"
  11. #include "settings/SettingsComponent.h"
  12. #include "settings/SettingsSection.h"
  13. #include "system/SystemComponent.h"
  14. #include "player/PlayerComponent.h"
  15. #include "player/PlayerQuickItem.h"
  16. #include "display/DisplayComponent.h"
  17. #include "QsLog.h"
  18. #include "utils/Utils.h"
  19. #include "Globals.h"
  20. #include "EventFilter.h"
  21. #ifdef USE_X11EXTRAS
  22. #include <QX11Info>
  23. #include <X11/Xlib.h>
  24. #endif
  25. ///////////////////////////////////////////////////////////////////////////////////////////////////
  26. class ScopedDecrementer
  27. {
  28. Q_DISABLE_COPY(ScopedDecrementer)
  29. int* m_value;
  30. public:
  31. ScopedDecrementer(int* value) : m_value(value) {}
  32. ~ScopedDecrementer() { (*m_value)--; }
  33. };
  34. ///////////////////////////////////////////////////////////////////////////////////////////////////
  35. KonvergoWindow::KonvergoWindow(QWindow* parent) :
  36. QQuickWindow(parent),
  37. m_debugLayer(false),
  38. m_ignoreFullscreenSettingsChange(0),
  39. m_showedUpdateDialog(false),
  40. m_osxPresentationOptions(0)
  41. {
  42. // NSWindowCollectionBehaviorFullScreenPrimary is only set on OSX if Qt::WindowFullscreenButtonHint is set on the window.
  43. setFlags(flags() | Qt::WindowFullscreenButtonHint);
  44. m_infoTimer = new QTimer(this);
  45. m_infoTimer->setInterval(1000);
  46. m_webDesktopMode = (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "webMode").toString() == "desktop");
  47. installEventFilter(new EventFilter(this));
  48. connect(m_infoTimer, &QTimer::timeout, this, &KonvergoWindow::updateDebugInfo);
  49. InputComponent::Get().registerHostCommand("close", this, "close");
  50. InputComponent::Get().registerHostCommand("toggleDebug", this, "toggleDebug");
  51. InputComponent::Get().registerHostCommand("reload", this, "reloadWeb");
  52. InputComponent::Get().registerHostCommand("fullscreen", this, "toggleFullscreen");
  53. InputComponent::Get().registerHostCommand("minimize", this, "minimizeWindow");
  54. InputComponent::Get().registerHostCommand("switchMode", this, "toggleWebMode");
  55. #ifdef TARGET_RPI
  56. // On RPI, we use dispmanx layering - the video is on a layer below Konvergo,
  57. // and during playback the Konvergo window is partially transparent. The OSD
  58. // will be visible on top of the video as part of the Konvergo window.
  59. setColor(QColor("transparent"));
  60. #else
  61. setColor(QColor("#000000"));
  62. #endif
  63. #ifdef USE_X11EXTRAS
  64. // On Gnome show a darker title bar
  65. if (QX11Info::isPlatformX11())
  66. {
  67. Display* dpy = QX11Info::display();
  68. if (dpy)
  69. {
  70. WId win = winId();
  71. XChangeProperty(dpy, win,
  72. XInternAtom(dpy, "_GTK_THEME_VARIANT", false),
  73. XInternAtom(dpy, "UTF8_STRING", false),
  74. 8, PropModeReplace, (unsigned char *) "dark", 4);
  75. }
  76. }
  77. #endif
  78. loadGeometry();
  79. connect(SettingsComponent::Get().getSection(SETTINGS_SECTION_MAIN), &SettingsSection::valuesUpdated,
  80. this, &KonvergoWindow::updateMainSectionSettings);
  81. connect(this, &KonvergoWindow::visibilityChanged,
  82. this, &KonvergoWindow::onVisibilityChanged);
  83. connect(this, &KonvergoWindow::screenChanged,
  84. this, &KonvergoWindow::updateCurrentScreen, Qt::QueuedConnection);
  85. connect(this, &KonvergoWindow::xChanged,
  86. this, &KonvergoWindow::updateCurrentScreen, Qt::QueuedConnection);
  87. connect(this, &KonvergoWindow::yChanged,
  88. this, &KonvergoWindow::updateCurrentScreen, Qt::QueuedConnection);
  89. connect(this, &KonvergoWindow::visibilityChanged,
  90. this, &KonvergoWindow::updateCurrentScreen, Qt::QueuedConnection);
  91. connect(this, &KonvergoWindow::windowStateChanged,
  92. this, &KonvergoWindow::updateCurrentScreen, Qt::QueuedConnection);
  93. connect(this, &KonvergoWindow::enableVideoWindowSignal,
  94. this, &KonvergoWindow::enableVideoWindow, Qt::QueuedConnection);
  95. connect(&PlayerComponent::Get(), &PlayerComponent::windowVisible,
  96. this, &KonvergoWindow::playerWindowVisible, Qt::QueuedConnection);
  97. // this is using old syntax because ... reasons. QQuickCloseEvent is not public class
  98. connect(this, SIGNAL(closing(QQuickCloseEvent*)), this, SLOT(closingWindow()));
  99. connect(qApp, &QCoreApplication::aboutToQuit, this, &KonvergoWindow::closingWindow);
  100. #ifdef Q_OS_MAC
  101. m_osxPresentationOptions = 0;
  102. #endif
  103. #ifdef KONVERGO_OPENELEC
  104. setVisibility(QWindow::FullScreen);
  105. #else
  106. updateWindowState(false);
  107. #endif
  108. updateScreens();
  109. connect(qApp, &QGuiApplication::screenAdded, this, &KonvergoWindow::onScreenAdded);
  110. connect(qApp, &QGuiApplication::screenRemoved, this, &KonvergoWindow::onScreenRemoved);
  111. emit enableVideoWindowSignal();
  112. }
  113. /////////////////////////////////////////////////////////////////////////////////////////
  114. void KonvergoWindow::closingWindow()
  115. {
  116. if (!SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "fullscreen").toBool())
  117. saveGeometry();
  118. qApp->quit();
  119. }
  120. ///////////////////////////////////////////////////////////////////////////////////////////////////
  121. KonvergoWindow::~KonvergoWindow()
  122. {
  123. DisplayComponent::Get().setApplicationWindow(nullptr);
  124. }
  125. ///////////////////////////////////////////////////////////////////////////////////////////////////
  126. bool KonvergoWindow::fitsInScreens(const QRect& rc)
  127. {
  128. for(QScreen *screen : QGuiApplication::screens())
  129. {
  130. if (screen->virtualGeometry().isValid() && screen->virtualGeometry().contains(rc))
  131. return true;
  132. }
  133. return false;
  134. }
  135. ///////////////////////////////////////////////////////////////////////////////////////////////////
  136. void KonvergoWindow::saveGeometry()
  137. {
  138. QLOG_DEBUG() << "Window state when saving geometry:" << visibility();
  139. QRect rc = geometry();
  140. // lets make sure we are not saving something craycray
  141. if (rc.size().width() < windowMinSize().width() || rc.size().height() < windowMinSize().height())
  142. return;
  143. if (!fitsInScreens(rc))
  144. return;
  145. QLOG_DEBUG() << "Saving window geometry:" << rc;
  146. if (visibility() == QWindow::Maximized)
  147. {
  148. SettingsComponent::Get().setValue(SETTINGS_SECTION_STATE, "maximized", true);
  149. }
  150. else if (visibility() != QWindow::Hidden)
  151. {
  152. QVariantMap map = {{"x", rc.x()}, {"y", rc.y()},
  153. {"width", rc.width()}, {"height", rc.height()}};
  154. SettingsComponent::Get().setValue(SETTINGS_SECTION_STATE, "geometry", map);
  155. SettingsComponent::Get().setValue(SETTINGS_SECTION_STATE, "maximized", false);
  156. }
  157. QScreen *curScreen = screen();
  158. SettingsComponent::Get().setValue(SETTINGS_SECTION_STATE, "lastUsedScreen", curScreen ? curScreen->name() : "");
  159. }
  160. ///////////////////////////////////////////////////////////////////////////////////////////////////
  161. QRect KonvergoWindow::loadGeometry()
  162. {
  163. QRect rc = loadGeometryRect();
  164. QScreen* myScreen = loadLastScreen();
  165. if (!myScreen)
  166. myScreen = screen();
  167. QRect nsize = rc;
  168. if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "fullscreen").toBool())
  169. {
  170. QLOG_DEBUG() << "Load FullScreen geo...";
  171. if (myScreen)
  172. {
  173. // On OSX we need to set the geometry to the size we want when we
  174. // return from fullscreen otherwise when we exit fullscreen it
  175. // will stay small or big. On Windows we need to set it to max
  176. // resolution for the screen (i.e. fullscreen) otherwise it will
  177. // just scale the webcontent to the minimum size we have defined
  178. //
  179. #ifndef Q_OS_MAC
  180. nsize = myScreen->geometry();
  181. #endif
  182. setGeometry(nsize);
  183. setScreen(myScreen);
  184. }
  185. }
  186. else
  187. {
  188. setGeometry(nsize);
  189. if (SettingsComponent::Get().value(SETTINGS_SECTION_STATE, "maximized").toBool())
  190. setVisibility(QWindow::Maximized);
  191. saveGeometry();
  192. }
  193. return nsize;
  194. }
  195. ///////////////////////////////////////////////////////////////////////////////////////////////////
  196. QRect KonvergoWindow::loadGeometryRect()
  197. {
  198. // if we dont have anything, default to 720p in the middle of the screen
  199. QScreen *curScreen = screen();
  200. QRect defaultRect = QRect(0, 0, WEBUI_SIZE.width(), WEBUI_SIZE.height());
  201. if (curScreen)
  202. {
  203. defaultRect = QRect((curScreen->geometry().width() - WEBUI_SIZE.width()) / 2,
  204. (curScreen->geometry().height() - WEBUI_SIZE.height()) / 2,
  205. WEBUI_SIZE.width(), WEBUI_SIZE.height());
  206. }
  207. QVariantMap map = SettingsComponent::Get().value(SETTINGS_SECTION_STATE, "geometry").toMap();
  208. if (map.isEmpty())
  209. return defaultRect;
  210. QRect rc(map["x"].toInt(), map["y"].toInt(), map["width"].toInt(), map["height"].toInt());
  211. QLOG_DEBUG() << "Restoring geo:" << rc;
  212. if (!rc.isValid() || rc.isEmpty())
  213. {
  214. QLOG_DEBUG() << "Geo bad, going for defaults";
  215. return defaultRect;
  216. }
  217. QSize minsz = windowMinSize();
  218. // Clamp to min size if we have really small values in there
  219. if (rc.size().width() < minsz.width())
  220. rc.setWidth(minsz.width());
  221. if (rc.size().height() < minsz.height())
  222. rc.setHeight(minsz.height());
  223. // also make sure we are not putting windows outside the screen somewhere
  224. if (!fitsInScreens(rc))
  225. {
  226. QLOG_DEBUG() << "Could not fit stored geo into current screens";
  227. return defaultRect;
  228. }
  229. return rc;
  230. }
  231. ///////////////////////////////////////////////////////////////////////////////////////////////////
  232. void KonvergoWindow::enableVideoWindow()
  233. {
  234. PlayerComponent::Get().setWindow(this);
  235. DisplayComponent::Get().setApplicationWindow(this);
  236. }
  237. ///////////////////////////////////////////////////////////////////////////////////////////////////
  238. void KonvergoWindow::setFullScreen(bool enable)
  239. {
  240. QLOG_DEBUG() << "setting fullscreen = " << enable;
  241. SettingsComponent::Get().setValue(SETTINGS_SECTION_MAIN, "fullscreen", enable);
  242. }
  243. ///////////////////////////////////////////////////////////////////////////////////////////////////
  244. void KonvergoWindow::toggleWebMode()
  245. {
  246. if (!m_webDesktopMode)
  247. SettingsComponent::Get().setValue(SETTINGS_SECTION_MAIN, "webMode", "desktop");
  248. else
  249. SettingsComponent::Get().setValue(SETTINGS_SECTION_MAIN, "webMode", "tv");
  250. }
  251. ///////////////////////////////////////////////////////////////////////////////////////////////////
  252. void KonvergoWindow::setAlwaysOnTop(bool enable)
  253. {
  254. QLOG_DEBUG() << "setting always on top = " << enable;
  255. // Update the settings value.
  256. SettingsComponent::Get().setValue(SETTINGS_SECTION_MAIN, "alwaysOnTop", enable);
  257. }
  258. ///////////////////////////////////////////////////////////////////////////////////////////////////
  259. void KonvergoWindow::playerWindowVisible(bool visible)
  260. {
  261. // adjust webengineview transparecy depending on player visibility
  262. QQuickItem *web = findChild<QQuickItem *>("web");
  263. if (web)
  264. web->setProperty("backgroundColor", visible ? "transparent" : "#000000");
  265. #ifdef Q_OS_MAC
  266. // On OSX, initializing VideoTooolbox (hardware decoder API) will mysteriously
  267. // show the hidden mouse pointer again. The VTDecompressionSessionCreate API
  268. // function does this, and we have no influence over its behavior.
  269. if (visible && !SystemComponent::Get().cursorVisible())
  270. {
  271. // "Refresh" it. (There doesn't seem to be a nicer way, and we have to do
  272. // this on the Cocoa level too.)
  273. SystemComponent::Get().setCursorVisibility(true);
  274. SystemComponent::Get().setCursorVisibility(false);
  275. }
  276. #endif
  277. }
  278. ///////////////////////////////////////////////////////////////////////////////////////////////////
  279. void KonvergoWindow::updateMainSectionSettings(const QVariantMap& values)
  280. {
  281. // update mouse visibility if needed
  282. if (values.find("disablemouse") != values.end())
  283. {
  284. SystemComponent::Get().setCursorVisibility(!SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "disablemouse").toBool());
  285. }
  286. if (values.contains("alwaysOnTop"))
  287. updateWindowState();
  288. if (values.contains("fullscreen") && !m_ignoreFullscreenSettingsChange)
  289. updateWindowState();
  290. if (values.contains("webMode"))
  291. {
  292. InputComponent::Get().cancelAutoRepeat();
  293. bool oldDesktopMode = m_webDesktopMode;
  294. bool newDesktopMode = (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "webMode").toString() == "desktop");
  295. if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "layout").toString() != "auto")
  296. {
  297. if (oldDesktopMode != newDesktopMode)
  298. {
  299. PlayerComponent::Get().stop();
  300. m_webDesktopMode = newDesktopMode;
  301. emit webDesktopModeChanged();
  302. emit webUrlChanged();
  303. }
  304. }
  305. else
  306. {
  307. if (oldDesktopMode != newDesktopMode)
  308. {
  309. QTimer::singleShot(0, [this, newDesktopMode]
  310. {
  311. PlayerComponent::Get().stop();
  312. m_webDesktopMode = newDesktopMode;
  313. emit webDesktopModeChanged();
  314. emit webUrlChanged();
  315. if (m_webDesktopMode)
  316. SystemComponent::Get().setCursorVisibility(true);
  317. });
  318. }
  319. }
  320. }
  321. if (values.contains("startupurl"))
  322. emit webUrlChanged();
  323. if (values.contains("forceFSScreen"))
  324. updateForcedScreen();
  325. }
  326. ///////////////////////////////////////////////////////////////////////////////////////////////////
  327. void KonvergoWindow::updateForcedScreen()
  328. {
  329. QString screenName = SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "forceFSScreen").toString();
  330. if (screenName.isEmpty())
  331. return;
  332. for (QScreen* scr : QGuiApplication::screens())
  333. {
  334. if (scr->name() == screenName)
  335. {
  336. QLOG_DEBUG() << "Forcing screen to" << scr->name();
  337. setScreen(scr);
  338. setGeometry(scr->geometry());
  339. setVisibility(QWindow::FullScreen);
  340. InputComponent::Get().cancelAutoRepeat();
  341. return;
  342. }
  343. }
  344. }
  345. ///////////////////////////////////////////////////////////////////////////////////////////////////
  346. void KonvergoWindow::updateWindowState(bool saveGeo)
  347. {
  348. if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "fullscreen").toBool() || SystemComponent::Get().isOpenELEC() || SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "forceAlwaysFS").toBool())
  349. {
  350. // if we were go from windowed to fullscreen
  351. // we want to store our current windowed position
  352. if (!isFullScreen() && saveGeo)
  353. saveGeometry();
  354. setVisibility(QWindow::FullScreen);
  355. // When fullscreening explicitly, we might have to move the window to a
  356. // different screen, as Qt will fullscreen to the current screen.
  357. QTimer::singleShot(200, [=]
  358. {
  359. updateForcedScreen();
  360. });
  361. }
  362. else
  363. {
  364. setVisibility(QWindow::Windowed);
  365. loadGeometry();
  366. Qt::WindowFlags forceOnTopFlags = Qt::WindowStaysOnTopHint;
  367. #ifdef Q_WS_X11
  368. forceOnTopFlags = forceOnTopFlags | Qt::X11BypassWindowManagerHint;
  369. #endif
  370. if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "alwaysOnTop").toBool())
  371. setFlags(flags() | forceOnTopFlags);
  372. else
  373. setFlags(flags() &~ forceOnTopFlags);
  374. }
  375. InputComponent::Get().cancelAutoRepeat();
  376. }
  377. ///////////////////////////////////////////////////////////////////////////////////////////////////
  378. QScreen* KonvergoWindow::findCurrentScreen()
  379. {
  380. // Return the screen that contains most of the window. Quite possible that
  381. // screen() would be sufficient, at least once the Qt bug returning a wrong
  382. // QScreen on Windows is fixed.
  383. QScreen *best = nullptr;
  384. qint64 bestArea = 0;
  385. for(QScreen* screen : qApp->screens())
  386. {
  387. QRect areaRC = screen->geometry().intersected(geometry());
  388. qint64 area = areaRC.width() * (qint64)areaRC.height();
  389. if (!best || area > bestArea)
  390. {
  391. best = screen;
  392. bestArea = area;
  393. }
  394. }
  395. return best ? best : screen();
  396. }
  397. ///////////////////////////////////////////////////////////////////////////////////////////////////
  398. void KonvergoWindow::onVisibilityChanged(QWindow::Visibility visibility)
  399. {
  400. QLOG_DEBUG() << "QWindow visibility set to" << visibility;
  401. #ifdef Q_OS_WIN32
  402. if (visibility == QWindow::Windowed)
  403. {
  404. QScreen* realScreen = findCurrentScreen();
  405. if (realScreen && realScreen->geometry() == geometry())
  406. {
  407. QLOG_WARN() << "winging it!";
  408. setScreen(realScreen);
  409. setVisibility(QWindow::FullScreen);
  410. return;
  411. }
  412. }
  413. #endif
  414. if (visibility == QWindow::Windowed && SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "forceAlwaysFS").toBool())
  415. {
  416. QLOG_WARN() << "Forcing re-entering fullscreen because of forceAlwaysFS setting!";
  417. updateForcedScreen(); // if a specific screen is forced, try to move the window there
  418. setVisibility(QWindow::FullScreen);
  419. return;
  420. }
  421. if (visibility == QWindow::FullScreen || visibility == QWindow::Windowed)
  422. {
  423. m_ignoreFullscreenSettingsChange++;
  424. ScopedDecrementer decrement(&m_ignoreFullscreenSettingsChange);
  425. bool fs = visibility == QWindow::FullScreen;
  426. SettingsComponent::Get().setValue(SETTINGS_SECTION_MAIN, "fullscreen", fs);
  427. SystemComponent::Get().setCursorVisibility(false);
  428. }
  429. InputComponent::Get().cancelAutoRepeat();
  430. }
  431. /////////////////////////////////////////////////////////////////////////////////////////
  432. void KonvergoWindow::focusOutEvent(QFocusEvent * ev)
  433. {
  434. #ifdef Q_OS_WIN32
  435. // Do this to workaround DWM compositor bugs with fullscreened OpenGL applications.
  436. // The compositor will not properly redraw anything when focusing other windows.
  437. if (visibility() == QWindow::FullScreen && SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "minimizeOnDefocus").toBool())
  438. {
  439. QLOG_DEBUG() << "minimizing window";
  440. showMinimized();
  441. }
  442. #endif
  443. QQuickWindow::focusOutEvent(ev);
  444. }
  445. /////////////////////////////////////////////////////////////////////////////////////////
  446. void KonvergoWindow::RegisterClass()
  447. {
  448. qmlRegisterType<KonvergoWindow>("Konvergo", 1, 0, "KonvergoWindow");
  449. }
  450. /////////////////////////////////////////////////////////////////////////////////////////
  451. void KonvergoWindow::updateDebugInfo()
  452. {
  453. if (m_systemDebugInfo.size() == 0)
  454. m_systemDebugInfo = SystemComponent::Get().debugInformation();
  455. m_debugInfo = m_systemDebugInfo;
  456. m_debugInfo += DisplayComponent::Get().debugInformation();
  457. PlayerQuickItem* video = findChild<PlayerQuickItem*>("video");
  458. if (video)
  459. m_debugInfo += video->debugInfo();
  460. QString infoString;
  461. QDebug info(&infoString);
  462. info << "Qt windowing info:\n";
  463. info << " FS: " << visibility() << "\n";
  464. info << " Geo: " << geometry() << "\n";
  465. for (QScreen* scr : QGuiApplication::screens())
  466. {
  467. info << " Screen" << scr->name() << scr->geometry() << "\n";
  468. }
  469. #ifdef Q_OS_WIN32
  470. HMONITOR mon = MonitorFromWindow((HWND)winId(), MONITOR_DEFAULTTONEAREST);
  471. MONITORINFO moninfo = {};
  472. moninfo.cbSize = sizeof(moninfo);
  473. RECT winrc;
  474. if (GetMonitorInfo(mon, &moninfo) &&GetWindowRect((HWND)winId(), &winrc))
  475. {
  476. RECT rc = moninfo.rcMonitor;
  477. info << " Win32 window" << QString("%1/%2 %3x%4").arg(rc.left).arg(rc.top).arg(rc.right).arg(rc.bottom) << QString("%1/%2 %3x%4").arg(winrc.left).arg(winrc.top).arg(winrc.right).arg(winrc.bottom) << "\n";
  478. }
  479. #endif
  480. info << "\n";
  481. m_debugInfo += infoString;
  482. m_videoInfo = PlayerComponent::Get().videoInformation();
  483. emit debugInfoChanged();
  484. }
  485. /////////////////////////////////////////////////////////////////////////////////////////
  486. void KonvergoWindow::toggleDebug()
  487. {
  488. if (property("showDebugLayer").toBool())
  489. {
  490. m_infoTimer->stop();
  491. setProperty("showDebugLayer", false);
  492. }
  493. else
  494. {
  495. m_infoTimer->start();
  496. updateDebugInfo();
  497. setProperty("showDebugLayer", true);
  498. }
  499. }
  500. /////////////////////////////////////////////////////////////////////////////////////////
  501. void KonvergoWindow::resizeEvent(QResizeEvent* event)
  502. {
  503. QLOG_DEBUG() << "resize event:" << event->size();
  504. // This next block was added at some point to workaround a problem with
  505. // resizing on windows. Unfortunately it broke the desktop client behavior
  506. // and when retried on Windows 10 with Qt5.7 the original bug seems to be
  507. // gone. I'll keep this code around until such a time that we dont get any
  508. // complaints about it.
  509. //
  510. #if 0
  511. // This next block should never really be needed in a prefect world...
  512. // Unfortunatly this is an imperfect world and on windows sometimes what
  513. // would happen on startup is that we got a resize event that would make
  514. // the window much smaller than fullscreen.
  515. //
  516. if (isFullScreen())
  517. {
  518. QSize fsSize = screen()->size();
  519. if (event->size().width() < fsSize.width() || event->size().height() < fsSize.height())
  520. {
  521. QLOG_DEBUG() << "Ignoring resize event when in fullscreen...";
  522. return;
  523. }
  524. }
  525. #endif
  526. QQuickWindow::resizeEvent(event);
  527. }
  528. /////////////////////////////////////////////////////////////////////////////////////////
  529. QScreen* KonvergoWindow::loadLastScreen()
  530. {
  531. QString screenName = SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "forceFSScreen").toString();
  532. if (screenName.isEmpty())
  533. screenName = SettingsComponent::Get().value(SETTINGS_SECTION_STATE, "lastUsedScreen").toString();
  534. if (screenName.isEmpty())
  535. return nullptr;
  536. for (QScreen* scr : QGuiApplication::screens())
  537. {
  538. if (scr->name() == screenName)
  539. return scr;
  540. }
  541. QLOG_DEBUG() << "Tried to find screen:" << screenName << "but it was not present";
  542. return nullptr;
  543. }
  544. /////////////////////////////////////////////////////////////////////////////////////////
  545. QString KonvergoWindow::webUrl()
  546. {
  547. return SettingsComponent::Get().getWebClientUrl(m_webDesktopMode);
  548. }
  549. /////////////////////////////////////////////////////////////////////////////////////////
  550. void KonvergoWindow::updateScreens()
  551. {
  552. QScreen* windowScreen = findCurrentScreen();
  553. QString screenName = SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "forceFSScreen").toString();
  554. QVariantList settingList;
  555. QVariantMap defentry;
  556. defentry["value"] = "";
  557. defentry["title"] = "Auto";
  558. settingList << defentry;
  559. bool currentPresent = false;
  560. int num = 0;
  561. for(QScreen* screen : qApp->screens())
  562. {
  563. QRect rc = screen->geometry();
  564. bool active = screen == windowScreen;
  565. QVariantMap entry;
  566. entry["value"] = screen->name();
  567. entry["title"] =
  568. QString("%1,%2 %3x%4").arg(rc.left()).arg(rc.top()).arg(rc.right()).arg(rc.bottom()) +
  569. " (" + screen->name() + ")" +
  570. (active ? " *" : "");
  571. settingList << entry;
  572. bool selected = screen->name() == screenName;
  573. if (selected)
  574. currentPresent = true;
  575. QLOG_DEBUG() << "Screen" << (num++) << screen << screen->geometry()
  576. << screen->virtualGeometry() << "active:" << active
  577. << "selected:" << selected;
  578. }
  579. if (!currentPresent && !screenName.isEmpty())
  580. {
  581. QVariantMap entry;
  582. entry["value"] = screenName;
  583. entry["title"] = "[Disconnected: " + screenName + "]";
  584. settingList << entry;
  585. }
  586. SettingsComponent::Get().updatePossibleValues(SETTINGS_SECTION_MAIN, "forceFSScreen", settingList);
  587. m_currentScreenName = windowScreen ? windowScreen->name() : "";
  588. }
  589. /////////////////////////////////////////////////////////////////////////////////////////
  590. void KonvergoWindow::onScreenAdded(QScreen *screen)
  591. {
  592. updateScreens();
  593. // The timer is out of fear for chaotic mid-change states.
  594. QTimer::singleShot(200, [this]
  595. {
  596. updateForcedScreen();
  597. });
  598. }
  599. /////////////////////////////////////////////////////////////////////////////////////////
  600. void KonvergoWindow::onScreenRemoved(QScreen *screen)
  601. {
  602. updateScreens();
  603. }
  604. /////////////////////////////////////////////////////////////////////////////////////////
  605. void KonvergoWindow::updateCurrentScreen()
  606. {
  607. QScreen* current = findCurrentScreen();
  608. QString currentName = current ? current->name() : "";
  609. if (currentName != m_currentScreenName)
  610. updateScreens();
  611. }