From: Liang Qi Date: Wed, 7 Jul 2021 11:19:14 +0000 (+0200) Subject: [PATCH] xcb: add a timeout control when reading INCR property X-Git-Tag: archive/raspbian/5.15.4+dfsg-5+rpi1^2~21 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b701349cac593dde9b16f47a639ac21c6fa24f24;p=qtbase-opensource-src.git [PATCH] xcb: add a timeout control when reading INCR property For the first call of QXcbClipboard::clipboardReadProperty() inside of clipboardReadIncrementalProperty() in getSelection(), it will get a XCB_NONE reply before the contents arrived via property change. Then we give a chance to read more. Manually tested with following setups: * examples/widgets/mainwindows/application with gvim(gtk3) * examples/widgets/widgets/imageviewer with GIMP 2.10.18(based on gtk2) and GIMP 2.99.6(based on gtk3 via flatpak) Fixes: QTBUG-56595 Pick-to: 5.12 5.15 6.1 6.2 Done-With: JiDe Zhang Change-Id: Ib45f08464d39ad79137b1da99808c89b7dca2d08 Reviewed-by: JiDe Zhang Reviewed-by: Tor Arne Vestbø Gbp-Pq: Name xcb_add_a_timeout_control_when_reading_INCR_property.diff --- diff --git a/src/plugins/platforms/xcb/qxcbclipboard.cpp b/src/plugins/platforms/xcb/qxcbclipboard.cpp index 0a4d67560..dabdfcb6c 100644 --- a/src/plugins/platforms/xcb/qxcbclipboard.cpp +++ b/src/plugins/platforms/xcb/qxcbclipboard.cpp @@ -835,6 +835,8 @@ QByteArray QXcbClipboard::clipboardReadIncrementalProperty(xcb_window_t win, xcb alloc_error = buf.size() != nbytes+1; } + QElapsedTimer timer; + timer.start(); for (;;) { connection()->flush(); xcb_generic_event_t *ge = waitForClipboardEvent(win, XCB_PROPERTY_NOTIFY); @@ -870,9 +872,11 @@ QByteArray QXcbClipboard::clipboardReadIncrementalProperty(xcb_window_t win, xcb tmp_buf.resize(0); offset += length; } - } else { - break; } + + const auto elapsed = timer.elapsed(); + if (elapsed > clipboard_timeout) + break; } // timed out ... create a new requestor window, otherwise the requestor