2014-09-02 07:34:31 +00:00
|
|
|
/********************************************************************
|
2014-09-17 13:57:56 +00:00
|
|
|
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-09-17 13:57:56 +00:00
|
|
|
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.
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-09-17 13:57:56 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
2014-09-02 07:34:31 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2014-09-17 13:57:56 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-09-17 13:57:56 +00:00
|
|
|
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/>.
|
2014-09-02 07:34:31 +00:00
|
|
|
*********************************************************************/
|
|
|
|
#include "seat_interface.h"
|
2014-11-13 14:07:31 +00:00
|
|
|
#include "global_p.h"
|
2014-09-02 07:34:31 +00:00
|
|
|
#include "display.h"
|
2014-11-25 12:39:24 +00:00
|
|
|
#include "keyboard_interface.h"
|
2014-11-25 12:52:40 +00:00
|
|
|
#include "pointer_interface.h"
|
2014-09-02 07:34:31 +00:00
|
|
|
#include "surface_interface.h"
|
2014-09-18 15:14:50 +00:00
|
|
|
// Qt
|
|
|
|
#include <QHash>
|
2014-11-26 09:34:23 +00:00
|
|
|
#include <QVector>
|
2014-09-18 15:14:50 +00:00
|
|
|
// Wayland
|
|
|
|
#include <wayland-server.h>
|
2014-09-02 09:11:26 +00:00
|
|
|
#ifndef WL_SEAT_NAME_SINCE_VERSION
|
|
|
|
#define WL_SEAT_NAME_SINCE_VERSION 2
|
|
|
|
#endif
|
2014-11-26 10:50:52 +00:00
|
|
|
// linux
|
|
|
|
#include <linux/input.h>
|
2014-09-02 09:11:26 +00:00
|
|
|
|
2014-09-17 14:10:38 +00:00
|
|
|
namespace KWayland
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
|
|
|
|
2014-09-17 14:10:38 +00:00
|
|
|
namespace Server
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
static const quint32 s_version = 3;
|
|
|
|
|
2014-11-13 14:07:31 +00:00
|
|
|
class SeatInterface::Private : public Global::Private
|
2014-09-18 14:35:28 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private(SeatInterface *q, Display *d);
|
2014-11-13 17:43:18 +00:00
|
|
|
void bind(wl_client *client, uint32_t version, uint32_t id) override;
|
2014-09-18 14:35:28 +00:00
|
|
|
void sendCapabilities(wl_resource *r);
|
|
|
|
void sendName(wl_resource *r);
|
2014-11-26 09:34:23 +00:00
|
|
|
PointerInterface *pointerForSurface(SurfaceInterface *surface) const;
|
2014-09-18 14:35:28 +00:00
|
|
|
|
|
|
|
QString name;
|
|
|
|
bool pointer = false;
|
|
|
|
bool keyboard = false;
|
|
|
|
bool touch = false;
|
|
|
|
QList<wl_resource*> resources;
|
2014-11-26 09:34:23 +00:00
|
|
|
struct FocusedPointer {
|
|
|
|
SurfaceInterface *surface = nullptr;
|
|
|
|
PointerInterface *pointer = nullptr;
|
|
|
|
QMetaObject::Connection destroyConnection;
|
|
|
|
QPointF offset = QPointF();
|
|
|
|
quint32 serial = 0;
|
|
|
|
};
|
|
|
|
FocusedPointer focusedPointer = FocusedPointer();
|
2014-11-13 14:07:31 +00:00
|
|
|
KeyboardInterface *keyboardInterface = nullptr;
|
2014-11-25 14:29:01 +00:00
|
|
|
quint32 timestamp = 0;
|
2014-11-26 09:34:23 +00:00
|
|
|
QVector<PointerInterface*> pointers;
|
2014-09-18 14:35:28 +00:00
|
|
|
|
2014-11-25 13:24:52 +00:00
|
|
|
// Pointer related members
|
|
|
|
QPointF pointerPos;
|
2014-11-26 10:50:52 +00:00
|
|
|
struct Pointer {
|
|
|
|
enum class ButtonState {
|
|
|
|
Released,
|
|
|
|
Pressed
|
|
|
|
};
|
|
|
|
QHash<quint32, quint32> buttonSerials;
|
|
|
|
QHash<quint32, ButtonState> buttonStates;
|
|
|
|
};
|
|
|
|
Pointer globalPointer;
|
|
|
|
void updatePointerButtonSerial(quint32 button, quint32 serial);
|
|
|
|
void updatePointerButtonState(quint32 button, Pointer::ButtonState state);
|
2014-11-25 13:24:52 +00:00
|
|
|
|
2014-11-05 14:29:18 +00:00
|
|
|
static SeatInterface *get(wl_resource *native) {
|
|
|
|
auto s = cast(native);
|
|
|
|
return s ? s->q : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
private:
|
2014-11-26 09:34:23 +00:00
|
|
|
void getPointer(wl_client *client, wl_resource *resource, uint32_t id);
|
2014-09-18 14:35:28 +00:00
|
|
|
static Private *cast(wl_resource *r);
|
|
|
|
static void unbind(wl_resource *r);
|
|
|
|
|
|
|
|
// interface
|
|
|
|
static void getPointerCallback(wl_client *client, wl_resource *resource, uint32_t id);
|
|
|
|
static void getKeyboardCallback(wl_client *client, wl_resource *resource, uint32_t id);
|
|
|
|
static void getTouchCallback(wl_client *client, wl_resource *resource, uint32_t id);
|
|
|
|
static const struct wl_seat_interface s_interface;
|
2014-11-05 14:29:18 +00:00
|
|
|
|
|
|
|
SeatInterface *q;
|
2014-09-18 14:35:28 +00:00
|
|
|
};
|
|
|
|
|
2014-11-13 14:07:31 +00:00
|
|
|
SeatInterface::Private::Private(SeatInterface *q, Display *display)
|
2014-11-13 17:43:18 +00:00
|
|
|
: Global::Private(display, &wl_seat_interface, s_version)
|
2014-11-05 14:29:18 +00:00
|
|
|
, q(q)
|
2014-09-18 14:35:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct wl_seat_interface SeatInterface::Private::s_interface = {
|
|
|
|
getPointerCallback,
|
|
|
|
getKeyboardCallback,
|
|
|
|
getTouchCallback
|
2014-09-02 07:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SeatInterface::SeatInterface(Display *display, QObject *parent)
|
2014-11-13 14:07:31 +00:00
|
|
|
: Global(new Private(this, display), parent)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-11-25 12:58:25 +00:00
|
|
|
d->keyboardInterface = new KeyboardInterface(this);
|
2014-09-02 07:34:31 +00:00
|
|
|
connect(this, &SeatInterface::nameChanged, this,
|
2014-11-13 14:07:31 +00:00
|
|
|
[this, d] {
|
2014-09-18 14:35:28 +00:00
|
|
|
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
|
|
|
|
d->sendName(*it);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2014-11-13 14:07:31 +00:00
|
|
|
auto sendCapabilitiesAll = [this, d] {
|
2014-09-18 14:35:28 +00:00
|
|
|
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
|
|
|
|
d->sendCapabilities(*it);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
connect(this, &SeatInterface::hasPointerChanged, this, sendCapabilitiesAll);
|
|
|
|
connect(this, &SeatInterface::hasKeyboardChanged, this, sendCapabilitiesAll);
|
|
|
|
connect(this, &SeatInterface::hasTouchChanged, this, sendCapabilitiesAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
SeatInterface::~SeatInterface()
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
while (!d->resources.isEmpty()) {
|
|
|
|
wl_resource_destroy(d->resources.takeLast());
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
void SeatInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
|
|
|
wl_resource *r = wl_resource_create(client, &wl_seat_interface, qMin(s_version, version), id);
|
|
|
|
if (!r) {
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-18 14:35:28 +00:00
|
|
|
resources << r;
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
wl_resource_set_implementation(r, &s_interface, this, unbind);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
sendCapabilities(r);
|
|
|
|
sendName(r);
|
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
void SeatInterface::Private::unbind(wl_resource *r)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2014-09-18 14:35:28 +00:00
|
|
|
cast(r)->resources.removeAll(r);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 10:50:52 +00:00
|
|
|
void SeatInterface::Private::updatePointerButtonSerial(quint32 button, quint32 serial)
|
|
|
|
{
|
|
|
|
auto it = globalPointer.buttonSerials.find(button);
|
|
|
|
if (it == globalPointer.buttonSerials.end()) {
|
|
|
|
globalPointer.buttonSerials.insert(button, serial);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
it.value() = serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::Private::updatePointerButtonState(quint32 button, Pointer::ButtonState state)
|
|
|
|
{
|
|
|
|
auto it = globalPointer.buttonStates.find(button);
|
|
|
|
if (it == globalPointer.buttonStates.end()) {
|
|
|
|
globalPointer.buttonStates.insert(button, state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
it.value() = state;
|
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
void SeatInterface::Private::sendName(wl_resource *r)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
|
|
|
if (wl_resource_get_version(r) < WL_SEAT_NAME_SINCE_VERSION) {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-18 14:35:28 +00:00
|
|
|
wl_seat_send_name(r, name.toUtf8().constData());
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
void SeatInterface::Private::sendCapabilities(wl_resource *r)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
|
|
|
uint32_t capabilities = 0;
|
2014-09-18 14:35:28 +00:00
|
|
|
if (pointer) {
|
2014-09-02 07:34:31 +00:00
|
|
|
capabilities |= WL_SEAT_CAPABILITY_POINTER;
|
|
|
|
}
|
2014-09-18 14:35:28 +00:00
|
|
|
if (keyboard) {
|
2014-09-02 07:34:31 +00:00
|
|
|
capabilities |= WL_SEAT_CAPABILITY_KEYBOARD;
|
|
|
|
}
|
2014-09-18 14:35:28 +00:00
|
|
|
if (touch) {
|
2014-09-02 07:34:31 +00:00
|
|
|
capabilities |= WL_SEAT_CAPABILITY_TOUCH;
|
|
|
|
}
|
|
|
|
wl_seat_send_capabilities(r, capabilities);
|
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
SeatInterface::Private *SeatInterface::Private::cast(wl_resource *r)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2014-11-05 14:29:18 +00:00
|
|
|
return r ? reinterpret_cast<SeatInterface::Private*>(wl_resource_get_user_data(r)) : nullptr;
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 09:34:23 +00:00
|
|
|
PointerInterface *SeatInterface::Private::pointerForSurface(SurfaceInterface *surface) const
|
|
|
|
{
|
|
|
|
if (!surface) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto it = pointers.begin(); it != pointers.end(); ++it) {
|
|
|
|
if (wl_resource_get_client((*it)->resource()) == *surface->client()) {
|
|
|
|
return (*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
void SeatInterface::setHasKeyboard(bool has)
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
if (d->keyboard == has) {
|
2014-09-02 07:34:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-18 14:35:28 +00:00
|
|
|
d->keyboard = has;
|
|
|
|
emit hasKeyboardChanged(d->keyboard);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setHasPointer(bool has)
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
if (d->pointer == has) {
|
2014-09-02 07:34:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-18 14:35:28 +00:00
|
|
|
d->pointer = has;
|
|
|
|
emit hasPointerChanged(d->pointer);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setHasTouch(bool has)
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
if (d->touch == has) {
|
2014-09-02 07:34:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-18 14:35:28 +00:00
|
|
|
d->touch = has;
|
|
|
|
emit hasTouchChanged(d->touch);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setName(const QString &name)
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
if (d->name == name) {
|
2014-09-02 07:34:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-18 14:35:28 +00:00
|
|
|
d->name = name;
|
|
|
|
emit nameChanged(d->name);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
void SeatInterface::Private::getPointerCallback(wl_client *client, wl_resource *resource, uint32_t id)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2014-11-26 09:34:23 +00:00
|
|
|
cast(resource)->getPointer(client, resource, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::Private::getPointer(wl_client *client, wl_resource *resource, uint32_t id)
|
|
|
|
{
|
|
|
|
// TODO: only create if seat has pointer?
|
2014-11-26 10:03:32 +00:00
|
|
|
PointerInterface *pointer = new PointerInterface(q, resource);
|
|
|
|
pointer->create(display->getConnection(client), wl_resource_get_version(resource), id);
|
|
|
|
if (!pointer->resource()) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
delete pointer;
|
|
|
|
return;
|
|
|
|
}
|
2014-11-26 09:34:23 +00:00
|
|
|
pointers << pointer;
|
|
|
|
if (focusedPointer.surface && focusedPointer.surface->client()->client() == client) {
|
|
|
|
// this is a pointer for the currently focused pointer surface
|
|
|
|
if (!focusedPointer.pointer) {
|
|
|
|
focusedPointer.pointer = pointer;
|
|
|
|
pointer->setFocusedSurface(focusedPointer.surface, focusedPointer.serial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QObject::connect(pointer, &QObject::destroyed, q,
|
|
|
|
[pointer,this] {
|
|
|
|
pointers.removeAt(pointers.indexOf(pointer));
|
|
|
|
if (focusedPointer.pointer == pointer) {
|
|
|
|
focusedPointer.pointer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
emit q->pointerCreated(pointer);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
void SeatInterface::Private::getKeyboardCallback(wl_client *client, wl_resource *resource, uint32_t id)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2014-09-18 14:35:28 +00:00
|
|
|
cast(resource)->keyboardInterface->createInterfae(client, resource, id);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
void SeatInterface::Private::getTouchCallback(wl_client *client, wl_resource *resource, uint32_t id)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
Q_UNUSED(id)
|
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
QString SeatInterface::name() const
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
return d->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::hasPointer() const
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
return d->pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::hasKeyboard() const
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
return d->keyboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::hasTouch() const
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
return d->touch;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyboardInterface *SeatInterface::keyboard()
|
|
|
|
{
|
2014-11-13 14:07:31 +00:00
|
|
|
Q_D();
|
2014-09-18 14:35:28 +00:00
|
|
|
return d->keyboardInterface;
|
|
|
|
}
|
|
|
|
|
2014-11-05 14:29:18 +00:00
|
|
|
SeatInterface *SeatInterface::get(wl_resource *native)
|
|
|
|
{
|
|
|
|
return Private::get(native);
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:07:31 +00:00
|
|
|
SeatInterface::Private *SeatInterface::d_func() const
|
|
|
|
{
|
|
|
|
return reinterpret_cast<Private*>(d.data());
|
|
|
|
}
|
|
|
|
|
2014-11-25 13:24:52 +00:00
|
|
|
QPointF SeatInterface::pointerPos() const
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
return d->pointerPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setPointerPos(const QPointF &pos)
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
if (d->pointerPos == pos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->pointerPos = pos;
|
|
|
|
emit pointerPosChanged(pos);
|
|
|
|
}
|
|
|
|
|
2014-11-25 14:29:01 +00:00
|
|
|
quint32 SeatInterface::timestamp() const
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
return d->timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setTimestamp(quint32 time)
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
if (d->timestamp == time) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->timestamp = time;
|
|
|
|
emit timestampChanged(time);
|
|
|
|
}
|
|
|
|
|
2014-11-25 14:54:28 +00:00
|
|
|
SurfaceInterface *SeatInterface::focusedPointerSurface() const
|
|
|
|
{
|
|
|
|
Q_D();
|
2014-11-26 09:34:23 +00:00
|
|
|
return d->focusedPointer.surface;
|
2014-11-25 14:54:28 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 09:34:23 +00:00
|
|
|
void SeatInterface::setFocusedPointerSurface(SurfaceInterface *surface, const QPointF &surfacePosition)
|
2014-11-25 14:54:28 +00:00
|
|
|
{
|
|
|
|
Q_D();
|
2014-11-26 09:34:23 +00:00
|
|
|
const quint32 serial = d->display->nextSerial();
|
|
|
|
if (d->focusedPointer.pointer) {
|
|
|
|
d->focusedPointer.pointer->setFocusedSurface(nullptr, serial);
|
|
|
|
}
|
|
|
|
if (d->focusedPointer.surface) {
|
|
|
|
disconnect(d->focusedPointer.destroyConnection);
|
|
|
|
}
|
|
|
|
d->focusedPointer = Private::FocusedPointer();
|
|
|
|
d->focusedPointer.surface = surface;
|
|
|
|
PointerInterface *p = d->pointerForSurface(surface);
|
|
|
|
d->focusedPointer.pointer = p;
|
|
|
|
if (d->focusedPointer.surface) {
|
|
|
|
d->focusedPointer.destroyConnection = connect(surface, &QObject::destroyed, this,
|
|
|
|
[this] {
|
|
|
|
Q_D();
|
|
|
|
d->focusedPointer = Private::FocusedPointer();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
d->focusedPointer.offset = surfacePosition;
|
|
|
|
d->focusedPointer.serial = serial;
|
|
|
|
}
|
|
|
|
if (!p) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p->setFocusedSurface(surface, serial);
|
2014-11-25 14:54:28 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 15:04:07 +00:00
|
|
|
PointerInterface *SeatInterface::focusedPointer() const
|
|
|
|
{
|
|
|
|
Q_D();
|
2014-11-26 09:34:23 +00:00
|
|
|
return d->focusedPointer.pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setFocusedPointerSurfacePosition(const QPointF &surfacePosition)
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
if (d->focusedPointer.surface) {
|
|
|
|
d->focusedPointer.offset = surfacePosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF SeatInterface::focusedPointerSurfacePosition() const
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
return d->focusedPointer.offset;
|
2014-11-25 15:04:07 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 10:50:52 +00:00
|
|
|
static quint32 qtToWaylandButton(Qt::MouseButton button)
|
|
|
|
{
|
|
|
|
static const QHash<Qt::MouseButton, quint32> s_buttons({
|
|
|
|
{Qt::LeftButton, BTN_LEFT},
|
|
|
|
{Qt::RightButton, BTN_RIGHT},
|
|
|
|
{Qt::MiddleButton, BTN_MIDDLE},
|
|
|
|
{Qt::ExtraButton1, BTN_BACK}, // note: QtWayland maps BTN_SIDE
|
|
|
|
{Qt::ExtraButton2, BTN_FORWARD}, // note: QtWayland maps BTN_EXTRA
|
|
|
|
{Qt::ExtraButton3, BTN_TASK}, // note: QtWayland maps BTN_FORWARD
|
|
|
|
{Qt::ExtraButton4, BTN_EXTRA}, // note: QtWayland maps BTN_BACK
|
|
|
|
{Qt::ExtraButton5, BTN_SIDE}, // note: QtWayland maps BTN_TASK
|
|
|
|
{Qt::ExtraButton6, BTN_TASK + 1},
|
|
|
|
{Qt::ExtraButton7, BTN_TASK + 2},
|
|
|
|
{Qt::ExtraButton8, BTN_TASK + 3},
|
|
|
|
{Qt::ExtraButton9, BTN_TASK + 4},
|
|
|
|
{Qt::ExtraButton10, BTN_TASK + 5},
|
|
|
|
{Qt::ExtraButton11, BTN_TASK + 6},
|
|
|
|
{Qt::ExtraButton12, BTN_TASK + 7},
|
|
|
|
{Qt::ExtraButton13, BTN_TASK + 8}
|
|
|
|
// further mapping not possible, 0x120 is BTN_JOYSTICK
|
|
|
|
});
|
|
|
|
return s_buttons.value(button, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool SeatInterface::isPointerButtonPressed(Qt::MouseButton button) const
|
|
|
|
{
|
|
|
|
return isPointerButtonPressed(qtToWaylandButton(button));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::isPointerButtonPressed(quint32 button) const
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
auto it = d->globalPointer.buttonStates.constFind(button);
|
|
|
|
if (it == d->globalPointer.buttonStates.constEnd()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return it.value() == Private::Pointer::ButtonState::Pressed ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::pointerAxis(Qt::Orientation orientation, quint32 delta)
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
if (d->focusedPointer.pointer && d->focusedPointer.surface) {
|
|
|
|
d->focusedPointer.pointer->axis(orientation, delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::pointerButtonPressed(Qt::MouseButton button)
|
|
|
|
{
|
|
|
|
const quint32 nativeButton = qtToWaylandButton(button);
|
|
|
|
if (nativeButton == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pointerButtonPressed(nativeButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::pointerButtonPressed(quint32 button)
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
const quint32 serial = d->display->nextSerial();
|
|
|
|
d->updatePointerButtonSerial(button, serial);
|
|
|
|
d->updatePointerButtonState(button, Private::Pointer::ButtonState::Pressed);
|
|
|
|
if (d->focusedPointer.pointer && d->focusedPointer.surface) {
|
|
|
|
d->focusedPointer.pointer->buttonPressed(button, serial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::pointerButtonReleased(Qt::MouseButton button)
|
|
|
|
{
|
|
|
|
const quint32 nativeButton = qtToWaylandButton(button);
|
|
|
|
if (nativeButton == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pointerButtonReleased(nativeButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::pointerButtonReleased(quint32 button)
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
const quint32 serial = d->display->nextSerial();
|
|
|
|
d->updatePointerButtonSerial(button, serial);
|
|
|
|
d->updatePointerButtonState(button, Private::Pointer::ButtonState::Released);
|
|
|
|
if (d->focusedPointer.pointer && d->focusedPointer.surface) {
|
|
|
|
d->focusedPointer.pointer->buttonReleased(button, serial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 SeatInterface::pointerButtonSerial(Qt::MouseButton button) const
|
|
|
|
{
|
|
|
|
return pointerButtonSerial(qtToWaylandButton(button));
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 SeatInterface::pointerButtonSerial(quint32 button) const
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
auto it = d->globalPointer.buttonSerials.constFind(button);
|
|
|
|
if (it == d->globalPointer.buttonSerials.constEnd()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return it.value();
|
|
|
|
}
|
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
}
|