aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/protocols/core/Output.hpp
blob: 46981635adf4c25cacb85dc609044d5819cd9a98 (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
#pragma once

#include <memory>
#include <vector>
#include <cstdint>
#include "../WaylandProtocol.hpp"
#include "wayland.hpp"
#include "../../helpers/signal/Signal.hpp"

class CMonitor;

class CWLOutputResource {
  public:
    CWLOutputResource(SP<CWlOutput> resource_, SP<CMonitor> pMonitor);
    static SP<CWLOutputResource> fromResource(wl_resource*);

    bool                         good();
    wl_client*                   client();
    SP<CWlOutput>                getResource();
    void                         updateState();

    WP<CMonitor>                 monitor;

    WP<CWLOutputResource>        self;

  private:
    SP<CWlOutput> resource;
    wl_client*    pClient = nullptr;
};

class CWLOutputProtocol : public IWaylandProtocol {
  public:
    CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, SP<CMonitor> pMonitor);

    virtual void          bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);

    SP<CWLOutputResource> outputResourceFrom(wl_client* client);

    WP<CMonitor>          monitor;

    // will mark the protocol for removal, will be removed when no. of bound outputs is 0 (or when overwritten by a new global)
    void remove();
    bool isDefunct(); // true if above was called

  private:
    void destroyResource(CWLOutputResource* resource);

    //
    std::vector<SP<CWLOutputResource>> m_vOutputs;
    bool                               defunct = false;
    std::string                        szName  = "";

    struct {
        CHyprSignalListener modeChanged;
    } listeners;

    friend class CWLOutputResource;
};

namespace PROTO {
    inline std::unordered_map<std::string, UP<CWLOutputProtocol>> outputs;
};