From adf6bd931fe479b058752fb615c30c87ba661f46 Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Tue, 21 Jun 2016 12:44:31 +0200 Subject: Add plugin arguments to VNC plugin It is now possible to specify a port number to run the VNC server on, as well as the screen properties: Logical Size Physical Size Depth Change-Id: I79b38c6e37ad5abb5e158eca9a17d7e8a86e692f Reviewed-by: Laszlo Agocs --- src/plugins/platforms/vnc/main.cpp | 1 - src/plugins/platforms/vnc/qvnc.cpp | 16 ++++------------ src/plugins/platforms/vnc/qvnc_p.h | 4 ++-- src/plugins/platforms/vnc/qvncintegration.cpp | 12 +++++++++++- src/plugins/platforms/vnc/qvncscreen.cpp | 17 +++++++++++++++++ 5 files changed, 34 insertions(+), 16 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/vnc/main.cpp b/src/plugins/platforms/vnc/main.cpp index b3c78e9caf..1a8c1eeb63 100644 --- a/src/plugins/platforms/vnc/main.cpp +++ b/src/plugins/platforms/vnc/main.cpp @@ -54,7 +54,6 @@ public: QPlatformIntegration* QVncIntegrationPlugin::create(const QString& system, const QStringList& paramList) { QT_VNC_DEBUG() << "loading vnc plugin" << system; - Q_UNUSED(paramList); if (!system.compare(QLatin1String("vnc"), Qt::CaseInsensitive)) return new QVncIntegration(paramList); diff --git a/src/plugins/platforms/vnc/qvnc.cpp b/src/plugins/platforms/vnc/qvnc.cpp index c14088c2a1..743888258e 100644 --- a/src/plugins/platforms/vnc/qvnc.cpp +++ b/src/plugins/platforms/vnc/qvnc.cpp @@ -611,28 +611,20 @@ uint QVncClientCursor::removeClient(QVncClient *client) } #endif - -QVncServer::QVncServer(QVncScreen *screen) - : qvnc_screen(screen) -{ - QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection); -} - -QVncServer::QVncServer(QVncScreen *screen, int /*id*/) +QVncServer::QVncServer(QVncScreen *screen, quint16 port) : qvnc_screen(screen) + , m_port(port) { QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection); } void QVncServer::init() { - const int port = 5900; - serverSocket = new QTcpServer(this); - if (!serverSocket->listen(QHostAddress::Any, port)) + if (!serverSocket->listen(QHostAddress::Any, m_port)) qDebug() << "QVncServer could not connect:" << serverSocket->errorString(); else - QT_VNC_DEBUG("QVncServer created on port %d", port); + QT_VNC_DEBUG("QVncServer created on port %d", m_port); QT_VNC_DEBUG() << "running in thread" << thread() << QThread::currentThread(); connect(serverSocket, SIGNAL(newConnection()), this, SLOT(newConnection())); diff --git a/src/plugins/platforms/vnc/qvnc_p.h b/src/plugins/platforms/vnc/qvnc_p.h index dd8189d30f..cdc49c030a 100644 --- a/src/plugins/platforms/vnc/qvnc_p.h +++ b/src/plugins/platforms/vnc/qvnc_p.h @@ -391,8 +391,7 @@ class QVncServer : public QObject { Q_OBJECT public: - QVncServer(QVncScreen *screen); - QVncServer(QVncScreen *screen, int id); + QVncServer(QVncScreen *screen, quint16 port = 5900); ~QVncServer(); enum ServerMsg { FramebufferUpdate = 0, @@ -414,6 +413,7 @@ private: QTcpServer *serverSocket; QVector clients; QVncScreen *qvnc_screen; + quint16 m_port; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/vnc/qvncintegration.cpp b/src/plugins/platforms/vnc/qvncintegration.cpp index ee224bd36a..810c5d2a90 100644 --- a/src/plugins/platforms/vnc/qvncintegration.cpp +++ b/src/plugins/platforms/vnc/qvncintegration.cpp @@ -53,14 +53,24 @@ #include #endif +#include + QT_BEGIN_NAMESPACE QVncIntegration::QVncIntegration(const QStringList ¶mList) : m_fontDb(new QGenericUnixFontDatabase), m_services(new QGenericUnixServices) { + QRegularExpression portRx(QLatin1String("port=(\\d+)")); + quint16 port = 5900; + for (const QString &arg : paramList) { + QRegularExpressionMatch match; + if (arg.contains(portRx, &match)) + port = match.captured(1).toInt(); + } + m_primaryScreen = new QVncScreen(paramList); - m_server = new QVncServer(m_primaryScreen); + m_server = new QVncServer(m_primaryScreen, port); m_primaryScreen->vncServer = m_server; } diff --git a/src/plugins/platforms/vnc/qvncscreen.cpp b/src/plugins/platforms/vnc/qvncscreen.cpp index 2b38ce6c51..532b9225da 100644 --- a/src/plugins/platforms/vnc/qvncscreen.cpp +++ b/src/plugins/platforms/vnc/qvncscreen.cpp @@ -43,6 +43,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -62,11 +63,27 @@ QVncScreen::~QVncScreen() bool QVncScreen::initialize() { + QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)")); + QRegularExpression mmSizeRx(QLatin1String("mmsize=(?(\\d*\\.)?\\d+)x(?(\\d*\\.)?\\d+)")); + QRegularExpression depthRx(QLatin1String("depth=(\\d+)")); + mGeometry = QRect(0, 0, 1024, 768); mFormat = QImage::Format_ARGB32_Premultiplied; mDepth = 32; mPhysicalSize = QSizeF(mGeometry.width()/96.*25.4, mGeometry.height()/96.*25.4); + for (const QString &arg : mArgs) { + QRegularExpressionMatch match; + if (arg.contains(mmSizeRx, &match)) { + mPhysicalSize = QSizeF(match.captured("width").toDouble(), match.captured("height").toDouble()); + } else if (arg.contains(sizeRx, &match)) { + mGeometry.setSize(QSize(match.captured(1).toInt(), match.captured(2).toInt())); + } else if (arg.contains(depthRx, &match)) { + mDepth = match.captured(1).toInt(); + } + } + + QFbScreen::initializeCompositor(); QT_VNC_DEBUG() << "QVncScreen::init" << geometry(); -- cgit v1.2.3