aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/protocols/DataDeviceWlr.hpp
blob: 0b70334798900d4a7e67c807f864463d44eb625e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once

#include <memory>
#include <vector>
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "wlr-data-control-unstable-v1.hpp"
#include "types/DataDevice.hpp"

class CWLRDataControlManagerResource;
class CWLRDataSource;
class CWLRDataDevice;
class CWLRDataOffer;

class CWLRDataOffer {
  public:
    CWLRDataOffer(SP<CZwlrDataControlOfferV1> resource_, SP<IDataSource> source);

    bool            good();
    void            sendData();

    bool            dead = false;

    WP<IDataSource> source;

  private:
    SP<CZwlrDataControlOfferV1> resource;

    friend class CWLRDataDevice;
};

class CWLRDataSource : public IDataSource {
  public:
    CWLRDataSource(SP<CZwlrDataControlSourceV1> resource_, SP<CWLRDataDevice> device_);
    ~CWLRDataSource();
    static SP<CWLRDataSource>        fromResource(wl_resource*);

    bool                             good();

    virtual std::vector<std::string> mimes();
    virtual void                     send(const std::string& mime, uint32_t fd);
    virtual void                     accepted(const std::string& mime);
    virtual void                     cancelled();
    virtual void                     error(uint32_t code, const std::string& msg);

    std::vector<std::string>         mimeTypes;
    WP<CWLRDataSource>               self;
    WP<CWLRDataDevice>               device;

  private:
    SP<CZwlrDataControlSourceV1> resource;
};

class CWLRDataDevice {
  public:
    CWLRDataDevice(SP<CZwlrDataControlDeviceV1> resource_);

    bool               good();
    wl_client*         client();
    void               sendInitialSelections();

    void               sendDataOffer(SP<CWLRDataOffer> offer);
    void               sendSelection(SP<CWLRDataOffer> selection);

    WP<CWLRDataDevice> self;

  private:
    SP<CZwlrDataControlDeviceV1> resource;
    wl_client*                   pClient = nullptr;

    friend class CDataDeviceWLRProtocol;
};

class CWLRDataControlManagerResource {
  public:
    CWLRDataControlManagerResource(SP<CZwlrDataControlManagerV1> resource_);

    bool                            good();

    WP<CWLRDataDevice>              device;
    std::vector<WP<CWLRDataSource>> sources;

  private:
    SP<CZwlrDataControlManagerV1> resource;
};

class CDataDeviceWLRProtocol : public IWaylandProtocol {
  public:
    CDataDeviceWLRProtocol(const wl_interface* iface, const int& ver, const std::string& name);

    virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);

  private:
    void destroyResource(CWLRDataControlManagerResource* resource);
    void destroyResource(CWLRDataSource* resource);
    void destroyResource(CWLRDataDevice* resource);
    void destroyResource(CWLRDataOffer* resource);

    //
    std::vector<SP<CWLRDataControlManagerResource>> m_vManagers;
    std::vector<SP<CWLRDataSource>>                 m_vSources;
    std::vector<SP<CWLRDataDevice>>                 m_vDevices;
    std::vector<SP<CWLRDataOffer>>                  m_vOffers;

    //
    void setSelection(SP<IDataSource> source);
    void sendSelectionToDevice(SP<CWLRDataDevice> dev, SP<IDataSource> sel);

    //
    SP<CWLRDataDevice> dataDeviceForClient(wl_client*);

    friend class CSeatManager;
    friend class CWLRDataControlManagerResource;
    friend class CWLRDataSource;
    friend class CWLRDataDevice;
    friend class CWLRDataOffer;
};

namespace PROTO {
    inline UP<CDataDeviceWLRProtocol> dataWlr;
};