blob: 3704edd575e73ef773a62af5d5126c2f71a1cf46 [file] [log] [blame]
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -08001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "TouchedWindow.h"
18
19#include <android-base/stringprintf.h>
20#include <input/PrintTools.h>
21
22using android::base::StringPrintf;
23
24namespace android {
25
26namespace inputdispatcher {
27
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000028bool TouchedWindow::hasHoveringPointers() const {
29 return !mHoveringPointerIdsByDevice.empty();
30}
31
32void TouchedWindow::clearHoveringPointers() {
33 mHoveringPointerIdsByDevice.clear();
34}
35
36bool TouchedWindow::hasHoveringPointer(int32_t deviceId, int32_t pointerId) const {
37 auto it = mHoveringPointerIdsByDevice.find(deviceId);
38 if (it == mHoveringPointerIdsByDevice.end()) {
39 return false;
40 }
41 return it->second.test(pointerId);
42}
43
44void TouchedWindow::addHoveringPointer(int32_t deviceId, int32_t pointerId) {
45 const auto [it, _] = mHoveringPointerIdsByDevice.insert({deviceId, {}});
46 it->second.set(pointerId);
47}
48
49void TouchedWindow::removeHoveringPointer(int32_t deviceId, int32_t pointerId) {
50 const auto it = mHoveringPointerIdsByDevice.find(deviceId);
51 if (it == mHoveringPointerIdsByDevice.end()) {
52 return;
53 }
54 it->second.set(pointerId, false);
55
56 if (it->second.none()) {
57 mHoveringPointerIdsByDevice.erase(deviceId);
58 }
59}
60
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080061std::string TouchedWindow::dump() const {
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000062 std::string out;
63 std::string hoveringPointers =
64 dumpMap(mHoveringPointerIdsByDevice, constToString, bitsetToString);
65 out += StringPrintf("name='%s', pointerIds=0x%0x, targetFlags=%s, firstDownTimeInTarget=%s, "
66 "mHoveringPointerIdsByDevice=%s\n",
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080067 windowHandle->getName().c_str(), pointerIds.value,
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000068 targetFlags.string().c_str(), toString(firstDownTimeInTarget).c_str(),
69 hoveringPointers.c_str());
70 return out;
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080071}
72
73} // namespace inputdispatcher
74} // namespace android