From 9fc2f04c75eca527d3b29cd095b9788f9b2c7f4e Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sun, 31 Oct 2021 20:15:18 +0200 Subject: [PATCH] platforms/virtual: Port to InputDevice --- .../platforms/virtual/virtual_backend.cpp | 150 +++++++++++++++++- .../platforms/virtual/virtual_backend.h | 64 ++++++++ 2 files changed, 209 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/virtual/virtual_backend.cpp b/src/plugins/platforms/virtual/virtual_backend.cpp index 835e3f7957..2a78364624 100644 --- a/src/plugins/platforms/virtual/virtual_backend.cpp +++ b/src/plugins/platforms/virtual/virtual_backend.cpp @@ -14,8 +14,6 @@ #include "egl_gbm_backend.h" // Qt #include -// KWayland -#include // system #include #include @@ -24,10 +22,135 @@ namespace KWin { +VirtualInputDevice::VirtualInputDevice(QObject *parent) + : InputDevice(parent) +{ +} + +void VirtualInputDevice::setPointer(bool set) +{ + m_pointer = set; +} + +void VirtualInputDevice::setKeyboard(bool set) +{ + m_keyboard = set; +} + +void VirtualInputDevice::setTouch(bool set) +{ + m_touch = set; +} + +void VirtualInputDevice::setName(const QString &name) +{ + m_name = name; +} + +QString VirtualInputDevice::sysName() const +{ + return QString(); +} + +QString VirtualInputDevice::name() const +{ + return m_name; +} + +bool VirtualInputDevice::isEnabled() const +{ + return true; +} + +void VirtualInputDevice::setEnabled(bool enabled) +{ + Q_UNUSED(enabled) +} + +LEDs VirtualInputDevice::leds() const +{ + return LEDs(); +} + +void VirtualInputDevice::setLeds(LEDs leds) +{ + Q_UNUSED(leds) +} + +bool VirtualInputDevice::isKeyboard() const +{ + return m_keyboard; +} + +bool VirtualInputDevice::isAlphaNumericKeyboard() const +{ + return m_keyboard; +} + +bool VirtualInputDevice::isPointer() const +{ + return m_pointer; +} + +bool VirtualInputDevice::isTouchpad() const +{ + return false; +} + +bool VirtualInputDevice::isTouch() const +{ + return m_touch; +} + +bool VirtualInputDevice::isTabletTool() const +{ + return false; +} + +bool VirtualInputDevice::isTabletPad() const +{ + return false; +} + +bool VirtualInputDevice::isTabletModeSwitch() const +{ + return false; +} + +bool VirtualInputDevice::isLidSwitch() const +{ + return false; +} + +VirtualInputBackend::VirtualInputBackend(VirtualBackend *backend, QObject *parent) + : InputBackend(parent) + , m_backend(backend) +{ +} + +void VirtualInputBackend::initialize() +{ + Q_EMIT deviceAdded(m_backend->virtualPointer()); + Q_EMIT deviceAdded(m_backend->virtualKeyboard()); + Q_EMIT deviceAdded(m_backend->virtualTouch()); +} + VirtualBackend::VirtualBackend(QObject *parent) : Platform(parent) , m_session(Session::create(Session::Type::Noop, this)) { + m_virtualKeyboard.reset(new VirtualInputDevice()); + m_virtualKeyboard->setName(QStringLiteral("Virtual Keyboard 1")); + m_virtualKeyboard->setKeyboard(true); + + m_virtualPointer.reset(new VirtualInputDevice()); + m_virtualPointer->setName(QStringLiteral("Virtual Pointer 1")); + m_virtualPointer->setPointer(true); + + m_virtualTouch.reset(new VirtualInputDevice()); + m_virtualTouch->setName(QStringLiteral("Virtual Touch 1")); + m_virtualTouch->setTouch(true); + if (qEnvironmentVariableIsSet("KWIN_WAYLAND_VIRTUAL_SCREENSHOTS")) { m_screenshotDir.reset(new QTemporaryDir); if (!m_screenshotDir->isValid()) { @@ -75,14 +198,26 @@ bool VirtualBackend::initialize() setSoftwareCursorForced(true); setReady(true); - waylandServer()->seat()->setHasPointer(true); - waylandServer()->seat()->setHasKeyboard(true); - waylandServer()->seat()->setHasTouch(true); Q_EMIT screensQueried(); return true; } +VirtualInputDevice *VirtualBackend::virtualPointer() const +{ + return m_virtualPointer.data(); +} + +VirtualInputDevice *VirtualBackend::virtualKeyboard() const +{ + return m_virtualKeyboard.data(); +} + +VirtualInputDevice *VirtualBackend::virtualTouch() const +{ + return m_virtualTouch.data(); +} + QString VirtualBackend::screenshotDirPath() const { if (m_screenshotDir.isNull()) { @@ -91,6 +226,11 @@ QString VirtualBackend::screenshotDirPath() const return m_screenshotDir->path(); } +InputBackend *VirtualBackend::createInputBackend() +{ + return new VirtualInputBackend(this); +} + QPainterBackend *VirtualBackend::createQPainterBackend() { return new VirtualQPainterBackend(this); diff --git a/src/plugins/platforms/virtual/virtual_backend.h b/src/plugins/platforms/virtual/virtual_backend.h index 330bdbe808..1875f82b76 100644 --- a/src/plugins/platforms/virtual/virtual_backend.h +++ b/src/plugins/platforms/virtual/virtual_backend.h @@ -8,6 +8,9 @@ */ #ifndef KWIN_VIRTUAL_BACKEND_H #define KWIN_VIRTUAL_BACKEND_H + +#include "inputbackend.h" +#include "inputdevice.h" #include "platform.h" #include @@ -19,8 +22,60 @@ class QTemporaryDir; namespace KWin { +class VirtualBackend; class VirtualOutput; +class VirtualInputDevice : public InputDevice +{ + Q_OBJECT + +public: + explicit VirtualInputDevice(QObject *parent = nullptr); + + void setPointer(bool set); + void setKeyboard(bool set); + void setTouch(bool set); + void setName(const QString &name); + + QString sysName() const override; + QString name() const override; + + bool isEnabled() const override; + void setEnabled(bool enabled) override; + + LEDs leds() const override; + void setLeds(LEDs leds) override; + + bool isKeyboard() const override; + bool isAlphaNumericKeyboard() const override; + bool isPointer() const override; + bool isTouchpad() const override; + bool isTouch() const override; + bool isTabletTool() const override; + bool isTabletPad() const override; + bool isTabletModeSwitch() const override; + bool isLidSwitch() const override; + +private: + QString m_name; + bool m_pointer = false; + bool m_keyboard = false; + bool m_touch = false; +}; + +class VirtualInputBackend : public InputBackend +{ + Q_OBJECT + +public: + explicit VirtualInputBackend(VirtualBackend *backend, QObject *parent = nullptr); + + void initialize() override; + +private: + VirtualBackend *m_backend; +}; + class KWIN_EXPORT VirtualBackend : public Platform { Q_OBJECT @@ -39,6 +94,11 @@ public: } QString screenshotDirPath() const; + VirtualInputDevice *virtualPointer() const; + VirtualInputDevice *virtualKeyboard() const; + VirtualInputDevice *virtualTouch() const; + + InputBackend *createInputBackend() override; QPainterBackend* createQPainterBackend() override; OpenGLBackend *createOpenGLBackend() override; @@ -66,6 +126,10 @@ private: QVector m_outputsEnabled; QScopedPointer m_screenshotDir; Session *m_session; + + QScopedPointer m_virtualPointer; + QScopedPointer m_virtualKeyboard; + QScopedPointer m_virtualTouch; }; }