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_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 void SelectAutoRepeat(const 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); 40 std::map<int32_t, DeviceConfig> GetDeviceConfig() const; 41 void RemoveTimer(); 42 int32_t SetKeyboardRepeatDelay(int32_t delay); 43 int32_t SetKeyboardRepeatRate(int32_t rate); 44 int32_t GetKeyboardRepeatDelay(int32_t &delay); 45 int32_t GetKeyboardRepeatRate(int32_t &rate); 46 private: 47 std::string GetTomlFilePath(const std::string &fileName) const; 48 DeviceConfig GetAutoSwitch(int32_t deviceId); 49 int32_t PutConfigDataToDatabase(std::string &key, int32_t value); 50 int32_t GetConfigDataFromDatabase(std::string &key, int32_t &value); 51 int32_t GetDelayTime(); 52 int32_t GetKeyboardRepeatTime(int32_t deviceId, bool isDelay); 53 54 private: 55 std::map<int32_t, DeviceConfig> deviceConfig_; 56 int32_t timerId_ { -1 }; 57 int32_t repeatKeyCode_ { -1 }; 58 std::shared_ptr<KeyEvent> keyEvent_ { nullptr }; 59 }; 60 61 #define KeyRepeat ::OHOS::DelayedSingleton<KeyAutoRepeat>::GetInstance() 62 } // namespace MMI 63 } // namespace OHOS 64 #endif // KEY_AUTO_REPEAT_H