1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#include "gtx_input_event_sender.h" 17e0dac50fSopenharmony_ci 18e0dac50fSopenharmony_cinamespace OHOS { 19e0dac50fSopenharmony_ci 20e0dac50fSopenharmony_ciGtxInputEventSender& GtxInputEventSender::GetInstance() 21e0dac50fSopenharmony_ci{ 22e0dac50fSopenharmony_ci static GtxInputEventSender instance; 23e0dac50fSopenharmony_ci return instance; 24e0dac50fSopenharmony_ci} 25e0dac50fSopenharmony_ci 26e0dac50fSopenharmony_civoid GtxInputEventSender::GetTouchEvent(GtxTouchEventInfo& touchEvent) 27e0dac50fSopenharmony_ci{ 28e0dac50fSopenharmony_ci std::unique_lock<std::mutex> lock(mEventMutex); 29e0dac50fSopenharmony_ci touchEvent = mEvent; 30e0dac50fSopenharmony_ci} 31e0dac50fSopenharmony_ci 32e0dac50fSopenharmony_civoid GtxInputEventSender::SetTouchEvent(Rosen::Rect rect, 33e0dac50fSopenharmony_ci std::shared_ptr<MMI::PointerEvent> pointerEvent) 34e0dac50fSopenharmony_ci{ 35e0dac50fSopenharmony_ci if (!mIsEnable.load()) { 36e0dac50fSopenharmony_ci return; 37e0dac50fSopenharmony_ci } 38e0dac50fSopenharmony_ci if (pointerEvent == nullptr) { 39e0dac50fSopenharmony_ci return; 40e0dac50fSopenharmony_ci } 41e0dac50fSopenharmony_ci 42e0dac50fSopenharmony_ci std::unique_lock<std::mutex> lock(mEventMutex); 43e0dac50fSopenharmony_ci mEvent = {}; 44e0dac50fSopenharmony_ci mEvent.windowId = static_cast<uint32_t>(pointerEvent->GetAgentWindowId()); 45e0dac50fSopenharmony_ci mEvent.pointerId = pointerEvent->GetPointerId(); 46e0dac50fSopenharmony_ci mEvent.extent = { rect.posX_, rect.posY_, rect.width_, rect.height_ }; 47e0dac50fSopenharmony_ci 48e0dac50fSopenharmony_ci std::vector<int32_t> pointIndex = pointerEvent->GetPointerIds(); 49e0dac50fSopenharmony_ci mEvent.numPoints = std::min(pointIndex.size(), static_cast<size_t>(GTX_MAX_TOUCH_POINTS_NUMBER)); 50e0dac50fSopenharmony_ci 51e0dac50fSopenharmony_ci for (uint32_t i = 0; i < mEvent.numPoints; i++) { 52e0dac50fSopenharmony_ci GtxTouchPoint& dstTouchPoint = mEvent.touchPoints[i]; 53e0dac50fSopenharmony_ci MMI::PointerEvent::PointerItem srcTouchPoint; 54e0dac50fSopenharmony_ci pointerEvent->GetPointerItem(pointIndex[i], srcTouchPoint); 55e0dac50fSopenharmony_ci 56e0dac50fSopenharmony_ci dstTouchPoint.id = pointIndex[i]; 57e0dac50fSopenharmony_ci dstTouchPoint.screenX = srcTouchPoint.GetDisplayX(); 58e0dac50fSopenharmony_ci dstTouchPoint.screenY = srcTouchPoint.GetDisplayY(); 59e0dac50fSopenharmony_ci dstTouchPoint.x = srcTouchPoint.GetWindowX(); 60e0dac50fSopenharmony_ci dstTouchPoint.y = srcTouchPoint.GetWindowY(); 61e0dac50fSopenharmony_ci dstTouchPoint.isPressed = srcTouchPoint.IsPressed(); 62e0dac50fSopenharmony_ci dstTouchPoint.pressure = srcTouchPoint.GetPressure(); 63e0dac50fSopenharmony_ci } 64e0dac50fSopenharmony_ci} 65e0dac50fSopenharmony_ci 66e0dac50fSopenharmony_ciextern "C" { 67e0dac50fSopenharmony_ci__attribute__((visibility("default"))) void SetGtxTouchEventStatus(bool isEnable) 68e0dac50fSopenharmony_ci{ 69e0dac50fSopenharmony_ci OHOS::GtxInputEventSender::GetInstance().SetOpt(isEnable); 70e0dac50fSopenharmony_ci} 71e0dac50fSopenharmony_ci 72e0dac50fSopenharmony_ci__attribute__((visibility("default"))) void GetGtxTouchEvent(OHOS::GtxTouchEventInfo& touchEvent) 73e0dac50fSopenharmony_ci{ 74e0dac50fSopenharmony_ci OHOS::GtxInputEventSender::GetInstance().GetTouchEvent(touchEvent); 75e0dac50fSopenharmony_ci} 76e0dac50fSopenharmony_ci} 77e0dac50fSopenharmony_ci 78e0dac50fSopenharmony_ci} // namespace OHOS 79