Commit ecf84c46 authored by Jan Grulich's avatar Jan Grulich

Implement mouse support

parent 57b21790
......@@ -126,12 +126,12 @@ uint RemoteDesktopPortal::Start(const QDBusObjectPath &handle,
if (remoteDesktopDialog->exec()) {
if (session->screenSharingEnabled()) {
WaylandIntegration::WaylandOutput selectedOutput = WaylandIntegration::screens().value(remoteDesktopDialog->selectedScreens().first());
if (!WaylandIntegration::startStreaming(selectedOutput)) {
if (!WaylandIntegration::startStreaming(remoteDesktopDialog->selectedScreens().first())) {
return 2;
}
WaylandIntegration::authenticate();
QVariant streams = WaylandIntegration::streams();
if (!streams.isValid()) {
......@@ -142,7 +142,7 @@ uint RemoteDesktopPortal::Start(const QDBusObjectPath &handle,
results.insert(QLatin1String("streams"), streams);
}
results.insert(QLatin1String("types"), QVariant::fromValue<uint>(remoteDesktopDialog->deviceTypes()));
results.insert(QLatin1String("devices"), QVariant::fromValue<uint>(remoteDesktopDialog->deviceTypes()));
return 0;
}
......@@ -155,14 +155,43 @@ void RemoteDesktopPortal::NotifyPointerMotion(const QDBusObjectPath &session_han
double dx,
double dy)
{
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << "NotifyPointerMotion called with parameters:";
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " options: " << options;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " dx: " << dx;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " dy: " << dy;
RemoteDesktopSession *session = qobject_cast<RemoteDesktopSession*>(Session::getSession(session_handle.path()));
if (!session) {
qCWarning(XdgDesktopPortalKdeRemoteDesktop) << "Tried to call NotifyPointerMotion on non-existing session " << session_handle.path();
return;
}
WaylandIntegration::requestPointerMotion(QSizeF(dx, dy));
}
void RemoteDesktopPortal::NotifyPointerMotionAbsolute(const QDBusObjectPath &session_handle,
const QVariantMap &options,
uint stream,
double dx,
double dy)
double x,
double y)
{
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << "NotifyPointerMotionAbsolute called with parameters:";
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " options: " << options;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " stream: " << stream;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " x: " << x;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " y: " << y;
RemoteDesktopSession *session = qobject_cast<RemoteDesktopSession*>(Session::getSession(session_handle.path()));
if (!session) {
qCWarning(XdgDesktopPortalKdeRemoteDesktop) << "Tried to call NotifyPointerMotionAbsolute on non-existing session " << session_handle.path();
return;
}
WaylandIntegration::requestPointerMotionAbsolute(QPointF(x, y));
}
void RemoteDesktopPortal::NotifyPointerButton(const QDBusObjectPath &session_handle,
......@@ -170,6 +199,24 @@ void RemoteDesktopPortal::NotifyPointerButton(const QDBusObjectPath &session_han
int button,
uint state)
{
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << "NotifyPointerButton called with parameters:";
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " options: " << options;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " button: " << button;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " state: " << state;
RemoteDesktopSession *session = qobject_cast<RemoteDesktopSession*>(Session::getSession(session_handle.path()));
if (!session) {
qCWarning(XdgDesktopPortalKdeRemoteDesktop) << "Tried to call NotifyPointerButton on non-existing session " << session_handle.path();
return;
}
if (state) {
WaylandIntegration::requestPointerButtonPress(button);
} else {
WaylandIntegration::requestPointerButtonRelease(button);
}
}
void RemoteDesktopPortal::NotifyPointerAxis(const QDBusObjectPath &session_handle,
......@@ -177,6 +224,11 @@ void RemoteDesktopPortal::NotifyPointerAxis(const QDBusObjectPath &session_handl
double dx,
double dy)
{
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << "NotifyPointerAxis called with parameters:";
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " options: " << options;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " dx: " << dx;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " dy: " << dy;
}
void RemoteDesktopPortal::NotifyPointerAxisDiscrete(const QDBusObjectPath &session_handle,
......@@ -184,6 +236,20 @@ void RemoteDesktopPortal::NotifyPointerAxisDiscrete(const QDBusObjectPath &sessi
uint axis,
int steps)
{
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << "NotifyPointerAxisDiscrete called with parameters:";
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " options: " << options;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " axis: " << axis;
qCDebug(XdgDesktopPortalKdeRemoteDesktop) << " steps: " << steps;
RemoteDesktopSession *session = qobject_cast<RemoteDesktopSession*>(Session::getSession(session_handle.path()));
if (!session) {
qCWarning(XdgDesktopPortalKdeRemoteDesktop) << "Tried to call NotifyPointerAxisDiscrete on non-existing session " << session_handle.path();
return;
}
WaylandIntegration::requestPointerAxisDiscrete(!axis ? Qt::Vertical : Qt::Horizontal, steps);
}
void RemoteDesktopPortal::NotifyKeyboardKeysym(const QDBusObjectPath &session_handle,
......
......@@ -74,8 +74,8 @@ public Q_SLOTS:
void NotifyPointerMotionAbsolute(const QDBusObjectPath &session_handle,
const QVariantMap &options,
uint stream,
double dx,
double dy);
double x,
double y);
void NotifyPointerButton(const QDBusObjectPath &session_handle,
const QVariantMap &options,
......
......@@ -148,9 +148,7 @@ uint ScreenCastPortal::Start(const QDBusObjectPath &handle,
Utils::setParentWindow(screenDialog.data(), parent_window);
if (screenDialog->exec()) {
WaylandIntegration::WaylandOutput selectedOutput = WaylandIntegration::screens().value(screenDialog->selectedScreens().first());
if (!WaylandIntegration::startStreaming(selectedOutput)) {
if (!WaylandIntegration::startStreaming(screenDialog->selectedScreens().first())) {
return 2;
}
......
......@@ -32,9 +32,12 @@
#include <QImage>
#include <KLocalizedString>
// KWayland
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/event_queue.h>
#include <KWayland/Client/fakeinput.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/output.h>
#include <KWayland/Client/remote_access.h>
......@@ -47,6 +50,11 @@ Q_LOGGING_CATEGORY(XdgDesktopPortalKdeWaylandIntegration, "xdp-kde-wayland-integ
Q_GLOBAL_STATIC(WaylandIntegration::WaylandIntegrationPrivate, globalWaylandIntegration)
void WaylandIntegration::authenticate()
{
globalWaylandIntegration->authenticate();
}
void WaylandIntegration::init()
{
globalWaylandIntegration->initDrm();
......@@ -58,9 +66,9 @@ bool WaylandIntegration::isEGLInitialized()
return globalWaylandIntegration->isEGLInitialized();
}
bool WaylandIntegration::startStreaming(const WaylandOutput &output)
bool WaylandIntegration::startStreaming(quint32 outputName)
{
return globalWaylandIntegration->startStreaming(output);
return globalWaylandIntegration->startStreaming(outputName);
}
void WaylandIntegration::stopStreaming()
......@@ -68,6 +76,31 @@ void WaylandIntegration::stopStreaming()
globalWaylandIntegration->stopStreaming();
}
void WaylandIntegration::requestPointerButtonPress(quint32 linuxButton)
{
globalWaylandIntegration->requestPointerButtonPress(linuxButton);
}
void WaylandIntegration::requestPointerButtonRelease(quint32 linuxButton)
{
globalWaylandIntegration->requestPointerButtonRelease(linuxButton);
}
void WaylandIntegration::requestPointerMotion(const QSizeF &delta)
{
globalWaylandIntegration->requestPointerMotion(delta);
}
void WaylandIntegration::requestPointerMotionAbsolute(const QPointF &pos)
{
globalWaylandIntegration->requestPointerMotionAbsolute(pos);
}
void WaylandIntegration::requestPointerAxisDiscrete(Qt::Orientation axis, qreal delta)
{
globalWaylandIntegration->requestPointerAxisDiscrete(axis, delta);
}
QMap<quint32, WaylandIntegration::WaylandOutput> WaylandIntegration::screens()
{
return globalWaylandIntegration->screens();
......@@ -167,8 +200,10 @@ WaylandIntegration::WaylandIntegrationPrivate::WaylandIntegrationPrivate()
: WaylandIntegration()
, m_eglInitialized(false)
, m_registryInitialized(false)
, m_waylandAuthenticationRequested(false)
, m_connection(nullptr)
, m_queue(nullptr)
, m_fakeInput(nullptr)
, m_registry(nullptr)
, m_remoteAccessManager(nullptr)
{
......@@ -199,8 +234,11 @@ void WaylandIntegration::WaylandIntegrationPrivate::bindOutput(int outputName, i
m_bindOutputs << output;
}
bool WaylandIntegration::WaylandIntegrationPrivate::startStreaming(const WaylandOutput &output)
bool WaylandIntegration::WaylandIntegrationPrivate::startStreaming(quint32 outputName)
{
WaylandOutput output = m_outputMap.value(outputName);
m_streamedScreenPosition = output.globalPosition();
m_stream = new ScreenCastStream(output.resolution());
m_stream->init();
......@@ -280,6 +318,41 @@ void WaylandIntegration::WaylandIntegrationPrivate::stopStreaming()
}
}
void WaylandIntegration::WaylandIntegrationPrivate::requestPointerButtonPress(quint32 linuxButton)
{
if (m_streamingEnabled && m_fakeInput) {
m_fakeInput->requestPointerButtonPress(linuxButton);
}
}
void WaylandIntegration::WaylandIntegrationPrivate::requestPointerButtonRelease(quint32 linuxButton)
{
if (m_streamingEnabled && m_fakeInput) {
m_fakeInput->requestPointerButtonRelease(linuxButton);
}
}
void WaylandIntegration::WaylandIntegrationPrivate::requestPointerMotion(const QSizeF &delta)
{
if (m_streamingEnabled && m_fakeInput) {
m_fakeInput->requestPointerMove(delta);
}
}
void WaylandIntegration::WaylandIntegrationPrivate::requestPointerMotionAbsolute(const QPointF &pos)
{
if (m_streamingEnabled && m_fakeInput) {
m_fakeInput->requestPointerMoveAbsolute(pos + m_streamedScreenPosition);
}
}
void WaylandIntegration::WaylandIntegrationPrivate::requestPointerAxisDiscrete(Qt::Orientation axis, qreal delta)
{
if (m_streamingEnabled && m_fakeInput) {
m_fakeInput->requestPointerAxis(axis, delta);
}
}
QMap<quint32, WaylandIntegration::WaylandOutput> WaylandIntegration::WaylandIntegrationPrivate::screens()
{
return m_outputMap;
......@@ -293,6 +366,14 @@ QVariant WaylandIntegration::WaylandIntegrationPrivate::streams()
return QVariant::fromValue<WaylandIntegrationPrivate::Streams>({stream});
}
void WaylandIntegration::WaylandIntegrationPrivate::authenticate()
{
if (!m_waylandAuthenticationRequested) {
m_fakeInput->authenticate(i18n("xdg-desktop-portals-kde"), i18n("Remote desktop"));
m_waylandAuthenticationRequested = true;
}
}
void WaylandIntegration::WaylandIntegrationPrivate::initDrm()
{
m_drmFd = open("/dev/dri/renderD128", O_RDWR);
......@@ -414,6 +495,7 @@ void WaylandIntegration::WaylandIntegrationPrivate::addOutput(quint32 name, quin
portalOutput.setManufacturer(output->manufacturer());
portalOutput.setModel(output->model());
portalOutput.setOutputType(output->model());
portalOutput.setGlobalPosition(output->globalPosition());
portalOutput.setResolution(output->pixelSize());
portalOutput.setWaylandOutputName(name);
portalOutput.setWaylandOutputVersion(version);
......@@ -532,6 +614,9 @@ void WaylandIntegration::WaylandIntegrationPrivate::setupRegistry()
m_registry = new KWayland::Client::Registry(this);
connect(m_registry, &KWayland::Client::Registry::fakeInputAnnounced, this, [this] (quint32 name, quint32 version) {
m_fakeInput = m_registry->createFakeInput(name, version, this);
});
connect(m_registry, &KWayland::Client::Registry::outputAnnounced, this, &WaylandIntegrationPrivate::addOutput);
connect(m_registry, &KWayland::Client::Registry::outputRemoved, this, &WaylandIntegrationPrivate::removeOutput);
......
......@@ -22,6 +22,7 @@
#define XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H
#include <QObject>
#include <QPoint>
#include <QSize>
#include <QVariant>
......@@ -44,6 +45,9 @@ public:
void setModel(const QString &model) { m_model = model; }
QString model() const { return m_model; }
void setGlobalPosition(const QPoint &pos) { m_globalPosition = pos; }
QPoint globalPosition() const { return m_globalPosition; }
void setResolution(const QSize &resolution) { m_resolution = resolution; }
QSize resolution() const { return m_resolution; }
......@@ -59,6 +63,7 @@ public:
private:
QString m_manufacturer;
QString m_model;
QPoint m_globalPosition;
QSize m_resolution;
OutputType m_outputType;
......@@ -74,13 +79,20 @@ Q_SIGNALS:
void newBuffer(uint8_t *screenData);
};
void authenticate();
void init();
bool isEGLInitialized();
bool startStreaming(const WaylandOutput &output);
bool startStreaming(quint32 outputName);
void stopStreaming();
void requestPointerButtonPress(quint32 linuxButton);
void requestPointerButtonRelease(quint32 linuxButton);
void requestPointerMotion(const QSizeF &delta);
void requestPointerMotionAbsolute(const QPointF &pos);
void requestPointerAxisDiscrete(Qt::Orientation axis, qreal delta);
QMap<quint32, WaylandOutput> screens();
QVariant streams();
......
......@@ -38,6 +38,7 @@ namespace KWayland {
namespace Client {
class ConnectionThread;
class EventQueue;
class FakeInput;
class OutputDevice;
class Registry;
class RemoteAccessManager;
......@@ -62,6 +63,7 @@ public:
WaylandIntegrationPrivate();
~WaylandIntegrationPrivate();
void authenticate();
void initDrm();
void initEGL();
void initWayland();
......@@ -69,8 +71,15 @@ public:
bool isEGLInitialized() const;
void bindOutput(int outputName, int outputVersion);
bool startStreaming(const WaylandOutput &output);
bool startStreaming(quint32 outputName);
void stopStreaming();
void requestPointerButtonPress(quint32 linuxButton);
void requestPointerButtonRelease(quint32 linuxButton);
void requestPointerMotion(const QSizeF &delta);
void requestPointerMotionAbsolute(const QPointF &pos);
void requestPointerAxisDiscrete(Qt::Orientation axis, qreal delta);
QMap<quint32, WaylandOutput> screens();
QVariant streams();
......@@ -84,6 +93,7 @@ private:
bool m_eglInitialized;
bool m_streamingEnabled;
bool m_registryInitialized;
bool m_waylandAuthenticationRequested;
quint32 m_output;
QDateTime m_lastFrameTime;
......@@ -91,11 +101,14 @@ private:
QThread *m_thread;
QPoint m_streamedScreenPosition;
QMap<quint32, WaylandOutput> m_outputMap;
QList<KWayland::Client::Output*> m_bindOutputs;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::EventQueue *m_queue;
KWayland::Client::FakeInput *m_fakeInput;
KWayland::Client::Registry *m_registry;
KWayland::Client::RemoteAccessManager *m_remoteAccessManager;
......
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