summaryrefslogtreecommitdiff
path: root/src/protocols/IdleInhibit.hpp
blob: 2e024a7a8768f9dd58dc906e7ba077aca5d69732 (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
66
67
68
69
#pragma once

#include <unordered_map>
#include "WaylandProtocol.hpp"
#include "idle-inhibit-unstable-v1.hpp"
#include "../helpers/signal/Signal.hpp"

class CIdleInhibitorResource;
class CWLSurfaceResource;

class CIdleInhibitor {
  public:
    CIdleInhibitor(SP<CIdleInhibitorResource> resource_, SP<CWLSurfaceResource> surf_);

    struct {
        CHyprSignalListener destroy;
    } listeners;

    WP<CIdleInhibitorResource> resource;
    WP<CWLSurfaceResource>     surface;
};

class CIdleInhibitorResource {
  public:
    CIdleInhibitorResource(SP<CZwpIdleInhibitorV1> resource_, SP<CWLSurfaceResource> surface_);
    ~CIdleInhibitorResource();

    SP<CIdleInhibitor> inhibitor;

    struct {
        CSignal destroy;
    } events;

  private:
    SP<CZwpIdleInhibitorV1> resource;
    WP<CWLSurfaceResource>  surface;
    bool                    destroySent = false;

    struct {
        CHyprSignalListener destroySurface;
    } listeners;
};

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

    struct {
        CSignal newIdleInhibitor; // data: SP<CIdleInhibitor>
    } events;

  private:
    void onManagerResourceDestroy(wl_resource* res);
    void onCreateInhibitor(CZwpIdleInhibitManagerV1* pMgr, uint32_t id, SP<CWLSurfaceResource> surface);

    void removeInhibitor(CIdleInhibitorResource*);

    //
    std::vector<UP<CZwpIdleInhibitManagerV1>> m_vManagers;
    std::vector<SP<CIdleInhibitorResource>>   m_vInhibitors;

    friend class CIdleInhibitorResource;
};

namespace PROTO {
    inline UP<CIdleInhibitProtocol> idleInhibit;
}