2014-11-25 12:39:24 +00:00
|
|
|
/********************************************************************
|
|
|
|
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) version 3, or any
|
|
|
|
later version accepted by the membership of KDE e.V. (or its
|
|
|
|
successor approved by the membership of KDE e.V.), which shall
|
|
|
|
act as a proxy defined in Section 6 of version 3 of the license.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "keyboard_interface.h"
|
2016-04-06 09:35:31 +00:00
|
|
|
#include "keyboard_interface_p.h"
|
2014-11-25 12:39:24 +00:00
|
|
|
#include "display.h"
|
|
|
|
#include "seat_interface.h"
|
|
|
|
#include "surface_interface.h"
|
|
|
|
// Qt
|
2014-11-26 14:00:44 +00:00
|
|
|
#include <QVector>
|
2014-11-25 12:39:24 +00:00
|
|
|
// Wayland
|
|
|
|
#include <wayland-server.h>
|
|
|
|
|
|
|
|
namespace KWayland
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Server
|
|
|
|
{
|
|
|
|
|
2014-11-26 14:28:47 +00:00
|
|
|
KeyboardInterface::Private::Private(SeatInterface *s, wl_resource *parentResource, KeyboardInterface *q)
|
|
|
|
: Resource::Private(q, s, parentResource, &wl_keyboard_interface, &s_interface)
|
|
|
|
, seat(s)
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-04-06 11:50:19 +00:00
|
|
|
void KeyboardInterface::Private::focusChildSurface(const QPointer<SurfaceInterface> &childSurface, quint32 serial)
|
|
|
|
{
|
|
|
|
if (focusedChildSurface == childSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sendLeave(focusedChildSurface.data(), serial);
|
|
|
|
focusedChildSurface = childSurface;
|
|
|
|
sendEnter(focusedChildSurface.data(), serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardInterface::Private::sendLeave(SurfaceInterface *surface, quint32 serial)
|
|
|
|
{
|
|
|
|
if (surface && resource && surface->resource()) {
|
|
|
|
wl_keyboard_send_leave(resource, serial, surface->resource());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardInterface::Private::sendEnter(SurfaceInterface *surface, quint32 serial)
|
|
|
|
{
|
|
|
|
wl_array keys;
|
|
|
|
wl_array_init(&keys);
|
|
|
|
const auto states = seat->pressedKeys();
|
|
|
|
for (auto it = states.begin(); it != states.end(); ++it) {
|
|
|
|
uint32_t *k = reinterpret_cast<uint32_t*>(wl_array_add(&keys, sizeof(uint32_t)));
|
|
|
|
*k = *it;
|
|
|
|
}
|
|
|
|
wl_keyboard_send_enter(resource, serial, surface->resource(), &keys);
|
|
|
|
wl_array_release(&keys);
|
|
|
|
|
|
|
|
sendModifiers();
|
|
|
|
}
|
|
|
|
|
2015-09-09 14:39:50 +00:00
|
|
|
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
2014-11-25 12:39:24 +00:00
|
|
|
const struct wl_keyboard_interface KeyboardInterface::Private::s_interface {
|
2016-06-28 15:02:22 +00:00
|
|
|
resourceDestroyedCallback
|
2014-11-25 12:39:24 +00:00
|
|
|
};
|
2015-09-09 14:39:50 +00:00
|
|
|
#endif
|
2014-11-25 12:39:24 +00:00
|
|
|
|
2014-11-26 14:28:47 +00:00
|
|
|
KeyboardInterface::KeyboardInterface(SeatInterface *parent, wl_resource *parentResource)
|
2016-05-19 13:17:07 +00:00
|
|
|
: Resource(new Private(parent, parentResource, this))
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-26 14:28:47 +00:00
|
|
|
KeyboardInterface::~KeyboardInterface() = default;
|
2014-11-25 12:39:24 +00:00
|
|
|
|
|
|
|
void KeyboardInterface::setKeymap(int fd, quint32 size)
|
|
|
|
{
|
2014-11-26 14:28:47 +00:00
|
|
|
Q_D();
|
2014-11-26 14:00:44 +00:00
|
|
|
d->sendKeymap(fd, size);
|
2014-11-25 12:39:24 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 14:00:44 +00:00
|
|
|
void KeyboardInterface::Private::sendKeymap(int fd, quint32 size)
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
2016-06-28 15:02:22 +00:00
|
|
|
if (!resource) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-26 14:00:44 +00:00
|
|
|
wl_keyboard_send_keymap(resource, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, fd, size);
|
2014-11-25 12:39:24 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 14:00:44 +00:00
|
|
|
void KeyboardInterface::Private::sendModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group, quint32 serial)
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
2016-06-28 15:02:22 +00:00
|
|
|
if (!resource) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-26 14:00:44 +00:00
|
|
|
wl_keyboard_send_modifiers(resource, serial, depressed, latched, locked, group);
|
2014-11-25 12:39:24 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 14:00:44 +00:00
|
|
|
void KeyboardInterface::Private::sendModifiers()
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
2014-11-26 14:00:44 +00:00
|
|
|
sendModifiers(seat->depressedModifiers(), seat->latchedModifiers(), seat->lockedModifiers(), seat->groupModifiers(), seat->lastModifiersSerial());
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardInterface::setFocusedSurface(SurfaceInterface *surface, quint32 serial)
|
|
|
|
{
|
2014-11-26 14:28:47 +00:00
|
|
|
Q_D();
|
2016-04-06 11:50:19 +00:00
|
|
|
d->sendLeave(d->focusedChildSurface, serial);
|
|
|
|
disconnect(d->destroyConnection);
|
|
|
|
d->focusedChildSurface.clear();
|
2014-11-26 14:00:44 +00:00
|
|
|
d->focusedSurface = surface;
|
|
|
|
if (!d->focusedSurface) {
|
2014-11-25 12:39:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-11-26 14:00:44 +00:00
|
|
|
d->destroyConnection = connect(d->focusedSurface, &QObject::destroyed, this,
|
|
|
|
[this] {
|
2014-11-26 14:28:47 +00:00
|
|
|
Q_D();
|
2014-11-26 14:00:44 +00:00
|
|
|
d->focusedSurface = nullptr;
|
2016-04-06 11:50:19 +00:00
|
|
|
d->focusedChildSurface.clear();
|
2014-11-26 14:00:44 +00:00
|
|
|
}
|
|
|
|
);
|
2016-04-06 11:50:19 +00:00
|
|
|
d->focusedChildSurface = QPointer<SurfaceInterface>(surface);
|
2014-11-25 12:39:24 +00:00
|
|
|
|
2016-04-06 11:50:19 +00:00
|
|
|
d->sendEnter(d->focusedSurface, serial);
|
2015-04-21 06:56:19 +00:00
|
|
|
d->client->flush();
|
2014-11-25 12:39:24 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 14:00:44 +00:00
|
|
|
void KeyboardInterface::keyPressed(quint32 key, quint32 serial)
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
2014-11-26 14:28:47 +00:00
|
|
|
Q_D();
|
2016-06-28 15:02:22 +00:00
|
|
|
if (!d->resource) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-26 14:00:44 +00:00
|
|
|
Q_ASSERT(d->focusedSurface);
|
|
|
|
wl_keyboard_send_key(d->resource, serial, d->seat->timestamp(), key, WL_KEYBOARD_KEY_STATE_PRESSED);
|
2014-11-25 12:39:24 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 14:00:44 +00:00
|
|
|
void KeyboardInterface::keyReleased(quint32 key, quint32 serial)
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
2014-11-26 14:28:47 +00:00
|
|
|
Q_D();
|
2016-06-28 15:02:22 +00:00
|
|
|
if (!d->resource) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-26 14:00:44 +00:00
|
|
|
Q_ASSERT(d->focusedSurface);
|
|
|
|
wl_keyboard_send_key(d->resource, serial, d->seat->timestamp(), key, WL_KEYBOARD_KEY_STATE_RELEASED);
|
2014-11-25 12:39:24 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 14:00:44 +00:00
|
|
|
void KeyboardInterface::updateModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group, quint32 serial)
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
2014-11-26 14:28:47 +00:00
|
|
|
Q_D();
|
2014-11-26 14:00:44 +00:00
|
|
|
Q_ASSERT(d->focusedSurface);
|
|
|
|
d->sendModifiers(depressed, latched, locked, group, serial);
|
2014-11-25 12:39:24 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 14:00:11 +00:00
|
|
|
void KeyboardInterface::repeatInfo(qint32 charactersPerSecond, qint32 delay)
|
|
|
|
{
|
|
|
|
Q_D();
|
2016-06-28 15:02:22 +00:00
|
|
|
if (!d->resource) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-02 14:14:16 +00:00
|
|
|
if (wl_resource_get_version(d->resource) < WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) {
|
2015-09-02 14:00:11 +00:00
|
|
|
// only supported since version 4
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wl_keyboard_send_repeat_info(d->resource, charactersPerSecond, delay);
|
|
|
|
}
|
|
|
|
|
2014-11-26 14:00:44 +00:00
|
|
|
SurfaceInterface *KeyboardInterface::focusedSurface() const
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
2014-11-26 14:28:47 +00:00
|
|
|
Q_D();
|
2014-11-26 14:00:44 +00:00
|
|
|
return d->focusedSurface;
|
2014-11-25 12:39:24 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 14:28:47 +00:00
|
|
|
KeyboardInterface::Private *KeyboardInterface::d_func() const
|
2014-11-25 12:39:24 +00:00
|
|
|
{
|
2014-11-26 14:28:47 +00:00
|
|
|
return reinterpret_cast<Private*>(d.data());
|
2014-11-25 12:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|