Changeset View
Changeset View
Standalone View
Standalone View
src/server/datadevice_interface.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 39 | public: | |||
---|---|---|---|---|---|
49 | 49 | | |||
50 | DataSourceInterface *selection = nullptr; | 50 | DataSourceInterface *selection = nullptr; | ||
51 | QMetaObject::Connection selectionUnboundConnection; | 51 | QMetaObject::Connection selectionUnboundConnection; | ||
52 | QMetaObject::Connection selectionDestroyedConnection; | 52 | QMetaObject::Connection selectionDestroyedConnection; | ||
53 | 53 | | |||
54 | struct Drag { | 54 | struct Drag { | ||
55 | SurfaceInterface *surface = nullptr; | 55 | SurfaceInterface *surface = nullptr; | ||
56 | QMetaObject::Connection destroyConnection; | 56 | QMetaObject::Connection destroyConnection; | ||
57 | QMetaObject::Connection pointerPosConnection; | 57 | QMetaObject::Connection posConnection; | ||
58 | QMetaObject::Connection sourceActionConnection; | 58 | QMetaObject::Connection sourceActionConnection; | ||
59 | QMetaObject::Connection targetActionConnection; | 59 | QMetaObject::Connection targetActionConnection; | ||
60 | quint32 serial = 0; | 60 | quint32 serial = 0; | ||
61 | }; | 61 | }; | ||
62 | Drag drag; | 62 | Drag drag; | ||
63 | 63 | | |||
64 | private: | 64 | private: | ||
65 | DataDeviceInterface *q_func() { | 65 | DataDeviceInterface *q_func() { | ||
Show All 27 Lines | |||||
93 | { | 93 | { | ||
94 | Q_UNUSED(client) | 94 | Q_UNUSED(client) | ||
95 | Q_UNUSED(serial) | 95 | Q_UNUSED(serial) | ||
96 | // TODO: verify serial | 96 | // TODO: verify serial | ||
97 | cast<Private>(resource)->startDrag(DataSourceInterface::get(source), SurfaceInterface::get(origin), SurfaceInterface::get(icon), serial); | 97 | cast<Private>(resource)->startDrag(DataSourceInterface::get(source), SurfaceInterface::get(origin), SurfaceInterface::get(icon), serial); | ||
98 | } | 98 | } | ||
99 | 99 | | |||
100 | void DataDeviceInterface::Private::startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *i, quint32 serial) | 100 | void DataDeviceInterface::Private::startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *i, quint32 serial) | ||
101 | { | 101 | { | ||
102 | // TODO: allow touch | 102 | const bool pointerGrab = seat->hasImplicitPointerGrab(serial) && seat->focusedPointerSurface() == origin; | ||
davidedmundson: done | |||||
103 | if (!seat->hasImplicitPointerGrab(serial) || seat->focusedPointerSurface() != origin) { | 103 | if (!pointerGrab) { | ||
104 | // Surface doesn't have pointer grab. | 104 | // Client doesn't have pointer grab. | ||
105 | const bool touchGrab = seat->hasImplicitTouchGrab(serial) && seat->focusedTouchSurface() == origin; | ||||
106 | if (!touchGrab) { | ||||
107 | // Client neither has pointer nor touch grab. No drag start allowed. | ||||
105 | return; | 108 | return; | ||
106 | } | 109 | } | ||
110 | } | ||||
107 | // TODO: source is allowed to be null, handled client internally! | 111 | // TODO: source is allowed to be null, handled client internally! | ||
108 | Q_Q(DataDeviceInterface); | 112 | Q_Q(DataDeviceInterface); | ||
109 | source = dataSource; | 113 | source = dataSource; | ||
110 | if (dataSource) { | 114 | if (dataSource) { | ||
111 | QObject::connect(dataSource, &Resource::aboutToBeUnbound, q, [this] { source = nullptr; }); | 115 | QObject::connect(dataSource, &Resource::aboutToBeUnbound, q, [this] { source = nullptr; }); | ||
112 | } | 116 | } | ||
113 | surface = origin; | 117 | surface = origin; | ||
114 | icon = i; | 118 | icon = i; | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | |||||
243 | 247 | | |||
244 | void DataDeviceInterface::drop() | 248 | void DataDeviceInterface::drop() | ||
245 | { | 249 | { | ||
246 | Q_D(); | 250 | Q_D(); | ||
247 | if (!d->resource) { | 251 | if (!d->resource) { | ||
248 | return; | 252 | return; | ||
249 | } | 253 | } | ||
250 | wl_data_device_send_drop(d->resource); | 254 | wl_data_device_send_drop(d->resource); | ||
251 | if (d->drag.pointerPosConnection) { | 255 | if (d->drag.posConnection) { | ||
252 | disconnect(d->drag.pointerPosConnection); | 256 | disconnect(d->drag.posConnection); | ||
253 | d->drag.pointerPosConnection = QMetaObject::Connection(); | 257 | d->drag.posConnection = QMetaObject::Connection(); | ||
254 | } | 258 | } | ||
255 | disconnect(d->drag.destroyConnection); | 259 | disconnect(d->drag.destroyConnection); | ||
256 | d->drag.destroyConnection = QMetaObject::Connection(); | 260 | d->drag.destroyConnection = QMetaObject::Connection(); | ||
257 | d->drag.surface = nullptr; | 261 | d->drag.surface = nullptr; | ||
258 | client()->flush(); | 262 | client()->flush(); | ||
259 | } | 263 | } | ||
260 | 264 | | |||
261 | void DataDeviceInterface::updateDragTarget(SurfaceInterface *surface, quint32 serial) | 265 | void DataDeviceInterface::updateDragTarget(SurfaceInterface *surface, quint32 serial) | ||
262 | { | 266 | { | ||
263 | Q_D(); | 267 | Q_D(); | ||
264 | if (d->drag.surface) { | 268 | if (d->drag.surface) { | ||
265 | if (d->resource && d->drag.surface->resource()) { | 269 | if (d->resource && d->drag.surface->resource()) { | ||
266 | wl_data_device_send_leave(d->resource); | 270 | wl_data_device_send_leave(d->resource); | ||
267 | } | 271 | } | ||
268 | if (d->drag.pointerPosConnection) { | 272 | if (d->drag.posConnection) { | ||
269 | disconnect(d->drag.pointerPosConnection); | 273 | disconnect(d->drag.posConnection); | ||
270 | d->drag.pointerPosConnection = QMetaObject::Connection(); | 274 | d->drag.posConnection = QMetaObject::Connection(); | ||
271 | } | 275 | } | ||
272 | disconnect(d->drag.destroyConnection); | 276 | disconnect(d->drag.destroyConnection); | ||
273 | d->drag.destroyConnection = QMetaObject::Connection(); | 277 | d->drag.destroyConnection = QMetaObject::Connection(); | ||
274 | d->drag.surface = nullptr; | 278 | d->drag.surface = nullptr; | ||
275 | if (d->drag.sourceActionConnection) { | 279 | if (d->drag.sourceActionConnection) { | ||
276 | disconnect(d->drag.sourceActionConnection); | 280 | disconnect(d->drag.sourceActionConnection); | ||
277 | d->drag.sourceActionConnection = QMetaObject::Connection(); | 281 | d->drag.sourceActionConnection = QMetaObject::Connection(); | ||
278 | } | 282 | } | ||
279 | if (d->drag.targetActionConnection) { | 283 | if (d->drag.targetActionConnection) { | ||
280 | disconnect(d->drag.targetActionConnection); | 284 | disconnect(d->drag.targetActionConnection); | ||
281 | d->drag.targetActionConnection = QMetaObject::Connection(); | 285 | d->drag.targetActionConnection = QMetaObject::Connection(); | ||
282 | } | 286 | } | ||
283 | // don't update serial, we need it | 287 | // don't update serial, we need it | ||
284 | } | 288 | } | ||
285 | if (!surface) { | 289 | if (!surface) { | ||
286 | if (auto s = d->seat->dragSource()->dragSource()) { | 290 | if (auto s = d->seat->dragSource()->dragSource()) { | ||
287 | s->dndAction(DataDeviceManagerInterface::DnDAction::None); | 291 | s->dndAction(DataDeviceManagerInterface::DnDAction::None); | ||
288 | } | 292 | } | ||
289 | return; | 293 | return; | ||
290 | } | 294 | } | ||
291 | auto *source = d->seat->dragSource()->dragSource(); | 295 | auto *source = d->seat->dragSource()->dragSource(); | ||
292 | DataOfferInterface *offer = d->createDataOffer(source); | 296 | DataOfferInterface *offer = d->createDataOffer(source); | ||
293 | d->drag.surface = surface; | 297 | d->drag.surface = surface; | ||
294 | if (d->seat->isDragPointer()) { | 298 | if (d->seat->isDragPointer()) { | ||
295 | d->drag.pointerPosConnection = connect(d->seat, &SeatInterface::pointerPosChanged, this, | 299 | d->drag.posConnection = connect(d->seat, &SeatInterface::pointerPosChanged, this, | ||
296 | [this] { | 300 | [this] { | ||
297 | Q_D(); | 301 | Q_D(); | ||
298 | const QPointF pos = d->seat->dragSurfaceTransformation().map(d->seat->pointerPos()); | 302 | const QPointF pos = d->seat->dragSurfaceTransformation().map(d->seat->pointerPos()); | ||
299 | wl_data_device_send_motion(d->resource, d->seat->timestamp(), | 303 | wl_data_device_send_motion(d->resource, d->seat->timestamp(), | ||
300 | wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); | 304 | wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); | ||
301 | client()->flush(); | 305 | client()->flush(); | ||
302 | } | 306 | } | ||
303 | ); | 307 | ); | ||
308 | } else if (d->seat->isDragTouch()) { | ||||
309 | d->drag.posConnection = connect(d->seat, &SeatInterface::touchMoved, this, | ||||
310 | [this](qint32 id, quint32 serial, const QPointF &globalPosition) { | ||||
311 | Q_D(); | ||||
312 | Q_UNUSED(id); | ||||
313 | if (serial != d->drag.serial) { | ||||
314 | // different touch down has been moved | ||||
315 | return; | ||||
316 | } | ||||
317 | const QPointF pos = d->seat->dragSurfaceTransformation().map(globalPosition); | ||||
318 | wl_data_device_send_motion(d->resource, d->seat->timestamp(), | ||||
319 | wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); | ||||
320 | client()->flush(); | ||||
321 | } | ||||
322 | ); | ||||
304 | } | 323 | } | ||
305 | // TODO: same for touch | | |||
306 | d->drag.destroyConnection = connect(d->drag.surface, &QObject::destroyed, this, | 324 | d->drag.destroyConnection = connect(d->drag.surface, &QObject::destroyed, this, | ||
307 | [this] { | 325 | [this] { | ||
308 | Q_D(); | 326 | Q_D(); | ||
309 | if (d->resource) { | 327 | if (d->resource) { | ||
310 | wl_data_device_send_leave(d->resource); | 328 | wl_data_device_send_leave(d->resource); | ||
311 | } | 329 | } | ||
312 | if (d->drag.pointerPosConnection) { | 330 | if (d->drag.posConnection) { | ||
313 | disconnect(d->drag.pointerPosConnection); | 331 | disconnect(d->drag.posConnection); | ||
314 | } | 332 | } | ||
315 | d->drag = Private::Drag(); | 333 | d->drag = Private::Drag(); | ||
316 | } | 334 | } | ||
317 | ); | 335 | ); | ||
318 | 336 | | |||
319 | // TODO: handle touch position | 337 | // TODO: handle touch position | ||
320 | const QPointF pos = d->seat->dragSurfaceTransformation().map(d->seat->pointerPos()); | 338 | const QPointF pos = d->seat->dragSurfaceTransformation().map(d->seat->pointerPos()); | ||
321 | wl_data_device_send_enter(d->resource, serial, surface->resource(), | 339 | wl_data_device_send_enter(d->resource, serial, surface->resource(), | ||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |
done