Debian Codegraph @

xcb/libqt5xcbqpa-dev/5.10.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 bool eventFilter(QObject *o, QEvent *e) override;
43
44 void startDrag() override;
45 void cancel() override;
46 void move(const QPoint &globalPos) override;
47 void drop(const QPoint &globalPos) override;
48 void endDrag() 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 override;
61
62 void updatePixmap();
63 xcb_timestamp_t targetTime() { return target_time; }
64
65 protected:
66 void timerEvent(QTimerEvent* e) 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> initiatorWindow;
81 QPointer<QWindow> currentWindow;
82 QPoint currentPosition;
83
84 QXcbDropData *m_dropData;
85 Qt::DropAction accepted_drop_action;
86
87 QWindow *desktop_proxy;
88
89 xcb_atom_t xdnd_dragsource;
90
91 // the types in this drop. 100 is no good, but at least it's big.
92 enum { xdnd_max_type = 100 };
93 QVector<xcb_atom_t> xdnd_types;
94
95 // timestamp from XdndPosition and XdndDroptime for retrieving the data
96 xcb_timestamp_t target_time;
97 xcb_timestamp_t source_time;
98
99 // rectangle in which the answer will be the same
100 QRect source_sameanswer;
101 bool waiting_for_status;
102
103 // top-level window we sent position to last.
104 xcb_window_t current_target;
105 // window to send events to (always valid if current_target)
106 xcb_window_t current_proxy_target;
107
108 QXcbVirtualDesktop *current_virtual_desktop;
109
110 // 10 minute timer used to discard old XdndDrop transactions
111 enum { XdndDropTransactionTimeout = 600000 };
112 int cleanup_timer;
113
114 QVector<xcb_atom_t> drag_types;
115
116 struct Transaction
117 {
118 xcb_timestamp_t timestamp;
119 xcb_window_t target;
120 xcb_window_t proxy_target;
121 QPlatformWindow *targetWindow;
122 // QWidget *embedding_widget;
123 QPointer<QDrag> drag;
124 QTime time;
125 };
126 friend class QTypeInfo<Transaction>;
127 QVector<Transaction> transactions;
128
129 int transaction_expiry_timer;
130 void restartDropExpiryTimer();
131 int findTransactionByWindow(xcb_window_t window);
132 int findTransactionByTime(xcb_timestamp_t timestamp);
133 xcb_window_t findRealWindow(const QPoint & pos, xcb_window_t w, int md, bool ignoreNonXdndAwareWindows);
134 };
135 Q_DECLARE_TYPEINFO(QXcbDrag::Transaction, Q_MOVABLE_TYPE);
136
137 #endif // QT_NO_DRAGANDDROP
138
139 QT_END_NAMESPACE
140
141 #endif