summaryrefslogtreecommitdiff
path: root/src/protocols/HyprlandSurface.hpp
blob: 5402e916d869852d5c28e3ebaaebc0c95157e9bc (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
#pragma once

#include <hyprutils/math/Region.hpp>
#include <vector>
#include <unordered_map>
#include "WaylandProtocol.hpp"
#include "hyprland-surface-v1.hpp"
#include "../helpers/signal/Signal.hpp"

class CWLSurfaceResource;
class CHyprlandSurfaceProtocol;

class CHyprlandSurface {
  public:
    CHyprlandSurface(SP<CHyprlandSurfaceV1> resource, SP<CWLSurfaceResource> surface);

    bool good() const;
    void setResource(SP<CHyprlandSurfaceV1> resource);

  private:
    SP<CHyprlandSurfaceV1> m_resource;
    WP<CWLSurfaceResource> m_surface;
    float                  m_opacity              = 1.0;
    bool                   m_visibleRegionChanged = false;
    CRegion                m_visibleRegion;

    void                   destroy();

    struct {
        CHyprSignalListener surfaceCommitted;
        CHyprSignalListener surfaceDestroyed;
    } m_listeners;

    friend class CHyprlandSurfaceProtocol;
};

class CHyprlandSurfaceProtocol : public IWaylandProtocol {
  public:
    CHyprlandSurfaceProtocol(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                                                             destroyManager(CHyprlandSurfaceManagerV1* res);
    void                                                             destroySurface(CHyprlandSurface* surface);
    void                                                             getSurface(CHyprlandSurfaceManagerV1* manager, uint32_t id, SP<CWLSurfaceResource> surface);

    std::vector<UP<CHyprlandSurfaceManagerV1>>                       m_managers;
    std::unordered_map<WP<CWLSurfaceResource>, UP<CHyprlandSurface>> m_surfaces;

    friend class CHyprlandSurface;
};

namespace PROTO {
    inline UP<CHyprlandSurfaceProtocol> hyprlandSurface;
}