kdeui: wait for owner after killing it in KSelectionOwner::claim()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-15 04:35:24 +02:00
parent e8e1d7c908
commit 6b0375f64f

View file

@ -27,6 +27,19 @@
#define KSELECTIONOWNER_SLEEPTIME 500 #define KSELECTIONOWNER_SLEEPTIME 500
#define KSELECTIONOWNER_CHECKTIME 250 #define KSELECTIONOWNER_CHECKTIME 250
static Window kWaitForOwner(Display* x11display, const Atom x11atom)
{
ushort counter = 0;
Window currentowner = XGetSelectionOwner(x11display, x11atom);
while (currentowner != None && counter < 10) {
QCoreApplication::processEvents(QEventLoop::AllEvents, KSELECTIONOWNER_TIMEOUT);
QThread::msleep(KSELECTIONOWNER_SLEEPTIME);
counter++;
currentowner = XGetSelectionOwner(x11display, x11atom);
}
return currentowner;
}
class KSelectionOwnerPrivate class KSelectionOwnerPrivate
{ {
public: public:
@ -94,16 +107,15 @@ bool KSelectionOwner::claim(const bool force)
} }
if (currentowner != None) { if (currentowner != None) {
kDebug(240) << d->atomname << "is owned, clearing owner"; kDebug(240) << d->atomname << "is owned, clearing owner";
KXErrorHandler kx11errorhandler(d->x11display);
XSetSelectionOwner(d->x11display, d->x11atom, None, CurrentTime); XSetSelectionOwner(d->x11display, d->x11atom, None, CurrentTime);
XFlush(d->x11display); XFlush(d->x11display);
ushort counter = 0; if (kx11errorhandler.error(true)) {
kDebug(240) << "Waiting for" << d->atomname << "owner"; kWarning(240) << KXErrorHandler::errorMessage(kx11errorhandler.errorEvent());
while (currentowner != None && counter < 10) { return false;
currentowner = XGetSelectionOwner(d->x11display, d->x11atom);
QCoreApplication::processEvents(QEventLoop::AllEvents, KSELECTIONOWNER_TIMEOUT);
QThread::msleep(KSELECTIONOWNER_SLEEPTIME);
counter++;
} }
kDebug(240) << "Waiting for" << d->atomname << "owner";
currentowner = kWaitForOwner(d->x11display, d->x11atom);
} }
if (currentowner != None) { if (currentowner != None) {
kDebug(240) << d->atomname << "is owned, killing owner"; kDebug(240) << d->atomname << "is owned, killing owner";
@ -114,6 +126,12 @@ bool KSelectionOwner::claim(const bool force)
kWarning(240) << KXErrorHandler::errorMessage(kx11errorhandler.errorEvent()); kWarning(240) << KXErrorHandler::errorMessage(kx11errorhandler.errorEvent());
return false; return false;
} }
kDebug(240) << "Waiting for" << d->atomname << "owner";
currentowner = kWaitForOwner(d->x11display, d->x11atom);
}
if (currentowner != None) {
kWarning(240) << d->atomname << "is still owned";
return false;
} }
kDebug(240) << "Creating" << d->atomname << "owner"; kDebug(240) << "Creating" << d->atomname << "owner";
KXErrorHandler kx11errorhandler(d->x11display); KXErrorHandler kx11errorhandler(d->x11display);