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 GTX_INPUT_EVENT_SENDER_H 17#define GTX_INPUT_EVENT_SENDER_H 18 19#include <mutex> 20#include <atomic> 21#include <algorithm> 22 23#include "window.h" 24#include "window_input_channel.h" 25#include "pointer_event.h" 26 27namespace OHOS { 28const uint32_t GTX_MAX_TOUCH_POINTS_NUMBER = 10; 29 30struct GtxTouchPoint { 31 int32_t id = -1; 32 float screenX = .0f; 33 float screenY = .0f; 34 float x = .0f; 35 float y = .0f; 36 bool isPressed = false; 37 double pressure = .0f; 38}; 39 40struct GtxWindowExtent { 41 int32_t offsetX = .0; 42 int32_t offsetY = .0; 43 uint32_t width = 0; 44 uint32_t height = 0; 45}; 46 47struct GtxTouchEventInfo { 48 uint32_t windowId = 0; 49 int32_t pointerId = -1; 50 GtxWindowExtent extent = {}; 51 uint32_t numPoints = 0; 52 GtxTouchPoint touchPoints[GTX_MAX_TOUCH_POINTS_NUMBER]; 53}; 54 55class GtxInputEventSender { 56public: 57 GtxInputEventSender() {} 58 59 ~GtxInputEventSender() {} 60 61 static GtxInputEventSender& GetInstance(); 62 63 void SetOpt(bool opt) 64 { 65 mIsEnable.store(opt); 66 } 67 68 void GetTouchEvent(GtxTouchEventInfo& touchEvent); 69 void SetTouchEvent(Rosen::Rect rect, std::shared_ptr<MMI::PointerEvent> pointerEvent); 70 71private: 72 std::atomic<bool> mIsEnable = false; 73 74 std::mutex mEventMutex; 75 GtxTouchEventInfo mEvent = {}; 76}; 77} // namespace OHOS 78 79#endif