Debian Codegraph @

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