1 /* 2 * Copyright (c) 2021-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 LIBINPUT_ADAPTER_H 17 #define LIBINPUT_ADAPTER_H 18 19 #include <array> 20 #include <functional> 21 #include <thread> 22 #include <unordered_map> 23 24 #include "hotplug_detector.h" 25 #include "libinput.h" 26 #include "nocopyable.h" 27 28 namespace OHOS { 29 namespace MMI { 30 typedef std::function<void(void *event, int64_t frameTime)> FunInputEvent; 31 class LibinputAdapter final { 32 public: 33 static int32_t DeviceLedUpdate(struct libinput_device *device, int32_t funcKey, bool isEnable); 34 LibinputAdapter() = default; 35 DISALLOW_COPY_AND_MOVE(LibinputAdapter); 36 ~LibinputAdapter() = default; 37 bool Init(FunInputEvent funInputEvent); 38 void EventDispatch(int32_t fd); 39 void Stop(); 40 void ProcessPendingEvents(); 41 void ReloadDevice(); 42 GetInputFds()43 auto GetInputFds() const 44 { 45 return std::array{fd_, hotplugDetector_.GetFd()}; 46 } 47 48 private: 49 void MultiKeyboardSetLedState(bool oldCapsLockState); 50 void MultiKeyboardSetFuncState(libinput_event* event); 51 void OnEventHandler(); 52 void OnDeviceAdded(std::string path); 53 void OnDeviceRemoved(std::string path); 54 55 int32_t fd_ { -1 }; 56 libinput *input_ { nullptr }; 57 58 FunInputEvent funInputEvent_; 59 60 HotplugDetector hotplugDetector_; 61 std::unordered_map<std::string, libinput_device*> devices_; 62 }; 63 } // namespace MMI 64 } // namespace OHOS 65 #endif // S_INPUT_H