1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
45 #include <qpa/qplatformdrag.h>
46 #include <QtPlatformSupport/private/qsimpledrag_p.h>
47 #include <qxcbobject.h>
52 #include <qsharedpointer.h>
55 #include <qdatetime.h>
57 #include <qbackingstore.h>
59 #include <QtCore/QDebug>
63 #ifndef QT_NO_DRAGANDDROP
72 class QShapedPixmapWindow;
74 class QXcbDrag : public QXcbObject, public QBasicDrag
77 QXcbDrag(QXcbConnection *c);
80 virtual QMimeData *platformDropData();
85 void move(const QMouseEvent *me);
86 void drop(const QMouseEvent *me);
89 void handleEnter(QWindow *window, const xcb_client_message_event_t *event);
90 void handlePosition(QWindow *w, const xcb_client_message_event_t *event);
91 void handleLeave(QWindow *w, const xcb_client_message_event_t *event);
92 void handleDrop(QWindow *, const xcb_client_message_event_t *event);
94 void handleStatus(const xcb_client_message_event_t *event);
95 void handleSelectionRequest(const xcb_selection_request_event_t *event);
96 void handleFinished(const xcb_client_message_event_t *event);
98 bool dndEnable(QXcbWindow *win, bool on);
101 xcb_timestamp_t targetTime() { return target_time; }
104 void timerEvent(QTimerEvent* e);
107 friend class QXcbDropData;
111 void handle_xdnd_position(QWindow *w, const xcb_client_message_event_t *event);
112 void handle_xdnd_status(const xcb_client_message_event_t *event);
115 Qt::DropAction toDropAction(xcb_atom_t atom) const;
116 xcb_atom_t toXdndAction(Qt::DropAction a) const;
118 QPointer<QWindow> currentWindow;
119 QPoint currentPosition;
121 QXcbDropData *dropData;
122 Qt::DropAction accepted_drop_action;
124 QWindow *desktop_proxy;
126 xcb_atom_t xdnd_dragsource;
128 // the types in this drop. 100 is no good, but at least it's big.
129 enum { xdnd_max_type = 100 };
130 QList<xcb_atom_t> xdnd_types;
132 // timestamp from XdndPosition and XdndDroptime for retrieving the data
133 xcb_timestamp_t target_time;
134 xcb_timestamp_t source_time;
136 // rectangle in which the answer will be the same
137 QRect source_sameanswer;
138 bool waiting_for_status;
140 // top-level window we sent position to last.
141 xcb_window_t current_target;
142 // window to send events to (always valid if current_target)
143 xcb_window_t current_proxy_target;
145 QXcbScreen *current_screen;
146 // timer used when target wants "continuous" move messages (eg. scroll)
149 // 10 minute timer used to discard old XdndDrop transactions
150 enum { XdndDropTransactionTimeout = 600000 };
153 QVector<xcb_atom_t> drag_types;
157 xcb_timestamp_t timestamp;
159 xcb_window_t proxy_target;
160 QWindow *targetWindow;
161 // QWidget *embedding_widget;
165 QList<Transaction> transactions;
167 int transaction_expiry_timer;
168 void restartDropExpiryTimer();
169 int findTransactionByWindow(xcb_window_t window);
170 int findTransactionByTime(xcb_timestamp_t timestamp);
171 xcb_window_t findRealWindow(const QPoint & pos, xcb_window_t w, int md, bool ignoreNonXdndAwareWindows);
174 #endif // QT_NO_DRAGANDDROP