aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/protocols/ForeignToplevel.hpp
blob: 076bfd7c0d8f2cb1696933cea7abc999a7dbf248 (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
#pragma once

#include <memory>
#include <vector>
#include <unordered_map>
#include "WaylandProtocol.hpp"
#include "ext-foreign-toplevel-list-v1.hpp"

class CForeignToplevelHandle {
  public:
    CForeignToplevelHandle(SP<CExtForeignToplevelHandleV1> resource_, PHLWINDOW pWindow);

    bool      good();
    PHLWINDOW window();

  private:
    SP<CExtForeignToplevelHandleV1> resource;
    PHLWINDOWREF                    pWindow;
    bool                            closed = false;

    friend class CForeignToplevelList;
};

class CForeignToplevelList {
  public:
    CForeignToplevelList(SP<CExtForeignToplevelListV1> resource_);

    void onMap(PHLWINDOW pWindow);
    void onTitle(PHLWINDOW pWindow);
    void onClass(PHLWINDOW pWindow);
    void onUnmap(PHLWINDOW pWindow);

    bool good();

  private:
    SP<CExtForeignToplevelListV1>           resource;
    bool                                    finished = false;

    SP<CForeignToplevelHandle>              handleForWindow(PHLWINDOW pWindow);

    std::vector<WP<CForeignToplevelHandle>> handles;
};

class CForeignToplevelProtocol : public IWaylandProtocol {
  public:
    CForeignToplevelProtocol(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 onManagerResourceDestroy(CForeignToplevelList* mgr);
    void destroyHandle(CForeignToplevelHandle* handle);
    bool windowValidForForeign(PHLWINDOW pWindow);

    //
    std::vector<UP<CForeignToplevelList>>   m_vManagers;
    std::vector<SP<CForeignToplevelHandle>> m_vHandles;

    friend class CForeignToplevelList;
    friend class CForeignToplevelHandle;
};

namespace PROTO {
    inline UP<CForeignToplevelProtocol> foreignToplevel;
};