blob: 99c476971291640222287701318b611244d76be6 [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
Siarhei Vishniakoue0431e42023-01-28 17:01:39 -080032bool TouchedWindow::hasHoveringPointers(int32_t deviceId) const {
33 return mHoveringPointerIdsByDevice.find(deviceId) != mHoveringPointerIdsByDevice.end();
34}
35
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000036void TouchedWindow::clearHoveringPointers() {
37 mHoveringPointerIdsByDevice.clear();
38}
39
40bool TouchedWindow::hasHoveringPointer(int32_t deviceId, int32_t pointerId) const {
41 auto it = mHoveringPointerIdsByDevice.find(deviceId);
42 if (it == mHoveringPointerIdsByDevice.end()) {
43 return false;
44 }
45 return it->second.test(pointerId);
46}
47
48void TouchedWindow::addHoveringPointer(int32_t deviceId, int32_t pointerId) {
49 const auto [it, _] = mHoveringPointerIdsByDevice.insert({deviceId, {}});
50 it->second.set(pointerId);
51}
52
Siarhei Vishniakou6464e462023-02-06 18:57:59 -080053void TouchedWindow::removeTouchingPointer(int32_t pointerId) {
54 pointerIds.reset(pointerId);
55 pilferedPointerIds.reset(pointerId);
56 if (pointerIds.none()) {
57 firstDownTimeInTarget.reset();
58 }
59}
60
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000061void TouchedWindow::removeHoveringPointer(int32_t deviceId, int32_t pointerId) {
62 const auto it = mHoveringPointerIdsByDevice.find(deviceId);
63 if (it == mHoveringPointerIdsByDevice.end()) {
64 return;
65 }
66 it->second.set(pointerId, false);
67
68 if (it->second.none()) {
69 mHoveringPointerIdsByDevice.erase(deviceId);
70 }
71}
72
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080073std::string TouchedWindow::dump() const {
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000074 std::string out;
75 std::string hoveringPointers =
76 dumpMap(mHoveringPointerIdsByDevice, constToString, bitsetToString);
Siarhei Vishniakou8a878352023-01-30 14:05:01 -080077 out += StringPrintf("name='%s', pointerIds=%s, targetFlags=%s, firstDownTimeInTarget=%s, "
Siarhei Vishniakou060f82b2023-01-27 06:39:14 -080078 "mHoveringPointerIdsByDevice=%s, pilferedPointerIds=%s\n",
Siarhei Vishniakou8a878352023-01-30 14:05:01 -080079 windowHandle->getName().c_str(), bitsetToString(pointerIds).c_str(),
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000080 targetFlags.string().c_str(), toString(firstDownTimeInTarget).c_str(),
Siarhei Vishniakou060f82b2023-01-27 06:39:14 -080081 hoveringPointers.c_str(), bitsetToString(pilferedPointerIds).c_str());
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000082 return out;
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080083}
84
85} // namespace inputdispatcher
86} // namespace android