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