From b219b9175cf96eee4093d121b7761571ea035600 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Fri, 10 Sep 2021 14:44:02 +0100 Subject: [PATCH] Only guard DND cancel events with the version check In a recent refactor a guard seemingly in the wrong place on SeatInterface was moved into AbstractDataSource, as typically that's where we guard. However it turns out the original code was correct, we want to send cancel for all clipboard cancels, but for D&D it's version dependent. This class introduces a new method to astract that from seat. --- src/wayland/abstract_data_source.h | 7 +++++++ src/wayland/datasource_interface.cpp | 13 ++++++++++--- src/wayland/datasource_interface.h | 1 + src/wayland/seat_interface.cpp | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/wayland/abstract_data_source.h b/src/wayland/abstract_data_source.h index aea38acbb8..3688c8b75f 100644 --- a/src/wayland/abstract_data_source.h +++ b/src/wayland/abstract_data_source.h @@ -67,6 +67,13 @@ public: Q_UNUSED(action); }; + /** + * Called when a user stops clicking but it is not accepted by a client. + */ + virtual void dndCancelled() + { + } + virtual wl_client *client() const { return nullptr; diff --git a/src/wayland/datasource_interface.cpp b/src/wayland/datasource_interface.cpp index 417ee7d100..445765a064 100644 --- a/src/wayland/datasource_interface.cpp +++ b/src/wayland/datasource_interface.cpp @@ -118,9 +118,7 @@ void DataSourceInterface::requestData(const QString &mimeType, qint32 fd) void DataSourceInterface::cancel() { - if (wl_resource_get_version(resource()) >= WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION) { - d->send_cancelled(); - } + d->send_cancelled(); } QStringList DataSourceInterface::mimeTypes() const @@ -173,6 +171,15 @@ void DataSourceInterface::dndAction(DataDeviceManagerInterface::DnDAction action d->send_action(wlAction); } +void DataSourceInterface::dndCancelled() +{ + // for v3 or less, cancel should not be called after a failed drag operation + if (wl_resource_get_version(resource()) < 3) { + return; + } + d->send_cancelled(); +} + wl_resource *DataSourceInterface::resource() const { return d->resource()->handle; diff --git a/src/wayland/datasource_interface.h b/src/wayland/datasource_interface.h index 5db7d45bb1..f99971f7d4 100644 --- a/src/wayland/datasource_interface.h +++ b/src/wayland/datasource_interface.h @@ -41,6 +41,7 @@ public: void dropPerformed() override; void dndFinished() override; void dndAction(DataDeviceManagerInterface::DnDAction action) override; + void dndCancelled() override; wl_resource *resource() const; diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index e046c72e21..0f7579e7d0 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -293,7 +293,7 @@ void SeatInterfacePrivate::endDrag(quint32 serial) dragTargetDevice->drop(); dragSource->dropPerformed(); } else { - dragSource->cancel(); + dragSource->dndCancelled(); } }