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 "key_map_manager.h" 20 #include "util.h" 21 22 namespace OHOS { 23 namespace MMI { 24 class KeyAutoRepeat final { 25 DECLARE_DELAYED_SINGLETON(KeyAutoRepeat); 26 public: 27 DISALLOW_COPY_AND_MOVE(KeyAutoRepeat); 28 int32_t AddDeviceConfig(struct libinput_device *device); 29 bool JudgeLimitPrint(const std::shared_ptr<KeyEvent>& keyEvent); 30 bool JudgeKeyEvent(const std::shared_ptr<KeyEvent>& keyEvent); 31 void SelectAutoRepeat(const std::shared_ptr<KeyEvent>& keyEvent); 32 void AddHandleTimer(int32_t timeout); 33 void RemoveDeviceConfig(struct libinput_device *device); 34 int32_t GetIntervalTime(int32_t deviceId); 35 std::map<int32_t, DeviceConfig> GetDeviceConfig() const; 36 void RemoveTimer(); 37 int32_t SetKeyboardRepeatDelay(int32_t delay); 38 int32_t SetKeyboardRepeatRate(int32_t rate); 39 int32_t GetKeyboardRepeatDelay(int32_t &delay); 40 int32_t GetKeyboardRepeatRate(int32_t &rate); 41 int32_t GetRepeatKeyCode() const; 42 private: 43 std::string GetTomlFilePath(const std::string &fileName) const; 44 DeviceConfig GetAutoSwitch(int32_t deviceId); 45 int32_t PutConfigDataToDatabase(std::string &key, int32_t value); 46 int32_t GetConfigDataFromDatabase(std::string &key, int32_t &value); 47 int32_t GetDelayTime(); 48 int32_t GetKeyboardRepeatTime(int32_t deviceId, bool isDelay); 49 50 private: 51 std::map<int32_t, DeviceConfig> deviceConfig_; 52 int32_t timerId_ { -1 }; 53 int32_t repeatKeyCode_ { -1 }; 54 std::shared_ptr<KeyEvent> keyEvent_ { nullptr }; 55 }; 56 57 #define KeyRepeat ::OHOS::DelayedSingleton<KeyAutoRepeat>::GetInstance() 58 } // namespace MMI 59 } // namespace OHOS 60 #endif // KEY_AUTO_REPEAT_H