Commit 3f511c6d authored by Eskil Abrahamsen-Blomfeldt's avatar Eskil Abrahamsen-Blomfeldt
Browse files

Make everything compile

Not implemented yet: Mouse support + ES2 support
parent 8e3080ec
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt VNC Server.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtQml/qqmlextensionplugin.h>
#include <QtQml/qqmlengine.h>
#include "qvncitem.h"
QT_BEGIN_NAMESPACE
class QQuickVncPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
QQuickVncPlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) {}
void registerTypes(const char *uri) override
{
Q_ASSERT(uri == QStringLiteral("QtQuickVnc"));
qmlRegisterModule(uri, 1, 0);
}
};
QT_END_NAMESPACE
#include "plugin.moc"
module QtQuickVnc
plugin qquickvncplugin
classname QQuickVncPlugin
CXX_MODULE = qml
TARGET = qquickvncplugin
TARGETPATH = QtWayland/Client/QuickVnc
IMPORT_VERSION = 1.$$QT_MINOR_VERSION
QT += quick-private gui-private core-private network vncserver
HEADERS += \
qvncitem.h
SOURCES += \
plugin.cpp \
qvncitem.cpp
load(qml_plugin)
......@@ -19,6 +19,14 @@ QVncItem::QVncItem()
: m_vncPort(QVncServer::DefaultPort)
{
connect(this, &QVncItem::imageChanged, this, &QVncItem::handleImageChange); //cross-thread, so needs signal/slot connection
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(this, &QQuickItem::xChanged, this, &QVncItem::registerGeometryChange);
connect(this, &QQuickItem::yChanged, this, &QVncItem::registerGeometryChange);
connect(this, &QQuickItem::widthChanged, this, &QVncItem::registerGeometryChange);
connect(this, &QQuickItem::heightChanged, this, &QVncItem::registerGeometryChange);
#endif
setFlag(ItemHasContents, true); // Just so updatePaintNode gets called
}
......@@ -27,8 +35,18 @@ QVncItem::~QVncItem()
delete m_vncServer;
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void QVncItem::registerGeometryChange()
{
QRectF newGeometry(x(), y(), width(), height());
geometryChange(newGeometry, m_oldGeometry);
m_oldGeometry = newGeometry;
}
#endif
void QVncItem::handleMouse(QMouseEvent *mev)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (!m_remoteInputEnabled)
return;
auto da = QQuickItemPrivate::get(this)->deliveryAgent();
......@@ -42,6 +60,12 @@ void QVncItem::handleMouse(QMouseEvent *mev)
QMouseEvent mappedEvent(mev->type(), pos, mev->globalPosition(), mev->button(), mev->buttons(), mev->modifiers() );
da->event(&mappedEvent);
#else
# warning Not implemented mouse support on 5.15
Q_UNUSED(mev);
#endif
}
static QQuickItem *getScopedFocusItem(QQuickItem *parentItem)
......@@ -95,7 +119,10 @@ void QVncItem::geometryChange(const QRectF &newGeometry, const QRectF &oldGeomet
if (!m_vncServer && newGeometry.size().isValid()) {
createServer();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QQuickItem::geometryChange(newGeometry, oldGeometry);
#endif
}
bool QVncItem::eventFilter(QObject *, QEvent *event)
......@@ -227,6 +254,7 @@ void QVncItem::setRemoteInputEnabled(bool newRemoteInputEnabled)
//#define EXTRA_EXTRA_DEBUG
//#define EXTRA_EXTRA_EXTRA_DEBUG
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
//Must be invoked on render thread:
void QVncItem::grabTexture()
{
......@@ -320,6 +348,48 @@ void QVncItem::grabTexture()
qCDebug(lcVncTiming) << "QVncItem::grabTexture: Took" << timer.elapsed() << "msecs";
}
#else
//Must be invoked on render thread:
void QVncItem::grabTexture()
{
QElapsedTimer timer;
if (lcVncTiming().isDebugEnabled())
timer.start();
QSGTextureProvider *provider = textureProvider();
QImage newImg;
if (provider != nullptr) {
QSGTexture *texture = provider->texture();
int textureId = texture->textureId();
if (textureId > 0) {
QSize s = texture->textureSize();
newImg = QImage(s, QImage::Format_ARGB32);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureId);
#ifdef GL_ES_VERSION_2_0
qWarning() << "OpenGL ES not supported without RHI";
#else
glGetTexImage(GL_TEXTURE_2D,
0,
GL_BGRA,
GL_UNSIGNED_BYTE,
newImg.bits());
#endif
}
}
if (!newImg.isNull()) {
m_image = newImg;
m_imageFlipped = false;
m_pendingImageRequest = false;
m_ungrabbedUpdate = false;
emit imageChanged();
m_grabCount++;
}
}
#endif
QSGNode *QVncItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *data)
{
......
......@@ -56,13 +56,20 @@ Q_SIGNALS:
void passwordChanged(QByteArray newPassword);
protected:
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
#else
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry);
#endif
QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) override;
private Q_SLOTS:
void handleImageChange();
void handleImageRequest();
void grabTexture();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void registerGeometryChange();
#endif
private:
void setConnectionActive(bool newConnectionActive);
......@@ -85,6 +92,10 @@ private:
bool m_connectionActive = false;
int m_vncPort;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRectF m_oldGeometry;
#endif
//Debug
QElapsedTimer m_frameTimer;
int m_frameCount = 0;
......
TEMPLATE = subdirs
SUBDIRS += \
vncserver
vncserver \
quickvnc
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment