From 0adb4aa26d7b9ea9c35827750d8ba96daddcee47 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 16 Jul 2018 16:56:27 +0200 Subject: [client] Show vnc window on rightmost screen In Multiscreen setups, we most likely show the VM on the primary (=leftmost) screen. --- src/client/vnc/vncwindow.cpp | 29 ++++++++++++++++++++++------- src/client/vnc/vncwindow.h | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/client/vnc/vncwindow.cpp b/src/client/vnc/vncwindow.cpp index c9c0d93..3ad75e8 100644 --- a/src/client/vnc/vncwindow.cpp +++ b/src/client/vnc/vncwindow.cpp @@ -22,7 +22,7 @@ #include VncWindow::VncWindow(QWidget *parent) : - QWidget(parent), _vncWorker(NULL), _viewOnly(true), _clientId(0), _redrawTimer(0), _tcpTimeoutTimer(0) + QWidget(parent), _vncWorker(NULL), _viewOnly(true), _multiScreen(false), _clientId(0), _redrawTimer(0), _tcpTimeoutTimer(0) { QTimer *upper = new QTimer(this); connect(upper, SIGNAL(timeout()), this, SLOT(timer_moveToTop())); @@ -40,7 +40,7 @@ VncWindow::~VncWindow() /** * Terminates the vnc worker thread and stops all related timers. * The thread will be signalled to stop, but we don't wait for it - * to actually terminate. All signaled of the thread are blocked, and we NULL + * to actually terminate. All signals of the thread are blocked, and we NULL * our reference to it. It will finish running in a detached state and finally * delete itself upon completion. */ @@ -123,22 +123,34 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool _remoteThumb.loadFromData(rawThumb); + QSize size; if (fullscreen) { setWindowFlags(Qt::WindowStaysOnTopHint); // | Qt::X11BypassWindowManagerHint); <- better, but window won't get any keyboard input + // Show projection on rightmost screen QDesktopWidget *desktop = QApplication::desktop(); - QRect size = desktop->screenGeometry(this); - resize(size.size()); + int ns = desktop->numScreens(); + QRect best; + for (int i = 0; i < ns; ++i) { + QRect r = desktop->screenGeometry(i); + if (best.isNull() || r.left() > best.left()) { + best = r; + } + } + _multiScreen = ns > 1; + size = best.size(); + setGeometry(best); showFullScreen(); activateWindow(); raise(); } else { - resize(800, 600); + size = QSize(800, 600); + resize(size); showNormal(); } this->repaint(); this->show(); - _vncWorker->setTargetSize(this->size()); + _vncWorker->setTargetSize(size); _tcpTimeoutTimer = startTimer(10000); _vncWorker->start(QThread::LowPriority); @@ -193,6 +205,7 @@ void VncWindow::onProjectionStarted() } emit running(true, _clientId); _redrawTimer = startTimer(3000); + _vncWorker->setTargetSize(this->size()); } /** @@ -211,7 +224,9 @@ void VncWindow::timer_moveToTop() { if (this->isHidden()) return; - activateWindow(); + if (!_multiScreen) { + activateWindow(); + } raise(); } diff --git a/src/client/vnc/vncwindow.h b/src/client/vnc/vncwindow.h index 277339c..df37513 100644 --- a/src/client/vnc/vncwindow.h +++ b/src/client/vnc/vncwindow.h @@ -50,6 +50,7 @@ protected: private: VncThread *_vncWorker; bool _viewOnly; + bool _multiScreen; int _clientId; int _redrawTimer; int _tcpTimeoutTimer; -- cgit v1.2.3-55-g7522