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