summaryrefslogtreecommitdiff
path: root/src/protocols/SessionLock.hpp
blob: 09b48b3275d284e0c1c2c4f2dba6c99a7f49cdff (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once

#include <vector>
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "ext-session-lock-v1.hpp"
#include "../helpers/signal/Signal.hpp"

class CMonitor;
class CSessionLock;
class CWLSurfaceResource;

class CSessionLockSurface {
  public:
    CSessionLockSurface(SP<CExtSessionLockSurfaceV1> resource_, SP<CWLSurfaceResource> surface_, PHLMONITOR pMonitor_, WP<CSessionLock> owner_);
    ~CSessionLockSurface();

    bool                   good();
    bool                   inert();
    PHLMONITOR             monitor();
    SP<CWLSurfaceResource> surface();

    struct {
        CSignalT<> map;
        CSignalT<> destroy;
        CSignalT<> commit;
    } m_events;

  private:
    SP<CExtSessionLockSurfaceV1> m_resource;
    WP<CSessionLock>             m_sessionLock;
    WP<CWLSurfaceResource>       m_surface;
    PHLMONITORREF                m_monitor;

    bool                         m_ackdConfigure = false;
    bool                         m_committed     = false;

    void                         sendConfigure();

    struct {
        CHyprSignalListener monitorMode;
        CHyprSignalListener surfaceCommit;
        CHyprSignalListener surfaceDestroy;
    } m_listeners;
};

class CSessionLock {
  public:
    CSessionLock(SP<CExtSessionLockV1> resource_);
    ~CSessionLock();

    bool good();
    void sendLocked();
    void sendDenied();

    struct {
        CSignalT<SP<CSessionLockSurface>> newLockSurface;
        CSignalT<>                        unlockAndDestroy;
        CSignalT<>                        destroyed; // fires regardless of whether there was a unlockAndDestroy or not.
    } m_events;

  private:
    SP<CExtSessionLockV1> m_resource;

    bool                  m_inert = false;

    friend class CSessionLockProtocol;
};

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

    bool         isLocked();

    struct {
        CSignalT<SP<CSessionLock>> newLock;
    } m_events;

  private:
    void onManagerResourceDestroy(wl_resource* res);
    void destroyResource(CSessionLock* lock);
    void destroyResource(CSessionLockSurface* surf);
    void onLock(CExtSessionLockManagerV1* pMgr, uint32_t id);
    void onGetLockSurface(CExtSessionLockV1* lock, uint32_t id, wl_resource* surface, wl_resource* output);

    bool m_locked = false;

    //
    std::vector<UP<CExtSessionLockManagerV1>> m_managers;
    std::vector<SP<CSessionLock>>             m_locks;
    std::vector<SP<CSessionLockSurface>>      m_lockSurfaces;

    friend class CSessionLock;
    friend class CSessionLockSurface;
};

namespace PROTO {
    inline UP<CSessionLockProtocol> sessionLock;
};