2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2020-05-12 11:26:57 +00:00
|
|
|
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
2021-02-13 15:40:56 +00:00
|
|
|
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2014-09-02 07:34:31 +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
|
|
|
|
*/
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "seat.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "abstract_data_source.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "datacontroldevice_v1.h"
|
|
|
|
#include "datacontrolsource_v1.h"
|
|
|
|
#include "datadevice.h"
|
|
|
|
#include "datadevice_p.h"
|
|
|
|
#include "datasource.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "display.h"
|
|
|
|
#include "display_p.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "keyboard.h"
|
|
|
|
#include "keyboard_p.h"
|
|
|
|
#include "pointer.h"
|
|
|
|
#include "pointer_p.h"
|
|
|
|
#include "pointerconstraints_v1.h"
|
|
|
|
#include "pointergestures_v1_p.h"
|
|
|
|
#include "primaryselectiondevice_v1.h"
|
|
|
|
#include "primaryselectionsource_v1.h"
|
|
|
|
#include "relativepointer_v1_p.h"
|
|
|
|
#include "seat_p.h"
|
|
|
|
#include "surface.h"
|
|
|
|
#include "textinput_v1_p.h"
|
|
|
|
#include "textinput_v2_p.h"
|
|
|
|
#include "textinput_v3_p.h"
|
|
|
|
#include "touch_p.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "utils/common.h"
|
2023-09-29 08:46:16 +00:00
|
|
|
#include "utils/resource.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "xdgtopleveldrag_v1.h"
|
2021-12-17 08:31:42 +00:00
|
|
|
|
2014-11-26 10:50:52 +00:00
|
|
|
#include <linux/input.h>
|
2014-09-02 09:11:26 +00:00
|
|
|
|
2016-11-07 14:03:40 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
namespace KWin
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2023-01-18 16:35:34 +00:00
|
|
|
static const int s_version = 9;
|
2021-02-13 15:40:56 +00:00
|
|
|
|
|
|
|
SeatInterfacePrivate *SeatInterfacePrivate::get(SeatInterface *seat)
|
|
|
|
{
|
2022-08-01 21:29:02 +00:00
|
|
|
return seat->d.get();
|
2021-02-13 15:40:56 +00:00
|
|
|
}
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
SeatInterfacePrivate::SeatInterfacePrivate(SeatInterface *q, Display *display)
|
|
|
|
: QtWaylandServer::wl_seat(*display, s_version)
|
2014-11-05 14:29:18 +00:00
|
|
|
, q(q)
|
2021-02-13 15:40:56 +00:00
|
|
|
, display(display)
|
2014-09-18 14:35:28 +00:00
|
|
|
{
|
2023-01-07 20:56:49 +00:00
|
|
|
textInputV1 = new TextInputV1Interface(q);
|
2020-07-28 15:39:13 +00:00
|
|
|
textInputV2 = new TextInputV2Interface(q);
|
2020-09-15 07:27:46 +00:00
|
|
|
textInputV3 = new TextInputV3Interface(q);
|
2023-02-09 11:54:56 +00:00
|
|
|
pointer.reset(new PointerInterface(q));
|
|
|
|
keyboard.reset(new KeyboardInterface(q));
|
|
|
|
touch.reset(new TouchInterface(q));
|
2014-09-18 14:35:28 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::seat_bind_resource(Resource *resource)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
send_capabilities(resource->handle, capabilities);
|
2020-12-09 20:13:19 +00:00
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
if (resource->version() >= WL_SEAT_NAME_SINCE_VERSION) {
|
|
|
|
send_name(resource->handle, name);
|
|
|
|
}
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::seat_get_pointer(Resource *resource, uint32_t id)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2023-02-09 11:54:56 +00:00
|
|
|
PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer.get());
|
|
|
|
pointerPrivate->add(resource->client(), id, resource->version());
|
2021-02-13 15:40:56 +00:00
|
|
|
}
|
2020-12-09 20:13:19 +00:00
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::seat_get_keyboard(Resource *resource, uint32_t id)
|
|
|
|
{
|
2023-02-09 11:54:56 +00:00
|
|
|
KeyboardInterfacePrivate *keyboardPrivate = KeyboardInterfacePrivate::get(keyboard.get());
|
|
|
|
keyboardPrivate->add(resource->client(), id, resource->version());
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::seat_get_touch(Resource *resource, uint32_t id)
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2023-02-09 11:54:56 +00:00
|
|
|
TouchInterfacePrivate *touchPrivate = TouchInterfacePrivate::get(touch.get());
|
|
|
|
touchPrivate->add(resource->client(), id, resource->version());
|
2021-02-13 15:40:56 +00:00
|
|
|
}
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::seat_release(Resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy(resource->handle);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
SeatInterface::SeatInterface(Display *display, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, d(new SeatInterfacePrivate(this, display))
|
2014-09-02 07:34:31 +00:00
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
DisplayPrivate *displayPrivate = DisplayPrivate::get(d->display);
|
|
|
|
displayPrivate->seats.append(this);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
SeatInterface::~SeatInterface()
|
2018-02-01 16:46:53 +00:00
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
if (d->display) {
|
|
|
|
DisplayPrivate *displayPrivate = DisplayPrivate::get(d->display);
|
|
|
|
displayPrivate->seats.removeOne(this);
|
|
|
|
}
|
2018-02-01 16:46:53 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::updatePointerButtonSerial(quint32 button, quint32 serial)
|
2014-11-26 10:50:52 +00:00
|
|
|
{
|
|
|
|
auto it = globalPointer.buttonSerials.find(button);
|
|
|
|
if (it == globalPointer.buttonSerials.end()) {
|
|
|
|
globalPointer.buttonSerials.insert(button, serial);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
it.value() = serial;
|
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::updatePointerButtonState(quint32 button, Pointer::State state)
|
2014-11-26 10:50:52 +00:00
|
|
|
{
|
|
|
|
auto it = globalPointer.buttonStates.find(button);
|
|
|
|
if (it == globalPointer.buttonStates.end()) {
|
|
|
|
globalPointer.buttonStates.insert(button, state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
it.value() = state;
|
|
|
|
}
|
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<DataDeviceInterface *> SeatInterfacePrivate::dataDevicesForSurface(SurfaceInterface *surface) const
|
2014-11-27 12:38:24 +00:00
|
|
|
{
|
2020-10-26 17:59:50 +00:00
|
|
|
if (!surface) {
|
|
|
|
return {};
|
|
|
|
}
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<DataDeviceInterface *> primarySelectionDevices;
|
2020-06-25 15:27:52 +00:00
|
|
|
for (auto it = dataDevices.constBegin(); it != dataDevices.constEnd(); ++it) {
|
|
|
|
if ((*it)->client() == *surface->client()) {
|
|
|
|
primarySelectionDevices << *it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return primarySelectionDevices;
|
2014-11-27 12:38:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::registerDataDevice(DataDeviceInterface *dataDevice)
|
2014-11-27 12:38:24 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(dataDevice->seat() == q);
|
|
|
|
dataDevices << dataDevice;
|
2016-06-14 12:46:39 +00:00
|
|
|
auto dataDeviceCleanup = [this, dataDevice] {
|
|
|
|
dataDevices.removeOne(dataDevice);
|
2020-10-02 14:22:59 +00:00
|
|
|
globalKeyboard.focus.selections.removeOne(dataDevice);
|
2016-06-14 12:46:39 +00:00
|
|
|
};
|
|
|
|
QObject::connect(dataDevice, &QObject::destroyed, q, dataDeviceCleanup);
|
2021-08-29 05:11:06 +00:00
|
|
|
QObject::connect(dataDevice, &DataDeviceInterface::selectionChanged, q, [this, dataDevice] {
|
|
|
|
updateSelection(dataDevice);
|
|
|
|
});
|
2021-09-03 12:27:16 +00:00
|
|
|
QObject::connect(dataDevice,
|
|
|
|
&DataDeviceInterface::dragStarted,
|
|
|
|
q,
|
|
|
|
[this](AbstractDataSource *source, SurfaceInterface *origin, quint32 serial, DragAndDropIcon *dragIcon) {
|
|
|
|
q->startDrag(source, origin, serial, dragIcon);
|
|
|
|
});
|
2014-11-27 12:38:24 +00:00
|
|
|
// is the new DataDevice for the current keyoard focus?
|
2020-10-02 14:22:59 +00:00
|
|
|
if (globalKeyboard.focus.surface) {
|
2014-11-27 12:38:24 +00:00
|
|
|
// same client?
|
2020-10-02 14:22:59 +00:00
|
|
|
if (*globalKeyboard.focus.surface->client() == dataDevice->client()) {
|
|
|
|
globalKeyboard.focus.selections.append(dataDevice);
|
2020-05-18 13:43:38 +00:00
|
|
|
if (currentSelection) {
|
2014-11-27 12:38:24 +00:00
|
|
|
dataDevice->sendSelection(currentSelection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
AbstractDropHandler *SeatInterface::dropHandlerForSurface(SurfaceInterface *surface) const
|
2021-09-03 12:43:06 +00:00
|
|
|
{
|
|
|
|
auto list = d->dataDevicesForSurface(surface);
|
|
|
|
if (list.isEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
return list.first();
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:09:27 +00:00
|
|
|
void SeatInterface::cancelDrag()
|
|
|
|
{
|
|
|
|
if (d->drag.mode != SeatInterfacePrivate::Drag::Mode::None) {
|
|
|
|
// cancel the drag, don't drop. serial does not matter
|
|
|
|
d->cancelDrag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::registerDataControlDevice(DataControlDeviceV1Interface *dataDevice)
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(dataDevice->seat() == q);
|
|
|
|
dataControlDevices << dataDevice;
|
|
|
|
auto dataDeviceCleanup = [this, dataDevice] {
|
|
|
|
dataControlDevices.removeOne(dataDevice);
|
|
|
|
};
|
|
|
|
QObject::connect(dataDevice, &QObject::destroyed, q, dataDeviceCleanup);
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
QObject::connect(dataDevice, &DataControlDeviceV1Interface::selectionChanged, q, [this, dataDevice] {
|
2020-08-04 11:58:43 +00:00
|
|
|
// Special klipper workaround to avoid a race
|
|
|
|
// If the mimetype x-kde-onlyReplaceEmpty is set, and we've had another update in the meantime, do nothing
|
2023-01-20 10:25:08 +00:00
|
|
|
// but resend selection to mimic normal event flow upon cancel and not confuse the client
|
2020-08-04 11:58:43 +00:00
|
|
|
// See https://github.com/swaywm/wlr-protocols/issues/92
|
2021-08-29 05:11:06 +00:00
|
|
|
if (dataDevice->selection() && dataDevice->selection()->mimeTypes().contains(QLatin1String("application/x-kde-onlyReplaceEmpty")) && currentSelection) {
|
2020-08-04 11:58:43 +00:00
|
|
|
dataDevice->selection()->cancel();
|
2023-01-20 10:25:08 +00:00
|
|
|
dataDevice->sendSelection(currentSelection);
|
2020-08-04 11:58:43 +00:00
|
|
|
return;
|
2020-05-12 11:26:57 +00:00
|
|
|
}
|
2020-08-04 11:58:43 +00:00
|
|
|
q->setSelection(dataDevice->selection());
|
2021-08-29 05:11:06 +00:00
|
|
|
});
|
2020-05-12 11:26:57 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
QObject::connect(dataDevice, &DataControlDeviceV1Interface::primarySelectionChanged, q, [this, dataDevice] {
|
2021-08-10 12:29:35 +00:00
|
|
|
// Special klipper workaround to avoid a race
|
|
|
|
// If the mimetype x-kde-onlyReplaceEmpty is set, and we've had another update in the meantime, do nothing
|
2023-01-20 10:25:08 +00:00
|
|
|
// but resend selection to mimic normal event flow upon cancel and not confuse the client
|
2021-08-10 12:29:35 +00:00
|
|
|
// See https://github.com/swaywm/wlr-protocols/issues/92
|
2021-09-10 11:27:52 +00:00
|
|
|
if (dataDevice->primarySelection() && dataDevice->primarySelection()->mimeTypes().contains(QLatin1String("application/x-kde-onlyReplaceEmpty"))
|
2021-08-29 05:11:06 +00:00
|
|
|
&& currentPrimarySelection) {
|
2021-08-10 12:29:35 +00:00
|
|
|
dataDevice->primarySelection()->cancel();
|
2023-01-20 10:25:08 +00:00
|
|
|
dataDevice->sendPrimarySelection(currentPrimarySelection);
|
2021-08-10 12:29:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
q->setPrimarySelection(dataDevice->primarySelection());
|
2021-08-29 05:11:06 +00:00
|
|
|
});
|
2021-08-10 12:29:35 +00:00
|
|
|
|
2023-08-10 08:13:48 +00:00
|
|
|
dataDevice->sendSelection(currentSelection);
|
|
|
|
dataDevice->sendPrimarySelection(currentPrimarySelection);
|
2020-05-12 11:26:57 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::registerPrimarySelectionDevice(PrimarySelectionDeviceV1Interface *primarySelectionDevice)
|
2020-06-01 22:29:53 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(primarySelectionDevice->seat() == q);
|
|
|
|
|
|
|
|
primarySelectionDevices << primarySelectionDevice;
|
|
|
|
auto dataDeviceCleanup = [this, primarySelectionDevice] {
|
|
|
|
primarySelectionDevices.removeOne(primarySelectionDevice);
|
2020-10-02 14:22:59 +00:00
|
|
|
globalKeyboard.focus.primarySelections.removeOne(primarySelectionDevice);
|
2020-06-01 22:29:53 +00:00
|
|
|
};
|
|
|
|
QObject::connect(primarySelectionDevice, &QObject::destroyed, q, dataDeviceCleanup);
|
2021-08-29 05:11:06 +00:00
|
|
|
QObject::connect(primarySelectionDevice, &PrimarySelectionDeviceV1Interface::selectionChanged, q, [this, primarySelectionDevice] {
|
|
|
|
updatePrimarySelection(primarySelectionDevice);
|
|
|
|
});
|
2020-06-01 22:29:53 +00:00
|
|
|
// is the new DataDevice for the current keyoard focus?
|
2020-10-02 14:22:59 +00:00
|
|
|
if (globalKeyboard.focus.surface) {
|
2020-06-01 22:29:53 +00:00
|
|
|
// same client?
|
2020-10-02 14:22:59 +00:00
|
|
|
if (*globalKeyboard.focus.surface->client() == primarySelectionDevice->client()) {
|
|
|
|
globalKeyboard.focus.primarySelections.append(primarySelectionDevice);
|
2020-06-01 22:29:53 +00:00
|
|
|
if (currentPrimarySelection) {
|
|
|
|
primarySelectionDevice->sendSelection(currentPrimarySelection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 11:26:57 +00:00
|
|
|
|
2022-03-03 09:09:27 +00:00
|
|
|
void SeatInterfacePrivate::cancelDrag()
|
2020-11-11 13:59:49 +00:00
|
|
|
{
|
|
|
|
if (drag.target) {
|
2022-03-03 09:09:27 +00:00
|
|
|
drag.target->updateDragTarget(nullptr, 0);
|
2020-11-11 13:59:49 +00:00
|
|
|
drag.target = nullptr;
|
|
|
|
}
|
2023-03-31 11:52:20 +00:00
|
|
|
QObject::disconnect(drag.dragSourceDestroyConnection);
|
|
|
|
if (drag.source) {
|
|
|
|
drag.source->dndCancelled();
|
|
|
|
}
|
|
|
|
drag = Drag();
|
|
|
|
Q_EMIT q->dragSurfaceChanged();
|
|
|
|
Q_EMIT q->dragEnded();
|
2020-11-11 13:59:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 09:09:27 +00:00
|
|
|
void SeatInterfacePrivate::endDrag()
|
2016-03-01 06:49:04 +00:00
|
|
|
{
|
2018-01-27 13:12:41 +00:00
|
|
|
QObject::disconnect(drag.dragSourceDestroyConnection);
|
2020-10-28 11:58:25 +00:00
|
|
|
|
2021-09-03 12:43:06 +00:00
|
|
|
AbstractDropHandler *dragTargetDevice = drag.target.data();
|
2021-09-03 12:27:16 +00:00
|
|
|
AbstractDataSource *dragSource = drag.source;
|
2023-02-09 08:40:13 +00:00
|
|
|
|
2020-10-28 11:58:25 +00:00
|
|
|
if (dragSource) {
|
|
|
|
// TODO: Also check the current drag-and-drop action.
|
2020-10-29 08:29:30 +00:00
|
|
|
if (dragTargetDevice && dragSource->isAccepted()) {
|
2021-06-02 13:06:42 +00:00
|
|
|
Q_EMIT q->dragDropped();
|
2020-10-29 08:29:30 +00:00
|
|
|
dragTargetDevice->drop();
|
2020-10-28 11:58:25 +00:00
|
|
|
dragSource->dropPerformed();
|
|
|
|
} else {
|
2023-03-31 11:52:20 +00:00
|
|
|
dragSource->dropPerformed();
|
2021-09-10 13:44:02 +00:00
|
|
|
dragSource->dndCancelled();
|
2020-10-28 11:58:25 +00:00
|
|
|
}
|
2017-11-26 15:31:57 +00:00
|
|
|
}
|
2020-10-28 11:58:25 +00:00
|
|
|
|
2020-10-29 08:29:30 +00:00
|
|
|
if (dragTargetDevice) {
|
2022-03-03 09:09:27 +00:00
|
|
|
dragTargetDevice->updateDragTarget(nullptr, 0);
|
2020-10-29 08:29:30 +00:00
|
|
|
}
|
2020-10-28 11:58:25 +00:00
|
|
|
|
2016-03-01 06:49:04 +00:00
|
|
|
drag = Drag();
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->dragSurfaceChanged();
|
|
|
|
Q_EMIT q->dragEnded();
|
2016-03-01 06:49:04 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::updateSelection(DataDeviceInterface *dataDevice)
|
2016-10-10 08:43:15 +00:00
|
|
|
{
|
2023-03-03 11:19:06 +00:00
|
|
|
DataSourceInterface *selection = dataDevice->selection();
|
2020-05-18 13:43:38 +00:00
|
|
|
// if the update is from the focussed window we should inform the active client
|
2020-10-02 14:22:59 +00:00
|
|
|
if (!(globalKeyboard.focus.surface && (*globalKeyboard.focus.surface->client() == dataDevice->client()))) {
|
2023-03-03 11:19:06 +00:00
|
|
|
if (selection) {
|
|
|
|
selection->cancel();
|
|
|
|
}
|
2016-10-10 08:43:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-03-03 11:19:06 +00:00
|
|
|
q->setSelection(selection);
|
2014-11-27 12:38:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::updatePrimarySelection(PrimarySelectionDeviceV1Interface *primarySelectionDevice)
|
2020-06-01 22:29:53 +00:00
|
|
|
{
|
2023-03-03 11:19:06 +00:00
|
|
|
PrimarySelectionSourceV1Interface *selection = primarySelectionDevice->selection();
|
2020-06-01 22:29:53 +00:00
|
|
|
// if the update is from the focussed window we should inform the active client
|
2020-10-02 14:22:59 +00:00
|
|
|
if (!(globalKeyboard.focus.surface && (*globalKeyboard.focus.surface->client() == primarySelectionDevice->client()))) {
|
2023-03-03 11:19:06 +00:00
|
|
|
if (selection) {
|
|
|
|
selection->cancel();
|
|
|
|
}
|
2020-06-01 22:29:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-03-03 11:19:06 +00:00
|
|
|
q->setPrimarySelection(selection);
|
2020-06-01 22:29:53 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
void SeatInterfacePrivate::sendCapabilities()
|
|
|
|
{
|
|
|
|
const auto seatResources = resourceMap();
|
|
|
|
for (SeatInterfacePrivate::Resource *resource : seatResources) {
|
|
|
|
send_capabilities(resource->handle, capabilities);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
void SeatInterface::setHasKeyboard(bool has)
|
|
|
|
{
|
2023-02-09 11:54:56 +00:00
|
|
|
if (hasKeyboard() == has) {
|
2014-09-02 07:34:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-02 14:22:59 +00:00
|
|
|
if (has) {
|
2021-02-13 15:40:56 +00:00
|
|
|
d->capabilities |= SeatInterfacePrivate::capability_keyboard;
|
2020-10-02 14:22:59 +00:00
|
|
|
} else {
|
2021-02-13 15:40:56 +00:00
|
|
|
d->capabilities &= ~SeatInterfacePrivate::capability_keyboard;
|
2020-10-02 14:22:59 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
d->sendCapabilities();
|
2023-02-09 11:54:56 +00:00
|
|
|
Q_EMIT hasKeyboardChanged(has);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setHasPointer(bool has)
|
|
|
|
{
|
2023-02-09 11:54:56 +00:00
|
|
|
if (hasPointer() == has) {
|
2014-09-02 07:34:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
if (has) {
|
2021-02-13 15:40:56 +00:00
|
|
|
d->capabilities |= SeatInterfacePrivate::capability_pointer;
|
2021-02-12 22:29:45 +00:00
|
|
|
} else {
|
2021-02-13 15:40:56 +00:00
|
|
|
d->capabilities &= ~SeatInterfacePrivate::capability_pointer;
|
2021-02-12 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
d->sendCapabilities();
|
2023-02-09 11:54:56 +00:00
|
|
|
Q_EMIT hasPointerChanged(has);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setHasTouch(bool has)
|
|
|
|
{
|
2023-02-09 11:54:56 +00:00
|
|
|
if (hasTouch() == has) {
|
2014-09-02 07:34:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-12 23:53:06 +00:00
|
|
|
if (has) {
|
2021-02-13 15:40:56 +00:00
|
|
|
d->capabilities |= SeatInterfacePrivate::capability_touch;
|
2021-02-12 23:53:06 +00:00
|
|
|
} else {
|
2021-02-13 15:40:56 +00:00
|
|
|
d->capabilities &= ~SeatInterfacePrivate::capability_touch;
|
2021-02-12 23:53:06 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
d->sendCapabilities();
|
2023-02-09 11:54:56 +00:00
|
|
|
Q_EMIT hasTouchChanged(has);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setName(const QString &name)
|
|
|
|
{
|
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;
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
const auto seatResources = d->resourceMap();
|
|
|
|
for (SeatInterfacePrivate::Resource *resource : seatResources) {
|
|
|
|
if (resource->version() >= WL_SEAT_NAME_SINCE_VERSION) {
|
|
|
|
d->send_name(resource->handle, d->name);
|
|
|
|
}
|
2014-11-26 14:28:47 +00:00
|
|
|
}
|
2020-10-02 14:22:59 +00:00
|
|
|
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT nameChanged(d->name);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 14:35:28 +00:00
|
|
|
QString SeatInterface::name() const
|
|
|
|
{
|
|
|
|
return d->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::hasPointer() const
|
|
|
|
{
|
2023-02-09 11:54:56 +00:00
|
|
|
return d->capabilities & SeatInterfacePrivate::capability_pointer;
|
2014-09-18 14:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::hasKeyboard() const
|
|
|
|
{
|
2023-02-09 11:54:56 +00:00
|
|
|
return d->capabilities & SeatInterfacePrivate::capability_keyboard;
|
2014-09-18 14:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::hasTouch() const
|
|
|
|
{
|
2023-02-09 11:54:56 +00:00
|
|
|
return d->capabilities & SeatInterfacePrivate::capability_touch;
|
2014-09-18 14:35:28 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
Display *SeatInterface::display() const
|
2014-11-05 14:29:18 +00:00
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
return d->display;
|
2014-11-05 14:29:18 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
SeatInterface *SeatInterface::get(wl_resource *native)
|
2014-11-13 14:07:31 +00:00
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
if (SeatInterfacePrivate *seatPrivate = resource_cast<SeatInterfacePrivate *>(native)) {
|
|
|
|
return seatPrivate->q;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2014-11-13 14:07:31 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 13:24:52 +00:00
|
|
|
QPointF SeatInterface::pointerPos() const
|
|
|
|
{
|
2014-11-26 10:57:10 +00:00
|
|
|
return d->globalPointer.pos;
|
2014-11-25 13:24:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
void SeatInterface::notifyPointerMotion(const QPointF &pos)
|
2014-11-25 13:24:52 +00:00
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-26 10:57:10 +00:00
|
|
|
if (d->globalPointer.pos == pos) {
|
2014-11-25 13:24:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-11-26 10:57:10 +00:00
|
|
|
d->globalPointer.pos = pos;
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT pointerPosChanged(pos);
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
SurfaceInterface *focusedSurface = focusedPointerSurface();
|
|
|
|
if (!focusedSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isDragPointer()) {
|
2021-09-03 12:27:16 +00:00
|
|
|
// data device will handle it directly
|
|
|
|
// for xwayland cases we still want to send pointer events
|
|
|
|
if (!d->dataDevicesForSurface(focusedSurface).isEmpty())
|
2021-02-12 22:29:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (focusedSurface->lockedPointer() && focusedSurface->lockedPointer()->isLocked()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF localPosition = focusedPointerSurfaceTransformation().map(pos);
|
|
|
|
SurfaceInterface *effectiveFocusedSurface = focusedSurface->inputSurfaceAt(localPosition);
|
|
|
|
if (!effectiveFocusedSurface) {
|
|
|
|
effectiveFocusedSurface = focusedSurface;
|
|
|
|
}
|
|
|
|
if (focusedSurface != effectiveFocusedSurface) {
|
|
|
|
localPosition = focusedSurface->mapToChild(effectiveFocusedSurface, localPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->pointer->focusedSurface() != effectiveFocusedSurface) {
|
2022-02-23 19:03:51 +00:00
|
|
|
d->pointer->sendEnter(effectiveFocusedSurface, localPosition, display()->nextSerial());
|
2022-08-09 02:10:45 +00:00
|
|
|
if (d->keyboard) {
|
|
|
|
d->keyboard->setModifierFocusSurface(effectiveFocusedSurface);
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
d->pointer->sendMotion(localPosition);
|
2014-11-25 13:24:52 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
std::chrono::milliseconds SeatInterface::timestamp() const
|
2014-11-25 14:29:01 +00:00
|
|
|
{
|
|
|
|
return d->timestamp;
|
|
|
|
}
|
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
void SeatInterface::setTimestamp(std::chrono::microseconds time)
|
2014-11-25 14:29:01 +00:00
|
|
|
{
|
2022-12-21 00:55:20 +00:00
|
|
|
const auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(time);
|
|
|
|
if (d->timestamp == milliseconds) {
|
2014-11-25 14:29:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-12-21 00:55:20 +00:00
|
|
|
d->timestamp = milliseconds;
|
|
|
|
Q_EMIT timestampChanged();
|
2014-11-25 14:29:01 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 12:43:06 +00:00
|
|
|
void SeatInterface::setDragTarget(AbstractDropHandler *dropTarget,
|
|
|
|
SurfaceInterface *surface,
|
|
|
|
const QPointF &globalPosition,
|
|
|
|
const QMatrix4x4 &inputTransformation)
|
2016-03-01 06:49:04 +00:00
|
|
|
{
|
|
|
|
if (surface == d->drag.surface) {
|
|
|
|
// no change
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const quint32 serial = d->display->nextSerial();
|
|
|
|
if (d->drag.target) {
|
|
|
|
d->drag.target->updateDragTarget(nullptr, serial);
|
|
|
|
}
|
2020-05-18 08:18:24 +00:00
|
|
|
|
2020-05-18 10:59:17 +00:00
|
|
|
// TODO: technically we can have mulitple data devices
|
2020-05-18 08:18:24 +00:00
|
|
|
// and we should send the drag to all of them, but that seems overly complicated
|
|
|
|
// in practice so far the only case for mulitple data devices is for clipboard overriding
|
2021-09-03 12:43:06 +00:00
|
|
|
d->drag.target = dropTarget;
|
2020-05-18 08:18:24 +00:00
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) {
|
2021-03-11 08:24:47 +00:00
|
|
|
notifyPointerMotion(globalPosition);
|
|
|
|
notifyPointerFrame();
|
2021-08-29 05:11:06 +00:00
|
|
|
} else if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Touch && d->globalTouch.focus.firstTouchPos != globalPosition) {
|
2021-03-11 08:24:47 +00:00
|
|
|
notifyTouchMotion(d->globalTouch.ids.first(), globalPosition);
|
2016-03-01 06:49:04 +00:00
|
|
|
}
|
2022-04-25 14:07:34 +00:00
|
|
|
|
2016-03-01 06:49:04 +00:00
|
|
|
if (d->drag.target) {
|
2022-07-19 11:36:05 +00:00
|
|
|
QMatrix4x4 surfaceInputTransformation = inputTransformation;
|
|
|
|
surfaceInputTransformation.scale(surface->scaleOverride());
|
2016-03-01 06:49:04 +00:00
|
|
|
d->drag.surface = surface;
|
2022-04-25 14:07:34 +00:00
|
|
|
d->drag.transformation = surfaceInputTransformation;
|
2016-03-01 06:49:04 +00:00
|
|
|
d->drag.target->updateDragTarget(surface, serial);
|
|
|
|
} else {
|
|
|
|
d->drag.surface = nullptr;
|
|
|
|
}
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT dragSurfaceChanged();
|
2016-03-01 06:49:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-03 12:43:06 +00:00
|
|
|
void SeatInterface::setDragTarget(AbstractDropHandler *target, SurfaceInterface *surface, const QMatrix4x4 &inputTransformation)
|
2016-03-01 06:49:04 +00:00
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) {
|
2021-09-03 12:43:06 +00:00
|
|
|
setDragTarget(target, surface, pointerPos(), inputTransformation);
|
2018-09-12 01:33:07 +00:00
|
|
|
} else {
|
2021-02-13 15:40:56 +00:00
|
|
|
Q_ASSERT(d->drag.mode == SeatInterfacePrivate::Drag::Mode::Touch);
|
2021-09-03 12:43:06 +00:00
|
|
|
setDragTarget(target, surface, d->globalTouch.focus.firstTouchPos, inputTransformation);
|
2018-09-12 01:33:07 +00:00
|
|
|
}
|
2016-03-01 06:49:04 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 14:54:28 +00:00
|
|
|
SurfaceInterface *SeatInterface::focusedPointerSurface() const
|
|
|
|
{
|
2014-11-26 14:42:33 +00:00
|
|
|
return d->globalPointer.focus.surface;
|
2014-11-25 14:54:28 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
void SeatInterface::notifyPointerEnter(SurfaceInterface *surface, const QPointF &position, const QPointF &surfacePosition)
|
2015-12-07 10:45:34 +00:00
|
|
|
{
|
|
|
|
QMatrix4x4 m;
|
|
|
|
m.translate(-surfacePosition.x(), -surfacePosition.y());
|
2022-02-23 19:03:51 +00:00
|
|
|
notifyPointerEnter(surface, position, m);
|
2015-12-07 10:45:34 +00:00
|
|
|
if (d->globalPointer.focus.surface) {
|
|
|
|
d->globalPointer.focus.offset = surfacePosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
void SeatInterface::notifyPointerEnter(SurfaceInterface *surface, const QPointF &position, const QMatrix4x4 &transformation)
|
2014-11-25 14:54:28 +00:00
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-13 15:40:56 +00:00
|
|
|
if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) {
|
2016-03-01 06:49:04 +00:00
|
|
|
// ignore
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
2014-11-26 09:34:23 +00:00
|
|
|
const quint32 serial = d->display->nextSerial();
|
2021-02-12 22:29:45 +00:00
|
|
|
|
2014-11-26 14:42:33 +00:00
|
|
|
if (d->globalPointer.focus.surface) {
|
|
|
|
disconnect(d->globalPointer.focus.destroyConnection);
|
2014-11-26 09:34:23 +00:00
|
|
|
}
|
2021-02-13 15:40:56 +00:00
|
|
|
d->globalPointer.focus = SeatInterfacePrivate::Pointer::Focus();
|
2014-11-26 14:42:33 +00:00
|
|
|
d->globalPointer.focus.surface = surface;
|
2022-02-23 19:03:51 +00:00
|
|
|
d->globalPointer.focus.destroyConnection = connect(surface, &QObject::destroyed, this, [this] {
|
|
|
|
d->globalPointer.focus = SeatInterfacePrivate::Pointer::Focus();
|
|
|
|
});
|
|
|
|
d->globalPointer.focus.serial = serial;
|
|
|
|
d->globalPointer.focus.transformation = transformation;
|
|
|
|
d->globalPointer.focus.offset = QPointF();
|
|
|
|
|
|
|
|
d->globalPointer.pos = position;
|
|
|
|
QPointF localPosition = focusedPointerSurfaceTransformation().map(position);
|
|
|
|
SurfaceInterface *effectiveFocusedSurface = surface->inputSurfaceAt(localPosition);
|
|
|
|
if (!effectiveFocusedSurface) {
|
|
|
|
effectiveFocusedSurface = surface;
|
|
|
|
}
|
|
|
|
if (surface != effectiveFocusedSurface) {
|
|
|
|
localPosition = surface->mapToChild(effectiveFocusedSurface, localPosition);
|
2014-11-26 09:34:23 +00:00
|
|
|
}
|
2022-02-23 19:03:51 +00:00
|
|
|
d->pointer->sendEnter(effectiveFocusedSurface, localPosition, serial);
|
2022-08-09 02:10:45 +00:00
|
|
|
if (d->keyboard) {
|
|
|
|
d->keyboard->setModifierFocusSurface(effectiveFocusedSurface);
|
|
|
|
}
|
2022-02-23 19:03:51 +00:00
|
|
|
}
|
2014-11-25 14:54:28 +00:00
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
void SeatInterface::notifyPointerLeave()
|
|
|
|
{
|
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) {
|
|
|
|
// ignore
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->globalPointer.focus.surface) {
|
|
|
|
disconnect(d->globalPointer.focus.destroyConnection);
|
2016-10-11 06:04:27 +00:00
|
|
|
}
|
2022-02-23 19:03:51 +00:00
|
|
|
d->globalPointer.focus = SeatInterfacePrivate::Pointer::Focus();
|
|
|
|
|
|
|
|
const quint32 serial = d->display->nextSerial();
|
|
|
|
d->pointer->sendLeave(serial);
|
2022-08-09 02:10:45 +00:00
|
|
|
if (d->keyboard) {
|
|
|
|
d->keyboard->setModifierFocusSurface(nullptr);
|
|
|
|
}
|
2014-11-26 09:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setFocusedPointerSurfacePosition(const QPointF &surfacePosition)
|
|
|
|
{
|
2014-11-26 14:42:33 +00:00
|
|
|
if (d->globalPointer.focus.surface) {
|
|
|
|
d->globalPointer.focus.offset = surfacePosition;
|
2015-12-07 10:45:34 +00:00
|
|
|
d->globalPointer.focus.transformation = QMatrix4x4();
|
|
|
|
d->globalPointer.focus.transformation.translate(-surfacePosition.x(), -surfacePosition.y());
|
2014-11-26 09:34:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF SeatInterface::focusedPointerSurfacePosition() const
|
|
|
|
{
|
2014-11-26 14:42:33 +00:00
|
|
|
return d->globalPointer.focus.offset;
|
2014-11-25 15:04:07 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 10:45:34 +00:00
|
|
|
void SeatInterface::setFocusedPointerSurfaceTransformation(const QMatrix4x4 &transformation)
|
|
|
|
{
|
|
|
|
if (d->globalPointer.focus.surface) {
|
|
|
|
d->globalPointer.focus.transformation = transformation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix4x4 SeatInterface::focusedPointerSurfaceTransformation() const
|
|
|
|
{
|
|
|
|
return d->globalPointer.focus.transformation;
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
PointerInterface *SeatInterface::pointer() const
|
|
|
|
{
|
2022-08-01 21:29:02 +00:00
|
|
|
return d->pointer.get();
|
2021-02-12 22:29:45 +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},
|
2021-08-29 05:11:06 +00:00
|
|
|
{Qt::ExtraButton1, BTN_BACK}, // note: QtWayland maps BTN_SIDE
|
2014-11-26 10:50:52 +00:00
|
|
|
{Qt::ExtraButton2, BTN_FORWARD}, // note: QtWayland maps BTN_EXTRA
|
2021-08-29 05:11:06 +00:00
|
|
|
{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
|
2014-11-26 10:50:52 +00:00
|
|
|
{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);
|
2015-09-02 14:20:10 +00:00
|
|
|
}
|
2014-11-26 10:50:52 +00:00
|
|
|
|
|
|
|
bool SeatInterface::isPointerButtonPressed(Qt::MouseButton button) const
|
|
|
|
{
|
|
|
|
return isPointerButtonPressed(qtToWaylandButton(button));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::isPointerButtonPressed(quint32 button) const
|
|
|
|
{
|
|
|
|
auto it = d->globalPointer.buttonStates.constFind(button);
|
|
|
|
if (it == d->globalPointer.buttonStates.constEnd()) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-13 15:40:56 +00:00
|
|
|
return it.value() == SeatInterfacePrivate::Pointer::State::Pressed;
|
2014-11-26 10:50:52 +00:00
|
|
|
}
|
|
|
|
|
2023-01-18 16:35:34 +00:00
|
|
|
void SeatInterface::notifyPointerAxis(Qt::Orientation orientation, qreal delta, qint32 deltaV120, PointerAxisSource source, PointerAxisRelativeDirection direction)
|
2019-02-11 16:35:23 +00:00
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-13 15:40:56 +00:00
|
|
|
if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) {
|
2019-02-11 16:35:23 +00:00
|
|
|
// ignore
|
|
|
|
return;
|
|
|
|
}
|
2023-01-18 16:35:34 +00:00
|
|
|
d->pointer->sendAxis(orientation, delta, deltaV120, source, direction);
|
2014-11-26 10:50:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 17:58:39 +00:00
|
|
|
void SeatInterface::notifyPointerButton(Qt::MouseButton button, PointerButtonState state)
|
2014-11-26 10:50:52 +00:00
|
|
|
{
|
|
|
|
const quint32 nativeButton = qtToWaylandButton(button);
|
|
|
|
if (nativeButton == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-15 17:58:39 +00:00
|
|
|
notifyPointerButton(nativeButton, state);
|
2014-11-26 10:50:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 17:58:39 +00:00
|
|
|
void SeatInterface::notifyPointerButton(quint32 button, PointerButtonState state)
|
2014-11-26 10:50:52 +00:00
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-26 10:50:52 +00:00
|
|
|
const quint32 serial = d->display->nextSerial();
|
2021-02-12 22:29:45 +00:00
|
|
|
|
2021-03-15 17:58:39 +00:00
|
|
|
if (state == PointerButtonState::Pressed) {
|
|
|
|
d->updatePointerButtonSerial(button, serial);
|
|
|
|
d->updatePointerButtonState(button, SeatInterfacePrivate::Pointer::State::Pressed);
|
|
|
|
if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) {
|
|
|
|
// ignore
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const quint32 currentButtonSerial = pointerButtonSerial(button);
|
|
|
|
d->updatePointerButtonSerial(button, serial);
|
|
|
|
d->updatePointerButtonState(button, SeatInterfacePrivate::Pointer::State::Released);
|
|
|
|
if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) {
|
2021-09-03 12:27:16 +00:00
|
|
|
if (d->drag.dragImplicitGrabSerial != currentButtonSerial) {
|
2021-03-15 17:58:39 +00:00
|
|
|
// not our drag button - ignore
|
|
|
|
return;
|
|
|
|
}
|
2023-04-07 22:14:27 +00:00
|
|
|
d->pointer->sendButton(button, state, serial);
|
2022-03-03 09:09:27 +00:00
|
|
|
d->endDrag();
|
2021-03-15 17:58:39 +00:00
|
|
|
return;
|
2016-04-06 11:50:19 +00:00
|
|
|
}
|
2014-11-26 10:50:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 17:58:39 +00:00
|
|
|
d->pointer->sendButton(button, state, serial);
|
2021-02-12 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
void SeatInterface::notifyPointerFrame()
|
2021-02-12 22:29:45 +00:00
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
d->pointer->sendFrame();
|
2014-11-26 10:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
quint32 SeatInterface::pointerButtonSerial(Qt::MouseButton button) const
|
|
|
|
{
|
|
|
|
return pointerButtonSerial(qtToWaylandButton(button));
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 SeatInterface::pointerButtonSerial(quint32 button) const
|
|
|
|
{
|
|
|
|
auto it = d->globalPointer.buttonSerials.constFind(button);
|
|
|
|
if (it == d->globalPointer.buttonSerials.constEnd()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return it.value();
|
|
|
|
}
|
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
void SeatInterface::relativePointerMotion(const QPointF &delta, const QPointF &deltaNonAccelerated, std::chrono::microseconds time)
|
2016-10-07 07:07:34 +00:00
|
|
|
{
|
2021-03-15 16:53:24 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
auto relativePointer = RelativePointerV1Interface::get(pointer());
|
|
|
|
if (relativePointer) {
|
2022-12-21 00:55:20 +00:00
|
|
|
relativePointer->sendRelativeMotion(delta, deltaNonAccelerated, time);
|
2016-10-07 07:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 08:27:14 +00:00
|
|
|
void SeatInterface::startPointerSwipeGesture(quint32 fingerCount)
|
|
|
|
{
|
2021-03-15 16:53:24 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
auto swipeGesture = PointerSwipeGestureV1Interface::get(pointer());
|
|
|
|
if (swipeGesture) {
|
|
|
|
swipeGesture->sendBegin(d->display->nextSerial(), fingerCount);
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-25 08:18:45 +00:00
|
|
|
void SeatInterface::updatePointerSwipeGesture(const QPointF &delta)
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-03-15 16:53:24 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
auto swipeGesture = PointerSwipeGestureV1Interface::get(pointer());
|
|
|
|
if (swipeGesture) {
|
|
|
|
swipeGesture->sendUpdate(delta);
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::endPointerSwipeGesture()
|
|
|
|
{
|
2021-03-15 16:53:24 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
auto swipeGesture = PointerSwipeGestureV1Interface::get(pointer());
|
|
|
|
if (swipeGesture) {
|
|
|
|
swipeGesture->sendEnd(d->display->nextSerial());
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::cancelPointerSwipeGesture()
|
|
|
|
{
|
2021-03-15 16:53:24 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
auto swipeGesture = PointerSwipeGestureV1Interface::get(pointer());
|
|
|
|
if (swipeGesture) {
|
|
|
|
swipeGesture->sendCancel(d->display->nextSerial());
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::startPointerPinchGesture(quint32 fingerCount)
|
|
|
|
{
|
2021-03-15 16:53:24 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
auto pinchGesture = PointerPinchGestureV1Interface::get(pointer());
|
|
|
|
if (pinchGesture) {
|
|
|
|
pinchGesture->sendBegin(d->display->nextSerial(), fingerCount);
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-25 08:18:45 +00:00
|
|
|
void SeatInterface::updatePointerPinchGesture(const QPointF &delta, qreal scale, qreal rotation)
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-03-15 16:53:24 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
auto pinchGesture = PointerPinchGestureV1Interface::get(pointer());
|
|
|
|
if (pinchGesture) {
|
|
|
|
pinchGesture->sendUpdate(delta, scale, rotation);
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::endPointerPinchGesture()
|
|
|
|
{
|
2021-03-15 16:53:24 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
auto pinchGesture = PointerPinchGestureV1Interface::get(pointer());
|
|
|
|
if (pinchGesture) {
|
|
|
|
pinchGesture->sendEnd(d->display->nextSerial());
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::cancelPointerPinchGesture()
|
|
|
|
{
|
2021-03-15 16:53:24 +00:00
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
auto pinchGesture = PointerPinchGestureV1Interface::get(pointer());
|
|
|
|
if (pinchGesture) {
|
|
|
|
pinchGesture->sendCancel(d->display->nextSerial());
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-05 08:21:29 +00:00
|
|
|
void SeatInterface::startPointerHoldGesture(quint32 fingerCount)
|
|
|
|
{
|
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto holdGesture = PointerHoldGestureV1Interface::get(pointer());
|
|
|
|
if (holdGesture) {
|
|
|
|
holdGesture->sendBegin(d->display->nextSerial(), fingerCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::endPointerHoldGesture()
|
|
|
|
{
|
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto holdGesture = PointerHoldGestureV1Interface::get(pointer());
|
|
|
|
if (holdGesture) {
|
|
|
|
holdGesture->sendEnd(d->display->nextSerial());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::cancelPointerHoldGesture()
|
|
|
|
{
|
|
|
|
if (!d->pointer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto holdGesture = PointerHoldGestureV1Interface::get(pointer());
|
|
|
|
if (holdGesture) {
|
|
|
|
holdGesture->sendCancel(d->display->nextSerial());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-26 14:00:44 +00:00
|
|
|
SurfaceInterface *SeatInterface::focusedKeyboardSurface() const
|
|
|
|
{
|
2020-10-02 14:22:59 +00:00
|
|
|
return d->globalKeyboard.focus.surface;
|
2014-11-26 14:00:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setFocusedKeyboardSurface(SurfaceInterface *surface)
|
|
|
|
{
|
2020-10-02 14:22:59 +00:00
|
|
|
if (!d->keyboard) {
|
|
|
|
return;
|
2014-11-26 14:00:44 +00:00
|
|
|
}
|
2020-10-02 14:22:59 +00:00
|
|
|
|
2022-01-27 19:14:53 +00:00
|
|
|
Q_EMIT focusedKeyboardSurfaceAboutToChange(surface);
|
2020-10-02 14:22:59 +00:00
|
|
|
const quint32 serial = d->display->nextSerial();
|
|
|
|
|
|
|
|
if (d->globalKeyboard.focus.surface) {
|
|
|
|
disconnect(d->globalKeyboard.focus.destroyConnection);
|
2014-11-26 14:00:44 +00:00
|
|
|
}
|
2021-02-13 15:40:56 +00:00
|
|
|
d->globalKeyboard.focus = SeatInterfacePrivate::Keyboard::Focus();
|
2020-10-02 14:22:59 +00:00
|
|
|
d->globalKeyboard.focus.surface = surface;
|
2021-03-29 17:27:42 +00:00
|
|
|
|
|
|
|
d->keyboard->setFocusedSurface(surface, serial);
|
|
|
|
|
2020-10-02 14:22:59 +00:00
|
|
|
if (d->globalKeyboard.focus.surface) {
|
2021-02-13 15:40:56 +00:00
|
|
|
d->globalKeyboard.focus.destroyConnection = connect(surface, &QObject::destroyed, this, [this]() {
|
|
|
|
d->globalKeyboard.focus = SeatInterfacePrivate::Keyboard::Focus();
|
|
|
|
});
|
2020-10-02 14:22:59 +00:00
|
|
|
d->globalKeyboard.focus.serial = serial;
|
2014-11-27 12:38:24 +00:00
|
|
|
// selection?
|
2023-10-19 06:50:15 +00:00
|
|
|
const QList<DataDeviceInterface *> dataDevices = d->dataDevicesForSurface(surface);
|
2020-10-02 14:22:59 +00:00
|
|
|
d->globalKeyboard.focus.selections = dataDevices;
|
2020-05-18 08:18:24 +00:00
|
|
|
for (auto dataDevice : dataDevices) {
|
2022-12-09 09:05:44 +00:00
|
|
|
dataDevice->sendSelection(d->currentSelection);
|
2014-11-27 12:38:24 +00:00
|
|
|
}
|
2020-06-01 22:29:53 +00:00
|
|
|
// primary selection
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<PrimarySelectionDeviceV1Interface *> primarySelectionDevices;
|
2020-06-01 22:29:53 +00:00
|
|
|
for (auto it = d->primarySelectionDevices.constBegin(); it != d->primarySelectionDevices.constEnd(); ++it) {
|
|
|
|
if ((*it)->client() == *surface->client()) {
|
|
|
|
primarySelectionDevices << *it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 14:22:59 +00:00
|
|
|
d->globalKeyboard.focus.primarySelections = primarySelectionDevices;
|
2020-06-01 22:29:53 +00:00
|
|
|
for (auto primaryDataDevice : primarySelectionDevices) {
|
2022-12-09 09:05:44 +00:00
|
|
|
primaryDataDevice->sendSelection(d->currentPrimarySelection);
|
2020-06-01 22:29:53 +00:00
|
|
|
}
|
2014-11-26 14:00:44 +00:00
|
|
|
}
|
2020-10-02 14:22:59 +00:00
|
|
|
|
2016-05-02 12:28:26 +00:00
|
|
|
// focused text input surface follows keyboard
|
|
|
|
if (hasKeyboard()) {
|
|
|
|
setFocusedTextInputSurface(surface);
|
2014-11-26 14:00:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 14:22:59 +00:00
|
|
|
KeyboardInterface *SeatInterface::keyboard() const
|
2014-11-26 14:00:44 +00:00
|
|
|
{
|
2022-08-01 21:29:02 +00:00
|
|
|
return d->keyboard.get();
|
2014-11-26 14:00:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 09:50:52 +00:00
|
|
|
void SeatInterface::notifyKeyboardKey(quint32 keyCode, KeyboardKeyState state)
|
|
|
|
{
|
|
|
|
if (!d->keyboard) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->keyboard->sendKey(keyCode, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::notifyKeyboardModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group)
|
|
|
|
{
|
|
|
|
if (!d->keyboard) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->keyboard->sendModifiers(depressed, latched, locked, group);
|
|
|
|
}
|
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
void SeatInterface::notifyTouchCancel()
|
2015-03-25 12:31:38 +00:00
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->touch) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 23:53:06 +00:00
|
|
|
d->touch->sendCancel();
|
|
|
|
|
2021-02-13 15:40:56 +00:00
|
|
|
if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Touch) {
|
2020-11-11 13:59:49 +00:00
|
|
|
// cancel the drag, don't drop. serial does not matter
|
2022-03-03 09:09:27 +00:00
|
|
|
d->cancelDrag();
|
2018-09-12 01:33:07 +00:00
|
|
|
}
|
2018-09-18 20:15:14 +00:00
|
|
|
d->globalTouch.ids.clear();
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface *SeatInterface::focusedTouchSurface() const
|
|
|
|
{
|
2018-09-18 20:15:14 +00:00
|
|
|
return d->globalTouch.focus.surface;
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPointF SeatInterface::focusedTouchSurfacePosition() const
|
|
|
|
{
|
2018-09-18 20:15:14 +00:00
|
|
|
return d->globalTouch.focus.offset;
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::isTouchSequence() const
|
|
|
|
{
|
2018-09-18 20:15:14 +00:00
|
|
|
return !d->globalTouch.ids.isEmpty();
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 23:53:06 +00:00
|
|
|
TouchInterface *SeatInterface::touch() const
|
|
|
|
{
|
2022-08-01 21:29:02 +00:00
|
|
|
return d->touch.get();
|
2021-02-12 23:53:06 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 14:53:13 +00:00
|
|
|
QPointF SeatInterface::firstTouchPointPosition() const
|
|
|
|
{
|
|
|
|
return d->globalTouch.focus.firstTouchPos;
|
|
|
|
}
|
|
|
|
|
2015-03-25 12:31:38 +00:00
|
|
|
void SeatInterface::setFocusedTouchSurface(SurfaceInterface *surface, const QPointF &surfacePosition)
|
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->touch) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-25 12:31:38 +00:00
|
|
|
if (isTouchSequence()) {
|
|
|
|
// changing surface not allowed during a touch sequence
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 23:53:06 +00:00
|
|
|
if (isDragTouch()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-18 20:15:14 +00:00
|
|
|
if (d->globalTouch.focus.surface) {
|
|
|
|
disconnect(d->globalTouch.focus.destroyConnection);
|
2015-06-13 22:52:55 +00:00
|
|
|
}
|
2021-02-13 15:40:56 +00:00
|
|
|
d->globalTouch.focus = SeatInterfacePrivate::Touch::Focus();
|
2018-09-18 20:15:14 +00:00
|
|
|
d->globalTouch.focus.surface = surface;
|
2021-10-26 11:32:05 +00:00
|
|
|
setFocusedTouchSurfacePosition(surfacePosition);
|
|
|
|
|
2018-09-18 20:15:14 +00:00
|
|
|
if (d->globalTouch.focus.surface) {
|
2021-02-12 23:53:06 +00:00
|
|
|
d->globalTouch.focus.destroyConnection = connect(surface, &QObject::destroyed, this, [this]() {
|
|
|
|
if (isTouchSequence()) {
|
|
|
|
// Surface destroyed during touch sequence - send a cancel
|
|
|
|
d->touch->sendCancel();
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
2021-02-13 15:40:56 +00:00
|
|
|
d->globalTouch.focus = SeatInterfacePrivate::Touch::Focus();
|
2021-02-12 23:53:06 +00:00
|
|
|
});
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeatInterface::setFocusedTouchSurfacePosition(const QPointF &surfacePosition)
|
|
|
|
{
|
2018-09-18 20:15:14 +00:00
|
|
|
d->globalTouch.focus.offset = surfacePosition;
|
2021-10-26 11:32:05 +00:00
|
|
|
d->globalTouch.focus.transformation = QMatrix4x4();
|
|
|
|
d->globalTouch.focus.transformation.translate(-surfacePosition.x(), -surfacePosition.y());
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
void SeatInterface::notifyTouchDown(qint32 id, const QPointF &globalPosition)
|
2015-03-25 12:31:38 +00:00
|
|
|
{
|
2022-07-21 22:04:53 +00:00
|
|
|
if (!d->touch || !focusedTouchSurface()) {
|
2021-03-15 16:12:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-09-18 20:15:14 +00:00
|
|
|
const qint32 serial = display()->nextSerial();
|
2022-07-21 22:04:53 +00:00
|
|
|
auto pos = globalPosition - d->globalTouch.focus.offset;
|
|
|
|
|
|
|
|
SurfaceInterface *effectiveFocusedSurface = focusedTouchSurface()->inputSurfaceAt(pos);
|
|
|
|
if (effectiveFocusedSurface && effectiveFocusedSurface != focusedTouchSurface()) {
|
|
|
|
pos = focusedTouchSurface()->mapToChild(effectiveFocusedSurface, pos);
|
|
|
|
} else if (!effectiveFocusedSurface) {
|
|
|
|
effectiveFocusedSurface = focusedTouchSurface();
|
|
|
|
}
|
|
|
|
d->touch->sendDown(id, serial, pos, effectiveFocusedSurface);
|
2018-09-18 20:15:14 +00:00
|
|
|
|
2018-09-12 01:33:07 +00:00
|
|
|
if (id == 0) {
|
|
|
|
d->globalTouch.focus.firstTouchPos = globalPosition;
|
|
|
|
}
|
|
|
|
|
2021-02-12 23:53:06 +00:00
|
|
|
if (id == 0 && hasPointer() && focusedTouchSurface()) {
|
2022-08-01 21:29:02 +00:00
|
|
|
TouchInterfacePrivate *touchPrivate = TouchInterfacePrivate::get(d->touch.get());
|
2022-07-21 22:04:53 +00:00
|
|
|
if (!touchPrivate->hasTouchesForClient(effectiveFocusedSurface->client())) {
|
2021-02-12 23:53:06 +00:00
|
|
|
// If the client did not bind the touch interface fall back
|
|
|
|
// to at least emulating touch through pointer events.
|
2022-07-21 22:04:53 +00:00
|
|
|
d->pointer->sendEnter(effectiveFocusedSurface, pos, serial);
|
2021-02-12 23:53:06 +00:00
|
|
|
d->pointer->sendMotion(pos);
|
|
|
|
d->pointer->sendFrame();
|
|
|
|
}
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
2015-06-20 21:18:31 +00:00
|
|
|
|
2018-09-12 01:33:07 +00:00
|
|
|
d->globalTouch.ids[id] = serial;
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
void SeatInterface::notifyTouchMotion(qint32 id, const QPointF &globalPosition)
|
2015-03-25 12:31:38 +00:00
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->touch) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-19 22:10:01 +00:00
|
|
|
auto itTouch = d->globalTouch.ids.constFind(id);
|
|
|
|
if (itTouch == d->globalTouch.ids.constEnd()) {
|
|
|
|
// This can happen in cases where the interaction started while the device was asleep
|
2022-04-22 09:27:33 +00:00
|
|
|
qCWarning(KWIN_CORE) << "Detected a touch move that never has been down, discarding";
|
2022-02-19 22:10:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-12 23:53:06 +00:00
|
|
|
|
2022-07-21 22:04:53 +00:00
|
|
|
auto pos = globalPosition - d->globalTouch.focus.offset;
|
|
|
|
SurfaceInterface *effectiveFocusedSurface = d->touch->focusedSurface();
|
|
|
|
if (effectiveFocusedSurface && focusedTouchSurface() != effectiveFocusedSurface) {
|
|
|
|
pos = focusedTouchSurface()->mapToChild(effectiveFocusedSurface, pos);
|
|
|
|
}
|
|
|
|
|
2021-02-12 23:53:06 +00:00
|
|
|
if (isDragTouch()) {
|
|
|
|
// handled by DataDevice
|
|
|
|
} else {
|
|
|
|
d->touch->sendMotion(id, pos);
|
2018-09-18 20:15:14 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 01:33:07 +00:00
|
|
|
if (id == 0) {
|
|
|
|
d->globalTouch.focus.firstTouchPos = globalPosition;
|
|
|
|
|
2021-02-12 23:53:06 +00:00
|
|
|
if (hasPointer() && focusedTouchSurface()) {
|
2022-08-01 21:29:02 +00:00
|
|
|
TouchInterfacePrivate *touchPrivate = TouchInterfacePrivate::get(d->touch.get());
|
2022-07-21 21:51:42 +00:00
|
|
|
if (!touchPrivate->hasTouchesForClient(focusedTouchSurface()->client())) {
|
2021-02-12 23:53:06 +00:00
|
|
|
// Client did not bind touch, fall back to emulating with pointer events.
|
|
|
|
d->pointer->sendMotion(pos);
|
|
|
|
d->pointer->sendFrame();
|
|
|
|
}
|
|
|
|
}
|
2018-09-18 20:15:14 +00:00
|
|
|
}
|
2022-02-19 22:10:01 +00:00
|
|
|
Q_EMIT touchMoved(id, *itTouch, globalPosition);
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
void SeatInterface::notifyTouchUp(qint32 id)
|
2015-03-25 12:31:38 +00:00
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->touch) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-19 22:10:01 +00:00
|
|
|
|
|
|
|
auto itTouch = d->globalTouch.ids.find(id);
|
|
|
|
if (itTouch == d->globalTouch.ids.end()) {
|
|
|
|
// This can happen in cases where the interaction started while the device was asleep
|
2022-04-22 09:27:33 +00:00
|
|
|
qCWarning(KWIN_CORE) << "Detected a touch that never started, discarding";
|
2022-02-19 22:10:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-13 15:40:56 +00:00
|
|
|
const qint32 serial = d->display->nextSerial();
|
2021-09-03 12:27:16 +00:00
|
|
|
if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Touch && d->drag.dragImplicitGrabSerial == d->globalTouch.ids.value(id)) {
|
2018-09-12 01:33:07 +00:00
|
|
|
// the implicitly grabbing touch point has been upped
|
2022-03-03 09:09:27 +00:00
|
|
|
d->endDrag();
|
2018-09-12 01:33:07 +00:00
|
|
|
}
|
2021-02-12 23:53:06 +00:00
|
|
|
d->touch->sendUp(id, serial);
|
2018-09-18 20:15:14 +00:00
|
|
|
|
2021-02-12 23:53:06 +00:00
|
|
|
if (id == 0 && hasPointer() && focusedTouchSurface()) {
|
2022-08-01 21:29:02 +00:00
|
|
|
TouchInterfacePrivate *touchPrivate = TouchInterfacePrivate::get(d->touch.get());
|
2022-07-21 21:51:42 +00:00
|
|
|
if (!touchPrivate->hasTouchesForClient(focusedTouchSurface()->client())) {
|
2021-02-12 23:53:06 +00:00
|
|
|
// Client did not bind touch, fall back to emulating with pointer events.
|
|
|
|
const quint32 serial = display()->nextSerial();
|
2021-03-15 17:58:39 +00:00
|
|
|
d->pointer->sendButton(BTN_LEFT, PointerButtonState::Released, serial);
|
2021-02-12 23:53:06 +00:00
|
|
|
d->pointer->sendFrame();
|
|
|
|
}
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
2018-09-18 20:15:14 +00:00
|
|
|
|
2022-02-19 22:10:01 +00:00
|
|
|
d->globalTouch.ids.erase(itTouch);
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
void SeatInterface::notifyTouchFrame()
|
2015-03-25 12:31:38 +00:00
|
|
|
{
|
2021-03-15 16:12:21 +00:00
|
|
|
if (!d->touch) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 23:53:06 +00:00
|
|
|
d->touch->sendFrame();
|
2015-03-25 12:31:38 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 01:33:07 +00:00
|
|
|
bool SeatInterface::hasImplicitTouchGrab(quint32 serial) const
|
|
|
|
{
|
|
|
|
if (!d->globalTouch.focus.surface) {
|
|
|
|
// origin surface has been destroyed
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return d->globalTouch.ids.key(serial, -1) != -1;
|
|
|
|
}
|
|
|
|
|
2016-03-01 06:49:04 +00:00
|
|
|
bool SeatInterface::isDrag() const
|
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
return d->drag.mode != SeatInterfacePrivate::Drag::Mode::None;
|
2016-03-01 06:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::isDragPointer() const
|
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
return d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer;
|
2016-03-01 06:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::isDragTouch() const
|
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
return d->drag.mode == SeatInterfacePrivate::Drag::Mode::Touch;
|
2016-03-01 06:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SeatInterface::hasImplicitPointerGrab(quint32 serial) const
|
|
|
|
{
|
|
|
|
const auto &serials = d->globalPointer.buttonSerials;
|
2019-09-14 09:07:04 +00:00
|
|
|
for (auto it = serials.constBegin(), end = serials.constEnd(); it != end; it++) {
|
2016-03-01 06:49:04 +00:00
|
|
|
if (it.value() == serial) {
|
|
|
|
return isPointerButtonPressed(it.key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix4x4 SeatInterface::dragSurfaceTransformation() const
|
|
|
|
{
|
|
|
|
return d->drag.transformation;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface *SeatInterface::dragSurface() const
|
|
|
|
{
|
|
|
|
return d->drag.surface;
|
|
|
|
}
|
|
|
|
|
2021-09-03 12:27:16 +00:00
|
|
|
AbstractDataSource *SeatInterface::dragSource() const
|
2016-03-01 06:49:04 +00:00
|
|
|
{
|
|
|
|
return d->drag.source;
|
|
|
|
}
|
|
|
|
|
2023-02-09 08:40:13 +00:00
|
|
|
XdgToplevelDragV1Interface *SeatInterface::xdgTopleveldrag() const
|
|
|
|
{
|
|
|
|
if (auto source = qobject_cast<DataSourceInterface *>(d->drag.source)) {
|
|
|
|
return source->xdgToplevelDrag();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-05-02 12:28:26 +00:00
|
|
|
void SeatInterface::setFocusedTextInputSurface(SurfaceInterface *surface)
|
|
|
|
{
|
|
|
|
const quint32 serial = d->display->nextSerial();
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2021-12-19 08:00:22 +00:00
|
|
|
if (d->focusedTextInputSurface == surface) {
|
|
|
|
return;
|
2020-07-28 15:39:13 +00:00
|
|
|
}
|
|
|
|
|
2021-12-19 08:00:22 +00:00
|
|
|
if (d->focusedTextInputSurface) {
|
|
|
|
disconnect(d->focusedSurfaceDestroyConnection);
|
2023-01-07 20:56:49 +00:00
|
|
|
d->textInputV1->d->sendLeave(d->focusedTextInputSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
d->textInputV2->d->sendLeave(serial, d->focusedTextInputSurface);
|
2020-09-15 07:27:46 +00:00
|
|
|
d->textInputV3->d->sendLeave(d->focusedTextInputSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
}
|
2021-12-19 08:00:22 +00:00
|
|
|
d->focusedTextInputSurface = surface;
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2021-12-19 08:00:22 +00:00
|
|
|
if (surface) {
|
2021-08-29 05:11:06 +00:00
|
|
|
d->focusedSurfaceDestroyConnection = connect(surface, &SurfaceInterface::aboutToBeDestroyed, this, [this] {
|
|
|
|
setFocusedTextInputSurface(nullptr);
|
|
|
|
});
|
2023-01-07 20:56:49 +00:00
|
|
|
d->textInputV1->d->sendEnter(surface);
|
2021-12-19 08:00:22 +00:00
|
|
|
d->textInputV2->d->sendEnter(surface, serial);
|
|
|
|
d->textInputV3->d->sendEnter(surface);
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
2022-10-16 05:03:32 +00:00
|
|
|
|
|
|
|
Q_EMIT focusedTextInputSurfaceChanged();
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface *SeatInterface::focusedTextInputSurface() const
|
|
|
|
{
|
2020-07-28 15:39:13 +00:00
|
|
|
return d->focusedTextInputSurface;
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 20:56:49 +00:00
|
|
|
TextInputV1Interface *SeatInterface::textInputV1() const
|
|
|
|
{
|
|
|
|
return d->textInputV1;
|
|
|
|
}
|
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
TextInputV2Interface *SeatInterface::textInputV2() const
|
2016-05-02 12:28:26 +00:00
|
|
|
{
|
2020-07-28 15:39:13 +00:00
|
|
|
return d->textInputV2;
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 07:27:46 +00:00
|
|
|
TextInputV3Interface *SeatInterface::textInputV3() const
|
|
|
|
{
|
|
|
|
return d->textInputV3;
|
|
|
|
}
|
2020-05-12 11:26:48 +00:00
|
|
|
AbstractDataSource *SeatInterface::selection() const
|
2016-06-21 09:14:46 +00:00
|
|
|
{
|
|
|
|
return d->currentSelection;
|
|
|
|
}
|
|
|
|
|
2020-05-12 11:26:48 +00:00
|
|
|
void SeatInterface::setSelection(AbstractDataSource *selection)
|
2016-06-21 09:14:46 +00:00
|
|
|
{
|
2020-05-18 13:43:38 +00:00
|
|
|
if (d->currentSelection == selection) {
|
2016-06-21 09:14:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-18 13:43:38 +00:00
|
|
|
|
|
|
|
if (d->currentSelection) {
|
|
|
|
d->currentSelection->cancel();
|
|
|
|
disconnect(d->currentSelection, nullptr, this, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection) {
|
|
|
|
auto cleanup = [this]() {
|
|
|
|
setSelection(nullptr);
|
|
|
|
};
|
2022-01-25 07:59:59 +00:00
|
|
|
connect(selection, &AbstractDataSource::aboutToBeDestroyed, this, cleanup);
|
2020-05-18 13:43:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
d->currentSelection = selection;
|
|
|
|
|
2022-10-31 19:02:23 +00:00
|
|
|
for (auto focussedSelection : std::as_const(d->globalKeyboard.focus.selections)) {
|
2022-12-09 09:05:44 +00:00
|
|
|
focussedSelection->sendSelection(selection);
|
2016-06-21 09:14:46 +00:00
|
|
|
}
|
2020-05-18 13:43:38 +00:00
|
|
|
|
2022-10-31 19:02:23 +00:00
|
|
|
for (auto control : std::as_const(d->dataControlDevices)) {
|
2022-12-09 09:05:44 +00:00
|
|
|
control->sendSelection(selection);
|
2020-05-12 11:26:57 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT selectionChanged(selection);
|
2016-06-21 09:14:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 12:29:35 +00:00
|
|
|
AbstractDataSource *SeatInterface::primarySelection() const
|
|
|
|
{
|
|
|
|
return d->currentPrimarySelection;
|
|
|
|
}
|
|
|
|
|
2020-06-01 22:29:53 +00:00
|
|
|
void SeatInterface::setPrimarySelection(AbstractDataSource *selection)
|
|
|
|
{
|
|
|
|
if (d->currentPrimarySelection == selection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (d->currentPrimarySelection) {
|
|
|
|
d->currentPrimarySelection->cancel();
|
|
|
|
disconnect(d->currentPrimarySelection, nullptr, this, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection) {
|
|
|
|
auto cleanup = [this]() {
|
|
|
|
setPrimarySelection(nullptr);
|
|
|
|
};
|
2022-01-25 07:59:59 +00:00
|
|
|
connect(selection, &AbstractDataSource::aboutToBeDestroyed, this, cleanup);
|
2020-06-01 22:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
d->currentPrimarySelection = selection;
|
|
|
|
|
2022-10-31 19:02:23 +00:00
|
|
|
for (auto focussedSelection : std::as_const(d->globalKeyboard.focus.primarySelections)) {
|
2022-12-09 09:05:44 +00:00
|
|
|
focussedSelection->sendSelection(selection);
|
2020-06-01 22:29:53 +00:00
|
|
|
}
|
2022-10-31 19:02:23 +00:00
|
|
|
for (auto control : std::as_const(d->dataControlDevices)) {
|
2022-12-09 09:05:44 +00:00
|
|
|
control->sendPrimarySelection(selection);
|
2021-08-10 12:29:35 +00:00
|
|
|
}
|
2020-06-01 22:29:53 +00:00
|
|
|
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT primarySelectionChanged(selection);
|
2020-06-01 22:29:53 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 12:27:16 +00:00
|
|
|
void SeatInterface::startDrag(AbstractDataSource *dragSource, SurfaceInterface *originSurface, int dragSerial, DragAndDropIcon *dragIcon)
|
|
|
|
{
|
|
|
|
if (hasImplicitPointerGrab(dragSerial)) {
|
|
|
|
d->drag.mode = SeatInterfacePrivate::Drag::Mode::Pointer;
|
|
|
|
d->drag.transformation = d->globalPointer.focus.transformation;
|
|
|
|
} else if (hasImplicitTouchGrab(dragSerial)) {
|
|
|
|
d->drag.mode = SeatInterfacePrivate::Drag::Mode::Touch;
|
2021-10-26 11:32:05 +00:00
|
|
|
d->drag.transformation = d->globalTouch.focus.transformation;
|
2021-09-03 12:27:16 +00:00
|
|
|
} else {
|
|
|
|
// no implicit grab, abort drag
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->drag.dragImplicitGrabSerial = dragSerial;
|
|
|
|
|
|
|
|
// set initial drag target to ourself
|
|
|
|
d->drag.surface = originSurface;
|
|
|
|
|
|
|
|
d->drag.source = dragSource;
|
|
|
|
if (dragSource) {
|
|
|
|
d->drag.dragSourceDestroyConnection = QObject::connect(dragSource, &AbstractDataSource::aboutToBeDestroyed, this, [this] {
|
2022-03-03 09:09:27 +00:00
|
|
|
d->cancelDrag();
|
2021-09-03 12:27:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
d->drag.dragIcon = dragIcon;
|
|
|
|
|
|
|
|
if (!d->dataDevicesForSurface(originSurface).isEmpty()) {
|
|
|
|
d->drag.target = d->dataDevicesForSurface(originSurface)[0];
|
|
|
|
}
|
|
|
|
if (d->drag.target) {
|
|
|
|
d->drag.target->updateDragTarget(originSurface, dragSerial);
|
|
|
|
}
|
|
|
|
Q_EMIT dragStarted();
|
|
|
|
Q_EMIT dragSurfaceChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
DragAndDropIcon *SeatInterface::dragIcon() const
|
|
|
|
{
|
|
|
|
return d->drag.dragIcon;
|
|
|
|
}
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
2023-07-05 06:30:14 +00:00
|
|
|
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "moc_seat.cpp"
|