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

#include <memory>
#include <vector>
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "relative-pointer-unstable-v1.hpp"
#include "../helpers/math/Math.hpp"

class CRelativePointer {
  public:
    CRelativePointer(SP<CZwpRelativePointerV1> resource_);

    void       sendRelativeMotion(uint64_t time, const Vector2D& delta, const Vector2D& deltaUnaccel);

    bool       good();
    wl_client* client();

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

class CRelativePointerProtocol : public IWaylandProtocol {
  public:
    CRelativePointerProtocol(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         sendRelativeMotion(uint64_t time, const Vector2D& delta, const Vector2D& deltaUnaccel);

  private:
    void onManagerResourceDestroy(wl_resource* res);
    void destroyRelativePointer(CRelativePointer* pointer);
    void onGetRelativePointer(CZwpRelativePointerManagerV1* pMgr, uint32_t id, wl_resource* pointer);

    //
    std::vector<UP<CZwpRelativePointerManagerV1>> m_vManagers;
    std::vector<UP<CRelativePointer>>             m_vRelativePointers;

    friend class CRelativePointer;
};

namespace PROTO {
    inline UP<CRelativePointerProtocol> relativePointer;
};