| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/xcb/qxcbclipboard.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 29 | ** | - | ||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 31 | ** | - | ||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | #include "qxcbclipboard.h" | - | ||||||||||||
| 35 | - | |||||||||||||
| 36 | #include "qxcbconnection.h" | - | ||||||||||||
| 37 | #include "qxcbscreen.h" | - | ||||||||||||
| 38 | #include "qxcbmime.h" | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include <private/qguiapplication_p.h> | - | ||||||||||||
| 41 | #include <QElapsedTimer> | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | #include <QtCore/QDebug> | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | #define class class_name // Workaround XCB-ICCCM 3.8 breakage | - | ||||||||||||
| 46 | #include <xcb/xcb_icccm.h> | - | ||||||||||||
| 47 | #undef class | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | class QXcbClipboardMime : public QXcbMime | - | ||||||||||||
| 54 | { | - | ||||||||||||
| 55 | Q_OBJECT | - | ||||||||||||
| 56 | public: | - | ||||||||||||
| 57 | QXcbClipboardMime(QClipboard::Mode mode, QXcbClipboard *clipboard) | - | ||||||||||||
| 58 | : QXcbMime() | - | ||||||||||||
| 59 | , m_clipboard(clipboard) | - | ||||||||||||
| 60 | { | - | ||||||||||||
| 61 | switch (mode) { | - | ||||||||||||
| 62 | case QClipboard::Selection: never executed: case QClipboard::Selection: | 0 | ||||||||||||
| 63 | modeAtom = XCB_ATOM_PRIMARY; | - | ||||||||||||
| 64 | break; never executed: break; | 0 | ||||||||||||
| 65 | - | |||||||||||||
| 66 | case QClipboard::Clipboard: executed 5 times by 5 tests: case QClipboard::Clipboard:Executed by:
| 5 | ||||||||||||
| 67 | modeAtom = m_clipboard->atom(QXcbAtom::CLIPBOARD); | - | ||||||||||||
| 68 | break; executed 5 times by 5 tests: break;Executed by:
| 5 | ||||||||||||
| 69 | - | |||||||||||||
| 70 | default: never executed: default: | 0 | ||||||||||||
| 71 | qWarning("QXcbClipboardMime: Internal error: Unsupported clipboard mode"); | - | ||||||||||||
| 72 | break; never executed: break; | 0 | ||||||||||||
| 73 | } | - | ||||||||||||
| 74 | } | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | void reset() | - | ||||||||||||
| 77 | { | - | ||||||||||||
| 78 | formatList.clear(); | - | ||||||||||||
| 79 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 80 | - | |||||||||||||
| 81 | bool isEmpty() const | - | ||||||||||||
| 82 | { | - | ||||||||||||
| 83 | return m_clipboard->getSelectionOwner(modeAtom) == XCB_NONE; executed 60 times by 5 tests: return m_clipboard->getSelectionOwner(modeAtom) == 0L;Executed by:
| 60 | ||||||||||||
| 84 | } | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | protected: | - | ||||||||||||
| 87 | QStringList formats_sys() const Q_DECL_OVERRIDE | - | ||||||||||||
| 88 | { | - | ||||||||||||
| 89 | if (isEmpty())
| 2-49 | ||||||||||||
| 90 | return QStringList(); executed 49 times by 2 tests: return QStringList();Executed by:
| 49 | ||||||||||||
| 91 | - | |||||||||||||
| 92 | if (!formatList.count()) {
| 0-2 | ||||||||||||
| 93 | QXcbClipboardMime *that = const_cast<QXcbClipboardMime *>(this); | - | ||||||||||||
| 94 | // get the list of targets from the current clipboard owner - we do this | - | ||||||||||||
| 95 | // once so that multiple calls to this function don't require multiple | - | ||||||||||||
| 96 | // server round trips... | - | ||||||||||||
| 97 | that->format_atoms = m_clipboard->getDataInFormat(modeAtom, m_clipboard->atom(QXcbAtom::TARGETS)); | - | ||||||||||||
| 98 | - | |||||||||||||
| 99 | if (format_atoms.size() > 0) {
| 0-2 | ||||||||||||
| 100 | const xcb_atom_t *targets = (const xcb_atom_t *) format_atoms.data(); | - | ||||||||||||
| 101 | int size = format_atoms.size() / sizeof(xcb_atom_t); | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | for (int i = 0; i < size; ++i) {
| 2-14 | ||||||||||||
| 104 | if (targets[i] == 0)
| 0-14 | ||||||||||||
| 105 | continue; never executed: continue; | 0 | ||||||||||||
| 106 | - | |||||||||||||
| 107 | QString format = mimeAtomToString(m_clipboard->connection(), targets[i]); | - | ||||||||||||
| 108 | if (!formatList.contains(format))
| 6-8 | ||||||||||||
| 109 | that->formatList.append(format); executed 8 times by 2 tests: that->formatList.append(format);Executed by:
| 8 | ||||||||||||
| 110 | } executed 14 times by 2 tests: end of blockExecuted by:
| 14 | ||||||||||||
| 111 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||
| 112 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||
| 113 | - | |||||||||||||
| 114 | return formatList; executed 2 times by 2 tests: return formatList;Executed by:
| 2 | ||||||||||||
| 115 | } | - | ||||||||||||
| 116 | - | |||||||||||||
| 117 | bool hasFormat_sys(const QString &format) const Q_DECL_OVERRIDE | - | ||||||||||||
| 118 | { | - | ||||||||||||
| 119 | QStringList list = formats(); | - | ||||||||||||
| 120 | return list.contains(format); executed 49 times by 2 tests: return list.contains(format);Executed by:
| 49 | ||||||||||||
| 121 | } | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | QVariant retrieveData_sys(const QString &fmt, QVariant::Type requestedType) const Q_DECL_OVERRIDE | - | ||||||||||||
| 124 | { | - | ||||||||||||
| 125 | if (fmt.isEmpty() || isEmpty())
| 0-5 | ||||||||||||
| 126 | return QByteArray(); executed 3 times by 1 test: return QByteArray();Executed by:
| 3 | ||||||||||||
| 127 | - | |||||||||||||
| 128 | (void)formats(); // trigger update of format list | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | QVector<xcb_atom_t> atoms; | - | ||||||||||||
| 131 | const xcb_atom_t *targets = (const xcb_atom_t *) format_atoms.data(); | - | ||||||||||||
| 132 | int size = format_atoms.size() / sizeof(xcb_atom_t); | - | ||||||||||||
| 133 | atoms.reserve(size); | - | ||||||||||||
| 134 | for (int i = 0; i < size; ++i)
| 2-14 | ||||||||||||
| 135 | atoms.append(targets[i]); executed 14 times by 2 tests: atoms.append(targets[i]);Executed by:
| 14 | ||||||||||||
| 136 | - | |||||||||||||
| 137 | QByteArray encoding; | - | ||||||||||||
| 138 | xcb_atom_t fmtatom = mimeAtomForFormat(m_clipboard->connection(), fmt, requestedType, atoms, &encoding); | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | if (fmtatom == 0)
| 0-2 | ||||||||||||
| 141 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||
| 142 | - | |||||||||||||
| 143 | return mimeConvertToFormat(m_clipboard->connection(), fmtatom, m_clipboard->getDataInFormat(modeAtom, fmtatom), fmt, requestedType, encoding); executed 2 times by 2 tests: return mimeConvertToFormat(m_clipboard->connection(), fmtatom, m_clipboard->getDataInFormat(modeAtom, fmtatom), fmt, requestedType, encoding);Executed by:
| 2 | ||||||||||||
| 144 | } | - | ||||||||||||
| 145 | private: | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | xcb_atom_t modeAtom; | - | ||||||||||||
| 148 | QXcbClipboard *m_clipboard; | - | ||||||||||||
| 149 | QStringList formatList; | - | ||||||||||||
| 150 | QByteArray format_atoms; | - | ||||||||||||
| 151 | }; | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | class INCRTransaction; | - | ||||||||||||
| 154 | typedef QMap<xcb_window_t,INCRTransaction*> TransactionMap; | - | ||||||||||||
| 155 | static TransactionMap *transactions = 0; | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | //#define INCR_DEBUG | - | ||||||||||||
| 158 | - | |||||||||||||
| 159 | class INCRTransaction : public QObject | - | ||||||||||||
| 160 | { | - | ||||||||||||
| 161 | Q_OBJECT | - | ||||||||||||
| 162 | public: | - | ||||||||||||
| 163 | INCRTransaction(QXcbConnection *c, xcb_window_t w, xcb_atom_t p, | - | ||||||||||||
| 164 | QByteArray d, uint i, xcb_atom_t t, int f, int to) : | - | ||||||||||||
| 165 | conn(c), win(w), property(p), data(d), increment(i), | - | ||||||||||||
| 166 | target(t), format(f), timeout(to), offset(0) | - | ||||||||||||
| 167 | { | - | ||||||||||||
| 168 | const quint32 values[] = { XCB_EVENT_MASK_PROPERTY_CHANGE }; | - | ||||||||||||
| 169 | xcb_change_window_attributes(conn->xcb_connection(), win, | - | ||||||||||||
| 170 | XCB_CW_EVENT_MASK, values); | - | ||||||||||||
| 171 | if (!transactions) {
| 0 | ||||||||||||
| 172 | #ifdef INCR_DEBUG | - | ||||||||||||
| 173 | qDebug("INCRTransaction: creating the TransactionMap"); | - | ||||||||||||
| 174 | #endif | - | ||||||||||||
| 175 | transactions = new TransactionMap; | - | ||||||||||||
| 176 | conn->clipboard()->setProcessIncr(true); | - | ||||||||||||
| 177 | } never executed: end of block | 0 | ||||||||||||
| 178 | transactions->insert(win, this); | - | ||||||||||||
| 179 | abort_timer = startTimer(timeout); | - | ||||||||||||
| 180 | } never executed: end of block | 0 | ||||||||||||
| 181 | - | |||||||||||||
| 182 | ~INCRTransaction() | - | ||||||||||||
| 183 | { | - | ||||||||||||
| 184 | if (abort_timer)
| 0 | ||||||||||||
| 185 | killTimer(abort_timer); never executed: killTimer(abort_timer); | 0 | ||||||||||||
| 186 | abort_timer = 0; | - | ||||||||||||
| 187 | transactions->remove(win); | - | ||||||||||||
| 188 | if (transactions->isEmpty()) {
| 0 | ||||||||||||
| 189 | #ifdef INCR_DEBUG | - | ||||||||||||
| 190 | qDebug("INCRTransaction: no more INCR transactions left in the TransactionMap"); | - | ||||||||||||
| 191 | #endif | - | ||||||||||||
| 192 | delete transactions; | - | ||||||||||||
| 193 | transactions = 0; | - | ||||||||||||
| 194 | conn->clipboard()->setProcessIncr(false); | - | ||||||||||||
| 195 | } never executed: end of block | 0 | ||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||
| 197 | - | |||||||||||||
| 198 | void updateIncrProperty(xcb_property_notify_event_t *event, bool &accepted) | - | ||||||||||||
| 199 | { | - | ||||||||||||
| 200 | xcb_connection_t *c = conn->xcb_connection(); | - | ||||||||||||
| 201 | if (event->atom == property && event->state == XCB_PROPERTY_DELETE) {
| 0 | ||||||||||||
| 202 | accepted = true; | - | ||||||||||||
| 203 | // restart the timer | - | ||||||||||||
| 204 | if (abort_timer)
| 0 | ||||||||||||
| 205 | killTimer(abort_timer); never executed: killTimer(abort_timer); | 0 | ||||||||||||
| 206 | abort_timer = startTimer(timeout); | - | ||||||||||||
| 207 | - | |||||||||||||
| 208 | unsigned int bytes_left = data.size() - offset; | - | ||||||||||||
| 209 | if (bytes_left > 0) {
| 0 | ||||||||||||
| 210 | unsigned int bytes_to_send = qMin(increment, bytes_left); | - | ||||||||||||
| 211 | #ifdef INCR_DEBUG | - | ||||||||||||
| 212 | qDebug("INCRTransaction: sending %d bytes, %d remaining (INCR transaction %p)", | - | ||||||||||||
| 213 | bytes_to_send, bytes_left - bytes_to_send, this); | - | ||||||||||||
| 214 | #endif | - | ||||||||||||
| 215 | int dataSize = bytes_to_send / (format / 8); | - | ||||||||||||
| 216 | xcb_change_property(c, XCB_PROP_MODE_REPLACE, win, property, | - | ||||||||||||
| 217 | target, format, dataSize, data.constData() + offset); | - | ||||||||||||
| 218 | offset += bytes_to_send; | - | ||||||||||||
| 219 | } else { never executed: end of block | 0 | ||||||||||||
| 220 | #ifdef INCR_DEBUG | - | ||||||||||||
| 221 | qDebug("INCRTransaction: INCR transaction %p completed", this); | - | ||||||||||||
| 222 | #endif | - | ||||||||||||
| 223 | xcb_change_property(c, XCB_PROP_MODE_REPLACE, win, property, | - | ||||||||||||
| 224 | target, format, 0, (const void *)0); | - | ||||||||||||
| 225 | const quint32 values[] = { XCB_EVENT_MASK_NO_EVENT }; | - | ||||||||||||
| 226 | xcb_change_window_attributes(conn->xcb_connection(), win, | - | ||||||||||||
| 227 | XCB_CW_EVENT_MASK, values); | - | ||||||||||||
| 228 | // self destroy | - | ||||||||||||
| 229 | delete this; | - | ||||||||||||
| 230 | } never executed: end of block | 0 | ||||||||||||
| 231 | } | - | ||||||||||||
| 232 | } never executed: end of block | 0 | ||||||||||||
| 233 | - | |||||||||||||
| 234 | protected: | - | ||||||||||||
| 235 | void timerEvent(QTimerEvent *ev) Q_DECL_OVERRIDE | - | ||||||||||||
| 236 | { | - | ||||||||||||
| 237 | if (ev->timerId() == abort_timer) {
| 0 | ||||||||||||
| 238 | // this can happen when the X client we are sending data | - | ||||||||||||
| 239 | // to decides to exit (normally or abnormally) | - | ||||||||||||
| 240 | #ifdef INCR_DEBUG | - | ||||||||||||
| 241 | qDebug("INCRTransaction: Timed out while sending data to %p", this); | - | ||||||||||||
| 242 | #endif | - | ||||||||||||
| 243 | delete this; | - | ||||||||||||
| 244 | } never executed: end of block | 0 | ||||||||||||
| 245 | } never executed: end of block | 0 | ||||||||||||
| 246 | - | |||||||||||||
| 247 | private: | - | ||||||||||||
| 248 | QXcbConnection *conn; | - | ||||||||||||
| 249 | xcb_window_t win; | - | ||||||||||||
| 250 | xcb_atom_t property; | - | ||||||||||||
| 251 | QByteArray data; | - | ||||||||||||
| 252 | uint increment; | - | ||||||||||||
| 253 | xcb_atom_t target; | - | ||||||||||||
| 254 | int format; | - | ||||||||||||
| 255 | int timeout; | - | ||||||||||||
| 256 | uint offset; | - | ||||||||||||
| 257 | int abort_timer; | - | ||||||||||||
| 258 | }; | - | ||||||||||||
| 259 | - | |||||||||||||
| 260 | const int QXcbClipboard::clipboard_timeout = 5000; | - | ||||||||||||
| 261 | - | |||||||||||||
| 262 | QXcbClipboard::QXcbClipboard(QXcbConnection *c) | - | ||||||||||||
| 263 | : QXcbObject(c), QPlatformClipboard() | - | ||||||||||||
| 264 | , m_requestor(XCB_NONE) | - | ||||||||||||
| 265 | , m_owner(XCB_NONE) | - | ||||||||||||
| 266 | , m_incr_active(false) | - | ||||||||||||
| 267 | , m_clipboard_closing(false) | - | ||||||||||||
| 268 | , m_incr_receive_time(0) | - | ||||||||||||
| 269 | { | - | ||||||||||||
| 270 | Q_ASSERT(QClipboard::Clipboard == 0); | - | ||||||||||||
| 271 | Q_ASSERT(QClipboard::Selection == 1); | - | ||||||||||||
| 272 | m_clientClipboard[QClipboard::Clipboard] = 0; | - | ||||||||||||
| 273 | m_clientClipboard[QClipboard::Selection] = 0; | - | ||||||||||||
| 274 | m_timestamp[QClipboard::Clipboard] = XCB_CURRENT_TIME; | - | ||||||||||||
| 275 | m_timestamp[QClipboard::Selection] = XCB_CURRENT_TIME; | - | ||||||||||||
| 276 | m_owner = connection()->getQtSelectionOwner(); | - | ||||||||||||
| 277 | - | |||||||||||||
| 278 | #ifndef QT_NO_DEBUG | - | ||||||||||||
| 279 | QByteArray ba("Qt clipboard window"); | - | ||||||||||||
| 280 | Q_XCB_CALL(xcb_change_property(xcb_connection(), | - | ||||||||||||
| 281 | XCB_PROP_MODE_REPLACE, | - | ||||||||||||
| 282 | m_owner, | - | ||||||||||||
| 283 | atom(QXcbAtom::_NET_WM_NAME), | - | ||||||||||||
| 284 | atom(QXcbAtom::UTF8_STRING), | - | ||||||||||||
| 285 | 8, | - | ||||||||||||
| 286 | ba.length(), | - | ||||||||||||
| 287 | ba.constData())); | - | ||||||||||||
| 288 | #endif | - | ||||||||||||
| 289 | - | |||||||||||||
| 290 | if (connection()->hasXFixes()) {
| 0-129 | ||||||||||||
| 291 | const uint32_t mask = XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER | | - | ||||||||||||
| 292 | XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_WINDOW_DESTROY | | - | ||||||||||||
| 293 | XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE; | - | ||||||||||||
| 294 | Q_XCB_CALL(xcb_xfixes_select_selection_input_checked(xcb_connection(), m_owner, XCB_ATOM_PRIMARY, mask)); | - | ||||||||||||
| 295 | Q_XCB_CALL(xcb_xfixes_select_selection_input_checked(xcb_connection(), m_owner, atom(QXcbAtom::CLIPBOARD), mask)); | - | ||||||||||||
| 296 | } executed 129 times by 5 tests: end of blockExecuted by:
| 129 | ||||||||||||
| 297 | } executed 129 times by 5 tests: end of blockExecuted by:
| 129 | ||||||||||||
| 298 | - | |||||||||||||
| 299 | QXcbClipboard::~QXcbClipboard() | - | ||||||||||||
| 300 | { | - | ||||||||||||
| 301 | m_clipboard_closing = true; | - | ||||||||||||
| 302 | // Transfer the clipboard content to the clipboard manager if we own a selection | - | ||||||||||||
| 303 | if (m_timestamp[QClipboard::Clipboard] != XCB_CURRENT_TIME ||
| 5-336 | ||||||||||||
| 304 | m_timestamp[QClipboard::Selection] != XCB_CURRENT_TIME) {
| 1-335 | ||||||||||||
| 305 | - | |||||||||||||
| 306 | // First we check if there is a clipboard manager. | - | ||||||||||||
| 307 | xcb_get_selection_owner_cookie_t cookie = xcb_get_selection_owner(xcb_connection(), atom(QXcbAtom::CLIPBOARD_MANAGER)); | - | ||||||||||||
| 308 | xcb_get_selection_owner_reply_t *reply = xcb_get_selection_owner_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 309 | if (reply && reply->owner != XCB_NONE) {
| 0-6 | ||||||||||||
| 310 | // we delete the property so the manager saves all TARGETS. | - | ||||||||||||
| 311 | xcb_delete_property(xcb_connection(), m_owner, atom(QXcbAtom::_QT_SELECTION)); | - | ||||||||||||
| 312 | xcb_convert_selection(xcb_connection(), m_owner, atom(QXcbAtom::CLIPBOARD_MANAGER), atom(QXcbAtom::SAVE_TARGETS), | - | ||||||||||||
| 313 | atom(QXcbAtom::_QT_SELECTION), connection()->time()); | - | ||||||||||||
| 314 | connection()->sync(); | - | ||||||||||||
| 315 | - | |||||||||||||
| 316 | // waiting until the clipboard manager fetches the content. | - | ||||||||||||
| 317 | if (!waitForClipboardEvent(m_owner, XCB_SELECTION_NOTIFY, clipboard_timeout, true)) {
| 0-6 | ||||||||||||
| 318 | qWarning("QXcbClipboard: Unable to receive an event from the " | - | ||||||||||||
| 319 | "clipboard manager in a reasonable time"); | - | ||||||||||||
| 320 | } never executed: end of block | 0 | ||||||||||||
| 321 | } executed 6 times by 6 tests: end of blockExecuted by:
| 6 | ||||||||||||
| 322 | free(reply); | - | ||||||||||||
| 323 | } executed 6 times by 6 tests: end of blockExecuted by:
| 6 | ||||||||||||
| 324 | - | |||||||||||||
| 325 | if (m_clientClipboard[QClipboard::Clipboard] != m_clientClipboard[QClipboard::Selection])
| 6-335 | ||||||||||||
| 326 | delete m_clientClipboard[QClipboard::Clipboard]; executed 6 times by 6 tests: delete m_clientClipboard[QClipboard::Clipboard];Executed by:
| 6 | ||||||||||||
| 327 | delete m_clientClipboard[QClipboard::Selection]; | - | ||||||||||||
| 328 | } executed 341 times by 220 tests: end of blockExecuted by:
| 341 | ||||||||||||
| 329 | - | |||||||||||||
| 330 | void QXcbClipboard::incrTransactionPeeker(xcb_generic_event_t *ge, bool &accepted) | - | ||||||||||||
| 331 | { | - | ||||||||||||
| 332 | uint response_type = ge->response_type & ~0x80; | - | ||||||||||||
| 333 | if (response_type == XCB_PROPERTY_NOTIFY) {
| 0 | ||||||||||||
| 334 | xcb_property_notify_event_t *event = (xcb_property_notify_event_t *)ge; | - | ||||||||||||
| 335 | TransactionMap::Iterator it = transactions->find(event->window); | - | ||||||||||||
| 336 | if (it != transactions->end()) {
| 0 | ||||||||||||
| 337 | (*it)->updateIncrProperty(event, accepted); | - | ||||||||||||
| 338 | } never executed: end of block | 0 | ||||||||||||
| 339 | } never executed: end of block | 0 | ||||||||||||
| 340 | } never executed: end of block | 0 | ||||||||||||
| 341 | - | |||||||||||||
| 342 | xcb_window_t QXcbClipboard::getSelectionOwner(xcb_atom_t atom) const | - | ||||||||||||
| 343 | { | - | ||||||||||||
| 344 | return connection()->getSelectionOwner(atom); executed 217 times by 7 tests: return connection()->getSelectionOwner(atom);Executed by:
| 217 | ||||||||||||
| 345 | } | - | ||||||||||||
| 346 | - | |||||||||||||
| 347 | xcb_atom_t QXcbClipboard::atomForMode(QClipboard::Mode mode) const | - | ||||||||||||
| 348 | { | - | ||||||||||||
| 349 | if (mode == QClipboard::Clipboard)
| 16-140 | ||||||||||||
| 350 | return atom(QXcbAtom::CLIPBOARD); executed 140 times by 6 tests: return atom(QXcbAtom::CLIPBOARD);Executed by:
| 140 | ||||||||||||
| 351 | if (mode == QClipboard::Selection)
| 0-16 | ||||||||||||
| 352 | return XCB_ATOM_PRIMARY; executed 16 times by 4 tests: return XCB_ATOM_PRIMARY;Executed by:
| 16 | ||||||||||||
| 353 | return XCB_NONE; never executed: return 0L; | 0 | ||||||||||||
| 354 | } | - | ||||||||||||
| 355 | - | |||||||||||||
| 356 | QClipboard::Mode QXcbClipboard::modeForAtom(xcb_atom_t a) const | - | ||||||||||||
| 357 | { | - | ||||||||||||
| 358 | if (a == XCB_ATOM_PRIMARY)
| 11-81 | ||||||||||||
| 359 | return QClipboard::Selection; executed 11 times by 4 tests: return QClipboard::Selection;Executed by:
| 11 | ||||||||||||
| 360 | if (a == atom(QXcbAtom::CLIPBOARD))
| 0-81 | ||||||||||||
| 361 | return QClipboard::Clipboard; executed 81 times by 9 tests: return QClipboard::Clipboard;Executed by:
| 81 | ||||||||||||
| 362 | // not supported enum value, used to detect errors | - | ||||||||||||
| 363 | return QClipboard::FindBuffer; never executed: return QClipboard::FindBuffer; | 0 | ||||||||||||
| 364 | } | - | ||||||||||||
| 365 | - | |||||||||||||
| 366 | - | |||||||||||||
| 367 | QMimeData * QXcbClipboard::mimeData(QClipboard::Mode mode) | - | ||||||||||||
| 368 | { | - | ||||||||||||
| 369 | if (mode > QClipboard::Selection)
| 0-89 | ||||||||||||
| 370 | return 0; never executed: return 0; | 0 | ||||||||||||
| 371 | - | |||||||||||||
| 372 | xcb_window_t clipboardOwner = getSelectionOwner(atomForMode(mode)); | - | ||||||||||||
| 373 | if (clipboardOwner == owner()) {
| 24-65 | ||||||||||||
| 374 | return m_clientClipboard[mode]; executed 65 times by 4 tests: return m_clientClipboard[mode];Executed by:
| 65 | ||||||||||||
| 375 | } else { | - | ||||||||||||
| 376 | if (!m_xClipboard[mode])
| 5-19 | ||||||||||||
| 377 | m_xClipboard[mode].reset(new QXcbClipboardMime(mode, this)); executed 5 times by 5 tests: m_xClipboard[mode].reset(new QXcbClipboardMime(mode, this));Executed by:
| 5 | ||||||||||||
| 378 | - | |||||||||||||
| 379 | return m_xClipboard[mode].data(); executed 24 times by 5 tests: return m_xClipboard[mode].data();Executed by:
| 24 | ||||||||||||
| 380 | } | - | ||||||||||||
| 381 | } | - | ||||||||||||
| 382 | - | |||||||||||||
| 383 | void QXcbClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) | - | ||||||||||||
| 384 | { | - | ||||||||||||
| 385 | if (mode > QClipboard::Selection)
| 0-72 | ||||||||||||
| 386 | return; never executed: return; | 0 | ||||||||||||
| 387 | - | |||||||||||||
| 388 | QXcbClipboardMime *xClipboard = 0; | - | ||||||||||||
| 389 | // verify if there is data to be cleared on global X Clipboard. | - | ||||||||||||
| 390 | if (!data) {
| 19-53 | ||||||||||||
| 391 | xClipboard = qobject_cast<QXcbClipboardMime *>(mimeData(mode)); | - | ||||||||||||
| 392 | if (xClipboard) {
| 4-15 | ||||||||||||
| 393 | if (xClipboard->isEmpty())
| 0-4 | ||||||||||||
| 394 | return; executed 4 times by 2 tests: return;Executed by:
| 4 | ||||||||||||
| 395 | } never executed: end of block | 0 | ||||||||||||
| 396 | } executed 15 times by 3 tests: end of blockExecuted by:
| 15 | ||||||||||||
| 397 | - | |||||||||||||
| 398 | if (!xClipboard && (m_clientClipboard[mode] == data))
| 0-68 | ||||||||||||
| 399 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||
| 400 | - | |||||||||||||
| 401 | xcb_atom_t modeAtom = atomForMode(mode); | - | ||||||||||||
| 402 | xcb_window_t newOwner = XCB_NONE; | - | ||||||||||||
| 403 | - | |||||||||||||
| 404 | if (m_clientClipboard[mode]) {
| 24-43 | ||||||||||||
| 405 | if (m_clientClipboard[QClipboard::Clipboard] != m_clientClipboard[QClipboard::Selection])
| 3-40 | ||||||||||||
| 406 | delete m_clientClipboard[mode]; executed 40 times by 4 tests: delete m_clientClipboard[mode];Executed by:
| 40 | ||||||||||||
| 407 | m_clientClipboard[mode] = 0; | - | ||||||||||||
| 408 | m_timestamp[mode] = XCB_CURRENT_TIME; | - | ||||||||||||
| 409 | } executed 43 times by 4 tests: end of blockExecuted by:
| 43 | ||||||||||||
| 410 | - | |||||||||||||
| 411 | if (connection()->time() == XCB_CURRENT_TIME)
| 5-62 | ||||||||||||
| 412 | connection()->setTime(connection()->getTimestamp()); executed 5 times by 5 tests: connection()->setTime(connection()->getTimestamp());Executed by:
| 5 | ||||||||||||
| 413 | - | |||||||||||||
| 414 | if (data) {
| 15-52 | ||||||||||||
| 415 | newOwner = owner(); | - | ||||||||||||
| 416 | - | |||||||||||||
| 417 | m_clientClipboard[mode] = data; | - | ||||||||||||
| 418 | m_timestamp[mode] = connection()->time(); | - | ||||||||||||
| 419 | } executed 52 times by 6 tests: end of blockExecuted by:
| 52 | ||||||||||||
| 420 | - | |||||||||||||
| 421 | xcb_set_selection_owner(xcb_connection(), newOwner, modeAtom, connection()->time()); | - | ||||||||||||
| 422 | - | |||||||||||||
| 423 | if (getSelectionOwner(modeAtom) != newOwner) {
| 0-67 | ||||||||||||
| 424 | qWarning("QXcbClipboard::setMimeData: Cannot set X11 selection owner"); | - | ||||||||||||
| 425 | } never executed: end of block | 0 | ||||||||||||
| 426 | - | |||||||||||||
| 427 | emitChanged(mode); | - | ||||||||||||
| 428 | } executed 67 times by 6 tests: end of blockExecuted by:
| 67 | ||||||||||||
| 429 | - | |||||||||||||
| 430 | bool QXcbClipboard::supportsMode(QClipboard::Mode mode) const | - | ||||||||||||
| 431 | { | - | ||||||||||||
| 432 | if (mode <= QClipboard::Selection)
| 9-169 | ||||||||||||
| 433 | return true; executed 169 times by 7 tests: return true;Executed by:
| 169 | ||||||||||||
| 434 | return false; executed 9 times by 1 test: return false;Executed by:
| 9 | ||||||||||||
| 435 | } | - | ||||||||||||
| 436 | - | |||||||||||||
| 437 | bool QXcbClipboard::ownsMode(QClipboard::Mode mode) const | - | ||||||||||||
| 438 | { | - | ||||||||||||
| 439 | if (m_owner == XCB_NONE || mode > QClipboard::Selection)
| 0-3 | ||||||||||||
| 440 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||
| 441 | - | |||||||||||||
| 442 | Q_ASSERT(m_timestamp[mode] == XCB_CURRENT_TIME || getSelectionOwner(atomForMode(mode)) == m_owner); | - | ||||||||||||
| 443 | - | |||||||||||||
| 444 | return m_timestamp[mode] != XCB_CURRENT_TIME; executed 2 times by 1 test: return m_timestamp[mode] != 0L;Executed by:
| 2 | ||||||||||||
| 445 | } | - | ||||||||||||
| 446 | - | |||||||||||||
| 447 | QXcbScreen *QXcbClipboard::screen() const | - | ||||||||||||
| 448 | { | - | ||||||||||||
| 449 | return connection()->primaryScreen(); executed 24 times by 6 tests: return connection()->primaryScreen();Executed by:
| 24 | ||||||||||||
| 450 | } | - | ||||||||||||
| 451 | - | |||||||||||||
| 452 | xcb_window_t QXcbClipboard::requestor() const | - | ||||||||||||
| 453 | { | - | ||||||||||||
| 454 | QXcbScreen *platformScreen = screen(); | - | ||||||||||||
| 455 | - | |||||||||||||
| 456 | if (!m_requestor && platformScreen) {
| 0-18 | ||||||||||||
| 457 | const int x = 0, y = 0, w = 3, h = 3; | - | ||||||||||||
| 458 | QXcbClipboard *that = const_cast<QXcbClipboard *>(this); | - | ||||||||||||
| 459 | - | |||||||||||||
| 460 | xcb_window_t window = xcb_generate_id(xcb_connection()); | - | ||||||||||||
| 461 | Q_XCB_CALL(xcb_create_window(xcb_connection(), | - | ||||||||||||
| 462 | XCB_COPY_FROM_PARENT, // depth -- same as root | - | ||||||||||||
| 463 | window, // window id | - | ||||||||||||
| 464 | platformScreen->screen()->root, // parent window id | - | ||||||||||||
| 465 | x, y, w, h, | - | ||||||||||||
| 466 | 0, // border width | - | ||||||||||||
| 467 | XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class | - | ||||||||||||
| 468 | platformScreen->screen()->root_visual, // visual | - | ||||||||||||
| 469 | 0, // value mask | - | ||||||||||||
| 470 | 0)); // value list | - | ||||||||||||
| 471 | #ifndef QT_NO_DEBUG | - | ||||||||||||
| 472 | QByteArray ba("Qt clipboard requestor window"); | - | ||||||||||||
| 473 | Q_XCB_CALL(xcb_change_property(xcb_connection(), | - | ||||||||||||
| 474 | XCB_PROP_MODE_REPLACE, | - | ||||||||||||
| 475 | window, | - | ||||||||||||
| 476 | atom(QXcbAtom::_NET_WM_NAME), | - | ||||||||||||
| 477 | atom(QXcbAtom::UTF8_STRING), | - | ||||||||||||
| 478 | 8, | - | ||||||||||||
| 479 | ba.length(), | - | ||||||||||||
| 480 | ba.constData())); | - | ||||||||||||
| 481 | #endif | - | ||||||||||||
| 482 | - | |||||||||||||
| 483 | uint32_t mask = XCB_EVENT_MASK_PROPERTY_CHANGE; | - | ||||||||||||
| 484 | xcb_change_window_attributes(xcb_connection(), window, XCB_CW_EVENT_MASK, &mask); | - | ||||||||||||
| 485 | - | |||||||||||||
| 486 | that->setRequestor(window); | - | ||||||||||||
| 487 | } executed 6 times by 6 tests: end of blockExecuted by:
| 6 | ||||||||||||
| 488 | return m_requestor; executed 24 times by 6 tests: return m_requestor;Executed by:
| 24 | ||||||||||||
| 489 | } | - | ||||||||||||
| 490 | - | |||||||||||||
| 491 | void QXcbClipboard::setRequestor(xcb_window_t window) | - | ||||||||||||
| 492 | { | - | ||||||||||||
| 493 | if (m_requestor != XCB_NONE) {
| 0-6 | ||||||||||||
| 494 | xcb_destroy_window(xcb_connection(), m_requestor); | - | ||||||||||||
| 495 | } never executed: end of block | 0 | ||||||||||||
| 496 | m_requestor = window; | - | ||||||||||||
| 497 | } executed 6 times by 6 tests: end of blockExecuted by:
| 6 | ||||||||||||
| 498 | - | |||||||||||||
| 499 | xcb_window_t QXcbClipboard::owner() const | - | ||||||||||||
| 500 | { | - | ||||||||||||
| 501 | return m_owner; executed 208 times by 7 tests: return m_owner;Executed by:
| 208 | ||||||||||||
| 502 | } | - | ||||||||||||
| 503 | - | |||||||||||||
| 504 | xcb_atom_t QXcbClipboard::sendTargetsSelection(QMimeData *d, xcb_window_t window, xcb_atom_t property) | - | ||||||||||||
| 505 | { | - | ||||||||||||
| 506 | QVector<xcb_atom_t> types; | - | ||||||||||||
| 507 | QStringList formats = QInternalMimeData::formatsHelper(d); | - | ||||||||||||
| 508 | for (int i = 0; i < formats.size(); ++i) {
| 5-9 | ||||||||||||
| 509 | QVector<xcb_atom_t> atoms = QXcbMime::mimeAtomsForFormat(connection(), formats.at(i)); | - | ||||||||||||
| 510 | for (int j = 0; j < atoms.size(); ++j) {
| 9-24 | ||||||||||||
| 511 | if (!types.contains(atoms.at(j)))
| 0-24 | ||||||||||||
| 512 | types.append(atoms.at(j)); executed 24 times by 5 tests: types.append(atoms.at(j));Executed by:
| 24 | ||||||||||||
| 513 | } executed 24 times by 5 tests: end of blockExecuted by:
| 24 | ||||||||||||
| 514 | } executed 9 times by 5 tests: end of blockExecuted by:
| 9 | ||||||||||||
| 515 | types.append(atom(QXcbAtom::TARGETS)); | - | ||||||||||||
| 516 | types.append(atom(QXcbAtom::MULTIPLE)); | - | ||||||||||||
| 517 | types.append(atom(QXcbAtom::TIMESTAMP)); | - | ||||||||||||
| 518 | types.append(atom(QXcbAtom::SAVE_TARGETS)); | - | ||||||||||||
| 519 | - | |||||||||||||
| 520 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, window, property, XCB_ATOM_ATOM, | - | ||||||||||||
| 521 | 32, types.size(), (const void *)types.constData()); | - | ||||||||||||
| 522 | return property; executed 5 times by 5 tests: return property;Executed by:
| 5 | ||||||||||||
| 523 | } | - | ||||||||||||
| 524 | - | |||||||||||||
| 525 | xcb_atom_t QXcbClipboard::sendSelection(QMimeData *d, xcb_atom_t target, xcb_window_t window, xcb_atom_t property) | - | ||||||||||||
| 526 | { | - | ||||||||||||
| 527 | xcb_atom_t atomFormat = target; | - | ||||||||||||
| 528 | int dataFormat = 0; | - | ||||||||||||
| 529 | QByteArray data; | - | ||||||||||||
| 530 | - | |||||||||||||
| 531 | QString fmt = QXcbMime::mimeAtomToString(connection(), target); | - | ||||||||||||
| 532 | if (fmt.isEmpty()) { // Not a MIME type we have
| 0-29 | ||||||||||||
| 533 | // qDebug() << "QClipboard: send_selection(): converting to type" << connection()->atomName(target) << "is not supported"; | - | ||||||||||||
| 534 | return XCB_NONE; never executed: return 0L; | 0 | ||||||||||||
| 535 | } | - | ||||||||||||
| 536 | // qDebug() << "QClipboard: send_selection(): converting to type" << fmt; | - | ||||||||||||
| 537 | - | |||||||||||||
| 538 | if (QXcbMime::mimeDataForAtom(connection(), target, d, &data, &atomFormat, &dataFormat)) {
| 5-24 | ||||||||||||
| 539 | - | |||||||||||||
| 540 | // don't allow INCR transfers when using MULTIPLE or to | - | ||||||||||||
| 541 | // Motif clients (since Motif doesn't support INCR) | - | ||||||||||||
| 542 | static xcb_atom_t motif_clip_temporary = atom(QXcbAtom::CLIP_TEMPORARY); | - | ||||||||||||
| 543 | bool allow_incr = property != motif_clip_temporary; | - | ||||||||||||
| 544 | // This 'bool' can be removed once there is a proper fix for QTBUG-32853 | - | ||||||||||||
| 545 | if (m_clipboard_closing)
| 0-24 | ||||||||||||
| 546 | allow_incr = false; executed 24 times by 5 tests: allow_incr = false;Executed by:
| 24 | ||||||||||||
| 547 | // X_ChangeProperty protocol request is 24 bytes | - | ||||||||||||
| 548 | const int increment = (xcb_get_maximum_request_length(xcb_connection()) * 4) - 24; | - | ||||||||||||
| 549 | if (data.size() > increment && allow_incr) {
| 0-24 | ||||||||||||
| 550 | long bytes = data.size(); | - | ||||||||||||
| 551 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, window, property, | - | ||||||||||||
| 552 | atom(QXcbAtom::INCR), 32, 1, (const void *)&bytes); | - | ||||||||||||
| 553 | new INCRTransaction(connection(), window, property, data, increment, | - | ||||||||||||
| 554 | atomFormat, dataFormat, clipboard_timeout); | - | ||||||||||||
| 555 | return property; never executed: return property; | 0 | ||||||||||||
| 556 | } | - | ||||||||||||
| 557 | - | |||||||||||||
| 558 | // make sure we can perform the XChangeProperty in a single request | - | ||||||||||||
| 559 | if (data.size() > increment)
| 0-24 | ||||||||||||
| 560 | return XCB_NONE; // ### perhaps use several XChangeProperty calls w/ PropModeAppend? never executed: return 0L; | 0 | ||||||||||||
| 561 | int dataSize = data.size() / (dataFormat / 8); | - | ||||||||||||
| 562 | // use a single request to transfer data | - | ||||||||||||
| 563 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, window, property, atomFormat, | - | ||||||||||||
| 564 | dataFormat, dataSize, (const void *)data.constData()); | - | ||||||||||||
| 565 | } executed 24 times by 5 tests: end of blockExecuted by:
| 24 | ||||||||||||
| 566 | return property; executed 29 times by 5 tests: return property;Executed by:
| 29 | ||||||||||||
| 567 | } | - | ||||||||||||
| 568 | - | |||||||||||||
| 569 | void QXcbClipboard::handleSelectionClearRequest(xcb_selection_clear_event_t *event) | - | ||||||||||||
| 570 | { | - | ||||||||||||
| 571 | QClipboard::Mode mode = modeForAtom(event->selection); | - | ||||||||||||
| 572 | if (mode > QClipboard::Selection)
| 0-15 | ||||||||||||
| 573 | return; never executed: return; | 0 | ||||||||||||
| 574 | - | |||||||||||||
| 575 | // ignore the event if it was generated before we gained selection ownership | - | ||||||||||||
| 576 | if (m_timestamp[mode] != XCB_CURRENT_TIME && event->time <= m_timestamp[mode])
| 0-14 | ||||||||||||
| 577 | return; executed 14 times by 3 tests: return;Executed by:
| 14 | ||||||||||||
| 578 | - | |||||||||||||
| 579 | // DEBUG("QClipboard: new selection owner 0x%lx at time %lx (ours %lx)", | - | ||||||||||||
| 580 | // XGetSelectionOwner(dpy, XA_PRIMARY), | - | ||||||||||||
| 581 | // xevent->xselectionclear.time, d->timestamp); | - | ||||||||||||
| 582 | - | |||||||||||||
| 583 | xcb_window_t newOwner = getSelectionOwner(event->selection); | - | ||||||||||||
| 584 | - | |||||||||||||
| 585 | /* If selection ownership was given up voluntarily from QClipboard::clear(), then we do nothing here | - | ||||||||||||
| 586 | since its already handled in setMimeData. Otherwise, the event must have come from another client | - | ||||||||||||
| 587 | as a result of a call to xcb_set_selection_owner in which case we need to delete the local mime data | - | ||||||||||||
| 588 | */ | - | ||||||||||||
| 589 | if (newOwner != XCB_NONE) {
| 0-1 | ||||||||||||
| 590 | if (m_clientClipboard[QClipboard::Clipboard] != m_clientClipboard[QClipboard::Selection])
| 0 | ||||||||||||
| 591 | delete m_clientClipboard[mode]; never executed: delete m_clientClipboard[mode]; | 0 | ||||||||||||
| 592 | m_clientClipboard[mode] = 0; | - | ||||||||||||
| 593 | m_timestamp[mode] = XCB_CURRENT_TIME; | - | ||||||||||||
| 594 | } never executed: end of block | 0 | ||||||||||||
| 595 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 596 | - | |||||||||||||
| 597 | void QXcbClipboard::handleSelectionRequest(xcb_selection_request_event_t *req) | - | ||||||||||||
| 598 | { | - | ||||||||||||
| 599 | if (requestor() && req->requestor == requestor()) {
| 0-10 | ||||||||||||
| 600 | qWarning("QXcbClipboard: Selection request should be caught before"); | - | ||||||||||||
| 601 | return; never executed: return; | 0 | ||||||||||||
| 602 | } | - | ||||||||||||
| 603 | - | |||||||||||||
| 604 | Q_DECLARE_XCB_EVENT(event, xcb_selection_notify_event_t); | - | ||||||||||||
| 605 | event.response_type = XCB_SELECTION_NOTIFY; | - | ||||||||||||
| 606 | event.requestor = req->requestor; | - | ||||||||||||
| 607 | event.selection = req->selection; | - | ||||||||||||
| 608 | event.target = req->target; | - | ||||||||||||
| 609 | event.property = XCB_NONE; | - | ||||||||||||
| 610 | event.time = req->time; | - | ||||||||||||
| 611 | - | |||||||||||||
| 612 | QMimeData *d; | - | ||||||||||||
| 613 | QClipboard::Mode mode = modeForAtom(req->selection); | - | ||||||||||||
| 614 | if (mode > QClipboard::Selection) {
| 0-10 | ||||||||||||
| 615 | qWarning() << "QXcbClipboard: Unknown selection" << connection()->atomName(req->selection); | - | ||||||||||||
| 616 | xcb_send_event(xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); | - | ||||||||||||
| 617 | return; never executed: return; | 0 | ||||||||||||
| 618 | } | - | ||||||||||||
| 619 | - | |||||||||||||
| 620 | d = m_clientClipboard[mode]; | - | ||||||||||||
| 621 | - | |||||||||||||
| 622 | if (!d) {
| 0-10 | ||||||||||||
| 623 | qWarning("QXcbClipboard: Cannot transfer data, no data available"); | - | ||||||||||||
| 624 | xcb_send_event(xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); | - | ||||||||||||
| 625 | return; never executed: return; | 0 | ||||||||||||
| 626 | } | - | ||||||||||||
| 627 | - | |||||||||||||
| 628 | if (m_timestamp[mode] == XCB_CURRENT_TIME // we don't own the selection anymore
| 0-10 | ||||||||||||
| 629 | || (req->time != XCB_CURRENT_TIME && req->time < m_timestamp[mode])) {
| 0-10 | ||||||||||||
| 630 | qWarning("QXcbClipboard: SelectionRequest too old"); | - | ||||||||||||
| 631 | xcb_send_event(xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); | - | ||||||||||||
| 632 | return; never executed: return; | 0 | ||||||||||||
| 633 | } | - | ||||||||||||
| 634 | - | |||||||||||||
| 635 | xcb_atom_t targetsAtom = atom(QXcbAtom::TARGETS); | - | ||||||||||||
| 636 | xcb_atom_t multipleAtom = atom(QXcbAtom::MULTIPLE); | - | ||||||||||||
| 637 | xcb_atom_t timestampAtom = atom(QXcbAtom::TIMESTAMP); | - | ||||||||||||
| 638 | - | |||||||||||||
| 639 | struct AtomPair { xcb_atom_t target; xcb_atom_t property; } *multi = 0; | - | ||||||||||||
| 640 | xcb_atom_t multi_type = XCB_NONE; | - | ||||||||||||
| 641 | int multi_format = 0; | - | ||||||||||||
| 642 | int nmulti = 0; | - | ||||||||||||
| 643 | int imulti = -1; | - | ||||||||||||
| 644 | bool multi_writeback = false; | - | ||||||||||||
| 645 | - | |||||||||||||
| 646 | if (req->target == multipleAtom) {
| 5 | ||||||||||||
| 647 | QByteArray multi_data; | - | ||||||||||||
| 648 | if (req->property == XCB_NONE
| 0-5 | ||||||||||||
| 649 | || !clipboardReadProperty(req->requestor, req->property, false, &multi_data,
| 0-5 | ||||||||||||
| 650 | 0, &multi_type, &multi_format)
| 0-5 | ||||||||||||
| 651 | || multi_format != 32) {
| 0-5 | ||||||||||||
| 652 | // MULTIPLE property not formatted correctly | - | ||||||||||||
| 653 | xcb_send_event(xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); | - | ||||||||||||
| 654 | return; never executed: return; | 0 | ||||||||||||
| 655 | } | - | ||||||||||||
| 656 | nmulti = multi_data.size()/sizeof(*multi); | - | ||||||||||||
| 657 | multi = new AtomPair[nmulti]; | - | ||||||||||||
| 658 | memcpy(multi,multi_data.data(),multi_data.size()); | - | ||||||||||||
| 659 | imulti = 0; | - | ||||||||||||
| 660 | } executed 5 times by 5 tests: end of blockExecuted by:
| 5 | ||||||||||||
| 661 | - | |||||||||||||
| 662 | for (; imulti < nmulti; ++imulti) {
| 5-39 | ||||||||||||
| 663 | xcb_atom_t target; | - | ||||||||||||
| 664 | xcb_atom_t property; | - | ||||||||||||
| 665 | - | |||||||||||||
| 666 | if (multi) {
| 5-34 | ||||||||||||
| 667 | target = multi[imulti].target; | - | ||||||||||||
| 668 | property = multi[imulti].property; | - | ||||||||||||
| 669 | } else { executed 34 times by 5 tests: end of blockExecuted by:
| 34 | ||||||||||||
| 670 | target = req->target; | - | ||||||||||||
| 671 | property = req->property; | - | ||||||||||||
| 672 | if (property == XCB_NONE) // obsolete client
| 0-5 | ||||||||||||
| 673 | property = target; never executed: property = target; | 0 | ||||||||||||
| 674 | } executed 5 times by 5 tests: end of blockExecuted by:
| 5 | ||||||||||||
| 675 | - | |||||||||||||
| 676 | xcb_atom_t ret = XCB_NONE; | - | ||||||||||||
| 677 | if (target == XCB_NONE || property == XCB_NONE) {
| 0-39 | ||||||||||||
| 678 | ; | - | ||||||||||||
| 679 | } else if (target == timestampAtom) { never executed: end of block
| 0-34 | ||||||||||||
| 680 | if (m_timestamp[mode] != XCB_CURRENT_TIME) {
| 0-5 | ||||||||||||
| 681 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, req->requestor, | - | ||||||||||||
| 682 | property, XCB_ATOM_INTEGER, 32, 1, &m_timestamp[mode]); | - | ||||||||||||
| 683 | ret = property; | - | ||||||||||||
| 684 | } else { executed 5 times by 5 tests: end of blockExecuted by:
| 5 | ||||||||||||
| 685 | qWarning("QXcbClipboard: Invalid data timestamp"); | - | ||||||||||||
| 686 | } never executed: end of block | 0 | ||||||||||||
| 687 | } else if (target == targetsAtom) {
| 5-29 | ||||||||||||
| 688 | ret = sendTargetsSelection(d, req->requestor, property); | - | ||||||||||||
| 689 | } else { executed 5 times by 5 tests: end of blockExecuted by:
| 5 | ||||||||||||
| 690 | ret = sendSelection(d, target, req->requestor, property); | - | ||||||||||||
| 691 | } executed 29 times by 5 tests: end of blockExecuted by:
| 29 | ||||||||||||
| 692 | - | |||||||||||||
| 693 | if (nmulti > 0) {
| 5-34 | ||||||||||||
| 694 | if (ret == XCB_NONE) {
| 0-34 | ||||||||||||
| 695 | multi[imulti].property = XCB_NONE; | - | ||||||||||||
| 696 | multi_writeback = true; | - | ||||||||||||
| 697 | } never executed: end of block | 0 | ||||||||||||
| 698 | } else { executed 34 times by 5 tests: end of blockExecuted by:
| 34 | ||||||||||||
| 699 | event.property = ret; | - | ||||||||||||
| 700 | break; executed 5 times by 5 tests: break;Executed by:
| 5 | ||||||||||||
| 701 | } | - | ||||||||||||
| 702 | } | - | ||||||||||||
| 703 | - | |||||||||||||
| 704 | if (nmulti > 0) {
| 5 | ||||||||||||
| 705 | if (multi_writeback) {
| 0-5 | ||||||||||||
| 706 | // according to ICCCM 2.6.2 says to put None back | - | ||||||||||||
| 707 | // into the original property on the requestor window | - | ||||||||||||
| 708 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, req->requestor, req->property, | - | ||||||||||||
| 709 | multi_type, 32, nmulti*2, (const void *)multi); | - | ||||||||||||
| 710 | } never executed: end of block | 0 | ||||||||||||
| 711 | - | |||||||||||||
| 712 | delete [] multi; | - | ||||||||||||
| 713 | event.property = req->property; | - | ||||||||||||
| 714 | } executed 5 times by 5 tests: end of blockExecuted by:
| 5 | ||||||||||||
| 715 | - | |||||||||||||
| 716 | // send selection notify to requestor | - | ||||||||||||
| 717 | xcb_send_event(xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); | - | ||||||||||||
| 718 | } executed 10 times by 5 tests: end of blockExecuted by:
| 10 | ||||||||||||
| 719 | - | |||||||||||||
| 720 | void QXcbClipboard::handleXFixesSelectionRequest(xcb_xfixes_selection_notify_event_t *event) | - | ||||||||||||
| 721 | { | - | ||||||||||||
| 722 | QClipboard::Mode mode = modeForAtom(event->selection); | - | ||||||||||||
| 723 | if (mode > QClipboard::Selection)
| 0-67 | ||||||||||||
| 724 | return; never executed: return; | 0 | ||||||||||||
| 725 | - | |||||||||||||
| 726 | // Note1: Here we care only about the xfixes events that come from other processes. | - | ||||||||||||
| 727 | // Note2: If the QClipboard::clear() is issued, event->owner is XCB_NONE, | - | ||||||||||||
| 728 | // so we check selection_timestamp to not handle our own QClipboard::clear(). | - | ||||||||||||
| 729 | if (event->owner != owner() && event->selection_timestamp > m_timestamp[mode]) {
| 1-52 | ||||||||||||
| 730 | if (!m_xClipboard[mode]) {
| 0-1 | ||||||||||||
| 731 | m_xClipboard[mode].reset(new QXcbClipboardMime(mode, this)); | - | ||||||||||||
| 732 | } else { never executed: end of block | 0 | ||||||||||||
| 733 | m_xClipboard[mode]->reset(); | - | ||||||||||||
| 734 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 735 | emitChanged(mode); | - | ||||||||||||
| 736 | } else if (event->subtype == XCB_XFIXES_SELECTION_EVENT_SELECTION_CLIENT_CLOSE || executed 1 time by 1 test: end of blockExecuted by:
| 0-66 | ||||||||||||
| 737 | event->subtype == XCB_XFIXES_SELECTION_EVENT_SELECTION_WINDOW_DESTROY)
| 0-66 | ||||||||||||
| 738 | emitChanged(mode); never executed: emitChanged(mode); | 0 | ||||||||||||
| 739 | } executed 67 times by 6 tests: end of blockExecuted by:
| 67 | ||||||||||||
| 740 | - | |||||||||||||
| 741 | - | |||||||||||||
| 742 | static inline int maxSelectionIncr(xcb_connection_t *c) | - | ||||||||||||
| 743 | { | - | ||||||||||||
| 744 | int l = xcb_get_maximum_request_length(c); | - | ||||||||||||
| 745 | return (l > 65536 ? 65536*4 : l*4) - 100; executed 9 times by 6 tests: return (l > 65536 ? 65536*4 : l*4) - 100;Executed by:
| 0-9 | ||||||||||||
| 746 | } | - | ||||||||||||
| 747 | - | |||||||||||||
| 748 | bool QXcbClipboard::clipboardReadProperty(xcb_window_t win, xcb_atom_t property, bool deleteProperty, QByteArray *buffer, int *size, xcb_atom_t *type, int *format) | - | ||||||||||||
| 749 | { | - | ||||||||||||
| 750 | int maxsize = maxSelectionIncr(xcb_connection()); | - | ||||||||||||
| 751 | ulong bytes_left; // bytes_after | - | ||||||||||||
| 752 | xcb_atom_t dummy_type; | - | ||||||||||||
| 753 | int dummy_format; | - | ||||||||||||
| 754 | - | |||||||||||||
| 755 | if (!type) // allow null args
| 0-9 | ||||||||||||
| 756 | type = &dummy_type; never executed: type = &dummy_type; | 0 | ||||||||||||
| 757 | if (!format)
| 4-5 | ||||||||||||
| 758 | format = &dummy_format; executed 4 times by 2 tests: format = &dummy_format;Executed by:
| 4 | ||||||||||||
| 759 | - | |||||||||||||
| 760 | // Don't read anything, just get the size of the property data | - | ||||||||||||
| 761 | xcb_get_property_cookie_t cookie = Q_XCB_CALL(xcb_get_property(xcb_connection(), false, win, property, XCB_GET_PROPERTY_TYPE_ANY, 0, 0)); | - | ||||||||||||
| 762 | xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 763 | if (!reply || reply->type == XCB_NONE) {
| 0-9 | ||||||||||||
| 764 | free(reply); | - | ||||||||||||
| 765 | buffer->resize(0); | - | ||||||||||||
| 766 | return false; never executed: return false; | 0 | ||||||||||||
| 767 | } | - | ||||||||||||
| 768 | *type = reply->type; | - | ||||||||||||
| 769 | *format = reply->format; | - | ||||||||||||
| 770 | bytes_left = reply->bytes_after; | - | ||||||||||||
| 771 | free(reply); | - | ||||||||||||
| 772 | - | |||||||||||||
| 773 | int offset = 0, buffer_offset = 0; | - | ||||||||||||
| 774 | - | |||||||||||||
| 775 | int newSize = bytes_left; | - | ||||||||||||
| 776 | buffer->resize(newSize); | - | ||||||||||||
| 777 | - | |||||||||||||
| 778 | bool ok = (buffer->size() == newSize); | - | ||||||||||||
| 779 | - | |||||||||||||
| 780 | if (ok && newSize) {
| 0-9 | ||||||||||||
| 781 | // could allocate buffer | - | ||||||||||||
| 782 | - | |||||||||||||
| 783 | while (bytes_left) {
| 9 | ||||||||||||
| 784 | // more to read... | - | ||||||||||||
| 785 | - | |||||||||||||
| 786 | xcb_get_property_cookie_t cookie = Q_XCB_CALL(xcb_get_property(xcb_connection(), false, win, property, XCB_GET_PROPERTY_TYPE_ANY, offset, maxsize/4)); | - | ||||||||||||
| 787 | reply = xcb_get_property_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 788 | if (!reply || reply->type == XCB_NONE) {
| 0-9 | ||||||||||||
| 789 | free(reply); | - | ||||||||||||
| 790 | break; never executed: break; | 0 | ||||||||||||
| 791 | } | - | ||||||||||||
| 792 | *type = reply->type; | - | ||||||||||||
| 793 | *format = reply->format; | - | ||||||||||||
| 794 | bytes_left = reply->bytes_after; | - | ||||||||||||
| 795 | char *data = (char *)xcb_get_property_value(reply); | - | ||||||||||||
| 796 | int length = xcb_get_property_value_length(reply); | - | ||||||||||||
| 797 | - | |||||||||||||
| 798 | // Here we check if we get a buffer overflow and tries to | - | ||||||||||||
| 799 | // recover -- this shouldn't normally happen, but it doesn't | - | ||||||||||||
| 800 | // hurt to be defensive | - | ||||||||||||
| 801 | if ((int)(buffer_offset + length) > buffer->size()) {
| 0-9 | ||||||||||||
| 802 | qWarning("QXcbClipboard: buffer overflow"); | - | ||||||||||||
| 803 | length = buffer->size() - buffer_offset; | - | ||||||||||||
| 804 | - | |||||||||||||
| 805 | // escape loop | - | ||||||||||||
| 806 | bytes_left = 0; | - | ||||||||||||
| 807 | } never executed: end of block | 0 | ||||||||||||
| 808 | - | |||||||||||||
| 809 | memcpy(buffer->data() + buffer_offset, data, length); | - | ||||||||||||
| 810 | buffer_offset += length; | - | ||||||||||||
| 811 | - | |||||||||||||
| 812 | if (bytes_left) {
| 0-9 | ||||||||||||
| 813 | // offset is specified in 32-bit multiples | - | ||||||||||||
| 814 | offset += length / 4; | - | ||||||||||||
| 815 | } never executed: end of block | 0 | ||||||||||||
| 816 | free(reply); | - | ||||||||||||
| 817 | } executed 9 times by 6 tests: end of blockExecuted by:
| 9 | ||||||||||||
| 818 | } executed 9 times by 6 tests: end of blockExecuted by:
| 9 | ||||||||||||
| 819 | - | |||||||||||||
| 820 | - | |||||||||||||
| 821 | // correct size, not 0-term. | - | ||||||||||||
| 822 | if (size)
| 0-9 | ||||||||||||
| 823 | *size = buffer_offset; never executed: *size = buffer_offset; | 0 | ||||||||||||
| 824 | if (*type == atom(QXcbAtom::INCR))
| 0-9 | ||||||||||||
| 825 | m_incr_receive_time = connection()->getTimestamp(); never executed: m_incr_receive_time = connection()->getTimestamp(); | 0 | ||||||||||||
| 826 | if (deleteProperty)
| 4-5 | ||||||||||||
| 827 | xcb_delete_property(xcb_connection(), win, property); executed 4 times by 2 tests: xcb_delete_property(xcb_connection(), win, property);Executed by:
| 4 | ||||||||||||
| 828 | - | |||||||||||||
| 829 | connection()->flush(); | - | ||||||||||||
| 830 | - | |||||||||||||
| 831 | return ok; executed 9 times by 6 tests: return ok;Executed by:
| 9 | ||||||||||||
| 832 | } | - | ||||||||||||
| 833 | - | |||||||||||||
| 834 | - | |||||||||||||
| 835 | namespace | - | ||||||||||||
| 836 | { | - | ||||||||||||
| 837 | class Notify { | - | ||||||||||||
| 838 | public: | - | ||||||||||||
| 839 | Notify(xcb_window_t win, int t) | - | ||||||||||||
| 840 | : window(win), type(t) {} executed 25 times by 7 tests: end of blockExecuted by:
| 25 | ||||||||||||
| 841 | xcb_window_t window; | - | ||||||||||||
| 842 | int type; | - | ||||||||||||
| 843 | bool checkEvent(xcb_generic_event_t *event) const { | - | ||||||||||||
| 844 | if (!event)
| 17-2092 | ||||||||||||
| 845 | return false; executed 17 times by 6 tests: return false;Executed by:
| 17 | ||||||||||||
| 846 | int t = event->response_type & 0x7f; | - | ||||||||||||
| 847 | if (t != type)
| 10-2082 | ||||||||||||
| 848 | return false; executed 2082 times by 7 tests: return false;Executed by:
| 2082 | ||||||||||||
| 849 | if (t == XCB_PROPERTY_NOTIFY) {
| 0-10 | ||||||||||||
| 850 | xcb_property_notify_event_t *pn = (xcb_property_notify_event_t *)event; | - | ||||||||||||
| 851 | if (pn->window == window)
| 0 | ||||||||||||
| 852 | return true; never executed: return true; | 0 | ||||||||||||
| 853 | } else if (t == XCB_SELECTION_NOTIFY) { never executed: end of block
| 0-10 | ||||||||||||
| 854 | xcb_selection_notify_event_t *sn = (xcb_selection_notify_event_t *)event; | - | ||||||||||||
| 855 | if (sn->requestor == window)
| 0-10 | ||||||||||||
| 856 | return true; executed 10 times by 7 tests: return true;Executed by:
| 10 | ||||||||||||
| 857 | } never executed: end of block | 0 | ||||||||||||
| 858 | return false; never executed: return false; | 0 | ||||||||||||
| 859 | } | - | ||||||||||||
| 860 | }; | - | ||||||||||||
| 861 | class ClipboardEvent { | - | ||||||||||||
| 862 | public: | - | ||||||||||||
| 863 | ClipboardEvent(QXcbConnection *c) | - | ||||||||||||
| 864 | { clipboard = c->internAtom("CLIPBOARD"); } executed 15 times by 5 tests: end of blockExecuted by:
| 15 | ||||||||||||
| 865 | xcb_atom_t clipboard; | - | ||||||||||||
| 866 | bool checkEvent(xcb_generic_event_t *e) const { | - | ||||||||||||
| 867 | if (!e)
| 5-1282 | ||||||||||||
| 868 | return false; executed 5 times by 5 tests: return false;Executed by:
| 5 | ||||||||||||
| 869 | int type = e->response_type & 0x7f; | - | ||||||||||||
| 870 | if (type == XCB_SELECTION_REQUEST) {
| 10-1272 | ||||||||||||
| 871 | xcb_selection_request_event_t *sr = (xcb_selection_request_event_t *)e; | - | ||||||||||||
| 872 | return sr->selection == XCB_ATOM_PRIMARY || sr->selection == clipboard; executed 10 times by 5 tests: return sr->selection == XCB_ATOM_PRIMARY || sr->selection == clipboard;Executed by:
| 0-10 | ||||||||||||
| 873 | } else if (type == XCB_SELECTION_CLEAR) {
| 0-1272 | ||||||||||||
| 874 | xcb_selection_clear_event_t *sc = (xcb_selection_clear_event_t *)e; | - | ||||||||||||
| 875 | return sc->selection == XCB_ATOM_PRIMARY || sc->selection == clipboard; never executed: return sc->selection == XCB_ATOM_PRIMARY || sc->selection == clipboard;
| 0 | ||||||||||||
| 876 | } | - | ||||||||||||
| 877 | return false; executed 1272 times by 4 tests: return false;Executed by:
| 1272 | ||||||||||||
| 878 | } | - | ||||||||||||
| 879 | }; | - | ||||||||||||
| 880 | } | - | ||||||||||||
| 881 | - | |||||||||||||
| 882 | xcb_generic_event_t *QXcbClipboard::waitForClipboardEvent(xcb_window_t win, int type, int timeout, bool checkManager) | - | ||||||||||||
| 883 | { | - | ||||||||||||
| 884 | QElapsedTimer timer; | - | ||||||||||||
| 885 | timer.start(); | - | ||||||||||||
| 886 | do { | - | ||||||||||||
| 887 | Notify notify(win, type); | - | ||||||||||||
| 888 | xcb_generic_event_t *e = connection()->checkEvent(notify); | - | ||||||||||||
| 889 | if (e)
| 10-15 | ||||||||||||
| 890 | return e; executed 10 times by 7 tests: return e;Executed by:
| 10 | ||||||||||||
| 891 | - | |||||||||||||
| 892 | if (checkManager) {
| 1-14 | ||||||||||||
| 893 | xcb_get_selection_owner_cookie_t cookie = xcb_get_selection_owner(xcb_connection(), atom(QXcbAtom::CLIPBOARD_MANAGER)); | - | ||||||||||||
| 894 | xcb_get_selection_owner_reply_t *reply = xcb_get_selection_owner_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 895 | if (!reply || reply->owner == XCB_NONE) {
| 0-14 | ||||||||||||
| 896 | free(reply); | - | ||||||||||||
| 897 | return 0; never executed: return 0; | 0 | ||||||||||||
| 898 | } | - | ||||||||||||
| 899 | free(reply); | - | ||||||||||||
| 900 | } executed 14 times by 5 tests: end of blockExecuted by:
| 14 | ||||||||||||
| 901 | - | |||||||||||||
| 902 | // process other clipboard events, since someone is probably requesting data from us | - | ||||||||||||
| 903 | ClipboardEvent clipboard(connection()); | - | ||||||||||||
| 904 | e = connection()->checkEvent(clipboard); | - | ||||||||||||
| 905 | if (e) {
| 5-10 | ||||||||||||
| 906 | connection()->handleXcbEvent(e); | - | ||||||||||||
| 907 | free(e); | - | ||||||||||||
| 908 | } executed 10 times by 5 tests: end of blockExecuted by:
| 10 | ||||||||||||
| 909 | - | |||||||||||||
| 910 | connection()->flush(); | - | ||||||||||||
| 911 | - | |||||||||||||
| 912 | // sleep 50 ms, so we don't use up CPU cycles all the time. | - | ||||||||||||
| 913 | struct timeval usleep_tv; | - | ||||||||||||
| 914 | usleep_tv.tv_sec = 0; | - | ||||||||||||
| 915 | usleep_tv.tv_usec = 50000; | - | ||||||||||||
| 916 | select(0, 0, 0, 0, &usleep_tv); | - | ||||||||||||
| 917 | } while (timer.elapsed() < timeout); executed 15 times by 5 tests: end of blockExecuted by:
| 0-15 | ||||||||||||
| 918 | - | |||||||||||||
| 919 | return 0; never executed: return 0; | 0 | ||||||||||||
| 920 | } | - | ||||||||||||
| 921 | - | |||||||||||||
| 922 | QByteArray QXcbClipboard::clipboardReadIncrementalProperty(xcb_window_t win, xcb_atom_t property, int nbytes, bool nullterm) | - | ||||||||||||
| 923 | { | - | ||||||||||||
| 924 | QByteArray buf; | - | ||||||||||||
| 925 | QByteArray tmp_buf; | - | ||||||||||||
| 926 | bool alloc_error = false; | - | ||||||||||||
| 927 | int length; | - | ||||||||||||
| 928 | int offset = 0; | - | ||||||||||||
| 929 | xcb_timestamp_t prev_time = m_incr_receive_time; | - | ||||||||||||
| 930 | - | |||||||||||||
| 931 | if (nbytes > 0) {
| 0 | ||||||||||||
| 932 | // Reserve buffer + zero-terminator (for text data) | - | ||||||||||||
| 933 | // We want to complete the INCR transfer even if we cannot | - | ||||||||||||
| 934 | // allocate more memory | - | ||||||||||||
| 935 | buf.resize(nbytes+1); | - | ||||||||||||
| 936 | alloc_error = buf.size() != nbytes+1; | - | ||||||||||||
| 937 | } never executed: end of block | 0 | ||||||||||||
| 938 | - | |||||||||||||
| 939 | for (;;) { | - | ||||||||||||
| 940 | connection()->flush(); | - | ||||||||||||
| 941 | xcb_generic_event_t *ge = waitForClipboardEvent(win, XCB_PROPERTY_NOTIFY, clipboard_timeout); | - | ||||||||||||
| 942 | if (!ge)
| 0 | ||||||||||||
| 943 | break; never executed: break; | 0 | ||||||||||||
| 944 | xcb_property_notify_event_t *event = (xcb_property_notify_event_t *)ge; | - | ||||||||||||
| 945 | - | |||||||||||||
| 946 | if (event->atom != property
| 0 | ||||||||||||
| 947 | || event->state != XCB_PROPERTY_NEW_VALUE
| 0 | ||||||||||||
| 948 | || event->time < prev_time)
| 0 | ||||||||||||
| 949 | continue; never executed: continue; | 0 | ||||||||||||
| 950 | prev_time = event->time; | - | ||||||||||||
| 951 | - | |||||||||||||
| 952 | if (clipboardReadProperty(win, property, true, &tmp_buf, &length, 0, 0)) {
| 0 | ||||||||||||
| 953 | if (length == 0) { // no more data, we're done
| 0 | ||||||||||||
| 954 | if (nullterm) {
| 0 | ||||||||||||
| 955 | buf.resize(offset+1); | - | ||||||||||||
| 956 | buf[offset] = '\0'; | - | ||||||||||||
| 957 | } else { never executed: end of block | 0 | ||||||||||||
| 958 | buf.resize(offset); | - | ||||||||||||
| 959 | } never executed: end of block | 0 | ||||||||||||
| 960 | return buf; never executed: return buf; | 0 | ||||||||||||
| 961 | } else if (!alloc_error) {
| 0 | ||||||||||||
| 962 | if (offset+length > (int)buf.size()) {
| 0 | ||||||||||||
| 963 | buf.resize(offset+length+65535); | - | ||||||||||||
| 964 | if (buf.size() != offset+length+65535) {
| 0 | ||||||||||||
| 965 | alloc_error = true; | - | ||||||||||||
| 966 | length = buf.size() - offset; | - | ||||||||||||
| 967 | } never executed: end of block | 0 | ||||||||||||
| 968 | } never executed: end of block | 0 | ||||||||||||
| 969 | memcpy(buf.data()+offset, tmp_buf.constData(), length); | - | ||||||||||||
| 970 | tmp_buf.resize(0); | - | ||||||||||||
| 971 | offset += length; | - | ||||||||||||
| 972 | } never executed: end of block | 0 | ||||||||||||
| 973 | } else { never executed: end of block | 0 | ||||||||||||
| 974 | break; never executed: break; | 0 | ||||||||||||
| 975 | } | - | ||||||||||||
| 976 | - | |||||||||||||
| 977 | free(ge); | - | ||||||||||||
| 978 | } never executed: end of block | 0 | ||||||||||||
| 979 | - | |||||||||||||
| 980 | // timed out ... create a new requestor window, otherwise the requestor | - | ||||||||||||
| 981 | // could consider next request to be still part of this timed out request | - | ||||||||||||
| 982 | setRequestor(0); | - | ||||||||||||
| 983 | - | |||||||||||||
| 984 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||
| 985 | } | - | ||||||||||||
| 986 | - | |||||||||||||
| 987 | QByteArray QXcbClipboard::getDataInFormat(xcb_atom_t modeAtom, xcb_atom_t fmtAtom) | - | ||||||||||||
| 988 | { | - | ||||||||||||
| 989 | return getSelection(modeAtom, fmtAtom, atom(QXcbAtom::_QT_SELECTION)); executed 4 times by 2 tests: return getSelection(modeAtom, fmtAtom, atom(QXcbAtom::_QT_SELECTION));Executed by:
| 4 | ||||||||||||
| 990 | } | - | ||||||||||||
| 991 | - | |||||||||||||
| 992 | QByteArray QXcbClipboard::getSelection(xcb_atom_t selection, xcb_atom_t target, xcb_atom_t property, xcb_timestamp_t time) | - | ||||||||||||
| 993 | { | - | ||||||||||||
| 994 | QByteArray buf; | - | ||||||||||||
| 995 | xcb_window_t win = requestor(); | - | ||||||||||||
| 996 | - | |||||||||||||
| 997 | if (time == 0) time = connection()->time(); executed 4 times by 2 tests: time = connection()->time();Executed by:
| 0-4 | ||||||||||||
| 998 | - | |||||||||||||
| 999 | xcb_delete_property(xcb_connection(), win, property); | - | ||||||||||||
| 1000 | xcb_convert_selection(xcb_connection(), win, selection, target, property, time); | - | ||||||||||||
| 1001 | - | |||||||||||||
| 1002 | connection()->sync(); | - | ||||||||||||
| 1003 | - | |||||||||||||
| 1004 | xcb_generic_event_t *ge = waitForClipboardEvent(win, XCB_SELECTION_NOTIFY, clipboard_timeout); | - | ||||||||||||
| 1005 | bool no_selection = !ge || ((xcb_selection_notify_event_t *)ge)->property == XCB_NONE;
| 0-4 | ||||||||||||
| 1006 | free(ge); | - | ||||||||||||
| 1007 | - | |||||||||||||
| 1008 | if (no_selection)
| 0-4 | ||||||||||||
| 1009 | return buf; never executed: return buf; | 0 | ||||||||||||
| 1010 | - | |||||||||||||
| 1011 | xcb_atom_t type; | - | ||||||||||||
| 1012 | if (clipboardReadProperty(win, property, true, &buf, 0, &type, 0)) {
| 0-4 | ||||||||||||
| 1013 | if (type == atom(QXcbAtom::INCR)) {
| 0-4 | ||||||||||||
| 1014 | int nbytes = buf.size() >= 4 ? *((int*)buf.data()) : 0;
| 0 | ||||||||||||
| 1015 | buf = clipboardReadIncrementalProperty(win, property, nbytes, false); | - | ||||||||||||
| 1016 | } never executed: end of block | 0 | ||||||||||||
| 1017 | } executed 4 times by 2 tests: end of blockExecuted by:
| 4 | ||||||||||||
| 1018 | - | |||||||||||||
| 1019 | return buf; executed 4 times by 2 tests: return buf;Executed by:
| 4 | ||||||||||||
| 1020 | } | - | ||||||||||||
| 1021 | - | |||||||||||||
| 1022 | #endif // QT_NO_CLIPBOARD | - | ||||||||||||
| 1023 | - | |||||||||||||
| 1024 | QT_END_NAMESPACE | - | ||||||||||||
| 1025 | - | |||||||||||||
| 1026 | #include "qxcbclipboard.moc" | - | ||||||||||||
| Source code | Switch to Preprocessed file |