summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2012-01-10 15:00:48 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-02-02 21:06:41 (GMT)
commit6a91b3bcdf1b5e491aa8531579c4e62fcc794d6e (patch)
tree8b40ef857d3dc0d9a094a5abdd12f27a1de5e9ed /src/gui
parent5aff681afb8284388a717a45e7ffd030b0ce3613 (diff)
downloadQt-6a91b3bcdf1b5e491aa8531579c4e62fcc794d6e.zip
Qt-6a91b3bcdf1b5e491aa8531579c4e62fcc794d6e.tar.gz
Qt-6a91b3bcdf1b5e491aa8531579c4e62fcc794d6e.tar.bz2
Check for the clipboard manager when looping due to app quiting
One can be extremely unlucky and on session logout get this: * All apps are going down * A Qt app checks if the clipboard manager is there to yield its clipboard contents * The clipboard manager is still there * Then just after that check, the clipboard manager finishes because of the session end * This means the Qt app will loop for 5 seconds trying to yield its clipboard contents to a clipboard manager that is not there anymore This is a backport of 689c4009fb9be348f9137a9092b068e056a3d8b3 in the qtbase (Qt 5.0) repo Change-Id: I8ab1f460aa5936c03f1afc1b6ff18824f1d6cbc1 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qclipboard_x11.cpp10
-rw-r--r--src/gui/kernel/qt_x11_p.h2
2 files changed, 9 insertions, 3 deletions
diff --git a/src/gui/kernel/qclipboard_x11.cpp b/src/gui/kernel/qclipboard_x11.cpp
index 7990f5d..803b1ba 100644
--- a/src/gui/kernel/qclipboard_x11.cpp
+++ b/src/gui/kernel/qclipboard_x11.cpp
@@ -515,7 +515,7 @@ static Bool checkForClipboardEvents(Display *, XEvent *e, XPointer)
|| e->xselectionclear.selection == ATOM(CLIPBOARD))));
}
-bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int timeout)
+bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int timeout, bool checkManager)
{
QElapsedTimer started;
started.start();
@@ -544,6 +544,9 @@ bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int ti
return true;
}
+ if (checkManager && XGetSelectionOwner(X11->display, ATOM(CLIPBOARD_MANAGER)) == XNone)
+ return false;
+
XSync(X11->display, false);
usleep(50000);
@@ -571,6 +574,9 @@ bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int ti
if (XCheckTypedWindowEvent(X11->display,win,type,event))
return true;
+ if (checkManager && XGetSelectionOwner(X11->display, ATOM(CLIPBOARD_MANAGER)) == XNone)
+ return false;
+
// process other clipboard events, since someone is probably requesting data from us
XEvent e;
if (XCheckIfEvent(X11->display, &e, checkForClipboardEvents, 0))
@@ -933,7 +939,7 @@ bool QClipboard::event(QEvent *e)
XEvent event;
// waiting until the clipboard manager fetches the content.
- if (!X11->clipboardWaitForEvent(ownerId, SelectionNotify, &event, 10000)) {
+ if (!X11->clipboardWaitForEvent(ownerId, SelectionNotify, &event, 10000, true)) {
qWarning("QClipboard: Unable to receive an event from the "
"clipboard manager in a reasonable time");
}
diff --git a/src/gui/kernel/qt_x11_p.h b/src/gui/kernel/qt_x11_p.h
index bdca019..ed7c146 100644
--- a/src/gui/kernel/qt_x11_p.h
+++ b/src/gui/kernel/qt_x11_p.h
@@ -350,7 +350,7 @@ struct QX11Data
Window findClientWindow(Window, Atom, bool);
// from qclipboard_x11.cpp
- bool clipboardWaitForEvent(Window win, int type, XEvent *event, int timeout);
+ bool clipboardWaitForEvent(Window win, int type, XEvent *event, int timeout, bool checkManager = false);
bool clipboardReadProperty(Window win, Atom property, bool deleteProperty,
QByteArray *buffer, int *size, Atom *type, int *format);
QByteArray clipboardReadIncrementalProperty(Window win, Atom property, int nbytes, bool nullterm);