| 1 |
/* |
| 2 |
* Copyright (C) 2017-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include "Seat.h" |
| 12 |
#include "input/touch/ITouchInputHandler.h" |
| 13 |
|
| 14 |
#include <cstdint> |
| 15 |
#include <map> |
| 16 |
|
| 17 |
#include <wayland-client-protocol.hpp> |
| 18 |
|
| 19 |
namespace KODI |
| 20 |
{ |
| 21 |
namespace WINDOWING |
| 22 |
{ |
| 23 |
namespace WAYLAND |
| 24 |
{ |
| 25 |
|
| 26 |
/** |
| 27 |
* Touch input processor |
| 28 |
* |
| 29 |
* Events go directly to \ref CGenericTouchInputHandler, so no callbacks here |
| 30 |
*/ |
| 31 |
class CInputProcessorTouch final : public IRawInputHandlerTouch |
| 32 |
{ |
| 33 |
public: |
| 34 |
CInputProcessorTouch(wayland::surface_t const& surface); |
| 35 |
~CInputProcessorTouch() noexcept; |
| 36 |
void SetCoordinateScale(std::int32_t scale) { m_coordinateScale = scale; } |
| 37 |
|
| 38 |
void OnTouchDown(CSeat* seat, |
| 39 |
std::uint32_t serial, |
| 40 |
std::uint32_t time, |
| 41 |
const wayland::surface_t& surface, |
| 42 |
std::int32_t id, |
| 43 |
double x, |
| 44 |
double y) override; |
| 45 |
void OnTouchUp(CSeat* seat, std::uint32_t serial, std::uint32_t time, std::int32_t id) override; |
| 46 |
void OnTouchMotion(CSeat* seat, std::uint32_t time, std::int32_t id, double x, double y) override; |
| 47 |
void OnTouchCancel(CSeat* seat) override; |
| 48 |
void OnTouchShape(CSeat* seat, std::int32_t id, double major, double minor) override; |
| 49 |
|
| 50 |
private: |
| 51 |
CInputProcessorTouch(CInputProcessorTouch const& other) = delete; |
| 52 |
CInputProcessorTouch& operator=(CInputProcessorTouch const& other) = delete; |
| 53 |
|
| 54 |
struct TouchPoint |
| 55 |
{ |
| 56 |
std::uint32_t lastEventTime; |
| 57 |
/// Pointer number passed to \ref ITouchInputHandler |
| 58 |
std::int32_t kodiPointerNumber; |
| 59 |
/** |
| 60 |
* Last coordinates - needed for TouchInputUp events where Wayland does not |
| 61 |
* send new coordinates but Kodi needs them anyway |
| 62 |
*/ |
| 63 |
float x, y, size; |
| 64 |
TouchPoint(std::uint32_t initialEventTime, std::int32_t kodiPointerNumber, float x, float y, float size) |
| 65 |
: lastEventTime{initialEventTime}, kodiPointerNumber{kodiPointerNumber}, x{x}, y{y}, size{size} |
| 66 |
{} |
| 67 |
}; |
| 68 |
|
| 69 |
void SendTouchPointEvent(TouchInput event, TouchPoint const& point); |
| 70 |
void UpdateTouchPoint(TouchPoint const& point); |
| 71 |
void AbortTouches(); |
| 72 |
|
| 73 |
wayland::surface_t m_surface; |
| 74 |
std::int32_t m_coordinateScale{1}; |
| 75 |
|
| 76 |
/// Map of wl_touch point id to data |
| 77 |
std::map<std::int32_t, TouchPoint> m_touchPoints; |
| 78 |
}; |
| 79 |
|
| 80 |
} |
| 81 |
} |
| 82 |
} |