1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "LibInputTouch.h"
#include "ServiceBroker.h"
#include "input/touch/generic/GenericTouchActionHandler.h"
#include "utils/log.h"
#include "windowing/GraphicContext.h"
static inline CPoint GetPos(libinput_event_touch *e)
{
const double x = libinput_event_touch_get_x_transformed(e, CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth());
const double y = libinput_event_touch_get_y_transformed(e, CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight());
CLog::Log(LOGDEBUG, "CLibInputTouch::{} - x: {:f} y: {:f}", __FUNCTION__, x, y);
return CPoint(x, y);
}
CLibInputTouch::CLibInputTouch()
{
m_points.reserve(2);
CGenericTouchInputHandler::GetInstance().RegisterHandler(&CGenericTouchActionHandler::GetInstance());
}
void CLibInputTouch::CheckSlot(int slot)
{
if (slot + 1 > static_cast<int>(m_points.size()))
m_points.resize(slot + 1, std::make_pair(TouchInputUnchanged, CPoint(0, 0)));
}
TouchInput CLibInputTouch::GetEvent(int slot)
{
CheckSlot(slot);
return m_points.at(slot).first;
}
void CLibInputTouch::SetEvent(int slot, TouchInput event)
{
CheckSlot(slot);
m_points.at(slot).first = event;
}
void CLibInputTouch::SetPosition(int slot, CPoint point)
{
CheckSlot(slot);
m_points.at(slot).second = point;
}
void CLibInputTouch::ProcessTouchDown(libinput_event_touch *e)
{
int slot = libinput_event_touch_get_seat_slot(e);
SetPosition(slot, GetPos(e));
SetEvent(slot, TouchInputDown);
CLog::Log(LOGDEBUG, "CLibInputTouch::{} - touch input down", __FUNCTION__);
}
void CLibInputTouch::ProcessTouchMotion(libinput_event_touch *e)
{
int slot = libinput_event_touch_get_seat_slot(e);
uint64_t nanotime = libinput_event_touch_get_time_usec(e) * 1000LL;
SetPosition(slot, GetPos(e));
if (GetEvent(slot) != TouchInputDown)
SetEvent(slot, TouchInputMove);
CLog::Log(LOGDEBUG, "CLibInputTouch::{} - touch input move", __FUNCTION__);
CGenericTouchInputHandler::GetInstance().UpdateTouchPointer(slot, GetX(slot), GetY(slot), nanotime);
}
void CLibInputTouch::ProcessTouchUp(libinput_event_touch *e)
{
int slot = libinput_event_touch_get_seat_slot(e);
SetEvent(slot, TouchInputUp);
CLog::Log(LOGDEBUG, "CLibInputTouch::{} - touch input up", __FUNCTION__);
}
void CLibInputTouch::ProcessTouchCancel(libinput_event_touch *e)
{
int slot = libinput_event_touch_get_seat_slot(e);
uint64_t nanotime = libinput_event_touch_get_time_usec(e) * 1000LL;
CLog::Log(LOGDEBUG, "CLibInputTouch::{} - touch input cancel", __FUNCTION__);
CGenericTouchInputHandler::GetInstance().HandleTouchInput(TouchInputAbort, GetX(slot), GetY(slot), nanotime, slot);
}
void CLibInputTouch::ProcessTouchFrame(libinput_event_touch *e)
{
uint64_t nanotime = libinput_event_touch_get_time_usec(e) * 1000LL;
for (size_t slot = 0; slot < m_points.size(); ++slot)
{
CLog::Log(LOGDEBUG, "CLibInputTouch::{} - touch input frame: event {}", __FUNCTION__,
GetEvent(slot));
CLog::Log(LOGDEBUG, "CLibInputTouch::{} - touch input frame: slot {}", __FUNCTION__, slot);
CGenericTouchInputHandler::GetInstance().HandleTouchInput(GetEvent(slot), GetX(slot), GetY(slot), nanotime, slot);
SetEvent(slot, TouchInputUnchanged);
}
}
|