Debian Codegraph @

xcb/libqt5xcbqpa-dev/5.12.3/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_REQUIRE_CONFIG(draganddrop);
24
25 QT_BEGIN_NAMESPACE
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, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
47 void drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) 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 Qt::MouseButtons b = 0, Qt::KeyboardModifiers mods = 0);
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 bool ownsDragObject() const override;
62
63 void updatePixmap();
64 xcb_timestamp_t targetTime() { return target_time; }
65
66 protected:
67 void timerEvent(QTimerEvent* e) override;
68
69 bool findXdndAwareTarget(const QPoint &globalPos, xcb_window_t *target_out);
70
71 private:
72 friend class QXcbDropData;
73
74 void init();
75
76 void handle_xdnd_position(QPlatformWindow *w, const xcb_client_message_event_t *event,
77 Qt::MouseButtons b = 0, Qt::KeyboardModifiers mods = 0);
78 void handle_xdnd_status(const xcb_client_message_event_t *event);
79 void send_leave();
80
81 Qt::DropAction toDropAction(xcb_atom_t atom) const;
82 xcb_atom_t toXdndAction(Qt::DropAction a) const;
83
84 QPointer<QWindow> initiatorWindow;
85 QPointer<QWindow> currentWindow;
86 QPoint currentPosition;
87
88 QXcbDropData *m_dropData;
89 Qt::DropAction accepted_drop_action;
90
91 QWindow *desktop_proxy;
92
93 xcb_atom_t xdnd_dragsource;
94
95 // the types in this drop. 100 is no good, but at least it's big.
96 enum { xdnd_max_type = 100 };
97 QVector<xcb_atom_t> xdnd_types;
98
99 // timestamp from XdndPosition and XdndDroptime for retrieving the data
100 xcb_timestamp_t target_time;
101 xcb_timestamp_t source_time;
102
103 // rectangle in which the answer will be the same
104 QRect source_sameanswer;
105 bool waiting_for_status;
106
107 // helpers for setting executed drop action outside application
108 bool dropped;
109 bool canceled;
110
111 // A window from Unity DnD Manager, which does not respect the XDnD spec
112 xcb_window_t xdndCollectionWindow = XCB_NONE;
113
114 // top-level window we sent position to last.
115 xcb_window_t current_target;
116 // window to send events to (always valid if current_target)
117 xcb_window_t current_proxy_target;
118
119 QXcbVirtualDesktop *current_virtual_desktop;
120
121 // 10 minute timer used to discard old XdndDrop transactions
122 enum { XdndDropTransactionTimeout = 600000 };
123 int cleanup_timer;
124
125 QVector<xcb_atom_t> drag_types;
126
127 struct Transaction
128 {
129 xcb_timestamp_t timestamp;
130 xcb_window_t target;
131 xcb_window_t proxy_target;
132 QPlatformWindow *targetWindow;
133 // QWidget *embedding_widget;
134 QPointer<QDrag> drag;
135 QTime time;
136 };
137 friend class QTypeInfo<Transaction>;
138 QVector<Transaction> transactions;
139
140 int transaction_expiry_timer;
141 void restartDropExpiryTimer();
142 int findTransactionByWindow(xcb_window_t window);
143 int findTransactionByTime(xcb_timestamp_t timestamp);
144 xcb_window_t findRealWindow(const QPoint & pos, xcb_window_t w, int md, bool ignoreNonXdndAwareWindows);
145 };
146 Q_DECLARE_TYPEINFO(QXcbDrag::Transaction, Q_MOVABLE_TYPE);
147
148 QT_END_NAMESPACE
149
150 #endif