1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Compositor.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
41 #include "wldatadevice.h"
43 #include "wldatasource.h"
44 #include "wldataoffer.h"
45 #include "wldatadevicemanager.h"
53 void DataDevice::start_drag(struct wl_client *client,
54 struct wl_resource *resource,
55 struct wl_resource *source,
56 struct wl_resource *surface,
59 DataDevice *data_device = static_cast<DataDevice *>(resource->data);
60 DataSource *data_source = static_cast<DataSource *>(source->data);
65 void DataDevice::attach(struct wl_client *client,
66 struct wl_resource *resource,
68 struct wl_resource *buffer,
75 void DataDevice::set_selection(struct wl_client *client,
76 struct wl_resource *data_device_resource,
77 struct wl_resource *source,
80 DataDevice *data_device = static_cast<DataDevice *>(data_device_resource->data);
81 DataSource *data_source = static_cast<DataSource *>(source->data);
83 data_device->m_data_device_manager->setCurrentSelectionSource(data_source);
87 const struct wl_data_device_interface DataDevice::data_device_interface = {
88 DataDevice::start_drag,
90 DataDevice::set_selection
93 DataDevice::DataDevice(DataDeviceManager *data_device_manager, struct wl_client *client, uint32_t id)
94 : m_data_device_manager(data_device_manager)
95 , m_sent_selection_time(0)
99 qDebug() << "data device" << ++i;
100 m_data_device_resource =
101 wl_client_add_object(client,&wl_data_device_interface,&data_device_interface,id, this);
104 void DataDevice::sendSelectionFocus()
106 if (m_data_device_manager->offerFromCompositorToClient(m_data_device_resource))
109 DataSource *source = m_data_device_manager->currentSelectionSource();
113 if (source->time() > m_sent_selection_time) { //this makes sure we don't resend
114 if (source->client() != m_data_device_resource->client) { //don't send selection to the client that owns the selection
115 DataOffer *data_offer = m_data_device_manager->currentSelectionSource()->dataOffer();
116 wl_resource *client_resource =
117 data_offer->addDataDeviceResource(m_data_device_resource);
118 qDebug() << "sending data_offer for source" << source;
119 wl_resource_post_event(m_data_device_resource,WL_DATA_DEVICE_SELECTION,client_resource);
120 m_sent_selection_time = source->time();
125 struct wl_resource *DataDevice::dataDeviceResource() const
127 return m_data_device_resource;