summaryrefslogtreecommitdiff
path: root/src/protocols/GammaControl.hpp
blob: 525f5b676a6d2164c25d6b99fa0056a3df2b5d88 (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
#pragma once

#include <vector>
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "wlr-gamma-control-unstable-v1.hpp"
#include "../helpers/signal/Signal.hpp"

class CMonitor;

class CGammaControl {
  public:
    CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* output);
    ~CGammaControl();

    bool       good();
    void       applyToMonitor();
    PHLMONITOR getMonitor();

  private:
    SP<CZwlrGammaControlV1> m_resource;
    PHLMONITORREF           m_monitor;
    size_t                  m_gammaSize     = 0;
    bool                    m_gammaTableSet = false;
    std::vector<uint16_t>   m_gammaTable; // [r,g,b]+

    void                    onMonitorDestroy();

    struct {
        CHyprSignalListener monitorDisconnect;
        CHyprSignalListener monitorDestroy;
    } m_listeners;
};

class CGammaControlProtocol : public IWaylandProtocol {
  public:
    CGammaControlProtocol(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         applyGammaToState(PHLMONITOR pMonitor);

  private:
    void onManagerResourceDestroy(wl_resource* res);
    void destroyGammaControl(CGammaControl* gamma);
    void onGetGammaControl(CZwlrGammaControlManagerV1* pMgr, uint32_t id, wl_resource* output);

    //
    std::vector<UP<CZwlrGammaControlManagerV1>> m_managers;
    std::vector<UP<CGammaControl>>              m_gammaControllers;

    friend class CGammaControl;
};

namespace PROTO {
    inline UP<CGammaControlProtocol> gamma;
};