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

#include <memory>
#include <unordered_map>
#include "WaylandProtocol.hpp"
#include "fractional-scale-v1.hpp"

class CFractionalScaleProtocol;
class CWLSurfaceResource;

class CFractionalScaleAddon {
  public:
    CFractionalScaleAddon(SP<CWpFractionalScaleV1> resource_, SP<CWLSurfaceResource> surf_);

    void                   setScale(const float& scale);
    void                   onSurfaceDestroy();

    bool                   good();

    SP<CWLSurfaceResource> surf();

    bool                   operator==(const wl_resource* other) const {
        return other == resource->resource();
    }

    bool operator==(const CFractionalScaleAddon* other) const {
        return other->resource == resource;
    }

  private:
    SP<CWpFractionalScaleV1> resource;
    float                    scale = 1.F;
    WP<CWLSurfaceResource>   surface;
    bool                     surfaceGone = false;

    friend class CFractionalScaleProtocol;
};

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

    void         onSurfaceDestroy(SP<CWLSurfaceResource> surf);
    void         sendScale(SP<CWLSurfaceResource> surf, const float& scale);

  private:
    void removeAddon(CFractionalScaleAddon*);
    void onManagerResourceDestroy(wl_resource* res);
    void onGetFractionalScale(CWpFractionalScaleManagerV1* pMgr, uint32_t id, SP<CWLSurfaceResource> surface);

    //

    std::unordered_map<WP<CWLSurfaceResource>, float>                     m_mSurfaceScales;
    std::unordered_map<WP<CWLSurfaceResource>, UP<CFractionalScaleAddon>> m_mAddons;
    std::vector<UP<CWpFractionalScaleManagerV1>>                          m_vManagers;

    friend class CFractionalScaleAddon;
};

namespace PROTO {
    inline UP<CFractionalScaleProtocol> fractional;
};