File indexing completed on 2024-05-19 16:35:17

0001 /*
0002     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003     SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
0004     SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 #pragma once
0009 
0010 #include "kwin_export.h"
0011 
0012 #include <QObject>
0013 #include <memory>
0014 
0015 #include "abstract_drop_handler.h"
0016 
0017 struct wl_client;
0018 struct wl_resource;
0019 
0020 namespace KWaylandServer
0021 {
0022 class DataDeviceManagerInterface;
0023 class DataOfferInterface;
0024 class DataSourceInterface;
0025 class AbstractDataSource;
0026 class SeatInterface;
0027 class SurfaceInterface;
0028 class DataDeviceInterfacePrivate;
0029 class DragAndDropIconPrivate;
0030 
0031 /**
0032  * The DragAndDropIcon class represents a drag-and-drop icon.
0033  *
0034  * Note that the lifetime of the drag-and-drop icon is bound to the lifetime of the underlying
0035  * icon surface.
0036  */
0037 class KWIN_EXPORT DragAndDropIcon : public QObject
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     ~DragAndDropIcon() override;
0043 
0044     /**
0045      * Returns the position of the icon relative to the cursor's hotspot.
0046      */
0047     QPoint position() const;
0048 
0049     /**
0050      * Returns the underlying icon surface. This function always returns a valid surface.
0051      */
0052     SurfaceInterface *surface() const;
0053 
0054 Q_SIGNALS:
0055     void changed();
0056 
0057 private:
0058     explicit DragAndDropIcon(SurfaceInterface *surface);
0059     friend class DataDeviceInterfacePrivate;
0060     std::unique_ptr<DragAndDropIconPrivate> d;
0061 };
0062 
0063 /**
0064  * @brief DataDeviceInterface allows clients to share data by copy-and-paste and drag-and-drop.
0065  *
0066  * The data device is per seat.
0067  * Copy-and-paste use the selection functions.
0068  *
0069  * Represents the Resource for the wl_data_device interface.
0070  *
0071  * @see SeatInterface
0072  * @see DataSourceInterface
0073  */
0074 class KWIN_EXPORT DataDeviceInterface : public AbstractDropHandler
0075 {
0076     Q_OBJECT
0077 public:
0078     virtual ~DataDeviceInterface();
0079 
0080     SeatInterface *seat() const;
0081 
0082     DataSourceInterface *selection() const;
0083 
0084     void sendSelection(KWaylandServer::AbstractDataSource *other);
0085     /**
0086      * The event is sent when a drag-and-drop operation is ended because the implicit grab is removed.
0087      */
0088     void drop() override;
0089     /**
0090      * Updates the SurfaceInterface to which drag motion events are sent.
0091      *
0092      * If a SurfaceInterface was registered in this DataDeviceInterface for drag motion events, it
0093      * will be sent a leave event.
0094      *
0095      * If @p surface is not null it will be sent a drag enter event.
0096      *
0097      * @param surface The SurfaceInterface which gets motion events
0098      * @param serial The serial to be used for enter/leave
0099      */
0100     void updateDragTarget(SurfaceInterface *surface, quint32 serial) override;
0101 
0102     wl_client *client();
0103 
0104 Q_SIGNALS:
0105     void aboutToBeDestroyed();
0106     void dragStarted(AbstractDataSource *source, SurfaceInterface *originSurface, quint32 serial, DragAndDropIcon *dragIcon);
0107     void selectionChanged(KWaylandServer::DataSourceInterface *);
0108 
0109 private:
0110     friend class DataDeviceManagerInterfacePrivate;
0111     explicit DataDeviceInterface(SeatInterface *seat, wl_resource *resource);
0112     std::unique_ptr<DataDeviceInterfacePrivate> d;
0113     friend class DataDeviceInterfacePrivate;
0114 };
0115 
0116 }
0117 
0118 Q_DECLARE_METATYPE(KWaylandServer::DataDeviceInterface *)