1 /* 2 * Copyright (c) 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 STYLUS_KEY_HANDLER_H 17 #define STYLUS_KEY_HANDLER_H 18 19 #include "key_command_handler.h" 20 #include "key_event.h" 21 22 #include "singleton.h" 23 24 namespace OHOS { 25 namespace MMI { 26 struct StylusKey { 27 bool lastEventIsStylus { false }; 28 bool isLaunchAbility { false }; 29 std::string statusConfig; 30 bool statusConfigValue { false }; 31 Ability ability; 32 }; 33 34 struct ShortHandTarget { 35 std::string statusConfig; 36 bool statusConfigValue { false }; 37 }; 38 class StylusKeyHandler final { 39 DECLARE_DELAYED_SINGLETON(StylusKeyHandler); 40 public: 41 DISALLOW_COPY_AND_MOVE(StylusKeyHandler); 42 bool HandleStylusKey(std::shared_ptr<KeyEvent> keyEvent); 43 void IsLaunchAbility(); 44 void SetLastEventState(bool state); 45 private: 46 template <class T> 47 void CreateStatusConfigObserver(T& item); 48 void LaunchAbility(const Ability &ability); 49 private: 50 StylusKey stylusKey_; 51 ShortHandTarget shortHandTarget_; 52 bool isShortHandConfig_ { false }; 53 }; 54 #define STYLUS_HANDLER ::OHOS::DelayedSingleton<StylusKeyHandler>::GetInstance() 55 } // namespace MMI 56 } // namespace OHOS 57 #endif // STYLUS_KEY_HANDLER_H