~aleteoryx/muditaos

ref: b95894a8abc10cddf0b58dda4b2569b01eec0d7e muditaos/module-gui/gui/input/Translator.hpp -rw-r--r-- 2.1 KiB
b95894a8 — Lefucjusz [MOS-1064] Fix no input language selected for French/Spanish 1 year, 9 months ago
                                                                                
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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "InputEvent.hpp"
#include "Profile.hpp"
#include <hal/key_input/RawKey.hpp>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <vector>

namespace gui
{
    class KeyBaseTranslation
    {
      public:
        /// RawKey to Input Event translation
        InputEvent set(RawKey key);
        /// Check if keyPress is timed out for particular timestamp
        bool isKeyPressTimedOut(std::uint32_t actualTimeStamp);
        /// Reset previous key press status
        void resetPreviousKeyPress();
        /// Set previous key press timeout status
        void setPreviousKeyTimedOut(bool status);

      protected:
        RawKey previousKeyPress    = {};
        bool isPreviousKeyPressed  = false;
        bool isPreviousKeyTimedOut = false;

      private:
        void translateRelease(InputEvent &evt, const RawKey &key);
    };

    class KeyInputSimpleTranslation : public KeyBaseTranslation
    {
      public:
        /// translate incomming key
        InputEvent translate(RawKey key);
        /// translate timeout - simulate key release
        InputEvent translate(std::uint32_t timeout);
    };

    /// profiles cache - load once for all
    class Profiles
    {
      private:
        std::map<std::string, gui::Profile> profilesList = {};

        void loadProfile(const std::string &filepath);
        std::vector<std::string> getProfilesFilenames();
        void init();
        Profile empty;

        static Profiles &get();

      public:
        std::vector<std::string> getAvailableInputLanguages();
        Profile &get(const std::string &name);
    };

    /// translator using & switching KeyMaps for use per widget basis ,called for selected widget, per widget basis
    class KeyInputMappedTranslation : public KeyBaseTranslation
    {
        std::uint32_t times = 0;
        Profiles profiles;

      public:
        std::uint32_t handle(RawKey key, const std::string &keymap, bool incrementTimes = true);
        std::uint32_t getTimes() const noexcept;
    };
} // namespace gui