7#include <QtNetwork/QTcpSocket>
8#include <QtCore/QCoreApplication>
10#include <qpa/qwindowsysteminterface.h>
11#include <QtGui/qguiapplication.h>
28 , m_encodingsPending(0)
30 , m_supportHextile(
false)
32 , m_dirtyCursor(
false)
33 , m_updatePending(
false)
34 , m_protocolVersion(V3_3)
40 const char *proto =
"RFB 003.003\n";
41 m_clientSocket->
write(proto, 12);
52 return m_clientSocket;
57 m_dirtyRegion += region;
58 if (m_state == Connected &&
67#if Q_BYTE_ORDER == Q_BIG_ENDIAN
73 switch (screendepth) {
89 const int bytesPerPixel = (m_pixelFormat.
bitsPerPixel + 7) / 8;
94 switch (screendepth) {
105#if Q_BYTE_ORDER == Q_BIG_ENDIAN
107 p = ((
p & 0xff) << 8) | ((
p & 0xff00) >> 8);
109 r = (
p >> 11) & 0x1f;
120 r = (
p >> 16) & 0xff;
128 qWarning(
"QVNCServer: don't support %dbpp display", screendepth);
133#if Q_BYTE_ORDER == Q_BIG_ENDIAN
142 int pixel = (
r << m_pixelFormat.
redShift) |
147 memcpy(
dst, &pixel, bytesPerPixel);
148 dst += bytesPerPixel;
156 pixel = (((pixel & 0x0000ff00) << 8) |
157 ((pixel & 0x000000ff) << 24));
160 pixel = (((pixel & 0xff000000) >> 24) |
161 ((pixel & 0x00ff0000) >> 8) |
162 ((pixel & 0x0000ff00) << 8) |
163 ((pixel & 0x000000ff) << 24));
171 pixel = (((pixel & 0xff000000) >> 8) |
172 ((pixel & 0x00ff0000) << 8));
175 pixel = (((pixel & 0xff000000) >> 24) |
176 ((pixel & 0x00ff0000) >> 8) |
177 ((pixel & 0x0000ff00) << 8) |
178 ((pixel & 0x000000ff) << 24));
181 qWarning(
"Cannot handle %d bpp client",
186 memcpy(
dst, &pixel, bytesPerPixel);
187 dst += bytesPerPixel;
191void QVncClient::readClient()
193 qCDebug(lcVnc) <<
"readClient" << m_state;
201 m_clientSocket->
read(proto, 12);
203 qCDebug(lcVnc,
"Client protocol version %s", proto);
204 if (!strcmp(proto,
"RFB 003.008\n")) {
205 m_protocolVersion = V3_8;
206 }
else if (!strcmp(proto,
"RFB 003.007\n")) {
207 m_protocolVersion = V3_7;
209 m_protocolVersion = V3_3;
212 if (m_protocolVersion == V3_3) {
215 m_clientSocket->
write((
char *) &auth,
sizeof(auth));
226 m_clientSocket->
read((
char *) &shared, 1);
331 sim.
setName(
"Qt for Embedded Linux VNC Server");
332 sim.
write(m_clientSocket);
340 m_clientSocket->
read((
char *)&m_msgType, 1);
344 switch (m_msgType ) {
349 qWarning(
"Not supported: FixColourMapEntries");
356 frameBufferUpdateRequest();
368 qWarning(
"Unknown message type: %d", (
int)m_msgType);
379void QVncClient::discardClient()
381 m_state = Disconnected;
385void QVncClient::checkUpdate()
391 m_server->
screen()->clientCursor->write(
this);
392 m_dirtyCursor =
false;
393 m_wantUpdate =
false;
397 if (!m_dirtyRegion.
isEmpty()) {
400 m_wantUpdate =
false;
405void QVncClient::scheduleUpdate()
407 if (!m_updatePending) {
408 m_updatePending =
true;
416 m_updatePending =
false;
423void QVncClient::setPixelFormat()
428 m_pixelFormat.
read(m_clientSocket);
429 qCDebug(lcVnc,
"Want format: %d %d %d %d %d %d %d %d %d %d",
431 int(m_pixelFormat.
depth),
441 qWarning(
"Can only handle true color clients");
446 m_needConversion = pixelConversionNeeded();
447#if Q_BYTE_ORDER == Q_BIG_ENDIAN
453void QVncClient::setEncodings()
457 if (!m_encodingsPending && enc.
read(m_clientSocket)) {
458 m_encodingsPending = enc.
count;
459 if (!m_encodingsPending)
479 if (m_encodingsPending && (
unsigned)m_clientSocket->
bytesAvailable() >=
480 m_encodingsPending *
sizeof(
quint32)) {
481 for (
int i = 0;
i < m_encodingsPending; ++
i) {
483 m_clientSocket->
read((
char *)&enc,
sizeof(
qint32));
485 qCDebug(lcVnc,
"QVncServer::setEncodings: %d", enc);
490 qCDebug(lcVnc,
"QVncServer::setEncodings: using raw");
494 m_supportCopyRect =
true;
500 m_supportCoRRE =
true;
503 m_supportHextile =
true;
508 m_supportZRLE =
true;
511 m_supportCursor =
true;
515 m_supportDesktopSize =
true;
522 m_encodingsPending = 0;
527 qCDebug(lcVnc,
"QVncServer::setEncodings: fallback using raw");
531void QVncClient::frameBufferUpdateRequest()
533 qCDebug(lcVnc) <<
"FramebufferUpdateRequest";
536 if (ev.
read(m_clientSocket)) {
548void QVncClient::pointerEvent()
552 if (ev.
read(m_clientSocket)) {
554 int buttonStateChange = buttonState ^ int(ev.
buttons);
556 if (
int(ev.
buttons) > buttonState)
558 else if (
int(ev.
buttons) < buttonState)
567void QVncClient::keyEvent()
571 if (ev.
read(m_clientSocket)) {
574 m_keymod &
~Qt::ShiftModifier;
577 m_keymod &
~Qt::ControlModifier;
580 m_keymod &
~Qt::AltModifier;
587void QVncClient::clientCutText()
591 if (m_cutTextPending == 0 && ev.
read(m_clientSocket)) {
592 m_cutTextPending = ev.
length;
593 if (!m_cutTextPending)
597 if (m_cutTextPending && m_clientSocket->
bytesAvailable() >= m_cutTextPending) {
598 char *
text =
new char [m_cutTextPending+1];
599 m_clientSocket->
read(
text, m_cutTextPending);
601 m_cutTextPending = 0;
606bool QVncClient::pixelConversionNeeded()
const
611#if Q_BYTE_ORDER == Q_BIG_ENDIAN
616 const int screendepth = m_server->
screen()->
depth();
620 switch (screendepth) {
625 return (m_pixelFormat.
redBits == 5
634#include "moc_qvncclient.cpp"
qint64 bytesAvailable() const override
Returns the number of incoming bytes that are waiting to be read.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
Type
This enum type defines the valid event types in Qt.
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
int depth() const override
Reimplement in subclass to return current depth of the screen.
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
QList< QRgb > colorTable() const
Returns a list of the colors contained in the image's color table, or an empty list if the image does...
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr int width() const noexcept
Returns the width of the rectangle.
The QRegion class specifies a clip region for a painter.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
void setName(const char *n)
void write(QTcpSocket *s)
\macro QT_RESTRICTED_CAST_FROM_ASCII
The QTcpSocket class provides a TCP socket.
QVncClient(QTcpSocket *clientSocket, QVncServer *server)
@ FramebufferUpdateRequest
void convertPixels(char *dst, const char *src, int count, int depth) const
QTcpSocket * clientSocket() const
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void setDirty(const QRegion ®ion)
QVncServer * server() const
void enableClientCursor(QVncClient *client)
QVncScreen * screen() const
void discardClient(QVncClient *client)
QVncDirtyMap * dirtyMap() const
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
#define qCDebug(category,...)
GLboolean GLboolean GLboolean b
GLenum GLenum GLsizei count
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum format
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr int qBlue(QRgb rgb)
QUdpSocket clientSocket
[0]