1 /* 2 * Copyright (c) 2022-2024 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_event.h" 24 #include "key_map_manager.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 bool JudgeLimitPrint(const std::shared_ptr<KeyEvent>& keyEvent); 37 bool JudgeKeyEvent(const std::shared_ptr<KeyEvent>& keyEvent); 38 void SelectAutoRepeat(const std::shared_ptr<KeyEvent>& keyEvent); 39 void AddHandleTimer(int32_t timeout); 40 void RemoveDeviceConfig(struct libinput_device *device); 41 int32_t GetIntervalTime(int32_t deviceId); 42 std::map<int32_t, DeviceConfig> GetDeviceConfig() const; 43 void RemoveTimer(); 44 int32_t SetKeyboardRepeatDelay(int32_t delay); 45 int32_t SetKeyboardRepeatRate(int32_t rate); 46 int32_t GetKeyboardRepeatDelay(int32_t &delay); 47 int32_t GetKeyboardRepeatRate(int32_t &rate); 48 int32_t GetRepeatKeyCode() const; 49 private: 50 std::string GetTomlFilePath(const std::string &fileName) const; 51 DeviceConfig GetAutoSwitch(int32_t deviceId); 52 int32_t PutConfigDataToDatabase(std::string &key, int32_t value); 53 int32_t GetConfigDataFromDatabase(std::string &key, int32_t &value); 54 int32_t GetDelayTime(); 55 int32_t GetKeyboardRepeatTime(int32_t deviceId, bool isDelay); 56 57 private: 58 std::map<int32_t, DeviceConfig> deviceConfig_; 59 int32_t timerId_ { -1 }; 60 int32_t repeatKeyCode_ { -1 }; 61 std::shared_ptr<KeyEvent> keyEvent_ { nullptr }; 62 }; 63 64 #define KeyRepeat ::OHOS::DelayedSingleton<KeyAutoRepeat>::GetInstance() 65 } // namespace MMI 66 } // namespace OHOS 67 #endif // KEY_AUTO_REPEAT_H