Commit c4179eb7 authored by Alberto Mardegan's avatar Alberto Mardegan
Browse files

VncClient: add a method to send mouse events

parent 54174714
......@@ -23,6 +23,8 @@
#include <QDebug>
#include <QImage>
#include <QList>
#include <QMouseEvent>
#include <QPointF>
#include <QQuickItem>
#include <QScopedPointer>
#include <QSocketNotifier>
......@@ -46,6 +48,8 @@ public:
int x, int y, int w, int h);
static rfbBool mallocFrameBuffer(rfbClient* client);
static int qtToRfb(Qt::MouseButtons buttons);
void onUpdate(int x, int y, int w, int h);
void onResize();
......@@ -54,6 +58,8 @@ public:
void onSocketActivated();
void sendMouseEvent(const QPointF &pos, Qt::MouseButtons buttons);
private:
QScopedPointer<QSocketNotifier> m_notifier;
int m_bytesPerPixel;
......@@ -118,6 +124,15 @@ rfbBool VncClientPrivate::mallocFrameBuffer(rfbClient* client)
return true;
}
int VncClientPrivate::qtToRfb(Qt::MouseButtons buttons)
{
int ret = 0;
if (buttons & Qt::LeftButton) ret |= rfbButton1Mask;
if (buttons & Qt::RightButton) ret |= rfbButton2Mask;
if (buttons & Qt::MiddleButton) ret |= rfbButton3Mask;
return ret;
}
void VncClientPrivate::onUpdate(int x, int y, int w, int h)
{
Q_UNUSED(x);
......@@ -218,6 +233,16 @@ void VncClientPrivate::onSocketActivated()
}
}
void VncClientPrivate::sendMouseEvent(const QPointF &pos,
Qt::MouseButtons buttons)
{
if (Q_UNLIKELY(!m_client)) {
qWarning() << "Not connected";
return;
}
SendPointerEvent(m_client, pos.x(), pos.y(), qtToRfb(buttons));
}
VncClient::VncClient(QObject *parent):
QObject(parent),
d_ptr(new VncClientPrivate(this))
......@@ -261,3 +286,9 @@ void VncClient::disconnect()
Q_D(VncClient);
return d->disconnect();
}
void VncClient::sendMouseEvent(const QPointF &pos, Qt::MouseButtons buttons)
{
Q_D(VncClient);
return d->sendMouseEvent(pos, buttons);
}
......@@ -24,6 +24,7 @@
#include <QScopedPointer>
class QImage;
class QPointF;
class QQuickItem;
namespace LomiriVNC {
......@@ -47,6 +48,9 @@ public:
Q_INVOKABLE bool connectToServer(const QString &host);
Q_INVOKABLE void disconnect();
Q_INVOKABLE void sendMouseEvent(const QPointF &pos,
Qt::MouseButtons buttons);
Q_SIGNALS:
void connectionStatusChanged();
......
Markdown is supported
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