Skip to content

Commit

Permalink
Add plugin arguments to VNC plugin
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nezticle committed Jun 28, 2016
1 parent 2cf3696 commit adf6bd9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/plugins/platforms/vnc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class QVncIntegrationPlugin : public QPlatformIntegrationPlugin
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);

Expand Down
16 changes: 4 additions & 12 deletions src/plugins/platforms/vnc/qvnc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/platforms/vnc/qvnc_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -414,6 +413,7 @@ private slots:
QTcpServer *serverSocket;
QVector<QVncClient*> clients;
QVncScreen *qvnc_screen;
quint16 m_port;
};

QT_END_NAMESPACE
Expand Down
12 changes: 11 additions & 1 deletion src/plugins/platforms/vnc/qvncintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,24 @@
#include <QtPlatformSupport/private/qlibinputhandler_p.h>
#endif

#include <QtCore/QRegularExpression>

QT_BEGIN_NAMESPACE

QVncIntegration::QVncIntegration(const QStringList &paramList)
: 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;
}

Expand Down
17 changes: 17 additions & 0 deletions src/plugins/platforms/vnc/qvncscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <QtPlatformSupport/private/qfbcursor_p.h>

#include <QtGui/QPainter>
#include <QtCore/QRegularExpression>


QT_BEGIN_NAMESPACE
Expand All @@ -62,11 +63,27 @@ QVncScreen::~QVncScreen()

bool QVncScreen::initialize()
{
QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)"));
QRegularExpression mmSizeRx(QLatin1String("mmsize=(?<width>(\\d*\\.)?\\d+)x(?<height>(\\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();

Expand Down

0 comments on commit adf6bd9

Please sign in to comment.