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

#include "../defines.hpp"
#include "../protocols/core/Compositor.hpp"
#include "text-input-unstable-v1.hpp"
#include "WaylandProtocol.hpp"

#include <vector>

class CTextInput;

class CTextInputV1 {
  public:
    CTextInputV1(SP<CZwpTextInputV1> resource);
    ~CTextInputV1();

    void       enter(SP<CWLSurfaceResource> surface);
    void       leave();

    void       preeditCursor(int32_t index);
    void       preeditStyling(uint32_t index, uint32_t length, zwpTextInputV1PreeditStyle style);
    void       preeditString(uint32_t serial, const char* text, const char* commit);
    void       commitString(uint32_t serial, const char* text);
    void       deleteSurroundingText(int32_t index, uint32_t length);

    bool       good();
    wl_client* client();

  private:
    SP<CZwpTextInputV1> resource;
    WP<CTextInputV1>    self;

    uint32_t            serial = 0;
    bool                active = false;

    struct {
        CSignal onCommit;
        CSignal enable;
        CSignal disable;
        CSignal destroy;
    } events;

    struct SPendingSurr {
        bool        isPending = false;
        std::string text      = "";
        uint32_t    cursor    = 0;
        uint32_t    anchor    = 0;
    } pendingSurrounding;

    struct SPendingCT {
        bool     isPending = false;
        uint32_t hint      = 0;
        uint32_t purpose   = 0;
    } pendingContentType;

    CBox cursorRectangle = {0, 0, 0, 0};

    friend class CTextInput;
    friend class CTextInputV1Protocol;
};

class CTextInputV1Protocol : IWaylandProtocol {
  public:
    CTextInputV1Protocol(const wl_interface* iface, const int& ver, const std::string& name);

    virtual void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
    void         destroyResource(CTextInputV1* resource);
    void         destroyResource(CZwpTextInputManagerV1* client);

    struct {
        CSignal newTextInput; // WP<CTextInputV3>
    } events;

  private:
    std::vector<SP<CZwpTextInputManagerV1>> m_vManagers;
    std::vector<SP<CTextInputV1>>           m_vClients;

    friend class CTextInputV1;
};

namespace PROTO {
    inline UP<CTextInputV1Protocol> textInputV1;
};