1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#ifndef KEY_AUTO_REPEAT_H
17c29fa5a6Sopenharmony_ci#define KEY_AUTO_REPEAT_H
18c29fa5a6Sopenharmony_ci
19c29fa5a6Sopenharmony_ci#include <map>
20c29fa5a6Sopenharmony_ci#include <string>
21c29fa5a6Sopenharmony_ci
22c29fa5a6Sopenharmony_ci#include "event_dispatch_handler.h"
23c29fa5a6Sopenharmony_ci#include "key_event.h"
24c29fa5a6Sopenharmony_ci#include "key_map_manager.h"
25c29fa5a6Sopenharmony_ci#include "libinput.h"
26c29fa5a6Sopenharmony_ci#include "singleton.h"
27c29fa5a6Sopenharmony_ci#include "util.h"
28c29fa5a6Sopenharmony_ci
29c29fa5a6Sopenharmony_cinamespace OHOS {
30c29fa5a6Sopenharmony_cinamespace MMI {
31c29fa5a6Sopenharmony_ciclass KeyAutoRepeat final {
32c29fa5a6Sopenharmony_ci    DECLARE_DELAYED_SINGLETON(KeyAutoRepeat);
33c29fa5a6Sopenharmony_cipublic:
34c29fa5a6Sopenharmony_ci    DISALLOW_COPY_AND_MOVE(KeyAutoRepeat);
35c29fa5a6Sopenharmony_ci    int32_t AddDeviceConfig(struct libinput_device *device);
36c29fa5a6Sopenharmony_ci    bool JudgeLimitPrint(const std::shared_ptr<KeyEvent>& keyEvent);
37c29fa5a6Sopenharmony_ci    bool JudgeKeyEvent(const std::shared_ptr<KeyEvent>& keyEvent);
38c29fa5a6Sopenharmony_ci    void SelectAutoRepeat(const std::shared_ptr<KeyEvent>& keyEvent);
39c29fa5a6Sopenharmony_ci    void AddHandleTimer(int32_t timeout);
40c29fa5a6Sopenharmony_ci    void RemoveDeviceConfig(struct libinput_device *device);
41c29fa5a6Sopenharmony_ci    int32_t GetIntervalTime(int32_t deviceId);
42c29fa5a6Sopenharmony_ci    std::map<int32_t, DeviceConfig> GetDeviceConfig() const;
43c29fa5a6Sopenharmony_ci    void RemoveTimer();
44c29fa5a6Sopenharmony_ci    int32_t SetKeyboardRepeatDelay(int32_t delay);
45c29fa5a6Sopenharmony_ci    int32_t SetKeyboardRepeatRate(int32_t rate);
46c29fa5a6Sopenharmony_ci    int32_t GetKeyboardRepeatDelay(int32_t &delay);
47c29fa5a6Sopenharmony_ci    int32_t GetKeyboardRepeatRate(int32_t &rate);
48c29fa5a6Sopenharmony_ci    int32_t GetRepeatKeyCode() const;
49c29fa5a6Sopenharmony_ciprivate:
50c29fa5a6Sopenharmony_ci    std::string GetTomlFilePath(const std::string &fileName) const;
51c29fa5a6Sopenharmony_ci    DeviceConfig GetAutoSwitch(int32_t deviceId);
52c29fa5a6Sopenharmony_ci    int32_t PutConfigDataToDatabase(std::string &key, int32_t value);
53c29fa5a6Sopenharmony_ci    int32_t GetConfigDataFromDatabase(std::string &key, int32_t &value);
54c29fa5a6Sopenharmony_ci    int32_t GetDelayTime();
55c29fa5a6Sopenharmony_ci    int32_t GetKeyboardRepeatTime(int32_t deviceId, bool isDelay);
56c29fa5a6Sopenharmony_ci
57c29fa5a6Sopenharmony_ciprivate:
58c29fa5a6Sopenharmony_ci    std::map<int32_t, DeviceConfig> deviceConfig_;
59c29fa5a6Sopenharmony_ci    int32_t timerId_ { -1 };
60c29fa5a6Sopenharmony_ci    int32_t repeatKeyCode_ { -1 };
61c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent_ { nullptr };
62c29fa5a6Sopenharmony_ci};
63c29fa5a6Sopenharmony_ci
64c29fa5a6Sopenharmony_ci#define KeyRepeat ::OHOS::DelayedSingleton<KeyAutoRepeat>::GetInstance()
65c29fa5a6Sopenharmony_ci} // namespace MMI
66c29fa5a6Sopenharmony_ci} // namespace OHOS
67c29fa5a6Sopenharmony_ci#endif // KEY_AUTO_REPEAT_H