diff options
Diffstat (limited to 'src/plugins/platforms/vnc/qvnc.cpp')
-rw-r--r-- | src/plugins/platforms/vnc/qvnc.cpp | 135 |
1 files changed, 53 insertions, 82 deletions
diff --git a/src/plugins/platforms/vnc/qvnc.cpp b/src/plugins/platforms/vnc/qvnc.cpp index 7d8649d12f..99e80e5801 100644 --- a/src/plugins/platforms/vnc/qvnc.cpp +++ b/src/plugins/platforms/vnc/qvnc.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or 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.GPL2 and 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qvnc_p.h" #include "qvncscreen.h" #include "qvncclient.h" @@ -48,7 +12,7 @@ #include <QtGui/QWindow> #ifdef Q_OS_WIN -#include <Winsock2.h> +#include <winsock2.h> #else #include <arpa/inet.h> #endif @@ -245,7 +209,7 @@ static const struct { void QRfbRect::read(QTcpSocket *s) { quint16 buf[4]; - s->read((char*)buf, 8); + s->read(reinterpret_cast<char*>(buf), 8); x = ntohs(buf[0]); y = ntohs(buf[1]); w = ntohs(buf[2]); @@ -259,7 +223,7 @@ void QRfbRect::write(QTcpSocket *s) const buf[1] = htons(y); buf[2] = htons(w); buf[3] = htons(h); - s->write((char*)buf, 8); + s->write(reinterpret_cast<char*>(buf) , 8); } void QRfbPixelFormat::read(QTcpSocket *s) @@ -271,15 +235,15 @@ void QRfbPixelFormat::read(QTcpSocket *s) bigEndian = buf[2]; trueColor = buf[3]; - quint16 a = ntohs(*(quint16 *)(buf + 4)); + quint16 a = ntohs(*reinterpret_cast<quint16 *>(buf + 4)); redBits = 0; while (a) { a >>= 1; redBits++; } - a = ntohs(*(quint16 *)(buf + 6)); + a = ntohs(*reinterpret_cast<quint16 *>(buf + 6)); greenBits = 0; while (a) { a >>= 1; greenBits++; } - a = ntohs(*(quint16 *)(buf + 8)); + a = ntohs(*reinterpret_cast<quint16 *>(buf + 8)); blueBits = 0; while (a) { a >>= 1; blueBits++; } @@ -298,15 +262,15 @@ void QRfbPixelFormat::write(QTcpSocket *s) quint16 a = 0; for (int i = 0; i < redBits; i++) a = (a << 1) | 1; - *(quint16 *)(buf + 4) = htons(a); + *reinterpret_cast<quint16 *>(buf + 4) = htons(a); a = 0; for (int i = 0; i < greenBits; i++) a = (a << 1) | 1; - *(quint16 *)(buf + 6) = htons(a); + *reinterpret_cast<quint16 *>(buf + 6) = htons(a); a = 0; for (int i = 0; i < blueBits; i++) a = (a << 1) | 1; - *(quint16 *)(buf + 8) = htons(a); + *reinterpret_cast<quint16 *>(buf + 8) = htons(a); buf[10] = redShift; buf[11] = greenShift; @@ -324,14 +288,14 @@ void QRfbServerInit::setName(const char *n) void QRfbServerInit::read(QTcpSocket *s) { - s->read((char *)&width, 2); + s->read(reinterpret_cast<char *>(&width), 2); width = ntohs(width); - s->read((char *)&height, 2); + s->read(reinterpret_cast<char *>(&height), 2); height = ntohs(height); format.read(s); quint32 len; - s->read((char *)&len, 4); + s->read(reinterpret_cast<char *>(&len), 4); len = ntohl(len); name = new char [len + 1]; @@ -342,14 +306,14 @@ void QRfbServerInit::read(QTcpSocket *s) void QRfbServerInit::write(QTcpSocket *s) { quint16 t = htons(width); - s->write((char *)&t, 2); + s->write(reinterpret_cast<char *>(&t), 2); t = htons(height); - s->write((char *)&t, 2); + s->write(reinterpret_cast<char *>(&t), 2); format.write(s); - quint32 len = strlen(name); + quint32 len = static_cast<quint32>(strlen(name)); len = htonl(len); - s->write((char *)&len, 4); - s->write(name, strlen(name)); + s->write(reinterpret_cast<char *>(&len), 4); + s->write(name, static_cast<qint64>(strlen(name))); } bool QRfbSetEncodings::read(QTcpSocket *s) @@ -359,7 +323,7 @@ bool QRfbSetEncodings::read(QTcpSocket *s) char tmp; s->read(&tmp, 1); // padding - s->read((char *)&count, 2); + s->read(reinterpret_cast<char *>(&count), 2); count = ntohs(count); return true; @@ -383,17 +347,17 @@ bool QRfbKeyEvent::read(QTcpSocket *s) s->read(&down, 1); quint16 tmp; - s->read((char *)&tmp, 2); // padding + s->read(reinterpret_cast<char *>(&tmp), 2); // padding quint32 key; - s->read((char *)&key, 4); + s->read(reinterpret_cast<char *>(&key), 4); key = ntohl(key); unicode = 0; keycode = 0; int i = 0; while (keyMap[i].keysym && !keycode) { - if (keyMap[i].keysym == (int)key) + if (keyMap[i].keysym == static_cast<int>(key)) keycode = keyMap[i].keycode; i++; } @@ -430,9 +394,9 @@ bool QRfbPointerEvent::read(QTcpSocket *s) buttons |= Qt::RightButton; quint16 tmp; - s->read((char *)&tmp, 2); + s->read(reinterpret_cast<char *>(&tmp), 2); x = ntohs(tmp); - s->read((char *)&tmp, 2); + s->read(reinterpret_cast<char *>(&tmp), 2); y = ntohs(tmp); return true; @@ -445,7 +409,7 @@ bool QRfbClientCutText::read(QTcpSocket *s) char tmp[3]; s->read(tmp, 3); // padding - s->read((char *)&length, 4); + s->read(reinterpret_cast<char *>(&length), 4); length = ntohl(length); return true; @@ -477,6 +441,9 @@ void QRfbRawEncoder::write() // server->screen()->geometry().height()); // } + const QImage screenImage = client->server()->screenImage(); + rgn &= screenImage.rect(); + const auto rectsInRegion = rgn.rectCount(); { @@ -486,21 +453,19 @@ void QRfbRawEncoder::write() { const quint16 count = htons(rectsInRegion); - socket->write((char *)&count, sizeof(count)); + socket->write(reinterpret_cast<const char *>(&count), sizeof(count)); } if (rectsInRegion <= 0) return; - const QImage screenImage = client->server()->screenImage(); - for (const QRect &tileRect: rgn) { const QRfbRect rect(tileRect.x(), tileRect.y(), tileRect.width(), tileRect.height()); rect.write(socket); const quint32 encoding = htonl(0); // raw encoding - socket->write((char *)&encoding, sizeof(encoding)); + socket->write(reinterpret_cast<const char *>(&encoding), sizeof(encoding)); qsizetype linestep = screenImage.bytesPerLine(); const uchar *screendata = screenImage.scanLine(rect.y) @@ -514,15 +479,16 @@ void QRfbRawEncoder::write() // convert pixels char *b = buffer.data(); const int bstep = rect.w * bytesPerPixel; + const int depth = screenImage.depth(); for (int i = 0; i < rect.h; ++i) { - client->convertPixels(b, (const char*)screendata, rect.w); + client->convertPixels(b, reinterpret_cast<const char*>(screendata), rect.w, depth); screendata += linestep; b += bstep; } socket->write(buffer.constData(), bufferSize); } else { for (int i = 0; i < rect.h; ++i) { - socket->write((const char*)screendata, rect.w * bytesPerPixel); + socket->write(reinterpret_cast<const char*>(screendata), rect.w * bytesPerPixel); screendata += linestep; } } @@ -552,13 +518,13 @@ void QVncClientCursor::write(QVncClient *client) const { const quint16 tmp[6] = { htons(0), htons(1), - htons(uint16_t(hotspot.x())), htons(uint16_t(hotspot.y())), - htons(uint16_t(cursor.width())), - htons(uint16_t(cursor.height())) }; - socket->write((char*)tmp, sizeof(tmp)); + htons(static_cast<uint16_t>(hotspot.x())), htons(static_cast<uint16_t>(hotspot.y())), + htons(static_cast<uint16_t>(cursor.width())), + htons(static_cast<uint16_t>(cursor.height())) }; + socket->write(reinterpret_cast<const char*>(tmp), sizeof(tmp)); const qint32 encoding = qToBigEndian(-239); - socket->write((char*)(&encoding), sizeof(encoding)); + socket->write(reinterpret_cast<const char*>(&encoding), sizeof(encoding)); } if (cursor.isNull()) @@ -568,9 +534,10 @@ void QVncClientCursor::write(QVncClient *client) const Q_ASSERT(cursor.hasAlphaChannel()); const QImage img = cursor.convertToFormat(client->server()->screen()->format()); const int n = client->clientBytesPerPixel() * img.width(); + const int depth = img.depth(); char *buffer = new char[n]; for (int i = 0; i < img.height(); ++i) { - client->convertPixels(buffer, (const char*)img.scanLine(i), img.width()); + client->convertPixels(buffer, (const char*)img.scanLine(i), img.width(), depth); socket->write(buffer, n); } delete[] buffer; @@ -581,7 +548,7 @@ void QVncClientCursor::write(QVncClient *client) const Q_ASSERT(bitmap.size() == img.size()); const int width = (bitmap.width() + 7) / 8; for (int i = 0; i < bitmap.height(); ++i) - socket->write((const char*)bitmap.scanLine(i), width); + socket->write(reinterpret_cast<const char*>(bitmap.scanLine(i)), width); } void QVncClientCursor::changeCursor(QCursor *widgetCursor, QWindow *window) @@ -600,20 +567,23 @@ void QVncClientCursor::changeCursor(QCursor *widgetCursor, QWindow *window) cursor = *platformImage.image(); hotspot = platformImage.hotspot(); } - for (auto client : qAsConst(clients)) + for (auto client : std::as_const(clients)) client->setDirtyCursor(); } void QVncClientCursor::addClient(QVncClient *client) { - if (!clients.contains(client)) + if (!clients.contains(client)) { clients.append(client); + // Force a cursor update when the client connects. + client->setDirtyCursor(); + } } uint QVncClientCursor::removeClient(QVncClient *client) { clients.removeOne(client); - return clients.count(); + return clients.size(); } #endif // QT_CONFIG(cursor) @@ -643,7 +613,7 @@ QVncServer::~QVncServer() void QVncServer::setDirty() { - for (auto client : qAsConst(clients)) + for (auto client : std::as_const(clients)) client->setDirty(qvnc_screen->dirtyRegion); qvnc_screen->clearDirty(); @@ -665,11 +635,10 @@ void QVncServer::newConnection() void QVncServer::discardClient(QVncClient *client) { clients.removeOne(client); + qvnc_screen->disableClientCursor(client); client->deleteLater(); - if (clients.isEmpty()) { - qvnc_screen->disableClientCursor(client); + if (clients.isEmpty()) qvnc_screen->setPowerState(QPlatformScreen::PowerStateOff); - } } inline QImage QVncServer::screenImage() const @@ -678,3 +647,5 @@ inline QImage QVncServer::screenImage() const } QT_END_NAMESPACE + +#include "moc_qvnc_p.cpp" |