Debian Codegraph @

xcb/libqt5xcbqpa-dev/5.6.0/qxcbdrag.h

raw
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 QWindow;
28 class QPlatformWindow;
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() Q_DECL_OVERRIDE;
43
44 void startDrag() Q_DECL_OVERRIDE;
45 void cancel() Q_DECL_OVERRIDE;
46 void move(const QPoint &globalPos) Q_DECL_OVERRIDE;
47 void drop(const QPoint &globalPos) Q_DECL_OVERRIDE;
48 void endDrag() Q_DECL_OVERRIDE;
49
50 void handleEnter(QPlatformWindow *window, const xcb_client_message_event_t *event, xcb_window_t proxy = 0);
51 void handlePosition(QPlatformWindow *w, const xcb_client_message_event_t *event);
52 void handleLeave(QPlatformWindow *w, const xcb_client_message_event_t *event);
53 void handleDrop(QPlatformWindow *, const xcb_client_message_event_t *event);
54
55 void handleStatus(const xcb_client_message_event_t *event);
56 void handleSelectionRequest(const xcb_selection_request_event_t *event);
57 void handleFinished(const xcb_client_message_event_t *event);
58
59 bool dndEnable(QXcbWindow *win, bool on);
60 bool ownsDragObject() const Q_DECL_OVERRIDE;
61
62 void updatePixmap();
63 xcb_timestamp_t targetTime() { return target_time; }
64
65 protected:
66 void timerEvent(QTimerEvent* e) Q_DECL_OVERRIDE;
67
68 private:
69 friend class QXcbDropData;
70
71 void init();
72
73 void handle_xdnd_position(QPlatformWindow *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 QXcbVirtualDesktop *current_virtual_desktop;
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 QPlatformWindow *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