diff --git a/src/wayland/autotests/client/test_datadevice.cpp b/src/wayland/autotests/client/test_datadevice.cpp index d261b0bbd0..06d52f854f 100644 --- a/src/wayland/autotests/client/test_datadevice.cpp +++ b/src/wayland/autotests/client/test_datadevice.cpp @@ -371,13 +371,11 @@ void TestDataDevice::testSetSelection() // everything setup, now we can test setting the selection QSignalSpy selectionChangedSpy(deviceInterface, &KWaylandServer::DataDeviceInterface::selectionChanged); - QSignalSpy selectionClearedSpy(deviceInterface, &KWaylandServer::DataDeviceInterface::selectionCleared); QVERIFY(!deviceInterface->selection()); dataDevice->setSelection(1, dataSource.get()); QVERIFY(selectionChangedSpy.wait()); QCOMPARE(selectionChangedSpy.count(), 1); - QCOMPARE(selectionClearedSpy.count(), 0); QCOMPARE(selectionChangedSpy.first().first().value(), sourceInterface); QCOMPARE(deviceInterface->selection(), sourceInterface); @@ -403,9 +401,8 @@ void TestDataDevice::testSetSelection() // now clear the selection dataDevice->clearSelection(1); - QVERIFY(selectionClearedSpy.wait()); - QCOMPARE(selectionChangedSpy.count(), 1); - QCOMPARE(selectionClearedSpy.count(), 1); + QVERIFY(selectionChangedSpy.wait()); + QCOMPARE(selectionChangedSpy.count(), 2); QVERIFY(!deviceInterface->selection()); // set another selection diff --git a/src/wayland/datacontroldevice_v1_interface.cpp b/src/wayland/datacontroldevice_v1_interface.cpp index 64ca3944b6..45a1992b82 100644 --- a/src/wayland/datacontroldevice_v1_interface.cpp +++ b/src/wayland/datacontroldevice_v1_interface.cpp @@ -137,38 +137,13 @@ DataControlSourceV1Interface *DataControlDeviceV1Interface::primarySelection() c void DataControlDeviceV1Interface::sendSelection(AbstractDataSource *other) { - if (!other) { - sendClearSelection(); - return; - } DataControlOfferV1Interface *offer = d->createDataOffer(other); - if (!offer) { - return; - } - d->send_selection(offer->resource()); -} - -void DataControlDeviceV1Interface::sendClearSelection() -{ - d->send_selection(nullptr); + d->send_selection(offer ? offer->resource() : nullptr); } void DataControlDeviceV1Interface::sendPrimarySelection(KWaylandServer::AbstractDataSource *other) { - if (!other) { - sendClearPrimarySelection(); - return; - } DataControlOfferV1Interface *offer = d->createDataOffer(other); - if (!offer) { - return; - } - d->send_primary_selection(offer->resource()); + d->send_primary_selection(offer ? offer->resource() : nullptr); } - -void DataControlDeviceV1Interface::sendClearPrimarySelection() -{ - d->send_primary_selection(nullptr); -} - } diff --git a/src/wayland/datacontroldevice_v1_interface.h b/src/wayland/datacontroldevice_v1_interface.h index 1fe9804385..8b4d1dfa49 100644 --- a/src/wayland/datacontroldevice_v1_interface.h +++ b/src/wayland/datacontroldevice_v1_interface.h @@ -39,14 +39,11 @@ public: DataControlSourceV1Interface *primarySelection() const; void sendSelection(AbstractDataSource *other); - void sendClearSelection(); void sendPrimarySelection(AbstractDataSource *other); - void sendClearPrimarySelection(); Q_SIGNALS: void selectionChanged(KWaylandServer::DataControlSourceV1Interface *dataSource); - void selectionCleared(); void primarySelectionChanged(KWaylandServer::DataControlSourceV1Interface *dataSource); diff --git a/src/wayland/datadevice_interface.cpp b/src/wayland/datadevice_interface.cpp index 1136483431..907eb6b44b 100644 --- a/src/wayland/datadevice_interface.cpp +++ b/src/wayland/datadevice_interface.cpp @@ -126,11 +126,7 @@ void DataDeviceInterfacePrivate::data_device_set_selection(Resource *resource, w selection->cancel(); } selection = dataSource; - if (selection) { - Q_EMIT q->selectionChanged(selection); - } else { - Q_EMIT q->selectionCleared(); - } + Q_EMIT q->selectionChanged(selection); } void DataDeviceInterfacePrivate::data_device_release(QtWaylandServer::wl_data_device::Resource *resource) @@ -186,16 +182,8 @@ DataSourceInterface *DataDeviceInterface::selection() const void DataDeviceInterface::sendSelection(AbstractDataSource *other) { - auto r = d->createDataOffer(other); - if (!r) { - return; - } - d->send_selection(r->resource()); -} - -void DataDeviceInterface::sendClearSelection() -{ - d->send_selection(nullptr); + auto r = other ? d->createDataOffer(other) : nullptr; + d->send_selection(r ? r->resource() : nullptr); } void DataDeviceInterface::drop() diff --git a/src/wayland/datadevice_interface.h b/src/wayland/datadevice_interface.h index edf1c5c586..d158dfbddf 100644 --- a/src/wayland/datadevice_interface.h +++ b/src/wayland/datadevice_interface.h @@ -79,7 +79,6 @@ public: DataSourceInterface *selection() const; void sendSelection(KWaylandServer::AbstractDataSource *other); - void sendClearSelection(); /** * The event is sent when a drag-and-drop operation is ended because the implicit grab is removed. */ @@ -103,7 +102,6 @@ Q_SIGNALS: void aboutToBeDestroyed(); void dragStarted(AbstractDataSource *source, SurfaceInterface *originSurface, quint32 serial, DragAndDropIcon *dragIcon); void selectionChanged(KWaylandServer::DataSourceInterface *); - void selectionCleared(); private: friend class DataDeviceManagerInterfacePrivate; diff --git a/src/wayland/primaryselectiondevice_v1_interface.cpp b/src/wayland/primaryselectiondevice_v1_interface.cpp index e37b257325..7017a17840 100644 --- a/src/wayland/primaryselectiondevice_v1_interface.cpp +++ b/src/wayland/primaryselectiondevice_v1_interface.cpp @@ -118,20 +118,8 @@ PrimarySelectionSourceV1Interface *PrimarySelectionDeviceV1Interface::selection( void PrimarySelectionDeviceV1Interface::sendSelection(AbstractDataSource *other) { - if (!other) { - sendClearSelection(); - return; - } PrimarySelectionOfferV1Interface *offer = d->createDataOffer(other); - if (!offer) { - return; - } - d->send_selection(offer->resource()); -} - -void PrimarySelectionDeviceV1Interface::sendClearSelection() -{ - d->send_selection(nullptr); + d->send_selection(offer ? offer->resource() : nullptr); } wl_client *PrimarySelectionDeviceV1Interface::client() const diff --git a/src/wayland/primaryselectiondevice_v1_interface.h b/src/wayland/primaryselectiondevice_v1_interface.h index 45d7cf72a1..d0fb61538f 100644 --- a/src/wayland/primaryselectiondevice_v1_interface.h +++ b/src/wayland/primaryselectiondevice_v1_interface.h @@ -41,13 +41,11 @@ public: PrimarySelectionSourceV1Interface *selection() const; void sendSelection(AbstractDataSource *other); - void sendClearSelection(); wl_client *client() const; Q_SIGNALS: void selectionChanged(KWaylandServer::PrimarySelectionSourceV1Interface *); - void selectionCleared(); private: friend class PrimarySelectionDeviceManagerV1InterfacePrivate; diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index d4b4e9b545..8143550a90 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -165,9 +165,6 @@ void SeatInterfacePrivate::registerDataDevice(DataDeviceInterface *dataDevice) QObject::connect(dataDevice, &DataDeviceInterface::selectionChanged, q, [this, dataDevice] { updateSelection(dataDevice); }); - QObject::connect(dataDevice, &DataDeviceInterface::selectionCleared, q, [this, dataDevice] { - updateSelection(dataDevice); - }); QObject::connect(dataDevice, &DataDeviceInterface::dragStarted, q, @@ -223,10 +220,6 @@ void SeatInterfacePrivate::registerDataControlDevice(DataControlDeviceV1Interfac q->setSelection(dataDevice->selection()); }); - QObject::connect(dataDevice, &DataControlDeviceV1Interface::selectionCleared, q, [this, dataDevice] { - q->setSelection(nullptr); - }); - QObject::connect(dataDevice, &DataControlDeviceV1Interface::primarySelectionChanged, q, [this, dataDevice] { // 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 @@ -260,9 +253,6 @@ void SeatInterfacePrivate::registerPrimarySelectionDevice(PrimarySelectionDevice QObject::connect(primarySelectionDevice, &PrimarySelectionDeviceV1Interface::selectionChanged, q, [this, primarySelectionDevice] { updatePrimarySelection(primarySelectionDevice); }); - QObject::connect(primarySelectionDevice, &PrimarySelectionDeviceV1Interface::selectionCleared, q, [this, primarySelectionDevice] { - updatePrimarySelection(primarySelectionDevice); - }); // is the new DataDevice for the current keyoard focus? if (globalKeyboard.focus.surface) { // same client? @@ -937,11 +927,7 @@ void SeatInterface::setFocusedKeyboardSurface(SurfaceInterface *surface) const QVector dataDevices = d->dataDevicesForSurface(surface); d->globalKeyboard.focus.selections = dataDevices; for (auto dataDevice : dataDevices) { - if (d->currentSelection) { - dataDevice->sendSelection(d->currentSelection); - } else { - dataDevice->sendClearSelection(); - } + dataDevice->sendSelection(d->currentSelection); } // primary selection QVector primarySelectionDevices; @@ -953,11 +939,7 @@ void SeatInterface::setFocusedKeyboardSurface(SurfaceInterface *surface) d->globalKeyboard.focus.primarySelections = primarySelectionDevices; for (auto primaryDataDevice : primarySelectionDevices) { - if (d->currentPrimarySelection) { - primaryDataDevice->sendSelection(d->currentPrimarySelection); - } else { - primaryDataDevice->sendClearSelection(); - } + primaryDataDevice->sendSelection(d->currentPrimarySelection); } } @@ -1293,19 +1275,11 @@ void SeatInterface::setSelection(AbstractDataSource *selection) d->currentSelection = selection; for (auto focussedSelection : std::as_const(d->globalKeyboard.focus.selections)) { - if (selection) { - focussedSelection->sendSelection(selection); - } else { - focussedSelection->sendClearSelection(); - } + focussedSelection->sendSelection(selection); } for (auto control : std::as_const(d->dataControlDevices)) { - if (selection) { - control->sendSelection(selection); - } else { - control->sendClearSelection(); - } + control->sendSelection(selection); } Q_EMIT selectionChanged(selection); @@ -1351,18 +1325,10 @@ void SeatInterface::setPrimarySelection(AbstractDataSource *selection) d->currentPrimarySelection = selection; for (auto focussedSelection : std::as_const(d->globalKeyboard.focus.primarySelections)) { - if (selection) { - focussedSelection->sendSelection(selection); - } else { - focussedSelection->sendClearSelection(); - } + focussedSelection->sendSelection(selection); } for (auto control : std::as_const(d->dataControlDevices)) { - if (selection) { - control->sendPrimarySelection(selection); - } else { - control->sendClearPrimarySelection(); - } + control->sendPrimarySelection(selection); } Q_EMIT primarySelectionChanged(selection);