1 /* 2 * Copyright (c) 2025 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 X_KEY_EVENT_PROCESSOR_H 17 #define X_KEY_EVENT_PROCESSOR_H 18 19 #include <memory> 20 #include "libinput.h" 21 #include "singleton.h" 22 23 namespace OHOS { 24 namespace MMI { 25 #ifdef OHOS_BUILD_ENABLE_X_KEY 26 27 class XKeyEventProcessor { 28 DECLARE_DELAYED_SINGLETON(XKeyEventProcessor); 29 public: 30 DISALLOW_COPY_AND_MOVE(XKeyEventProcessor); 31 void InterceptXKeyDown(); 32 void InterceptXKeyUp(); 33 bool IsXKeyEvent(struct libinput_event* event); 34 int32_t HandleXKeyEvent(struct libinput_event* event); 35 36 private: 37 int32_t AnalyseKeyEvent(struct libinput_event* event); 38 int32_t HandleQuickAccessMenu(int32_t xKeyEventType); 39 // 重置计数器 40 void ResetCount(); 41 void StartXKeyIfNeeded(int32_t xKeyEventType); 42 bool IsRemoveDelaySingleClick(); 43 void StartLongPressTimer(); 44 void StartSingleClickTimer(); 45 void RemoveTimer(); 46 47 int32_t singleClickTimerId_ { -1 }; 48 int32_t longPressTimerId_ { -1 }; 49 // 按压次数 50 std::atomic<int32_t> pressCount_ { 0 }; 51 52 const std::string X_KEY_SOURCE_KEY { "fkey" }; 53 std::atomic_bool isStartedXKey_ { false }; 54 std::atomic_bool handledLongPress_ { false }; 55 }; 56 #define XKeyEventHdr ::OHOS::DelayedSingleton<XKeyEventProcessor>::GetInstance() 57 #endif // OHOS_BUILD_ENABLE_X_KEY 58 } // namespace MMI 59 } // namespace OHOS 60 #endif // X_KEY_EVENT_PROCESSOR_H