platforms/virtual: Port to InputDevice

This commit is contained in:
Vlad Zahorodnii 2021-10-31 20:15:18 +02:00
parent 69bca8cf71
commit 9fc2f04c75
2 changed files with 209 additions and 5 deletions

View file

@ -14,8 +14,6 @@
#include "egl_gbm_backend.h"
// Qt
#include <QTemporaryDir>
// KWayland
#include <KWaylandServer/seat_interface.h>
// system
#include <fcntl.h>
#include <unistd.h>
@ -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);

View file

@ -8,6 +8,9 @@
*/
#ifndef KWIN_VIRTUAL_BACKEND_H
#define KWIN_VIRTUAL_BACKEND_H
#include "inputbackend.h"
#include "inputdevice.h"
#include "platform.h"
#include <kwin_export.h>
@ -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<VirtualOutput*> m_outputsEnabled;
QScopedPointer<QTemporaryDir> m_screenshotDir;
Session *m_session;
QScopedPointer<VirtualInputDevice> m_virtualPointer;
QScopedPointer<VirtualInputDevice> m_virtualKeyboard;
QScopedPointer<VirtualInputDevice> m_virtualTouch;
};
}