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