| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 |
|
| 5 |
#ifndef QXCBDRAG_H |
| 6 |
#define QXCBDRAG_H |
| 7 |
|
| 8 |
#include <qpa/qplatformdrag.h> |
| 9 |
#include <private/qsimpledrag_p.h> |
| 10 |
#include <qxcbobject.h> |
| 11 |
#include <xcb/xcb.h> |
| 12 |
#include <qpoint.h> |
| 13 |
#include <qrect.h> |
| 14 |
#include <qsharedpointer.h> |
| 15 |
#include <qpointer.h> |
| 16 |
#include <qvector.h> |
| 17 |
#include <qdatetime.h> |
| 18 |
#include <qpixmap.h> |
| 19 |
#include <qbackingstore.h> |
| 20 |
|
| 21 |
#include <QtCore/QDebug> |
| 22 |
|
| 23 |
QT_BEGIN_NAMESPACE |
| 24 |
|
| 25 |
#ifndef QT_NO_DRAGANDDROP |
| 26 |
|
| 27 |
class QMouseEvent; |
| 28 |
class QWindow; |
| 29 |
class QXcbConnection; |
| 30 |
class QXcbWindow; |
| 31 |
class QXcbDropData; |
| 32 |
class QXcbScreen; |
| 33 |
class QDrag; |
| 34 |
class QShapedPixmapWindow; |
| 35 |
|
| 36 |
class QXcbDrag : public QXcbObject, public QBasicDrag |
| 37 |
{ |
| 38 |
public: |
| 39 |
QXcbDrag(QXcbConnection *c); |
| 40 |
~QXcbDrag(); |
| 41 |
|
| 42 |
virtual QMimeData *platformDropData(); |
| 43 |
|
| 44 |
|
| 45 |
void startDrag(); |
| 46 |
void cancel(); |
| 47 |
void move(const QMouseEvent *me); |
| 48 |
void drop(const QMouseEvent *me); |
| 49 |
void endDrag(); |
| 50 |
|
| 51 |
void handleEnter(QWindow *window, const xcb_client_message_event_t *event); |
| 52 |
void handlePosition(QWindow *w, const xcb_client_message_event_t *event); |
| 53 |
void handleLeave(QWindow *w, const xcb_client_message_event_t *event); |
| 54 |
void handleDrop(QWindow *, const xcb_client_message_event_t *event); |
| 55 |
|
| 56 |
void handleStatus(const xcb_client_message_event_t *event); |
| 57 |
void handleSelectionRequest(const xcb_selection_request_event_t *event); |
| 58 |
void handleFinished(const xcb_client_message_event_t *event); |
| 59 |
|
| 60 |
bool dndEnable(QXcbWindow *win, bool on); |
| 61 |
|
| 62 |
void updatePixmap(); |
| 63 |
xcb_timestamp_t targetTime() { return target_time; } |
| 64 |
|
| 65 |
protected: |
| 66 |
void timerEvent(QTimerEvent* e); |
| 67 |
|
| 68 |
private: |
| 69 |
friend class QXcbDropData; |
| 70 |
|
| 71 |
void init(); |
| 72 |
|
| 73 |
void handle_xdnd_position(QWindow *w, const xcb_client_message_event_t *event); |
| 74 |
void handle_xdnd_status(const xcb_client_message_event_t *event); |
| 75 |
void send_leave(); |
| 76 |
|
| 77 |
Qt::DropAction toDropAction(xcb_atom_t atom) const; |
| 78 |
xcb_atom_t toXdndAction(Qt::DropAction a) const; |
| 79 |
|
| 80 |
QPointer<QWindow> currentWindow; |
| 81 |
QPoint currentPosition; |
| 82 |
|
| 83 |
QXcbDropData *dropData; |
| 84 |
Qt::DropAction accepted_drop_action; |
| 85 |
|
| 86 |
QWindow *desktop_proxy; |
| 87 |
|
| 88 |
xcb_atom_t xdnd_dragsource; |
| 89 |
|
| 90 |
// the types in this drop. 100 is no good, but at least it's big. |
| 91 |
enum { xdnd_max_type = 100 }; |
| 92 |
QVector<xcb_atom_t> xdnd_types; |
| 93 |
|
| 94 |
// timestamp from XdndPosition and XdndDroptime for retrieving the data |
| 95 |
xcb_timestamp_t target_time; |
| 96 |
xcb_timestamp_t source_time; |
| 97 |
|
| 98 |
// rectangle in which the answer will be the same |
| 99 |
QRect source_sameanswer; |
| 100 |
bool waiting_for_status; |
| 101 |
|
| 102 |
// top-level window we sent position to last. |
| 103 |
xcb_window_t current_target; |
| 104 |
// window to send events to (always valid if current_target) |
| 105 |
xcb_window_t current_proxy_target; |
| 106 |
|
| 107 |
QXcbScreen *current_screen; |
| 108 |
|
| 109 |
// 10 minute timer used to discard old XdndDrop transactions |
| 110 |
enum { XdndDropTransactionTimeout = 600000 }; |
| 111 |
int cleanup_timer; |
| 112 |
|
| 113 |
QVector<xcb_atom_t> drag_types; |
| 114 |
|
| 115 |
struct Transaction |
| 116 |
{ |
| 117 |
xcb_timestamp_t timestamp; |
| 118 |
xcb_window_t target; |
| 119 |
xcb_window_t proxy_target; |
| 120 |
QWindow *targetWindow; |
| 121 |
// QWidget *embedding_widget; |
| 122 |
QPointer<QDrag> drag; |
| 123 |
QTime time; |
| 124 |
}; |
| 125 |
QVector<Transaction> transactions; |
| 126 |
|
| 127 |
int transaction_expiry_timer; |
| 128 |
void restartDropExpiryTimer(); |
| 129 |
int findTransactionByWindow(xcb_window_t window); |
| 130 |
int findTransactionByTime(xcb_timestamp_t timestamp); |
| 131 |
xcb_window_t findRealWindow(const QPoint & pos, xcb_window_t w, int md, bool ignoreNonXdndAwareWindows); |
| 132 |
}; |
| 133 |
|
| 134 |
#endif // QT_NO_DRAGANDDROP |
| 135 |
|
| 136 |
QT_END_NAMESPACE |
| 137 |
|
| 138 |
#endif |