2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2019 Aleix Pol Gonzalez <aleixpol@kde.org>
|
2019-06-21 14:02:27 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2019-06-21 14:02:27 +00:00
|
|
|
|
|
|
|
#include "keystate_interface.h"
|
|
|
|
#include "display.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QVector>
|
2020-06-26 17:58:13 +00:00
|
|
|
#include <qwayland-server-keystate.h>
|
2019-06-21 14:02:27 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
namespace KWaylandServer
|
2019-06-21 14:02:27 +00:00
|
|
|
{
|
|
|
|
|
2020-06-26 17:58:13 +00:00
|
|
|
static const quint32 s_version = 1;
|
|
|
|
|
|
|
|
class KeyStateInterfacePrivate : public QtWaylandServer::org_kde_kwin_keystate
|
2019-06-21 14:02:27 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-06-26 17:58:13 +00:00
|
|
|
KeyStateInterfacePrivate(Display *d)
|
|
|
|
: QtWaylandServer::org_kde_kwin_keystate(*d, s_version)
|
2019-06-21 14:02:27 +00:00
|
|
|
{}
|
|
|
|
|
2020-06-26 17:58:13 +00:00
|
|
|
void org_kde_kwin_keystate_fetchStates(Resource *resource) override {
|
|
|
|
for (int i = 0; i < m_keyStates.count(); ++i) {
|
|
|
|
send_stateChanged(resource->handle, i, m_keyStates[i]);
|
2019-06-21 14:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:58:13 +00:00
|
|
|
QVector<KeyStateInterface::State> m_keyStates = QVector<KeyStateInterface::State>(3, KeyStateInterface::Unlocked);
|
2019-06-21 14:02:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
KeyStateInterface::KeyStateInterface(Display* d, QObject* parent)
|
2020-06-26 17:58:13 +00:00
|
|
|
: QObject(parent)
|
|
|
|
, d(new KeyStateInterfacePrivate(d))
|
2019-06-21 14:02:27 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
KeyStateInterface::~KeyStateInterface() = default;
|
|
|
|
|
|
|
|
void KeyStateInterface::setState(KeyStateInterface::Key key, KeyStateInterface::State state)
|
|
|
|
{
|
2020-06-26 17:58:13 +00:00
|
|
|
d->m_keyStates[int(key)] = state;
|
2019-06-21 14:02:27 +00:00
|
|
|
|
2020-06-26 17:58:13 +00:00
|
|
|
for (auto r : d->resourceMap()) {
|
|
|
|
d->send_stateChanged(r->handle, int(key), int(state));
|
2019-06-22 12:56:52 +00:00
|
|
|
}
|
2019-06-21 14:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|