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

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

class CPointerGestureSwipe {
  public:
    CPointerGestureSwipe(SP<CZwpPointerGestureSwipeV1> resource_);

    bool good();

  private:
    SP<CZwpPointerGestureSwipeV1> resource;

    friend class CPointerGesturesProtocol;
};

class CPointerGesturePinch {
  public:
    CPointerGesturePinch(SP<CZwpPointerGesturePinchV1> resource_);

    bool good();

  private:
    SP<CZwpPointerGesturePinchV1> resource;

    friend class CPointerGesturesProtocol;
};

class CPointerGestureHold {
  public:
    CPointerGestureHold(SP<CZwpPointerGestureHoldV1> resource_);

    bool good();

  private:
    SP<CZwpPointerGestureHoldV1> resource;

    friend class CPointerGesturesProtocol;
};

class CPointerGesturesProtocol : public IWaylandProtocol {
  public:
    CPointerGesturesProtocol(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         swipeBegin(uint32_t timeMs, uint32_t fingers);
    void         swipeUpdate(uint32_t timeMs, const Vector2D& delta);
    void         swipeEnd(uint32_t timeMs, bool cancelled);

    void         pinchBegin(uint32_t timeMs, uint32_t fingers);
    void         pinchUpdate(uint32_t timeMs, const Vector2D& delta, double scale, double rotation);
    void         pinchEnd(uint32_t timeMs, bool cancelled);

    void         holdBegin(uint32_t timeMs, uint32_t fingers);
    void         holdEnd(uint32_t timeMs, bool cancelled);

  private:
    void onManagerResourceDestroy(wl_resource* res);
    void onGestureDestroy(CPointerGestureSwipe* gesture);
    void onGestureDestroy(CPointerGesturePinch* gesture);
    void onGestureDestroy(CPointerGestureHold* gesture);
    void onGetPinchGesture(CZwpPointerGesturesV1* pMgr, uint32_t id, wl_resource* pointer);
    void onGetSwipeGesture(CZwpPointerGesturesV1* pMgr, uint32_t id, wl_resource* pointer);
    void onGetHoldGesture(CZwpPointerGesturesV1* pMgr, uint32_t id, wl_resource* pointer);

    //
    std::vector<UP<CZwpPointerGesturesV1>> m_vManagers;
    std::vector<UP<CPointerGestureSwipe>>  m_vSwipes;
    std::vector<UP<CPointerGesturePinch>>  m_vPinches;
    std::vector<UP<CPointerGestureHold>>   m_vHolds;

    friend class CPointerGestureHold;
    friend class CPointerGesturePinch;
    friend class CPointerGestureSwipe;
};

namespace PROTO {
    inline UP<CPointerGesturesProtocol> pointerGestures;
};