File indexing completed on 2024-06-16 05:11:02
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2018 The Qt Company Ltd. 0004 ** Contact: https://www.qt.io/licensing/ 0005 ** 0006 ** This file is part of the test suite of the Qt Toolkit. 0007 ** 0008 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 0009 ** Commercial License Usage 0010 ** Licensees holding valid commercial Qt licenses may use this file in 0011 ** accordance with the commercial license agreement provided with the 0012 ** Software or, alternatively, in accordance with the terms contained in 0013 ** a written agreement between you and The Qt Company. For licensing terms 0014 ** and conditions see https://www.qt.io/terms-conditions. For further 0015 ** information use the contact form at https://www.qt.io/contact-us. 0016 ** 0017 ** GNU General Public License Usage 0018 ** Alternatively, this file may be used under the terms of the GNU 0019 ** General Public License version 3 as published by the Free Software 0020 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 0021 ** included in the packaging of this file. Please review the following 0022 ** information to ensure the GNU General Public License requirements will 0023 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 0024 ** 0025 ** $QT_END_LICENSE$ 0026 ** 0027 ****************************************************************************/ 0028 0029 #pragma once 0030 0031 // TODO: need this? 0032 #include "coreprotocol.h" 0033 0034 namespace MockCompositor 0035 { 0036 class DataOffer; 0037 0038 class DataDeviceManager : public Global, public QtWaylandServer::wl_data_device_manager 0039 { 0040 Q_OBJECT 0041 public: 0042 explicit DataDeviceManager(CoreCompositor *compositor, int version = 1) 0043 : QtWaylandServer::wl_data_device_manager(compositor->m_display, version) 0044 , m_version(version) 0045 { 0046 } 0047 ~DataDeviceManager() override 0048 { 0049 qDeleteAll(m_dataDevices); 0050 } 0051 bool isClean() override; 0052 DataDevice *deviceFor(Seat *seat); 0053 0054 int m_version = 1; // TODO: remove on libwayland upgrade 0055 QMap<Seat *, DataDevice *> m_dataDevices; 0056 0057 protected: 0058 void data_device_manager_get_data_device(Resource *resource, uint32_t id, ::wl_resource *seatResource) override; 0059 }; 0060 0061 class DataDevice : public QtWaylandServer::wl_data_device 0062 { 0063 public: 0064 explicit DataDevice(DataDeviceManager *manager, Seat *seat) 0065 : m_manager(manager) 0066 , m_seat(seat) 0067 { 0068 } 0069 ~DataDevice() override; 0070 void send_data_offer(::wl_resource *resource) = delete; 0071 DataOffer *sendDataOffer(::wl_client *client, const QStringList &mimeTypes = {}); 0072 0073 void send_selection(::wl_resource *resource) = delete; 0074 void sendSelection(DataOffer *offer); 0075 0076 DataDeviceManager *m_manager = nullptr; 0077 Seat *m_seat = nullptr; 0078 QList<DataOffer *> m_sentSelectionOffers; 0079 0080 protected: 0081 void data_device_release(Resource *resource) override 0082 { 0083 int removed = m_manager->m_dataDevices.remove(m_seat); 0084 QVERIFY(removed); 0085 wl_resource_destroy(resource->handle); 0086 } 0087 }; 0088 0089 class DataOffer : public QObject, public QtWaylandServer::wl_data_offer 0090 { 0091 Q_OBJECT 0092 public: 0093 explicit DataOffer(DataDevice *dataDevice, ::wl_client *client, int version) 0094 : QtWaylandServer::wl_data_offer(client, 0, version) 0095 , m_dataDevice(dataDevice) 0096 { 0097 } 0098 0099 DataDevice *m_dataDevice = nullptr; 0100 0101 signals: 0102 void receive(QString mimeType, int fd); 0103 0104 protected: 0105 void data_offer_destroy_resource(Resource *resource) override; 0106 void data_offer_receive(Resource *resource, const QString &mime_type, int32_t fd) override; 0107 // void data_offer_accept(Resource *resource, uint32_t serial, const QString &mime_type) override; 0108 void data_offer_destroy(Resource *resource) override; 0109 }; 0110 0111 } // namespace MockCompositor