| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/xcb/qxcbdrag.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | const int xdnd_version = 5; | - | ||||||||||||
| 7 | - | |||||||||||||
| 8 | static inline xcb_window_t xcb_window(QPlatformWindow *w) | - | ||||||||||||
| 9 | { | - | ||||||||||||
| 10 | return static_cast<QXcbWindow *>(w)->xcb_window(); | - | ||||||||||||
| 11 | } | - | ||||||||||||
| 12 | - | |||||||||||||
| 13 | static inline xcb_window_t xcb_window(QWindow *w) | - | ||||||||||||
| 14 | { | - | ||||||||||||
| 15 | return static_cast<QXcbWindow *>(w->handle())->xcb_window(); | - | ||||||||||||
| 16 | } | - | ||||||||||||
| 17 | - | |||||||||||||
| 18 | static xcb_window_t xdndProxy(QXcbConnection *c, xcb_window_t w) | - | ||||||||||||
| 19 | { | - | ||||||||||||
| 20 | xcb_window_t proxy = 0L; | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | xcb_get_property_cookie_t cookie = xcb_get_property(c->xcb_connection(), false, w, c->atom(QXcbAtom::XdndProxy), XCB_ATOM_WINDOW, 0, 1) | - | ||||||||||||
| 23 | ; | - | ||||||||||||
| 24 | xcb_get_property_reply_t *reply = xcb_get_property_reply(c->xcb_connection(), cookie, 0); | - | ||||||||||||
| 25 | - | |||||||||||||
| 26 | if (reply && reply->type == XCB_ATOM_WINDOW) | - | ||||||||||||
| 27 | proxy = *((xcb_window_t *)xcb_get_property_value(reply)); | - | ||||||||||||
| 28 | free(reply); | - | ||||||||||||
| 29 | - | |||||||||||||
| 30 | if (proxy == 0L) | - | ||||||||||||
| 31 | return proxy; | - | ||||||||||||
| 32 | - | |||||||||||||
| 33 | - | |||||||||||||
| 34 | cookie = xcb_get_property(c->xcb_connection(), false, proxy, c->atom(QXcbAtom::XdndProxy), XCB_ATOM_WINDOW, 0, 1) | - | ||||||||||||
| 35 | ; | - | ||||||||||||
| 36 | reply = xcb_get_property_reply(c->xcb_connection(), cookie, 0); | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | if (reply && reply->type == XCB_ATOM_WINDOW) { | - | ||||||||||||
| 39 | xcb_window_t p = *((xcb_window_t *)xcb_get_property_value(reply)); | - | ||||||||||||
| 40 | if (proxy != p) | - | ||||||||||||
| 41 | proxy = 0; | - | ||||||||||||
| 42 | } else { | - | ||||||||||||
| 43 | proxy = 0; | - | ||||||||||||
| 44 | } | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | free(reply); | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | return proxy; | - | ||||||||||||
| 49 | } | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | class QXcbDropData : public QXcbMime | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | public: | - | ||||||||||||
| 54 | QXcbDropData(QXcbDrag *d); | - | ||||||||||||
| 55 | ~QXcbDropData(); | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | protected: | - | ||||||||||||
| 58 | bool hasFormat_sys(const QString &mimeType) const override; | - | ||||||||||||
| 59 | QStringList formats_sys() const override; | - | ||||||||||||
| 60 | QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const override; | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | QVariant xdndObtainData(const QByteArray &format, QVariant::Type requestedType) const; | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | QXcbDrag *drag; | - | ||||||||||||
| 65 | }; | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | - | |||||||||||||
| 68 | QXcbDrag::QXcbDrag(QXcbConnection *c) : QXcbObject(c) | - | ||||||||||||
| 69 | { | - | ||||||||||||
| 70 | dropData = new QXcbDropData(this); | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | init(); | - | ||||||||||||
| 73 | cleanup_timer = -1; | - | ||||||||||||
| 74 | } | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | QXcbDrag::~QXcbDrag() | - | ||||||||||||
| 77 | { | - | ||||||||||||
| 78 | delete dropData; | - | ||||||||||||
| 79 | } | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | void QXcbDrag::init() | - | ||||||||||||
| 82 | { | - | ||||||||||||
| 83 | currentWindow.clear(); | - | ||||||||||||
| 84 | - | |||||||||||||
| 85 | accepted_drop_action = Qt::IgnoreAction; | - | ||||||||||||
| 86 | - | |||||||||||||
| 87 | xdnd_dragsource = 0L; | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | waiting_for_status = false; | - | ||||||||||||
| 90 | current_target = 0L; | - | ||||||||||||
| 91 | current_proxy_target = 0L; | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | source_time = 0L; | - | ||||||||||||
| 94 | target_time = 0L; | - | ||||||||||||
| 95 | - | |||||||||||||
| 96 | QXcbCursor::queryPointer(connection(), ¤t_virtual_desktop, 0); | - | ||||||||||||
| 97 | drag_types.clear(); | - | ||||||||||||
| 98 | } | - | ||||||||||||
| 99 | - | |||||||||||||
| 100 | QMimeData *QXcbDrag::platformDropData() | - | ||||||||||||
| 101 | { | - | ||||||||||||
| 102 | return dropData; | - | ||||||||||||
| 103 | } | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | bool QXcbDrag::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||
| 106 | { | - | ||||||||||||
| 107 | - | |||||||||||||
| 108 | - | |||||||||||||
| 109 | - | |||||||||||||
| 110 | - | |||||||||||||
| 111 | if (initiatorWindow && o == shapedPixmapWindow()) | - | ||||||||||||
| 112 | o = initiatorWindow.data(); | - | ||||||||||||
| 113 | return QBasicDrag::eventFilter(o, e); | - | ||||||||||||
| 114 | } | - | ||||||||||||
| 115 | - | |||||||||||||
| 116 | void QXcbDrag::startDrag() | - | ||||||||||||
| 117 | { | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | - | |||||||||||||
| 120 | init(); | - | ||||||||||||
| 121 | - | |||||||||||||
| 122 | xcb_set_selection_owner(xcb_connection(), connection()->clipboard()->owner(), | - | ||||||||||||
| 123 | atom(QXcbAtom::XdndSelection), connection()->time()); | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | QStringList fmts = QXcbMime::formatsHelper(drag()->mimeData()); | - | ||||||||||||
| 126 | for (int i = 0; i < fmts.size(); ++i) { | - | ||||||||||||
| 127 | QVector<xcb_atom_t> atoms = QXcbMime::mimeAtomsForFormat(connection(), fmts.at(i)); | - | ||||||||||||
| 128 | for (int j = 0; j < atoms.size(); ++j) { | - | ||||||||||||
| 129 | if (!drag_types.contains(atoms.at(j))) | - | ||||||||||||
| 130 | drag_types.append(atoms.at(j)); | - | ||||||||||||
| 131 | } | - | ||||||||||||
| 132 | } | - | ||||||||||||
| 133 | if (drag_types.size() > 3) | - | ||||||||||||
| 134 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, connection()->clipboard()->owner(), | - | ||||||||||||
| 135 | atom(QXcbAtom::XdndTypelist), | - | ||||||||||||
| 136 | XCB_ATOM_ATOM, 32, drag_types.size(), (const void *)drag_types.constData()); | - | ||||||||||||
| 137 | - | |||||||||||||
| 138 | setUseCompositing(current_virtual_desktop->compositingActive()); | - | ||||||||||||
| 139 | setScreen(current_virtual_desktop->screens().constFirst()->screen()); | - | ||||||||||||
| 140 | initiatorWindow = QGuiApplicationPrivate::currentMouseWindow; | - | ||||||||||||
| 141 | QBasicDrag::startDrag(); | - | ||||||||||||
| 142 | if (connection()->mouseGrabber() == nullptr) | - | ||||||||||||
| 143 | shapedPixmapWindow()->setMouseGrabEnabled(true); | - | ||||||||||||
| 144 | } | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | void QXcbDrag::endDrag() | - | ||||||||||||
| 147 | { | - | ||||||||||||
| 148 | QBasicDrag::endDrag(); | - | ||||||||||||
| 149 | initiatorWindow.clear(); | - | ||||||||||||
| 150 | } | - | ||||||||||||
| 151 | - | |||||||||||||
| 152 | static xcb_translate_coordinates_reply_t * | - | ||||||||||||
| 153 | translateCoordinates(QXcbConnection *c, xcb_window_t from, xcb_window_t to, int x, int y) | - | ||||||||||||
| 154 | { | - | ||||||||||||
| 155 | xcb_translate_coordinates_cookie_t cookie = | - | ||||||||||||
| 156 | xcb_translate_coordinates(c->xcb_connection(), from, to, x, y); | - | ||||||||||||
| 157 | return xcb_translate_coordinates_reply(c->xcb_connection(), cookie, 0); | - | ||||||||||||
| 158 | } | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | static | - | ||||||||||||
| 161 | bool windowInteractsWithPosition(xcb_connection_t *connection, const QPoint & pos, xcb_window_t w, xcb_shape_sk_t shapeType) | - | ||||||||||||
| 162 | { | - | ||||||||||||
| 163 | bool interacts = false; | - | ||||||||||||
| 164 | xcb_shape_get_rectangles_reply_t *reply = xcb_shape_get_rectangles_reply(connection, xcb_shape_get_rectangles(connection, w, shapeType), __null); | - | ||||||||||||
| 165 | if (reply) { | - | ||||||||||||
| 166 | xcb_rectangle_t *rectangles = xcb_shape_get_rectangles_rectangles(reply); | - | ||||||||||||
| 167 | if (rectangles) { | - | ||||||||||||
| 168 | const int nRectangles = xcb_shape_get_rectangles_rectangles_length(reply); | - | ||||||||||||
| 169 | for (int i = 0; !interacts && i < nRectangles; ++i) { | - | ||||||||||||
| 170 | interacts = QRect(rectangles[i].x, rectangles[i].y, rectangles[i].width, rectangles[i].height).contains(pos); | - | ||||||||||||
| 171 | } | - | ||||||||||||
| 172 | } | - | ||||||||||||
| 173 | free(reply); | - | ||||||||||||
| 174 | } | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | return interacts; | - | ||||||||||||
| 177 | } | - | ||||||||||||
| 178 | - | |||||||||||||
| 179 | xcb_window_t QXcbDrag::findRealWindow(const QPoint & pos, xcb_window_t w, int md, bool ignoreNonXdndAwareWindows) | - | ||||||||||||
| 180 | { | - | ||||||||||||
| 181 | if (w == shapedPixmapWindow()->handle()->winId()) | - | ||||||||||||
| 182 | return 0; | - | ||||||||||||
| 183 | - | |||||||||||||
| 184 | if (md) { | - | ||||||||||||
| 185 | xcb_get_window_attributes_cookie_t cookie = xcb_get_window_attributes(xcb_connection(), w); | - | ||||||||||||
| 186 | xcb_get_window_attributes_reply_t *reply = xcb_get_window_attributes_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 187 | if (!reply) | - | ||||||||||||
| 188 | return 0; | - | ||||||||||||
| 189 | - | |||||||||||||
| 190 | if (reply->map_state != XCB_MAP_STATE_VIEWABLE) | - | ||||||||||||
| 191 | return 0; | - | ||||||||||||
| 192 | - | |||||||||||||
| 193 | free(reply); | - | ||||||||||||
| 194 | - | |||||||||||||
| 195 | xcb_get_geometry_cookie_t gcookie = xcb_get_geometry(xcb_connection(), w); | - | ||||||||||||
| 196 | xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(xcb_connection(), gcookie, 0); | - | ||||||||||||
| 197 | if (!greply) | - | ||||||||||||
| 198 | return 0; | - | ||||||||||||
| 199 | - | |||||||||||||
| 200 | QRect windowRect(greply->x, greply->y, greply->width, greply->height); | - | ||||||||||||
| 201 | free(greply); | - | ||||||||||||
| 202 | if (windowRect.contains(pos)) { | - | ||||||||||||
| 203 | bool windowContainsMouse = !ignoreNonXdndAwareWindows; | - | ||||||||||||
| 204 | { | - | ||||||||||||
| 205 | xcb_get_property_cookie_t cookie = | - | ||||||||||||
| 206 | xcb_get_property(xcb_connection(), false, w, connection()->atom(QXcbAtom::XdndAware), XCB_GET_PROPERTY_TYPE_ANY, 0, 0) | - | ||||||||||||
| 207 | ; | - | ||||||||||||
| 208 | xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 209 | - | |||||||||||||
| 210 | bool isAware = reply && reply->type != 0L; | - | ||||||||||||
| 211 | free(reply); | - | ||||||||||||
| 212 | if (isAware) { | - | ||||||||||||
| 213 | const QPoint relPos = pos - windowRect.topLeft(); | - | ||||||||||||
| 214 | - | |||||||||||||
| 215 | - | |||||||||||||
| 216 | if (connection()->hasInputShape()) | - | ||||||||||||
| 217 | windowContainsMouse = windowInteractsWithPosition(xcb_connection(), relPos, w, XCB_SHAPE_SK_INPUT); | - | ||||||||||||
| 218 | if (windowContainsMouse && connection()->hasXShape()) | - | ||||||||||||
| 219 | windowContainsMouse = windowInteractsWithPosition(xcb_connection(), relPos, w, XCB_SHAPE_SK_BOUNDING); | - | ||||||||||||
| 220 | if (!connection()->hasInputShape() && !connection()->hasXShape()) | - | ||||||||||||
| 221 | windowContainsMouse = true; | - | ||||||||||||
| 222 | if (windowContainsMouse) | - | ||||||||||||
| 223 | return w; | - | ||||||||||||
| 224 | } | - | ||||||||||||
| 225 | } | - | ||||||||||||
| 226 | - | |||||||||||||
| 227 | xcb_query_tree_cookie_t cookie = xcb_query_tree (xcb_connection(), w); | - | ||||||||||||
| 228 | xcb_query_tree_reply_t *reply = xcb_query_tree_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 229 | - | |||||||||||||
| 230 | if (!reply) | - | ||||||||||||
| 231 | return 0; | - | ||||||||||||
| 232 | int nc = xcb_query_tree_children_length(reply); | - | ||||||||||||
| 233 | xcb_window_t *c = xcb_query_tree_children(reply); | - | ||||||||||||
| 234 | - | |||||||||||||
| 235 | xcb_window_t r = 0; | - | ||||||||||||
| 236 | for (uint i = nc; !r && i--;) | - | ||||||||||||
| 237 | r = findRealWindow(pos - windowRect.topLeft(), c[i], md-1, ignoreNonXdndAwareWindows); | - | ||||||||||||
| 238 | - | |||||||||||||
| 239 | free(reply); | - | ||||||||||||
| 240 | if (r) | - | ||||||||||||
| 241 | return r; | - | ||||||||||||
| 242 | - | |||||||||||||
| 243 | - | |||||||||||||
| 244 | - | |||||||||||||
| 245 | - | |||||||||||||
| 246 | - | |||||||||||||
| 247 | if (!windowContainsMouse) | - | ||||||||||||
| 248 | return 0; | - | ||||||||||||
| 249 | else | - | ||||||||||||
| 250 | return w; | - | ||||||||||||
| 251 | } | - | ||||||||||||
| 252 | } | - | ||||||||||||
| 253 | return 0; | - | ||||||||||||
| 254 | } | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | void QXcbDrag::move(const QPoint &globalPos) | - | ||||||||||||
| 257 | { | - | ||||||||||||
| 258 | - | |||||||||||||
| 259 | if (source_sameanswer.contains(globalPos) && source_sameanswer.isValid()) | - | ||||||||||||
| 260 | return; | - | ||||||||||||
| 261 | - | |||||||||||||
| 262 | QXcbVirtualDesktop *virtualDesktop = nullptr; | - | ||||||||||||
| 263 | QPoint cursorPos; | - | ||||||||||||
| 264 | QXcbCursor::queryPointer(connection(), &virtualDesktop, &cursorPos); | - | ||||||||||||
| 265 | QXcbScreen *screen = virtualDesktop->screenAt(cursorPos); | - | ||||||||||||
| 266 | QPoint deviceIndependentPos = QHighDpiScaling::mapPositionFromNative(globalPos, screen); | - | ||||||||||||
| 267 | - | |||||||||||||
| 268 | if (virtualDesktop != current_virtual_desktop) { | - | ||||||||||||
| 269 | setUseCompositing(virtualDesktop->compositingActive()); | - | ||||||||||||
| 270 | recreateShapedPixmapWindow(static_cast<QPlatformScreen*>(screen)->screen(), deviceIndependentPos); | - | ||||||||||||
| 271 | if (connection()->mouseGrabber() == nullptr) | - | ||||||||||||
| 272 | shapedPixmapWindow()->setMouseGrabEnabled(true); | - | ||||||||||||
| 273 | - | |||||||||||||
| 274 | current_virtual_desktop = virtualDesktop; | - | ||||||||||||
| 275 | } else { | - | ||||||||||||
| 276 | QBasicDrag::moveShapedPixmapWindow(deviceIndependentPos); | - | ||||||||||||
| 277 | } | - | ||||||||||||
| 278 | - | |||||||||||||
| 279 | xcb_window_t rootwin = current_virtual_desktop->root(); | - | ||||||||||||
| 280 | xcb_translate_coordinates_reply_t *translate = | - | ||||||||||||
| 281 | ::translateCoordinates(connection(), rootwin, rootwin, globalPos.x(), globalPos.y()); | - | ||||||||||||
| 282 | if (!translate) | - | ||||||||||||
| 283 | return; | - | ||||||||||||
| 284 | - | |||||||||||||
| 285 | xcb_window_t target = translate->child; | - | ||||||||||||
| 286 | int lx = translate->dst_x; | - | ||||||||||||
| 287 | int ly = translate->dst_y; | - | ||||||||||||
| 288 | free (translate); | - | ||||||||||||
| 289 | - | |||||||||||||
| 290 | if (target && target != rootwin) { | - | ||||||||||||
| 291 | xcb_window_t src = rootwin; | - | ||||||||||||
| 292 | while (target != 0) { | - | ||||||||||||
| 293 | if(0) QMessageLogger(__FILE__, 362368, __PRETTY_FUNCTION__).debug() << "checking target for XdndAware" << target << lx << ly; dead code: QMessageLogger(__FILE__, 368, __PRETTY_FUNCTION__).debug() << "checking target for XdndAware" << target << lx << ly; | - | ||||||||||||
| 294 | - | |||||||||||||
| 295 | - | |||||||||||||
| 296 | translate = ::translateCoordinates(connection(), src, target, lx, ly); | - | ||||||||||||
| 297 | if (!translate) { | - | ||||||||||||
| 298 | target = 0; | - | ||||||||||||
| 299 | break; | - | ||||||||||||
| 300 | } | - | ||||||||||||
| 301 | lx = translate->dst_x; | - | ||||||||||||
| 302 | ly = translate->dst_y; | - | ||||||||||||
| 303 | src = target; | - | ||||||||||||
| 304 | xcb_window_t child = translate->child; | - | ||||||||||||
| 305 | free(translate); | - | ||||||||||||
| 306 | - | |||||||||||||
| 307 | - | |||||||||||||
| 308 | xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, target, atom(QXcbAtom::XdndAware), XCB_GET_PROPERTY_TYPE_ANY, 0, 0) | - | ||||||||||||
| 309 | ; | - | ||||||||||||
| 310 | xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 311 | bool aware = reply && reply->type != 0L; | - | ||||||||||||
| 312 | free(reply); | - | ||||||||||||
| 313 | if (aware) { | - | ||||||||||||
| 314 | if(0) QMessageLogger(__FILE__, 383389, __PRETTY_FUNCTION__).debug() << "Found XdndAware on " << target; dead code: QMessageLogger(__FILE__, 389, __PRETTY_FUNCTION__).debug() << "Found XdndAware on " << target; | - | ||||||||||||
| 315 | break; | - | ||||||||||||
| 316 | } | - | ||||||||||||
| 317 | - | |||||||||||||
| 318 | target = child; | - | ||||||||||||
| 319 | } | - | ||||||||||||
| 320 | - | |||||||||||||
| 321 | if (!target || target == shapedPixmapWindow()->handle()->winId()) { | - | ||||||||||||
| 322 | if(0) QMessageLogger(__FILE__, 391397, __PRETTY_FUNCTION__).debug() << "need to find real window"; dead code: QMessageLogger(__FILE__, 397, __PRETTY_FUNCTION__).debug() << "need to find real window"; | - | ||||||||||||
| 323 | target = findRealWindow(globalPos, rootwin, 6, true); | - | ||||||||||||
| 324 | if (target == 0) | - | ||||||||||||
| 325 | target = findRealWindow(globalPos, rootwin, 6, false); | - | ||||||||||||
| 326 | if(0) QMessageLogger(__FILE__, 395401, __PRETTY_FUNCTION__).debug() << "real window found" << target; dead code: QMessageLogger(__FILE__, 401, __PRETTY_FUNCTION__).debug() << "real window found" << target; | - | ||||||||||||
| 327 | } | - | ||||||||||||
| 328 | } | - | ||||||||||||
| 329 | - | |||||||||||||
| 330 | QXcbWindow *w = 0; | - | ||||||||||||
| 331 | if (target) { | - | ||||||||||||
| 332 | w = connection()->platformWindowFromId(target); | - | ||||||||||||
| 333 | if (w && (w->window()->type() == Qt::Desktop) ) | - | ||||||||||||
| 334 | w = 0; | - | ||||||||||||
| 335 | } else { | - | ||||||||||||
| 336 | w = 0; | - | ||||||||||||
| 337 | target = rootwin; | - | ||||||||||||
| 338 | } | - | ||||||||||||
| 339 | - | |||||||||||||
| 340 | xcb_window_t proxy_target = xdndProxy(connection(), target); | - | ||||||||||||
| 341 | if (!proxy_target) | - | ||||||||||||
| 342 | proxy_target = target; | - | ||||||||||||
| 343 | int target_version = 1; | - | ||||||||||||
| 344 | - | |||||||||||||
| 345 | if (proxy_target) { | - | ||||||||||||
| 346 | xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, proxy_target, | - | ||||||||||||
| 347 | atom(QXcbAtom::XdndAware), XCB_GET_PROPERTY_TYPE_ANY, 0, 1); | - | ||||||||||||
| 348 | xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 349 | if (!reply || reply->type == 0L) | - | ||||||||||||
| 350 | target = 0; | - | ||||||||||||
| 351 | - | |||||||||||||
| 352 | target_version = *(uint32_t *)xcb_get_property_value(reply); | - | ||||||||||||
| 353 | target_version = qMin(xdnd_version, target_version ? target_version : 1); | - | ||||||||||||
| 354 | - | |||||||||||||
| 355 | free(reply); | - | ||||||||||||
| 356 | } | - | ||||||||||||
| 357 | - | |||||||||||||
| 358 | if (target != current_target) { | - | ||||||||||||
| 359 | if (current_target) | - | ||||||||||||
| 360 | send_leave(); | - | ||||||||||||
| 361 | - | |||||||||||||
| 362 | current_target = target; | - | ||||||||||||
| 363 | current_proxy_target = proxy_target; | - | ||||||||||||
| 364 | if (target) { | - | ||||||||||||
| 365 | int flags = target_version << 24; | - | ||||||||||||
| 366 | if (drag_types.size() > 3) | - | ||||||||||||
| 367 | flags |= 0x0001; | - | ||||||||||||
| 368 | - | |||||||||||||
| 369 | xcb_client_message_event_t enter; | - | ||||||||||||
| 370 | enter.response_type = 33; | - | ||||||||||||
| 371 | enter.sequence = 0; | - | ||||||||||||
| 372 | enter.window = target; | - | ||||||||||||
| 373 | enter.format = 32; | - | ||||||||||||
| 374 | enter.type = atom(QXcbAtom::XdndEnter); | - | ||||||||||||
| 375 | enter.data.data32[0] = connection()->clipboard()->owner(); | - | ||||||||||||
| 376 | enter.data.data32[1] = flags; | - | ||||||||||||
| 377 | enter.data.data32[2] = drag_types.size()>0 ? drag_types.at(0) : 0; | - | ||||||||||||
| 378 | enter.data.data32[3] = drag_types.size()>1 ? drag_types.at(1) : 0; | - | ||||||||||||
| 379 | enter.data.data32[4] = drag_types.size()>2 ? drag_types.at(2) : 0; | - | ||||||||||||
| 380 | - | |||||||||||||
| 381 | source_sameanswer = QRect(globalPos.x() - 2, globalPos.y() -2 , 5, 5); | - | ||||||||||||
| 382 | - | |||||||||||||
| 383 | if(0) QMessageLogger(__FILE__, 452458, __PRETTY_FUNCTION__).debug() << "sending Xdnd enter source=" << enter.data.data32[0]; dead code: QMessageLogger(__FILE__, 458, __PRETTY_FUNCTION__).debug() << "sending Xdnd enter source=" << enter.data.data32[0]; | - | ||||||||||||
| 384 | if (w) | - | ||||||||||||
| 385 | handleEnter(w, &enter, current_proxy_target); | - | ||||||||||||
| 386 | else if (target) | - | ||||||||||||
| 387 | xcb_send_event(xcb_connection(), false, proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&enter); | - | ||||||||||||
| 388 | waiting_for_status = false; | - | ||||||||||||
| 389 | } | - | ||||||||||||
| 390 | } | - | ||||||||||||
| 391 | - | |||||||||||||
| 392 | if (waiting_for_status) | - | ||||||||||||
| 393 | return; | - | ||||||||||||
| 394 | - | |||||||||||||
| 395 | if (target) { | - | ||||||||||||
| 396 | waiting_for_status = true; | - | ||||||||||||
| 397 | - | |||||||||||||
| 398 | xcb_client_message_event_t move; | - | ||||||||||||
| 399 | move.response_type = 33; | - | ||||||||||||
| 400 | move.sequence = 0; | - | ||||||||||||
| 401 | move.window = target; | - | ||||||||||||
| 402 | move.format = 32; | - | ||||||||||||
| 403 | move.type = atom(QXcbAtom::XdndPosition); | - | ||||||||||||
| 404 | move.data.data32[0] = connection()->clipboard()->owner(); | - | ||||||||||||
| 405 | move.data.data32[1] = 0; | - | ||||||||||||
| 406 | move.data.data32[2] = (globalPos.x() << 16) + globalPos.y(); | - | ||||||||||||
| 407 | move.data.data32[3] = connection()->time(); | - | ||||||||||||
| 408 | move.data.data32[4] = toXdndAction(defaultAction(currentDrag()->supportedActions(), QGuiApplication::keyboardModifiers())); | - | ||||||||||||
| 409 | if(0) QMessageLogger(__FILE__, 478484, __PRETTY_FUNCTION__).debug() << "sending Xdnd position source=" << move.data.data32[0] << "target=" << move.window; dead code: QMessageLogger(__FILE__, 484, __PRETTY_FUNCTION__).debug() << "sending Xdnd position source=" << move.data.data32[0] << "target=" << move.window; | - | ||||||||||||
| 410 | - | |||||||||||||
| 411 | source_time = connection()->time(); | - | ||||||||||||
| 412 | - | |||||||||||||
| 413 | if (w) | - | ||||||||||||
| 414 | handle_xdnd_position(w, &move); | - | ||||||||||||
| 415 | else | - | ||||||||||||
| 416 | xcb_send_event(xcb_connection(), false, proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&move); | - | ||||||||||||
| 417 | } | - | ||||||||||||
| 418 | } | - | ||||||||||||
| 419 | - | |||||||||||||
| 420 | void QXcbDrag::drop(const QPoint &globalPos) | - | ||||||||||||
| 421 | { | - | ||||||||||||
| 422 | QBasicDrag::drop(globalPos); | - | ||||||||||||
| 423 | - | |||||||||||||
| 424 | if (!current_target) | - | ||||||||||||
| 425 | return; | - | ||||||||||||
| 426 | - | |||||||||||||
| 427 | xcb_client_message_event_t drop; | - | ||||||||||||
| 428 | drop.response_type = 33; | - | ||||||||||||
| 429 | drop.sequence = 0; | - | ||||||||||||
| 430 | drop.window = current_target; | - | ||||||||||||
| 431 | drop.format = 32; | - | ||||||||||||
| 432 | drop.type = atom(QXcbAtom::XdndDrop); | - | ||||||||||||
| 433 | drop.data.data32[0] = connection()->clipboard()->owner(); | - | ||||||||||||
| 434 | drop.data.data32[1] = 0; | - | ||||||||||||
| 435 | drop.data.data32[2] = connection()->time(); | - | ||||||||||||
| 436 | - | |||||||||||||
| 437 | drop.data.data32[3] = 0; | - | ||||||||||||
| 438 | drop.data.data32[4] = currentDrag()->supportedActions(); | - | ||||||||||||
| 439 | - | |||||||||||||
| 440 | QXcbWindow *w = connection()->platformWindowFromId(current_proxy_target); | - | ||||||||||||
| 441 | - | |||||||||||||
| 442 | if (w && (w->window()->type() == Qt::Desktop) ) | - | ||||||||||||
| 443 | w = 0; | - | ||||||||||||
| 444 | - | |||||||||||||
| 445 | Transaction t = { | - | ||||||||||||
| 446 | connection()->time(), | - | ||||||||||||
| 447 | current_target, | - | ||||||||||||
| 448 | current_proxy_target, | - | ||||||||||||
| 449 | w, | - | ||||||||||||
| 450 | - | |||||||||||||
| 451 | currentDrag(), | - | ||||||||||||
| 452 | QTime::currentTime() | - | ||||||||||||
| 453 | }; | - | ||||||||||||
| 454 | transactions.append(t); | - | ||||||||||||
| 455 | - | |||||||||||||
| 456 | - | |||||||||||||
| 457 | if (!t.targetWindow && cleanup_timer == -1) { | - | ||||||||||||
| 458 | cleanup_timer = startTimer(XdndDropTransactionTimeout); | - | ||||||||||||
| 459 | } | - | ||||||||||||
| 460 | - | |||||||||||||
| 461 | if (w) { | - | ||||||||||||
| 462 | handleDrop(w, &drop); | - | ||||||||||||
| 463 | } else { | - | ||||||||||||
| 464 | xcb_send_event(xcb_connection(), false, current_proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&drop); | - | ||||||||||||
| 465 | } | - | ||||||||||||
| 466 | - | |||||||||||||
| 467 | current_target = 0; | - | ||||||||||||
| 468 | current_proxy_target = 0; | - | ||||||||||||
| 469 | source_time = 0; | - | ||||||||||||
| 470 | - | |||||||||||||
| 471 | } | - | ||||||||||||
| 472 | - | |||||||||||||
| 473 | Qt::DropAction QXcbDrag::toDropAction(xcb_atom_t a) const | - | ||||||||||||
| 474 | { | - | ||||||||||||
| 475 | if (a == atom(QXcbAtom::XdndActionCopy) || a == 0) | - | ||||||||||||
| 476 | return Qt::CopyAction; | - | ||||||||||||
| 477 | if (a == atom(QXcbAtom::XdndActionLink)) | - | ||||||||||||
| 478 | return Qt::LinkAction; | - | ||||||||||||
| 479 | if (a == atom(QXcbAtom::XdndActionMove)) | - | ||||||||||||
| 480 | return Qt::MoveAction; | - | ||||||||||||
| 481 | return Qt::CopyAction; | - | ||||||||||||
| 482 | } | - | ||||||||||||
| 483 | - | |||||||||||||
| 484 | xcb_atom_t QXcbDrag::toXdndAction(Qt::DropAction a) const | - | ||||||||||||
| 485 | { | - | ||||||||||||
| 486 | switch (a) { | - | ||||||||||||
| 487 | case Qt::CopyAction: | - | ||||||||||||
| 488 | return atom(QXcbAtom::XdndActionCopy); | - | ||||||||||||
| 489 | case Qt::LinkAction: | - | ||||||||||||
| 490 | return atom(QXcbAtom::XdndActionLink); | - | ||||||||||||
| 491 | case Qt::MoveAction: | - | ||||||||||||
| 492 | case Qt::TargetMoveAction: | - | ||||||||||||
| 493 | return atom(QXcbAtom::XdndActionMove); | - | ||||||||||||
| 494 | case Qt::IgnoreAction: | - | ||||||||||||
| 495 | return 0L; | - | ||||||||||||
| 496 | default: | - | ||||||||||||
| 497 | return atom(QXcbAtom::XdndActionCopy); | - | ||||||||||||
| 498 | } | - | ||||||||||||
| 499 | } | - | ||||||||||||
| 500 | - | |||||||||||||
| 501 | int QXcbDrag::findTransactionByWindow(xcb_window_t window) | - | ||||||||||||
| 502 | { | - | ||||||||||||
| 503 | int at = -1; | - | ||||||||||||
| 504 | for (int i = 0; i < transactions.count(); ++i) { | - | ||||||||||||
| 505 | const Transaction &t = transactions.at(i); | - | ||||||||||||
| 506 | if (t.target == window || t.proxy_target == window) { | - | ||||||||||||
| 507 | at = i; | - | ||||||||||||
| 508 | break; | - | ||||||||||||
| 509 | } | - | ||||||||||||
| 510 | } | - | ||||||||||||
| 511 | return at; | - | ||||||||||||
| 512 | } | - | ||||||||||||
| 513 | - | |||||||||||||
| 514 | int QXcbDrag::findTransactionByTime(xcb_timestamp_t timestamp) | - | ||||||||||||
| 515 | { | - | ||||||||||||
| 516 | int at = -1; | - | ||||||||||||
| 517 | for (int i = 0; i < transactions.count(); ++i) { | - | ||||||||||||
| 518 | const Transaction &t = transactions.at(i); | - | ||||||||||||
| 519 | if (t.timestamp == timestamp) { | - | ||||||||||||
| 520 | at = i; | - | ||||||||||||
| 521 | break; | - | ||||||||||||
| 522 | } | - | ||||||||||||
| 523 | } | - | ||||||||||||
| 524 | return at; | - | ||||||||||||
| 525 | } | - | ||||||||||||
| 526 | void QXcbDrag::handleEnter(QPlatformWindow *window, const xcb_client_message_event_t *event, xcb_window_t proxy) | - | ||||||||||||
| 527 | { | - | ||||||||||||
| 528 | (void)window;; | - | ||||||||||||
| 529 | if(0) QMessageLogger(__FILE__, 680686, __PRETTY_FUNCTION__).debug() << "handleEnter" << window; dead code: QMessageLogger(__FILE__, 686, __PRETTY_FUNCTION__).debug() << "handleEnter" << window; | - | ||||||||||||
| 530 | - | |||||||||||||
| 531 | xdnd_types.clear(); | - | ||||||||||||
| 532 | - | |||||||||||||
| 533 | int version = (int)(event->data.data32[1] >> 24); | - | ||||||||||||
| 534 | if (version > xdnd_version) | - | ||||||||||||
| 535 | return; | - | ||||||||||||
| 536 | - | |||||||||||||
| 537 | xdnd_dragsource = event->data.data32[0]; | - | ||||||||||||
| 538 | if (!proxy) | - | ||||||||||||
| 539 | proxy = xdndProxy(connection(), xdnd_dragsource); | - | ||||||||||||
| 540 | current_proxy_target = proxy ? proxy : xdnd_dragsource; | - | ||||||||||||
| 541 | - | |||||||||||||
| 542 | if (event->data.data32[1] & 1) { | - | ||||||||||||
| 543 | - | |||||||||||||
| 544 | xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, xdnd_dragsource, | - | ||||||||||||
| 545 | atom(QXcbAtom::XdndTypelist), XCB_ATOM_ATOM, | - | ||||||||||||
| 546 | 0, xdnd_max_type); | - | ||||||||||||
| 547 | xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0); | - | ||||||||||||
| 548 | if (reply && reply->type != 0L && reply->format == 32) { | - | ||||||||||||
| 549 | int length = xcb_get_property_value_length(reply) / 4; | - | ||||||||||||
| 550 | if (length > xdnd_max_type) | - | ||||||||||||
| 551 | length = xdnd_max_type; | - | ||||||||||||
| 552 | - | |||||||||||||
| 553 | xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(reply); | - | ||||||||||||
| 554 | xdnd_types.reserve(length); | - | ||||||||||||
| 555 | for (int i = 0; i < length; ++i) | - | ||||||||||||
| 556 | xdnd_types.append(atoms[i]); | - | ||||||||||||
| 557 | } | - | ||||||||||||
| 558 | free(reply); | - | ||||||||||||
| 559 | } else { | - | ||||||||||||
| 560 | - | |||||||||||||
| 561 | for(int i = 2; i < 5; i++) { | - | ||||||||||||
| 562 | if (event->data.data32[i]) | - | ||||||||||||
| 563 | xdnd_types.append(event->data.data32[i]); | - | ||||||||||||
| 564 | } | - | ||||||||||||
| 565 | } | - | ||||||||||||
| 566 | for(int i = 0; i < xdnd_types.length(); ++i) | - | ||||||||||||
| 567 | if(0) QMessageLogger(__FILE__, 718724, __PRETTY_FUNCTION__).debug() << " " << connection()->atomName(xdnd_types.at(i)); dead code: QMessageLogger(__FILE__, 724, __PRETTY_FUNCTION__).debug() << " " << connection()->atomName(xdnd_types.at(i)); | - | ||||||||||||
| 568 | } | - | ||||||||||||
| 569 | - | |||||||||||||
| 570 | void QXcbDrag::handle_xdnd_position(QPlatformWindow *w, const xcb_client_message_event_t *e) | - | ||||||||||||
| 571 | { | - | ||||||||||||
| 572 | QPoint p((e->data.data32[2] & 0xffff0000) >> 16, e->data.data32[2] & 0x0000ffff); | - | ||||||||||||
| 573 | ((!(w)) ? qt_assert("w",__FILE__,724730) : qt_noop()); | - | ||||||||||||
| 574 | QRect geometry = w->geometry(); | - | ||||||||||||
| 575 | p -= geometry.topLeft(); | - | ||||||||||||
| 576 | - | |||||||||||||
| 577 | if (!w || !w->window() || (w->window()->type() == Qt::Desktop)) | - | ||||||||||||
| 578 | return; | - | ||||||||||||
| 579 | - | |||||||||||||
| 580 | if (e->data.data32[0] != xdnd_dragsource) { | - | ||||||||||||
| 581 | if(0) QMessageLogger(__FILE__, 732738, __PRETTY_FUNCTION__).debug("xdnd drag position from unexpected source (%x not %x)", e->data.data32[0], xdnd_dragsource); dead code: QMessageLogger(__FILE__, 738, __PRETTY_FUNCTION__).debug("xdnd drag position from unexpected source (%x not %x)", e->data.data32[0], xdnd_dragsource); | - | ||||||||||||
| 582 | return; | - | ||||||||||||
| 583 | } | - | ||||||||||||
| 584 | - | |||||||||||||
| 585 | currentPosition = p; | - | ||||||||||||
| 586 | currentWindow = w->window(); | - | ||||||||||||
| 587 | - | |||||||||||||
| 588 | - | |||||||||||||
| 589 | if (e->data.data32[3] != 0L) { | - | ||||||||||||
| 590 | target_time = e->data.data32[3]; | - | ||||||||||||
| 591 | } | - | ||||||||||||
| 592 | - | |||||||||||||
| 593 | QMimeData *dropData = 0; | - | ||||||||||||
| 594 | Qt::DropActions supported_actions = Qt::IgnoreAction; | - | ||||||||||||
| 595 | if (currentDrag()) { | - | ||||||||||||
| 596 | dropData = currentDrag()->mimeData(); | - | ||||||||||||
| 597 | supported_actions = currentDrag()->supportedActions(); | - | ||||||||||||
| 598 | } else { | - | ||||||||||||
| 599 | dropData = platformDropData(); | - | ||||||||||||
| 600 | supported_actions = Qt::DropActions(toDropAction(e->data.data32[4])); | - | ||||||||||||
| 601 | } | - | ||||||||||||
| 602 | - | |||||||||||||
| 603 | QPlatformDragQtResponse qt_response = QWindowSystemInterface::handleDrag(w->window(),dropData,p,supported_actions); | - | ||||||||||||
| 604 | QRect answerRect(p + geometry.topLeft(), QSize(1,1)); | - | ||||||||||||
| 605 | answerRect = qt_response.answerRect().translated(geometry.topLeft()).intersected(geometry); | - | ||||||||||||
| 606 | - | |||||||||||||
| 607 | xcb_client_message_event_t response; | - | ||||||||||||
| 608 | response.response_type = 33; | - | ||||||||||||
| 609 | response.sequence = 0; | - | ||||||||||||
| 610 | response.window = xdnd_dragsource; | - | ||||||||||||
| 611 | response.format = 32; | - | ||||||||||||
| 612 | response.type = atom(QXcbAtom::XdndStatus); | - | ||||||||||||
| 613 | response.data.data32[0] = xcb_window(w); | - | ||||||||||||
| 614 | response.data.data32[1] = qt_response.isAccepted(); | - | ||||||||||||
| 615 | response.data.data32[2] = 0; | - | ||||||||||||
| 616 | response.data.data32[3] = 0; | - | ||||||||||||
| 617 | response.data.data32[4] = toXdndAction(qt_response.acceptedAction()); | - | ||||||||||||
| 618 | - | |||||||||||||
| 619 | accepted_drop_action = qt_response.acceptedAction(); | - | ||||||||||||
| 620 | - | |||||||||||||
| 621 | if (answerRect.left() < 0) | - | ||||||||||||
| 622 | answerRect.setLeft(0); | - | ||||||||||||
| 623 | if (answerRect.right() > 4096) | - | ||||||||||||
| 624 | answerRect.setRight(4096); | - | ||||||||||||
| 625 | if (answerRect.top() < 0) | - | ||||||||||||
| 626 | answerRect.setTop(0); | - | ||||||||||||
| 627 | if (answerRect.bottom() > 4096) | - | ||||||||||||
| 628 | answerRect.setBottom(4096); | - | ||||||||||||
| 629 | if (answerRect.width() < 0) | - | ||||||||||||
| 630 | answerRect.setWidth(0); | - | ||||||||||||
| 631 | if (answerRect.height() < 0) | - | ||||||||||||
| 632 | answerRect.setHeight(0); | - | ||||||||||||
| 633 | - | |||||||||||||
| 634 | - | |||||||||||||
| 635 | target_time = 0L; | - | ||||||||||||
| 636 | - | |||||||||||||
| 637 | if (xdnd_dragsource == connection()->clipboard()->owner()) | - | ||||||||||||
| 638 | handle_xdnd_status(&response); | - | ||||||||||||
| 639 | else | - | ||||||||||||
| 640 | xcb_send_event(xcb_connection(), false, current_proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&response) | - | ||||||||||||
| 641 | ; | - | ||||||||||||
| 642 | } | - | ||||||||||||
| 643 | - | |||||||||||||
| 644 | namespace | - | ||||||||||||
| 645 | { | - | ||||||||||||
| 646 | class ClientMessageScanner { | - | ||||||||||||
| 647 | public: | - | ||||||||||||
| 648 | ClientMessageScanner(xcb_atom_t a) : atom(a) {} | - | ||||||||||||
| 649 | xcb_atom_t atom; | - | ||||||||||||
| 650 | bool checkEvent(xcb_generic_event_t *event) const { | - | ||||||||||||
| 651 | if (!event) | - | ||||||||||||
| 652 | return false; | - | ||||||||||||
| 653 | if ((event->response_type & 0x7f) != 33) | - | ||||||||||||
| 654 | return false; | - | ||||||||||||
| 655 | return ((xcb_client_message_event_t *)event)->type == atom; | - | ||||||||||||
| 656 | } | - | ||||||||||||
| 657 | }; | - | ||||||||||||
| 658 | } | - | ||||||||||||
| 659 | - | |||||||||||||
| 660 | void QXcbDrag::handlePosition(QPlatformWindow * w, const xcb_client_message_event_t *event) | - | ||||||||||||
| 661 | { | - | ||||||||||||
| 662 | xcb_client_message_event_t *lastEvent = const_cast<xcb_client_message_event_t *>(event); | - | ||||||||||||
| 663 | xcb_generic_event_t *nextEvent; | - | ||||||||||||
| 664 | ClientMessageScanner scanner(atom(QXcbAtom::XdndPosition)); | - | ||||||||||||
| 665 | while ((nextEvent = connection()->checkEvent(scanner))) { | - | ||||||||||||
| 666 | if (lastEvent != event) | - | ||||||||||||
| 667 | free(lastEvent); | - | ||||||||||||
| 668 | lastEvent = (xcb_client_message_event_t *)nextEvent; | - | ||||||||||||
| 669 | } | - | ||||||||||||
| 670 | - | |||||||||||||
| 671 | handle_xdnd_position(w, lastEvent); | - | ||||||||||||
| 672 | if (lastEvent != event) | - | ||||||||||||
| 673 | free(lastEvent); | - | ||||||||||||
| 674 | } | - | ||||||||||||
| 675 | - | |||||||||||||
| 676 | void QXcbDrag::handle_xdnd_status(const xcb_client_message_event_t *event) | - | ||||||||||||
| 677 | { | - | ||||||||||||
| 678 | if(0) QMessageLogger(__FILE__, 829835, __PRETTY_FUNCTION__).debug("xdndHandleStatus"); dead code: QMessageLogger(__FILE__, 835, __PRETTY_FUNCTION__).debug("xdndHandleStatus"); | - | ||||||||||||
| 679 | waiting_for_status = false; | - | ||||||||||||
| 680 | - | |||||||||||||
| 681 | if (event->data.data32[0] && event->data.data32[0] != current_target) | - | ||||||||||||
| 682 | return; | - | ||||||||||||
| 683 | - | |||||||||||||
| 684 | const bool dropPossible = event->data.data32[1]; | - | ||||||||||||
| 685 | setCanDrop(dropPossible); | - | ||||||||||||
| 686 | - | |||||||||||||
| 687 | if (dropPossible) { | - | ||||||||||||
| 688 | accepted_drop_action = toDropAction(event->data.data32[4]); | - | ||||||||||||
| 689 | updateCursor(accepted_drop_action); | - | ||||||||||||
| 690 | } else { | - | ||||||||||||
| 691 | updateCursor(Qt::IgnoreAction); | - | ||||||||||||
| 692 | } | - | ||||||||||||
| 693 | - | |||||||||||||
| 694 | if ((event->data.data32[1] & 2) == 0) { | - | ||||||||||||
| 695 | QPoint p((event->data.data32[2] & 0xffff0000) >> 16, event->data.data32[2] & 0x0000ffff); | - | ||||||||||||
| 696 | QSize s((event->data.data32[3] & 0xffff0000) >> 16, event->data.data32[3] & 0x0000ffff); | - | ||||||||||||
| 697 | source_sameanswer = QRect(p, s); | - | ||||||||||||
| 698 | } else { | - | ||||||||||||
| 699 | source_sameanswer = QRect(); | - | ||||||||||||
| 700 | } | - | ||||||||||||
| 701 | } | - | ||||||||||||
| 702 | - | |||||||||||||
| 703 | void QXcbDrag::handleStatus(const xcb_client_message_event_t *event) | - | ||||||||||||
| 704 | { | - | ||||||||||||
| 705 | if (event->window != connection()->clipboard()->owner() || !drag()) | - | ||||||||||||
| 706 | return; | - | ||||||||||||
| 707 | - | |||||||||||||
| 708 | xcb_client_message_event_t *lastEvent = const_cast<xcb_client_message_event_t *>(event); | - | ||||||||||||
| 709 | xcb_generic_event_t *nextEvent; | - | ||||||||||||
| 710 | ClientMessageScanner scanner(atom(QXcbAtom::XdndStatus)); | - | ||||||||||||
| 711 | while ((nextEvent = connection()->checkEvent(scanner))) { | - | ||||||||||||
| 712 | if (lastEvent != event) | - | ||||||||||||
| 713 | free(lastEvent); | - | ||||||||||||
| 714 | lastEvent = (xcb_client_message_event_t *)nextEvent; | - | ||||||||||||
| 715 | } | - | ||||||||||||
| 716 | - | |||||||||||||
| 717 | handle_xdnd_status(lastEvent); | - | ||||||||||||
| 718 | if (lastEvent != event) | - | ||||||||||||
| 719 | free(lastEvent); | - | ||||||||||||
| 720 | if(0) QMessageLogger(__FILE__, 871877, __PRETTY_FUNCTION__).debug("xdndHandleStatus end"); dead code: QMessageLogger(__FILE__, 877, __PRETTY_FUNCTION__).debug("xdndHandleStatus end"); | - | ||||||||||||
| 721 | } | - | ||||||||||||
| 722 | - | |||||||||||||
| 723 | void QXcbDrag::handleLeave(QPlatformWindow *w, const xcb_client_message_event_t *event) | - | ||||||||||||
| 724 | { | - | ||||||||||||
| 725 | if(0) QMessageLogger(__FILE__, 876882, __PRETTY_FUNCTION__).debug("xdnd leave"); dead code: QMessageLogger(__FILE__, 882, __PRETTY_FUNCTION__).debug("xdnd leave"); | - | ||||||||||||
| 726 | if (!currentWindow || w != currentWindow.data()->handle()) | - | ||||||||||||
| 727 | return; | - | ||||||||||||
| 728 | if (event->data.data32[0] != xdnd_dragsource) { | - | ||||||||||||
| 729 | - | |||||||||||||
| 730 | if(0) QMessageLogger(__FILE__, 889895, __PRETTY_FUNCTION__).debug("xdnd drag leave from unexpected source (%x not %x", event->data.data32[0], xdnd_dragsource); dead code: QMessageLogger(__FILE__, 895, __PRETTY_FUNCTION__).debug("xdnd drag leave from unexpected source (%x not %x", event->data.data32[0], xdnd_dragsource); | - | ||||||||||||
| 731 | } | - | ||||||||||||
| 732 | - | |||||||||||||
| 733 | QWindowSystemInterface::handleDrag(w->window(),0,QPoint(),Qt::IgnoreAction); | - | ||||||||||||
| 734 | - | |||||||||||||
| 735 | xdnd_dragsource = 0; | - | ||||||||||||
| 736 | xdnd_types.clear(); | - | ||||||||||||
| 737 | currentWindow.clear(); | - | ||||||||||||
| 738 | } | - | ||||||||||||
| 739 | - | |||||||||||||
| 740 | void QXcbDrag::send_leave() | - | ||||||||||||
| 741 | { | - | ||||||||||||
| 742 | if (!current_target) | - | ||||||||||||
| 743 | return; | - | ||||||||||||
| 744 | - | |||||||||||||
| 745 | - | |||||||||||||
| 746 | xcb_client_message_event_t leave; | - | ||||||||||||
| 747 | leave.response_type = 33; | - | ||||||||||||
| 748 | leave.sequence = 0; | - | ||||||||||||
| 749 | leave.window = current_target; | - | ||||||||||||
| 750 | leave.format = 32; | - | ||||||||||||
| 751 | leave.type = atom(QXcbAtom::XdndLeave); | - | ||||||||||||
| 752 | leave.data.data32[0] = connection()->clipboard()->owner(); | - | ||||||||||||
| 753 | leave.data.data32[1] = 0; | - | ||||||||||||
| 754 | leave.data.data32[2] = 0; | - | ||||||||||||
| 755 | leave.data.data32[3] = 0; | - | ||||||||||||
| 756 | leave.data.data32[4] = 0; | - | ||||||||||||
| 757 | - | |||||||||||||
| 758 | QXcbWindow *w = connection()->platformWindowFromId(current_proxy_target); | - | ||||||||||||
| 759 | - | |||||||||||||
| 760 | if (w && (w->window()->type() == Qt::Desktop) ) | - | ||||||||||||
| 761 | w = 0; | - | ||||||||||||
| 762 | - | |||||||||||||
| 763 | if (w) | - | ||||||||||||
| 764 | handleLeave(w, (const xcb_client_message_event_t *)&leave); | - | ||||||||||||
| 765 | else | - | ||||||||||||
| 766 | xcb_send_event(xcb_connection(), false,current_proxy_target, | - | ||||||||||||
| 767 | XCB_EVENT_MASK_NO_EVENT, (const char *)&leave); | - | ||||||||||||
| 768 | - | |||||||||||||
| 769 | current_target = 0; | - | ||||||||||||
| 770 | current_proxy_target = 0; | - | ||||||||||||
| 771 | source_time = 0L; | - | ||||||||||||
| 772 | waiting_for_status = false; | - | ||||||||||||
| 773 | } | - | ||||||||||||
| 774 | - | |||||||||||||
| 775 | void QXcbDrag::handleDrop(QPlatformWindow *, const xcb_client_message_event_t *event) | - | ||||||||||||
| 776 | { | - | ||||||||||||
| 777 | if(0) QMessageLogger(__FILE__, 936942, __PRETTY_FUNCTION__).debug("xdndHandleDrop"); dead code: QMessageLogger(__FILE__, 942, __PRETTY_FUNCTION__).debug("xdndHandleDrop"); | - | ||||||||||||
| 778 | if (!currentWindow) { | - | ||||||||||||
| 779 | xdnd_dragsource = 0; | - | ||||||||||||
| 780 | return; | - | ||||||||||||
| 781 | } | - | ||||||||||||
| 782 | - | |||||||||||||
| 783 | const uint32_t *l = event->data.data32; | - | ||||||||||||
| 784 | - | |||||||||||||
| 785 | if(0) QMessageLogger(__FILE__, 944950, __PRETTY_FUNCTION__).debug("xdnd drop"); dead code: QMessageLogger(__FILE__, 950, __PRETTY_FUNCTION__).debug("xdnd drop"); | - | ||||||||||||
| 786 | - | |||||||||||||
| 787 | if (l[0] != xdnd_dragsource) { | - | ||||||||||||
| 788 | if(0) QMessageLogger(__FILE__, 947953, __PRETTY_FUNCTION__).debug("xdnd drop from unexpected source (%x not %x", l[0], xdnd_dragsource); dead code: QMessageLogger(__FILE__, 953, __PRETTY_FUNCTION__).debug("xdnd drop from unexpected source (%x not %x", l[0], xdnd_dragsource); | - | ||||||||||||
| 789 | return; | - | ||||||||||||
| 790 | } | - | ||||||||||||
| 791 | - | |||||||||||||
| 792 | - | |||||||||||||
| 793 | if (l[2] != 0) | - | ||||||||||||
| 794 | target_time = l[2]; | - | ||||||||||||
| 795 | - | |||||||||||||
| 796 | Qt::DropActions supported_drop_actions; | - | ||||||||||||
| 797 | QMimeData *dropData = 0; | - | ||||||||||||
| 798 | if (currentDrag()) { | - | ||||||||||||
| 799 | dropData = currentDrag()->mimeData(); | - | ||||||||||||
| 800 | supported_drop_actions = Qt::DropActions(l[4]); | - | ||||||||||||
| 801 | } else { | - | ||||||||||||
| 802 | dropData = platformDropData(); | - | ||||||||||||
| 803 | supported_drop_actions = accepted_drop_action; | - | ||||||||||||
| 804 | - | |||||||||||||
| 805 | - | |||||||||||||
| 806 | QGuiApplicationPrivate::modifier_buttons = QGuiApplication::queryKeyboardModifiers(); | - | ||||||||||||
| 807 | } | - | ||||||||||||
| 808 | - | |||||||||||||
| 809 | if (!dropData) | - | ||||||||||||
| 810 | return; | - | ||||||||||||
| 811 | - | |||||||||||||
| 812 | - | |||||||||||||
| 813 | - | |||||||||||||
| 814 | - | |||||||||||||
| 815 | - | |||||||||||||
| 816 | - | |||||||||||||
| 817 | QPlatformDropQtResponse response = QWindowSystemInterface::handleDrop(currentWindow.data(),dropData,currentPosition,supported_drop_actions); | - | ||||||||||||
| 818 | setExecutedDropAction(response.acceptedAction()); | - | ||||||||||||
| 819 | - | |||||||||||||
| 820 | xcb_client_message_event_t finished; | - | ||||||||||||
| 821 | finished.response_type = 33; | - | ||||||||||||
| 822 | finished.sequence = 0; | - | ||||||||||||
| 823 | finished.window = xdnd_dragsource; | - | ||||||||||||
| 824 | finished.format = 32; | - | ||||||||||||
| 825 | finished.type = atom(QXcbAtom::XdndFinished); | - | ||||||||||||
| 826 | finished.data.data32[0] = currentWindow ? xcb_window(currentWindow.data()) : 0L; | - | ||||||||||||
| 827 | finished.data.data32[1] = response.isAccepted(); | - | ||||||||||||
| 828 | finished.data.data32[2] = toXdndAction(response.acceptedAction()); | - | ||||||||||||
| 829 | xcb_send_event(xcb_connection(), false, current_proxy_target, XCB_EVENT_MASK_NO_EVENT, (char *)&finished) | - | ||||||||||||
| 830 | ; | - | ||||||||||||
| 831 | - | |||||||||||||
| 832 | xdnd_dragsource = 0; | - | ||||||||||||
| 833 | currentWindow.clear(); | - | ||||||||||||
| 834 | waiting_for_status = false; | - | ||||||||||||
| 835 | - | |||||||||||||
| 836 | - | |||||||||||||
| 837 | target_time = 0L; | - | ||||||||||||
| 838 | } | - | ||||||||||||
| 839 | - | |||||||||||||
| 840 | - | |||||||||||||
| 841 | void QXcbDrag::handleFinished(const xcb_client_message_event_t *event) | - | ||||||||||||
| 842 | { | - | ||||||||||||
| 843 | if(0) QMessageLogger(__FILE__, 10021008, __PRETTY_FUNCTION__).debug("xdndHandleFinished"); dead code: QMessageLogger(__FILE__, 1008, __PRETTY_FUNCTION__).debug("xdndHandleFinished"); | - | ||||||||||||
| 844 | if (event->window != connection()->clipboard()->owner()) | - | ||||||||||||
| 845 | return; | - | ||||||||||||
| 846 | - | |||||||||||||
| 847 | const unsigned long *l = (const unsigned long *)event->data.data32; | - | ||||||||||||
| 848 | - | |||||||||||||
| 849 | if(0) QMessageLogger(__FILE__, 10081014, __PRETTY_FUNCTION__).debug() << "xdndHandleFinished, l[0]" << l[0] dead code: QMessageLogger(__FILE__, 1014, __PRETTY_FUNCTION__).debug() << "xdndHandleFinished, l[0]" << l[0] << "current_target" << current_target << "qt_xdnd_current_proxy_targe" << current_proxy_target; | - | ||||||||||||
| 850 | << "current_target" << current_target dead code: QMessageLogger(__FILE__, 1014, __PRETTY_FUNCTION__).debug() << "xdndHandleFinished, l[0]" << l[0] << "current_target" << current_target << "qt_xdnd_current_proxy_targe" << current_proxy_target; | - | ||||||||||||
| 851 | << "qt_xdnd_current_proxy_targe" << current_proxy_target; dead code: QMessageLogger(__FILE__, 1014, __PRETTY_FUNCTION__).debug() << "xdndHandleFinished, l[0]" << l[0] << "current_target" << current_target << "qt_xdnd_current_proxy_targe" << current_proxy_target; | - | ||||||||||||
| 852 | - | |||||||||||||
| 853 | if (l[0]) { | - | ||||||||||||
| 854 | int at = findTransactionByWindow(l[0]); | - | ||||||||||||
| 855 | if (at != -1) { | - | ||||||||||||
| 856 | - | |||||||||||||
| 857 | Transaction t = transactions.takeAt(at); | - | ||||||||||||
| 858 | if (t.drag) | - | ||||||||||||
| 859 | t.drag->deleteLater(); | - | ||||||||||||
| 860 | } else { | - | ||||||||||||
| 861 | QMessageLogger(__FILE__, 10431049, __PRETTY_FUNCTION__).warning("QXcbDrag::handleFinished - drop data has expired"); | - | ||||||||||||
| 862 | } | - | ||||||||||||
| 863 | } | - | ||||||||||||
| 864 | waiting_for_status = false; | - | ||||||||||||
| 865 | } | - | ||||||||||||
| 866 | - | |||||||||||||
| 867 | void QXcbDrag::timerEvent(QTimerEvent* e) | - | ||||||||||||
| 868 | { | - | ||||||||||||
| 869 | if (e->timerId() == cleanup_timer) { | - | ||||||||||||
| 870 | bool stopTimer = true; | - | ||||||||||||
| 871 | for (int i = 0; i < transactions.count(); ++i) { | - | ||||||||||||
| 872 | const Transaction &t = transactions.at(i); | - | ||||||||||||
| 873 | if (t.targetWindow) { | - | ||||||||||||
| 874 | - | |||||||||||||
| 875 | - | |||||||||||||
| 876 | continue; | - | ||||||||||||
| 877 | } | - | ||||||||||||
| 878 | QTime currentTime = QTime::currentTime(); | - | ||||||||||||
| 879 | int delta = t.time.msecsTo(currentTime); | - | ||||||||||||
| 880 | if (delta > XdndDropTransactionTimeout) { | - | ||||||||||||
| 881 | - | |||||||||||||
| 882 | - | |||||||||||||
| 883 | - | |||||||||||||
| 884 | - | |||||||||||||
| 885 | - | |||||||||||||
| 886 | - | |||||||||||||
| 887 | if (t.drag) | - | ||||||||||||
| 888 | t.drag->deleteLater(); | - | ||||||||||||
| 889 | transactions.removeAt(i--); | - | ||||||||||||
| 890 | } else { | - | ||||||||||||
| 891 | stopTimer = false; | - | ||||||||||||
| 892 | } | - | ||||||||||||
| 893 | - | |||||||||||||
| 894 | } | - | ||||||||||||
| 895 | if (stopTimer && cleanup_timer != -1) { | - | ||||||||||||
| 896 | killTimer(cleanup_timer); | - | ||||||||||||
| 897 | cleanup_timer = -1; | - | ||||||||||||
| 898 | } | - | ||||||||||||
| 899 | } | - | ||||||||||||
| 900 | } | - | ||||||||||||
| 901 | - | |||||||||||||
| 902 | void QXcbDrag::cancel() | - | ||||||||||||
| 903 | { | - | ||||||||||||
| 904 | if(0) QMessageLogger(__FILE__, 10861092, __PRETTY_FUNCTION__).debug("QXcbDrag::cancel"); dead code: QMessageLogger(__FILE__, 1092, __PRETTY_FUNCTION__).debug("QXcbDrag::cancel"); | - | ||||||||||||
| 905 | QBasicDrag::cancel(); | - | ||||||||||||
| 906 | if (current_target) | - | ||||||||||||
| 907 | send_leave(); | - | ||||||||||||
| 908 | } | - | ||||||||||||
| 909 | - | |||||||||||||
| 910 | - | |||||||||||||
| 911 | static xcb_window_t findXdndAwareParent(QXcbConnection *c, xcb_window_t window) | - | ||||||||||||
| 912 | { | - | ||||||||||||
| 913 | xcb_window_t target = 0; | - | ||||||||||||
| 914 | for(;;) { | - | ||||||||||||
| 915 | - | |||||||||||||
| 916 | xcb_get_property_cookie_t gpCookie = xcb_get_property(c->xcb_connection(), false, window, c->atom(QXcbAtom::XdndAware), XCB_GET_PROPERTY_TYPE_ANY, 0, 0) | - | ||||||||||||
| 917 | - | |||||||||||||
| 918 | ; | - | ||||||||||||
| 919 | xcb_get_property_reply_t *gpReply = xcb_get_property_reply( | - | ||||||||||||
| 920 | c->xcb_connection(), gpCookie, 0); | - | ||||||||||||
| 921 | bool aware = gpReply && gpReply->type != 0L; | - | ||||||||||||
| 922 | free(gpReply); | - | ||||||||||||
| 923 | if (aware) { | - | ||||||||||||
| 924 | target = window; | - | ||||||||||||
| 925 | break; | - | ||||||||||||
| 926 | } | - | ||||||||||||
| 927 | - | |||||||||||||
| 928 | - | |||||||||||||
| 929 | xcb_query_tree_cookie_t qtCookie = xcb_query_tree_unchecked(c->xcb_connection(), window) | - | ||||||||||||
| 930 | ; | - | ||||||||||||
| 931 | xcb_query_tree_reply_t *qtReply = xcb_query_tree_reply( | - | ||||||||||||
| 932 | c->xcb_connection(), qtCookie, __null); | - | ||||||||||||
| 933 | if (!qtReply) | - | ||||||||||||
| 934 | break; | - | ||||||||||||
| 935 | xcb_window_t root = qtReply->root; | - | ||||||||||||
| 936 | xcb_window_t parent = qtReply->parent; | - | ||||||||||||
| 937 | free(qtReply); | - | ||||||||||||
| 938 | if (window == root) | - | ||||||||||||
| 939 | break; | - | ||||||||||||
| 940 | window = parent; | - | ||||||||||||
| 941 | } | - | ||||||||||||
| 942 | return target; | - | ||||||||||||
| 943 | } | - | ||||||||||||
| 944 | - | |||||||||||||
| 945 | void QXcbDrag::handleSelectionRequest(const xcb_selection_request_event_t *event) | - | ||||||||||||
| 946 | { | - | ||||||||||||
| 947 | q_padded_xcb_event<xcb_selection_notify_event_t> store = q_padded_xcb_event<xcb_selection_notify_event_t >(); auto ¬ify = store.event;;notify; | - | ||||||||||||
| 948 | notify.response_type = 31; | - | ||||||||||||
| 949 | notify.requestor = event->requestor; | - | ||||||||||||
| 950 | notify.selection = event->selection; | - | ||||||||||||
| 951 | notify.target = 0L; | - | ||||||||||||
| 952 | notify.property = 0L; | - | ||||||||||||
| 953 | notify.time = event->time; | - | ||||||||||||
| 954 | - | |||||||||||||
| 955 | - | |||||||||||||
| 956 | int at = -1; | - | ||||||||||||
| 957 | - | |||||||||||||
| 958 | - | |||||||||||||
| 959 | if (currentDrag()
| 0 | ||||||||||||
| 960 | - | |||||||||||||
| 961 | at = -2; | - | ||||||||||||
| 962 | } never executed: else {end of block | 0 | ||||||||||||
| 963 | - | |||||||||||||
| 964 | - | |||||||||||||
| 965 | at = findTransactionByTime(event->time); | - | ||||||||||||
| 966 | if (at == -1
| 0 | ||||||||||||
| 967 | - | |||||||||||||
| 968 | - | |||||||||||||
| 969 | at = findTransactionByWindow(event->requestor); | - | ||||||||||||
| 970 | } never executed: end of block | 0 | ||||||||||||
| 971 | - | |||||||||||||
| 972 | if (at == -1
| 0 | ||||||||||||
| 973 | xcb_window_t target = findXdndAwareParent(connection(), event->requestor); | - | ||||||||||||
| 974 | if (target
| 0 | ||||||||||||
| 975 | if (event->time == 0L
| 0 | ||||||||||||
| 976 | at = -2; never executed: at = -2; | 0 | ||||||||||||
| 977 | else | - | ||||||||||||
| 978 | at = findTransactionByWindow(target); never executed: at = findTransactionByWindow(target); | 0 | ||||||||||||
| 979 | } | - | ||||||||||||
| 980 | } never executed: end of block | 0 | ||||||||||||
| 981 | } never executed: end of block | 0 | ||||||||||||
| 982 | - | |||||||||||||
| 983 | QDrag *transactionDrag = 0; | - | ||||||||||||
| 984 | if (at >= 0
| 0 | ||||||||||||
| 985 | transactionDrag = transactions.at(at).drag; | - | ||||||||||||
| 986 | } never executed: else if (at == -2end of block
| 0 | ||||||||||||
| 987 | transactionDrag = currentDrag(); | - | ||||||||||||
| 988 | } never executed: end of block | 0 | ||||||||||||
| 989 | - | |||||||||||||
| 990 | if (transactionDrag
| 0 | ||||||||||||
| 991 | xcb_atom_t atomFormat = event->target; | - | ||||||||||||
| 992 | int dataFormat = 0; | - | ||||||||||||
| 993 | QByteArray data; | - | ||||||||||||
| 994 | if (QXcbMime::mimeDataForAtom(connection(), event->target, transactionDrag->mimeData(),
| 0 | ||||||||||||
| 995 | &data, &atomFormat, &dataFormat)
| 0 | ||||||||||||
| 996 | int dataSize = data.size() / (dataFormat / 8); | - | ||||||||||||
| 997 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, event->requestor, event->property, | - | ||||||||||||
| 998 | atomFormat, dataFormat, dataSize, (const void *)data.constData()); | - | ||||||||||||
| 999 | notify.property = event->property; | - | ||||||||||||
| 1000 | notify.target = atomFormat; | - | ||||||||||||
| 1001 | } never executed: end of block | 0 | ||||||||||||
| 1002 | } never executed: end of block | 0 | ||||||||||||
| 1003 | - | |||||||||||||
| 1004 | xcb_window_t proxy_target = xdndProxy(connection(), event->requestor); | - | ||||||||||||
| 1005 | if (!proxy_target
| 0 | ||||||||||||
| 1006 | proxy_target = event->requestor; never executed: proxy_target = event->requestor; | 0 | ||||||||||||
| 1007 | - | |||||||||||||
| 1008 | xcb_send_event(xcb_connection(), false, proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)¬ify); | - | ||||||||||||
| 1009 | } never executed: end of block | 0 | ||||||||||||
| 1010 | - | |||||||||||||
| 1011 | - | |||||||||||||
| 1012 | bool QXcbDrag::dndEnable(QXcbWindow *w, bool on) | - | ||||||||||||
| 1013 | { | - | ||||||||||||
| 1014 | if(0) QMessageLogger(__FILE__, 11961202, __PRETTY_FUNCTION__).debug() << "xdndEnable" << w << on; dead code: QMessageLogger(__FILE__, 1202, __PRETTY_FUNCTION__).debug() << "xdndEnable" << w << on; | - | ||||||||||||
| 1015 | if (on) { | - | ||||||||||||
| 1016 | QXcbWindow *xdnd_widget = 0; | - | ||||||||||||
| 1017 | if ((w->window()->type() == Qt::Desktop)) { | - | ||||||||||||
| 1018 | if (desktop_proxy) | - | ||||||||||||
| 1019 | return false; | - | ||||||||||||
| 1020 | - | |||||||||||||
| 1021 | QXcbConnectionGrabber grabber(connection()); | - | ||||||||||||
| 1022 | - | |||||||||||||
| 1023 | - | |||||||||||||
| 1024 | xcb_window_t proxy_id = xdndProxy(connection(), w->xcb_window()); | - | ||||||||||||
| 1025 | - | |||||||||||||
| 1026 | if (!proxy_id) { | - | ||||||||||||
| 1027 | desktop_proxy = new QWindow; | - | ||||||||||||
| 1028 | xdnd_widget = static_cast<QXcbWindow *>(desktop_proxy->handle()); | - | ||||||||||||
| 1029 | proxy_id = xdnd_widget->xcb_window(); | - | ||||||||||||
| 1030 | xcb_atom_t xdnd_proxy = atom(QXcbAtom::XdndProxy); | - | ||||||||||||
| 1031 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, w->xcb_window(), xdnd_proxy, | - | ||||||||||||
| 1032 | XCB_ATOM_WINDOW, 32, 1, &proxy_id); | - | ||||||||||||
| 1033 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, proxy_id, xdnd_proxy, | - | ||||||||||||
| 1034 | XCB_ATOM_WINDOW, 32, 1, &proxy_id); | - | ||||||||||||
| 1035 | } | - | ||||||||||||
| 1036 | - | |||||||||||||
| 1037 | } else { | - | ||||||||||||
| 1038 | xdnd_widget = w; | - | ||||||||||||
| 1039 | } | - | ||||||||||||
| 1040 | if (xdnd_widget) { | - | ||||||||||||
| 1041 | if(0) QMessageLogger(__FILE__, 12231229, __PRETTY_FUNCTION__).debug() << "setting XdndAware for" << xdnd_widget << xdnd_widget->xcb_window(); dead code: QMessageLogger(__FILE__, 1229, __PRETTY_FUNCTION__).debug() << "setting XdndAware for" << xdnd_widget << xdnd_widget->xcb_window(); | - | ||||||||||||
| 1042 | xcb_atom_t atm = xdnd_version; | - | ||||||||||||
| 1043 | xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, xdnd_widget->xcb_window(), | - | ||||||||||||
| 1044 | atom(QXcbAtom::XdndAware), XCB_ATOM_ATOM, 32, 1, &atm); | - | ||||||||||||
| 1045 | return true; | - | ||||||||||||
| 1046 | } else { | - | ||||||||||||
| 1047 | return false; | - | ||||||||||||
| 1048 | } | - | ||||||||||||
| 1049 | } else { | - | ||||||||||||
| 1050 | if ((w->window()->type() == Qt::Desktop)) { | - | ||||||||||||
| 1051 | xcb_delete_property(xcb_connection(), w->xcb_window(), atom(QXcbAtom::XdndProxy)); | - | ||||||||||||
| 1052 | delete desktop_proxy; | - | ||||||||||||
| 1053 | desktop_proxy = 0; | - | ||||||||||||
| 1054 | } else { | - | ||||||||||||
| 1055 | if(0) QMessageLogger(__FILE__, 12371243, __PRETTY_FUNCTION__).debug() << "not deleting XDndAware"; dead code: QMessageLogger(__FILE__, 1243, __PRETTY_FUNCTION__).debug() << "not deleting XDndAware"; | - | ||||||||||||
| 1056 | } | - | ||||||||||||
| 1057 | return true; | - | ||||||||||||
| 1058 | } | - | ||||||||||||
| 1059 | } | - | ||||||||||||
| 1060 | - | |||||||||||||
| 1061 | bool QXcbDrag::ownsDragObject() const | - | ||||||||||||
| 1062 | { | - | ||||||||||||
| 1063 | return true; | - | ||||||||||||
| 1064 | } | - | ||||||||||||
| 1065 | - | |||||||||||||
| 1066 | QXcbDropData::QXcbDropData(QXcbDrag *d) | - | ||||||||||||
| 1067 | : QXcbMime(), | - | ||||||||||||
| 1068 | drag(d) | - | ||||||||||||
| 1069 | { | - | ||||||||||||
| 1070 | } | - | ||||||||||||
| 1071 | - | |||||||||||||
| 1072 | QXcbDropData::~QXcbDropData() | - | ||||||||||||
| 1073 | { | - | ||||||||||||
| 1074 | } | - | ||||||||||||
| 1075 | - | |||||||||||||
| 1076 | QVariant QXcbDropData::retrieveData_sys(const QString &mimetype, QVariant::Type requestedType) const | - | ||||||||||||
| 1077 | { | - | ||||||||||||
| 1078 | QByteArray mime = mimetype.toLatin1(); | - | ||||||||||||
| 1079 | QVariant data = xdndObtainData(mime, requestedType); | - | ||||||||||||
| 1080 | return data; | - | ||||||||||||
| 1081 | } | - | ||||||||||||
| 1082 | - | |||||||||||||
| 1083 | QVariant QXcbDropData::xdndObtainData(const QByteArray &format, QVariant::Type requestedType) const | - | ||||||||||||
| 1084 | { | - | ||||||||||||
| 1085 | QByteArray result; | - | ||||||||||||
| 1086 | - | |||||||||||||
| 1087 | QXcbConnection *c = drag->connection(); | - | ||||||||||||
| 1088 | QXcbWindow *xcb_window = c->platformWindowFromId(drag->xdnd_dragsource); | - | ||||||||||||
| 1089 | if (xcb_window && drag->currentDrag() && xcb_window->window()->type() != Qt::Desktop) { | - | ||||||||||||
| 1090 | QMimeData *data = drag->currentDrag()->mimeData(); | - | ||||||||||||
| 1091 | if (data->hasFormat(QLatin1String(format))) | - | ||||||||||||
| 1092 | result = data->data(QLatin1String(format)); | - | ||||||||||||
| 1093 | return result; | - | ||||||||||||
| 1094 | } | - | ||||||||||||
| 1095 | - | |||||||||||||
| 1096 | QVector<xcb_atom_t> atoms = drag->xdnd_types; | - | ||||||||||||
| 1097 | QByteArray encoding; | - | ||||||||||||
| 1098 | xcb_atom_t a = mimeAtomForFormat(c, QLatin1String(format), requestedType, atoms, &encoding); | - | ||||||||||||
| 1099 | if (a == 0L) | - | ||||||||||||
| 1100 | return result; | - | ||||||||||||
| 1101 | - | |||||||||||||
| 1102 | if (c->clipboard()->getSelectionOwner(drag->atom(QXcbAtom::XdndSelection)) == 0L) | - | ||||||||||||
| 1103 | return result; | - | ||||||||||||
| 1104 | - | |||||||||||||
| 1105 | xcb_atom_t xdnd_selection = c->atom(QXcbAtom::XdndSelection); | - | ||||||||||||
| 1106 | result = c->clipboard()->getSelection(xdnd_selection, a, xdnd_selection, drag->targetTime()); | - | ||||||||||||
| 1107 | - | |||||||||||||
| 1108 | return mimeConvertToFormat(c, a, result, QLatin1String(format), requestedType, encoding); | - | ||||||||||||
| 1109 | } | - | ||||||||||||
| 1110 | - | |||||||||||||
| 1111 | - | |||||||||||||
| 1112 | bool QXcbDropData::hasFormat_sys(const QString &format) const | - | ||||||||||||
| 1113 | { | - | ||||||||||||
| 1114 | return formats().contains(format); | - | ||||||||||||
| 1115 | } | - | ||||||||||||
| 1116 | - | |||||||||||||
| 1117 | QStringList QXcbDropData::formats_sys() const | - | ||||||||||||
| 1118 | { | - | ||||||||||||
| 1119 | QStringList formats; | - | ||||||||||||
| 1120 | for (int i = 0; i < drag->xdnd_types.size(); ++i) { | - | ||||||||||||
| 1121 | QString f = mimeAtomToString(drag->connection(), drag->xdnd_types.at(i)); | - | ||||||||||||
| 1122 | if (!formats.contains(f)) | - | ||||||||||||
| 1123 | formats.append(f); | - | ||||||||||||
| 1124 | } | - | ||||||||||||
| 1125 | return formats; | - | ||||||||||||
| 1126 | } | - | ||||||||||||
| 1127 | - | |||||||||||||
| 1128 | - | |||||||||||||
| 1129 | - | |||||||||||||
| 1130 | - | |||||||||||||
| Switch to Source code | Preprocessed file |