summaryrefslogtreecommitdiff
path: root/src/protocols/XDGForeignV2.hpp
blob: 092945d4d02608c221b4f4e7effb60c65127d5c9 (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
#include <hyprutils/signal/Listener.hpp>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
#include "WaylandProtocol.hpp"
#include "xdg-foreign-unstable-v2.hpp"
#include "../helpers/signal/Signal.hpp"

class CXDGImportedResourceV2;
class CWLSurface;
class CXDGToplevelResource;

class CXDGExportedResourceV2 {
  public:
    CXDGExportedResourceV2(SP<CZxdgExportedV2> resource_, SP<CXDGToplevelResource> surface_, const std::string& handle);
    ~CXDGExportedResourceV2();

    struct {
        CSignalT<> destroy;
    } m_events;

    bool                     good() const;
    std::string_view         handle() const;
    WP<CXDGToplevelResource> xdgSurf() const;

  private:
    bool m_topLevelDestroyed = false;
    struct {
        CHyprSignalListener topLevelDestroyed;
    } m_listeners;
    SP<CZxdgExportedV2>      m_resource;
    WP<CXDGToplevelResource> m_toplevel;
    std::string              m_handle;

    friend class CXDGForeignExporterProtocolV2;
};

// zxdg_imported_v2
class CXDGImportedResourceV2 {
  public:
    CXDGImportedResourceV2(SP<CZxdgImportedV2> resource, SP<CXDGExportedResourceV2> exported, const std::string& handle);
    ~CXDGImportedResourceV2();

    bool good() const;
    void invalidate();

  private:
    SP<CZxdgImportedV2>        m_resource;
    WP<CXDGExportedResourceV2> m_exported;
    std::string                m_handle;
    bool                       m_invalid       = false;
    bool                       m_destroyedSent = false;

    struct {
        CHyprSignalListener exportedDestroyed;
    } m_listeners;

    friend class CXDGForeignImporterProtocolV2;
};

class CXDGForeignExporterProtocolV2 : public IWaylandProtocol {
  public:
    CXDGForeignExporterProtocolV2(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) override;

    SP<CXDGExportedResourceV2> getExported(const std::string& handle) const;

  private:
    void                                                        destroyExported(CXDGExportedResourceV2*);
    void                                                        onExporterDestroyed(CZxdgExporterV2*);
    std::vector<UP<CZxdgExporterV2>>                            m_exporters;
    std::unordered_map<std::string, SP<CXDGExportedResourceV2>> m_exported;

    friend class CXDGExportedResourceV2;
};

class CXDGForeignImporterProtocolV2 : public IWaylandProtocol {
  public:
    CXDGForeignImporterProtocolV2(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) override;

  private:
    void                                    destroyImported(CXDGImportedResourceV2*);
    void                                    onImporterDestroyed(CZxdgImporterV2*);
    std::vector<UP<CZxdgImporterV2>>        m_importers;
    std::vector<UP<CXDGImportedResourceV2>> m_imports;

    friend class CXDGImportedResourceV2;
};

namespace PROTO {
    inline UP<CXDGForeignExporterProtocolV2> xdgForeignExporter;
    inline UP<CXDGForeignImporterProtocolV2> xdgForeignImporter;
};