Remove selectionCleared and sendClearSelection from datadevice and friends
Having both selectionChanged and selectionCleared as well as sendSelection and sendClearSelection complicates things. API users have to connect to both signals, internally the methods have logic to call themselves but in the end do the same as the protocols only know send_selection.
This commit is contained in:
parent
dbcbba5fac
commit
cb9ffbcd01
8 changed files with 14 additions and 107 deletions
|
@ -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<DataSourceInterface *>(), 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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<DataDeviceInterface *> 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<PrimarySelectionDeviceV1Interface *> 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);
|
||||
|
|
Loading…
Reference in a new issue