Debian Codegraph @

xcb/libqt6xcbqpa-dev/6.4.2/qxcbdrag.h

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4 #ifndef QXCBDRAG_H
5 #define QXCBDRAG_H
6
7 #include <qpa/qplatformdrag.h>
8 #include <private/qsimpledrag_p.h>
9 #include <xcb/xcb.h>
10 #include <qbackingstore.h>
11 #include <qdatetime.h>
12 #include <qlist.h>
13 #include <qpixmap.h>
14 #include <qpoint.h>
15 #include <qpointer.h>
16 #include <qrect.h>
17 #include <qsharedpointer.h>
18 #include <qxcbobject.h>
19
20 #include <QtCore/QDebug>
21
22 QT_REQUIRE_CONFIG(draganddrop);
23
24 QT_BEGIN_NAMESPACE
25
26 class QWindow;
27 class QPlatformWindow;
28 class QXcbConnection;
29 class QXcbWindow;
30 class QXcbDropData;
31 class QXcbScreen;
32 class QDrag;
33 class QShapedPixmapWindow;
34
35 class QXcbDrag : public QXcbObject, public QBasicDrag, public QXcbWindowEventListener
36 {
37 public:
38 QXcbDrag(QXcbConnection *c);
39 ~QXcbDrag();
40
41 bool eventFilter(QObject *o, QEvent *e) override;
42
43 void startDrag() override;
44 void cancel() override;
45 void move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
46 void drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
47 void endDrag() override;
48
49 Qt::DropAction defaultAction(Qt::DropActions possibleActions, Qt::KeyboardModifiers modifiers) const override;
50
51 void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event) override;
52
53 void handleEnter(QPlatformWindow *window, const xcb_client_message_event_t *event, xcb_window_t proxy = 0);
54 void handlePosition(QPlatformWindow *w, const xcb_client_message_event_t *event);
55 void handleLeave(QPlatformWindow *w, const xcb_client_message_event_t *event);
56 void handleDrop(QPlatformWindow *, const xcb_client_message_event_t *event,
57 Qt::MouseButtons b = { }, Qt::KeyboardModifiers mods = { });
58
59 void handleStatus(const xcb_client_message_event_t *event);
60 void handleSelectionRequest(const xcb_selection_request_event_t *event);
61 void handleFinished(const xcb_client_message_event_t *event);
62
63 bool dndEnable(QXcbWindow *win, bool on);
64 bool ownsDragObject() const override;
65
66 void updatePixmap();
67 xcb_timestamp_t targetTime() { return target_time; }
68
69 protected:
70 void timerEvent(QTimerEvent* e) override;
71
72 bool findXdndAwareTarget(const QPoint &globalPos, xcb_window_t *target_out);
73
74 private:
75 friend class QXcbDropData;
76
77 void init();
78
79 void handle_xdnd_position(QPlatformWindow *w, const xcb_client_message_event_t *event,
80 Qt::MouseButtons b = { }, Qt::KeyboardModifiers mods = { });
81 void handle_xdnd_status(const xcb_client_message_event_t *event);
82 void send_leave();
83
84 Qt::DropAction toDropAction(xcb_atom_t atom) const;
85 Qt::DropActions toDropActions(const QList<xcb_atom_t> &atoms) const;
86 xcb_atom_t toXdndAction(Qt::DropAction a) const;
87
88 void readActionList();
89 void setActionList(Qt::DropAction requestedAction, Qt::DropActions supportedActions);
90 void startListeningForActionListChanges();
91 void stopListeningForActionListChanges();
92
93 QPointer<QWindow> initiatorWindow;
94 QPointer<QWindow> currentWindow;
95 QPoint currentPosition;
96
97 QXcbDropData *m_dropData;
98 Qt::DropAction accepted_drop_action;
99
100 QWindow *desktop_proxy;
101
102 xcb_atom_t xdnd_dragsource;
103
104 // the types in this drop. 100 is no good, but at least it's big.
105 enum { xdnd_max_type = 100 };
106 QList<xcb_atom_t> xdnd_types;
107
108 // timestamp from XdndPosition and XdndDroptime for retrieving the data
109 xcb_timestamp_t target_time;
110 xcb_timestamp_t source_time;
111
112 // rectangle in which the answer will be the same
113 QRect source_sameanswer;
114 bool waiting_for_status;
115
116 // helpers for setting executed drop action outside application
117 bool dropped;
118 bool canceled;
119
120 // A window from Unity DnD Manager, which does not respect the XDnD spec
121 xcb_window_t xdndCollectionWindow = XCB_NONE;
122
123 // top-level window we sent position to last.
124 xcb_window_t current_target;
125 // window to send events to (always valid if current_target)
126 xcb_window_t current_proxy_target;
127
128 QXcbVirtualDesktop *current_virtual_desktop;
129
130 // 10 minute timer used to discard old XdndDrop transactions
131 enum { XdndDropTransactionTimeout = 600000 };
132 int cleanup_timer;
133
134 QList<xcb_atom_t> drag_types;
135
136 QList<xcb_atom_t> current_actions;
137 QList<xcb_atom_t> drop_actions;
138
139 struct Transaction
140 {
141 xcb_timestamp_t timestamp;
142 xcb_window_t target;
143 xcb_window_t proxy_target;
144 QPlatformWindow *targetWindow;
145 // QWidget *embedding_widget;
146 QPointer<QDrag> drag;
147 QTime time;
148 };
149 friend class QTypeInfo<Transaction>;
150 QList<Transaction> transactions;
151
152 int transaction_expiry_timer;
153 void restartDropExpiryTimer();
154 int findTransactionByWindow(xcb_window_t window);
155 int findTransactionByTime(xcb_timestamp_t timestamp);
156 xcb_window_t findRealWindow(const QPoint & pos, xcb_window_t w, int md, bool ignoreNonXdndAwareWindows);
157 };
158 Q_DECLARE_TYPEINFO(QXcbDrag::Transaction, Q_RELOCATABLE_TYPE);
159
160 QT_END_NAMESPACE
161
162 #endif