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
|
// everything setup, now we can test setting the selection
|
||||||
QSignalSpy selectionChangedSpy(deviceInterface, &KWaylandServer::DataDeviceInterface::selectionChanged);
|
QSignalSpy selectionChangedSpy(deviceInterface, &KWaylandServer::DataDeviceInterface::selectionChanged);
|
||||||
QSignalSpy selectionClearedSpy(deviceInterface, &KWaylandServer::DataDeviceInterface::selectionCleared);
|
|
||||||
|
|
||||||
QVERIFY(!deviceInterface->selection());
|
QVERIFY(!deviceInterface->selection());
|
||||||
dataDevice->setSelection(1, dataSource.get());
|
dataDevice->setSelection(1, dataSource.get());
|
||||||
QVERIFY(selectionChangedSpy.wait());
|
QVERIFY(selectionChangedSpy.wait());
|
||||||
QCOMPARE(selectionChangedSpy.count(), 1);
|
QCOMPARE(selectionChangedSpy.count(), 1);
|
||||||
QCOMPARE(selectionClearedSpy.count(), 0);
|
|
||||||
QCOMPARE(selectionChangedSpy.first().first().value<DataSourceInterface *>(), sourceInterface);
|
QCOMPARE(selectionChangedSpy.first().first().value<DataSourceInterface *>(), sourceInterface);
|
||||||
QCOMPARE(deviceInterface->selection(), sourceInterface);
|
QCOMPARE(deviceInterface->selection(), sourceInterface);
|
||||||
|
|
||||||
|
@ -403,9 +401,8 @@ void TestDataDevice::testSetSelection()
|
||||||
|
|
||||||
// now clear the selection
|
// now clear the selection
|
||||||
dataDevice->clearSelection(1);
|
dataDevice->clearSelection(1);
|
||||||
QVERIFY(selectionClearedSpy.wait());
|
QVERIFY(selectionChangedSpy.wait());
|
||||||
QCOMPARE(selectionChangedSpy.count(), 1);
|
QCOMPARE(selectionChangedSpy.count(), 2);
|
||||||
QCOMPARE(selectionClearedSpy.count(), 1);
|
|
||||||
QVERIFY(!deviceInterface->selection());
|
QVERIFY(!deviceInterface->selection());
|
||||||
|
|
||||||
// set another selection
|
// set another selection
|
||||||
|
|
|
@ -137,38 +137,13 @@ DataControlSourceV1Interface *DataControlDeviceV1Interface::primarySelection() c
|
||||||
|
|
||||||
void DataControlDeviceV1Interface::sendSelection(AbstractDataSource *other)
|
void DataControlDeviceV1Interface::sendSelection(AbstractDataSource *other)
|
||||||
{
|
{
|
||||||
if (!other) {
|
|
||||||
sendClearSelection();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DataControlOfferV1Interface *offer = d->createDataOffer(other);
|
DataControlOfferV1Interface *offer = d->createDataOffer(other);
|
||||||
if (!offer) {
|
d->send_selection(offer ? offer->resource() : nullptr);
|
||||||
return;
|
|
||||||
}
|
|
||||||
d->send_selection(offer->resource());
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataControlDeviceV1Interface::sendClearSelection()
|
|
||||||
{
|
|
||||||
d->send_selection(nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataControlDeviceV1Interface::sendPrimarySelection(KWaylandServer::AbstractDataSource *other)
|
void DataControlDeviceV1Interface::sendPrimarySelection(KWaylandServer::AbstractDataSource *other)
|
||||||
{
|
{
|
||||||
if (!other) {
|
|
||||||
sendClearPrimarySelection();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DataControlOfferV1Interface *offer = d->createDataOffer(other);
|
DataControlOfferV1Interface *offer = d->createDataOffer(other);
|
||||||
if (!offer) {
|
d->send_primary_selection(offer ? offer->resource() : nullptr);
|
||||||
return;
|
|
||||||
}
|
|
||||||
d->send_primary_selection(offer->resource());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataControlDeviceV1Interface::sendClearPrimarySelection()
|
|
||||||
{
|
|
||||||
d->send_primary_selection(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,14 +39,11 @@ public:
|
||||||
DataControlSourceV1Interface *primarySelection() const;
|
DataControlSourceV1Interface *primarySelection() const;
|
||||||
|
|
||||||
void sendSelection(AbstractDataSource *other);
|
void sendSelection(AbstractDataSource *other);
|
||||||
void sendClearSelection();
|
|
||||||
|
|
||||||
void sendPrimarySelection(AbstractDataSource *other);
|
void sendPrimarySelection(AbstractDataSource *other);
|
||||||
void sendClearPrimarySelection();
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void selectionChanged(KWaylandServer::DataControlSourceV1Interface *dataSource);
|
void selectionChanged(KWaylandServer::DataControlSourceV1Interface *dataSource);
|
||||||
void selectionCleared();
|
|
||||||
|
|
||||||
void primarySelectionChanged(KWaylandServer::DataControlSourceV1Interface *dataSource);
|
void primarySelectionChanged(KWaylandServer::DataControlSourceV1Interface *dataSource);
|
||||||
|
|
||||||
|
|
|
@ -126,11 +126,7 @@ void DataDeviceInterfacePrivate::data_device_set_selection(Resource *resource, w
|
||||||
selection->cancel();
|
selection->cancel();
|
||||||
}
|
}
|
||||||
selection = dataSource;
|
selection = dataSource;
|
||||||
if (selection) {
|
Q_EMIT q->selectionChanged(selection);
|
||||||
Q_EMIT q->selectionChanged(selection);
|
|
||||||
} else {
|
|
||||||
Q_EMIT q->selectionCleared();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataDeviceInterfacePrivate::data_device_release(QtWaylandServer::wl_data_device::Resource *resource)
|
void DataDeviceInterfacePrivate::data_device_release(QtWaylandServer::wl_data_device::Resource *resource)
|
||||||
|
@ -186,16 +182,8 @@ DataSourceInterface *DataDeviceInterface::selection() const
|
||||||
|
|
||||||
void DataDeviceInterface::sendSelection(AbstractDataSource *other)
|
void DataDeviceInterface::sendSelection(AbstractDataSource *other)
|
||||||
{
|
{
|
||||||
auto r = d->createDataOffer(other);
|
auto r = other ? d->createDataOffer(other) : nullptr;
|
||||||
if (!r) {
|
d->send_selection(r ? r->resource() : nullptr);
|
||||||
return;
|
|
||||||
}
|
|
||||||
d->send_selection(r->resource());
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataDeviceInterface::sendClearSelection()
|
|
||||||
{
|
|
||||||
d->send_selection(nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataDeviceInterface::drop()
|
void DataDeviceInterface::drop()
|
||||||
|
|
|
@ -79,7 +79,6 @@ public:
|
||||||
DataSourceInterface *selection() const;
|
DataSourceInterface *selection() const;
|
||||||
|
|
||||||
void sendSelection(KWaylandServer::AbstractDataSource *other);
|
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.
|
* 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 aboutToBeDestroyed();
|
||||||
void dragStarted(AbstractDataSource *source, SurfaceInterface *originSurface, quint32 serial, DragAndDropIcon *dragIcon);
|
void dragStarted(AbstractDataSource *source, SurfaceInterface *originSurface, quint32 serial, DragAndDropIcon *dragIcon);
|
||||||
void selectionChanged(KWaylandServer::DataSourceInterface *);
|
void selectionChanged(KWaylandServer::DataSourceInterface *);
|
||||||
void selectionCleared();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class DataDeviceManagerInterfacePrivate;
|
friend class DataDeviceManagerInterfacePrivate;
|
||||||
|
|
|
@ -118,20 +118,8 @@ PrimarySelectionSourceV1Interface *PrimarySelectionDeviceV1Interface::selection(
|
||||||
|
|
||||||
void PrimarySelectionDeviceV1Interface::sendSelection(AbstractDataSource *other)
|
void PrimarySelectionDeviceV1Interface::sendSelection(AbstractDataSource *other)
|
||||||
{
|
{
|
||||||
if (!other) {
|
|
||||||
sendClearSelection();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PrimarySelectionOfferV1Interface *offer = d->createDataOffer(other);
|
PrimarySelectionOfferV1Interface *offer = d->createDataOffer(other);
|
||||||
if (!offer) {
|
d->send_selection(offer ? offer->resource() : nullptr);
|
||||||
return;
|
|
||||||
}
|
|
||||||
d->send_selection(offer->resource());
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrimarySelectionDeviceV1Interface::sendClearSelection()
|
|
||||||
{
|
|
||||||
d->send_selection(nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_client *PrimarySelectionDeviceV1Interface::client() const
|
wl_client *PrimarySelectionDeviceV1Interface::client() const
|
||||||
|
|
|
@ -41,13 +41,11 @@ public:
|
||||||
PrimarySelectionSourceV1Interface *selection() const;
|
PrimarySelectionSourceV1Interface *selection() const;
|
||||||
|
|
||||||
void sendSelection(AbstractDataSource *other);
|
void sendSelection(AbstractDataSource *other);
|
||||||
void sendClearSelection();
|
|
||||||
|
|
||||||
wl_client *client() const;
|
wl_client *client() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void selectionChanged(KWaylandServer::PrimarySelectionSourceV1Interface *);
|
void selectionChanged(KWaylandServer::PrimarySelectionSourceV1Interface *);
|
||||||
void selectionCleared();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class PrimarySelectionDeviceManagerV1InterfacePrivate;
|
friend class PrimarySelectionDeviceManagerV1InterfacePrivate;
|
||||||
|
|
|
@ -165,9 +165,6 @@ void SeatInterfacePrivate::registerDataDevice(DataDeviceInterface *dataDevice)
|
||||||
QObject::connect(dataDevice, &DataDeviceInterface::selectionChanged, q, [this, dataDevice] {
|
QObject::connect(dataDevice, &DataDeviceInterface::selectionChanged, q, [this, dataDevice] {
|
||||||
updateSelection(dataDevice);
|
updateSelection(dataDevice);
|
||||||
});
|
});
|
||||||
QObject::connect(dataDevice, &DataDeviceInterface::selectionCleared, q, [this, dataDevice] {
|
|
||||||
updateSelection(dataDevice);
|
|
||||||
});
|
|
||||||
QObject::connect(dataDevice,
|
QObject::connect(dataDevice,
|
||||||
&DataDeviceInterface::dragStarted,
|
&DataDeviceInterface::dragStarted,
|
||||||
q,
|
q,
|
||||||
|
@ -223,10 +220,6 @@ void SeatInterfacePrivate::registerDataControlDevice(DataControlDeviceV1Interfac
|
||||||
q->setSelection(dataDevice->selection());
|
q->setSelection(dataDevice->selection());
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(dataDevice, &DataControlDeviceV1Interface::selectionCleared, q, [this, dataDevice] {
|
|
||||||
q->setSelection(nullptr);
|
|
||||||
});
|
|
||||||
|
|
||||||
QObject::connect(dataDevice, &DataControlDeviceV1Interface::primarySelectionChanged, q, [this, dataDevice] {
|
QObject::connect(dataDevice, &DataControlDeviceV1Interface::primarySelectionChanged, q, [this, dataDevice] {
|
||||||
// Special klipper workaround to avoid a race
|
// 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
|
// 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] {
|
QObject::connect(primarySelectionDevice, &PrimarySelectionDeviceV1Interface::selectionChanged, q, [this, primarySelectionDevice] {
|
||||||
updatePrimarySelection(primarySelectionDevice);
|
updatePrimarySelection(primarySelectionDevice);
|
||||||
});
|
});
|
||||||
QObject::connect(primarySelectionDevice, &PrimarySelectionDeviceV1Interface::selectionCleared, q, [this, primarySelectionDevice] {
|
|
||||||
updatePrimarySelection(primarySelectionDevice);
|
|
||||||
});
|
|
||||||
// is the new DataDevice for the current keyoard focus?
|
// is the new DataDevice for the current keyoard focus?
|
||||||
if (globalKeyboard.focus.surface) {
|
if (globalKeyboard.focus.surface) {
|
||||||
// same client?
|
// same client?
|
||||||
|
@ -937,11 +927,7 @@ void SeatInterface::setFocusedKeyboardSurface(SurfaceInterface *surface)
|
||||||
const QVector<DataDeviceInterface *> dataDevices = d->dataDevicesForSurface(surface);
|
const QVector<DataDeviceInterface *> dataDevices = d->dataDevicesForSurface(surface);
|
||||||
d->globalKeyboard.focus.selections = dataDevices;
|
d->globalKeyboard.focus.selections = dataDevices;
|
||||||
for (auto dataDevice : dataDevices) {
|
for (auto dataDevice : dataDevices) {
|
||||||
if (d->currentSelection) {
|
dataDevice->sendSelection(d->currentSelection);
|
||||||
dataDevice->sendSelection(d->currentSelection);
|
|
||||||
} else {
|
|
||||||
dataDevice->sendClearSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// primary selection
|
// primary selection
|
||||||
QVector<PrimarySelectionDeviceV1Interface *> primarySelectionDevices;
|
QVector<PrimarySelectionDeviceV1Interface *> primarySelectionDevices;
|
||||||
|
@ -953,11 +939,7 @@ void SeatInterface::setFocusedKeyboardSurface(SurfaceInterface *surface)
|
||||||
|
|
||||||
d->globalKeyboard.focus.primarySelections = primarySelectionDevices;
|
d->globalKeyboard.focus.primarySelections = primarySelectionDevices;
|
||||||
for (auto primaryDataDevice : primarySelectionDevices) {
|
for (auto primaryDataDevice : primarySelectionDevices) {
|
||||||
if (d->currentPrimarySelection) {
|
primaryDataDevice->sendSelection(d->currentPrimarySelection);
|
||||||
primaryDataDevice->sendSelection(d->currentPrimarySelection);
|
|
||||||
} else {
|
|
||||||
primaryDataDevice->sendClearSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1293,19 +1275,11 @@ void SeatInterface::setSelection(AbstractDataSource *selection)
|
||||||
d->currentSelection = selection;
|
d->currentSelection = selection;
|
||||||
|
|
||||||
for (auto focussedSelection : std::as_const(d->globalKeyboard.focus.selections)) {
|
for (auto focussedSelection : std::as_const(d->globalKeyboard.focus.selections)) {
|
||||||
if (selection) {
|
focussedSelection->sendSelection(selection);
|
||||||
focussedSelection->sendSelection(selection);
|
|
||||||
} else {
|
|
||||||
focussedSelection->sendClearSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto control : std::as_const(d->dataControlDevices)) {
|
for (auto control : std::as_const(d->dataControlDevices)) {
|
||||||
if (selection) {
|
control->sendSelection(selection);
|
||||||
control->sendSelection(selection);
|
|
||||||
} else {
|
|
||||||
control->sendClearSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT selectionChanged(selection);
|
Q_EMIT selectionChanged(selection);
|
||||||
|
@ -1351,18 +1325,10 @@ void SeatInterface::setPrimarySelection(AbstractDataSource *selection)
|
||||||
d->currentPrimarySelection = selection;
|
d->currentPrimarySelection = selection;
|
||||||
|
|
||||||
for (auto focussedSelection : std::as_const(d->globalKeyboard.focus.primarySelections)) {
|
for (auto focussedSelection : std::as_const(d->globalKeyboard.focus.primarySelections)) {
|
||||||
if (selection) {
|
focussedSelection->sendSelection(selection);
|
||||||
focussedSelection->sendSelection(selection);
|
|
||||||
} else {
|
|
||||||
focussedSelection->sendClearSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (auto control : std::as_const(d->dataControlDevices)) {
|
for (auto control : std::as_const(d->dataControlDevices)) {
|
||||||
if (selection) {
|
control->sendPrimarySelection(selection);
|
||||||
control->sendPrimarySelection(selection);
|
|
||||||
} else {
|
|
||||||
control->sendClearPrimarySelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT primarySelectionChanged(selection);
|
Q_EMIT primarySelectionChanged(selection);
|
||||||
|
|
Loading…
Reference in a new issue