KonvergoWindow.cpp 23 KB

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